Esempio n. 1
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]
Esempio n. 2
0
def test_hash160():
    assert lib_hash.hash160(
        b'hash_160'
    ) == b'\xb3\x96\x94\xfc\x978R\xa7)XqY\xbb\xdc\xeb\xac\xa7%\xb8$'
Esempio n. 3
0
 def P2PKH_address_from_pubkey(cls, pubkey):
     '''Return a coin address given a public key.'''
     return cls.P2PKH_address_from_hash160(hash160(pubkey))
Esempio n. 4
0
 def identifier(self):
     '''Return the key's identifier as 20 bytes.'''
     return hash160(self.pubkey_bytes)