Пример #1
0
 def address_handlers(cls):
     return ScriptPubKey.PayToHandlers(
         address=cls.P2PKH_address_from_hash160,
         script_hash=cls.P2SH_address_from_hash160,
         pubkey=cls.P2PKH_address_from_pubkey,
         unspendable=lambda: None,
         strange=cls.claim_address_handler,
     )
Пример #2
0
    def hashX_from_script(cls, script):
        '''Returns a hashX from a script, or None if the script is provably
        unspendable so the output can be dropped.
        '''
        if script and script[0] == OpCodes.OP_RETURN:
            return None

        # Qtum: make p2pk and p2pkh the same hashX
        if (len(script) == 35 and script[0] == 0x21 and script[1] in [2, 3]) \
                or (len(script) == 67 and script[0] == 0x41 and script[1] in [4, 6, 7]) \
                and script[-1] == OpCodes.OP_CHECKSIG:
            pubkey = script[1:-1]
            script = ScriptPubKey.P2PKH_script(hash160(pubkey))

        return sha256(script).digest()[:HASHX_LEN]
Пример #3
0
    def pay_to_address_script(cls, address):
        '''Return a pubkey script that pays to a pubkey hash.
        Pass the address (either P2PKH or P2SH) in base58 form.
        '''
        raw = cls.DECODE_CHECK(address)

        # Require version byte(s) plus hash160.
        verbyte = -1
        verlen = len(raw) - 20
        if verlen > 0:
            verbyte, hash160 = raw[:verlen], raw[verlen:]

        if verbyte == cls.P2PKH_VERBYTE:
            return cls.hash160_to_P2PKH_script(hash160)
        if verbyte in cls.P2SH_VERBYTES:
            return ScriptPubKey.P2SH_script(hash160)

        raise CoinError('invalid address: {}'.format(address))
Пример #4
0
 def hash160_to_P2PKH_script(cls, hash160):
     return ScriptPubKey.P2PKH_script(hash160)