示例#1
0
    def address(self, netcode=None):
        from aiobitcoin.tools.networks.default import get_current_netcode

        if netcode is None:
            netcode = get_current_netcode()

        return self.info().get("address_f", lambda n: "(unknown)")(netcode)
示例#2
0
    def address(self, netcode=None):
        from aiobitcoin.tools.networks import pay_to_script_prefix_for_netcode
        from aiobitcoin.tools.networks.default import get_current_netcode

        if netcode is None:
            netcode = get_current_netcode()

        address_prefix = pay_to_script_prefix_for_netcode(netcode)
        return encoding.hash160_sec_to_bitcoin_address(
            self.hash160, address_prefix=address_prefix)
示例#3
0
        def address_f(netcode=netcode):
            from aiobitcoin.tools.networks import bech32_hrp_for_netcode
            from aiobitcoin.tools.networks.default import get_current_netcode

            if netcode is None:
                netcode = get_current_netcode()

            bech32_hrp = bech32_hrp_for_netcode(netcode)
            address = segwit_addr.encode(bech32_hrp, self.version,
                                         self.hash256)
            return address
示例#4
0
        def address_f(netcode=netcode):
            from aiobitcoin.tools.networks import address_prefix_for_netcode
            from aiobitcoin.tools.networks.default import get_current_netcode

            if netcode is None:
                netcode = get_current_netcode()

            address_prefix = address_prefix_for_netcode(netcode)
            address = encoding.hash160_sec_to_bitcoin_address(
                hash160, address_prefix=address_prefix)

            return address
示例#5
0
    def addresses_f(self, netcode=None):
        from aiobitcoin.tools.networks import address_prefix_for_netcode
        from aiobitcoin.tools.networks.default import get_current_netcode

        if netcode is None:
            netcode = get_current_netcode()

        address_prefix = address_prefix_for_netcode(netcode)
        addresses = [encoding.hash160_sec_to_bitcoin_address(h1, address_prefix=address_prefix)
                     for h1 in self.hash160s()]

        return addresses
示例#6
0
        def address_f(netcode=netcode):
            from aiobitcoin.tools.networks import bech32_hrp_for_netcode
            from aiobitcoin.tools.networks.default import get_current_netcode

            if netcode is None:
                netcode = get_current_netcode()

            bech32_hrp = bech32_hrp_for_netcode(netcode)

            if bech32_hrp:
                return segwit_addr.encode(bech32_hrp, self.version,
                                          iterbytes(self.hash160))

            return None
示例#7
0
文件: Key.py 项目: mkbeh/aiobitcoin
    def __init__(self, secret_exponent=None, public_pair=None, hash160=None,
                 prefer_uncompressed=None, is_compressed=None, is_pay_to_script=False, netcode=None):
        """
        secret_exponent:
            a long representing the secret exponent
        public_pair:
            a tuple of long integers on the ecdsa curve
        hash160:
            a hash160 value corresponding to a bitcoin address

        Include at most one of secret_exponent, public_pair or hash160.

        prefer_uncompressed:
            whether or not to produce text outputs as compressed or uncompressed.

        is_pay_to_script:
            whether or not this key is for a pay-to-script style transaction

        netcode:
            the code for the network (as defined in pycoin.networks)

        Include at most one of secret_exponent, public_pair or hash160.
        prefer_uncompressed, is_compressed (booleans) are optional.
        """

        if is_compressed is None:
            is_compressed = False if hash160 else True

        if netcode is None:
            netcode = get_current_netcode()

        if [secret_exponent, public_pair, hash160].count(None) != 2:
            raise ValueError("exactly one of secret_exponent, public_pair, hash160 must be passed.")

        if prefer_uncompressed is None:
            prefer_uncompressed = not is_compressed

        self._prefer_uncompressed = prefer_uncompressed
        self._secret_exponent = secret_exponent
        self._public_pair = public_pair
        self._hash160_uncompressed = None
        self._hash160_compressed = None

        if hash160:
            if is_compressed:
                self._hash160_compressed = hash160
            else:
                self._hash160_uncompressed = hash160

        self._netcode = netcode

        if self._public_pair is None and self._secret_exponent is not None:
            if self._secret_exponent < 1 \
                    or self._secret_exponent >= ecdsa.generator_secp256k1.order():
                raise InvalidSecretExponentError()

            public_pair = ecdsa.public_pair_for_secret_exponent(
                ecdsa.generator_secp256k1, self._secret_exponent)
            self._public_pair = public_pair

        if self._public_pair is not None \
                and (None in self._public_pair or
                     not ecdsa.is_public_pair_valid(ecdsa.generator_secp256k1, self._public_pair)):
            raise InvalidPublicPairError()