Esempio n. 1
0
def get_address_from_output_script(bytes):
    try:
        decoded = [ x for x in script_GetOp(bytes) ]
    except:
        return None

    # The Genesis Block, self-payments, and pay-by-IP-address payments look like:
    # 65 BYTES:... CHECKSIG
    match = [opcodes.OP_PUSHDATA4, opcodes.OP_CHECKSIG]
    if match_decoded(decoded, match):
        return public_key_to_pubkey_address(decoded[0][1])

    # coins sent to black hole
    # DUP HASH160 20 BYTES:... EQUALVERIFY CHECKSIG
    match = [opcodes.OP_DUP, opcodes.OP_HASH160, opcodes.OP_0, opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG]
    if match_decoded(decoded, match):
        return None

    # Pay-by-Bitcoin-address TxOuts look like:
    # DUP HASH160 20 BYTES:... EQUALVERIFY CHECKSIG
    match = [opcodes.OP_DUP, opcodes.OP_HASH160, opcodes.OP_PUSHDATA4, opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG]
    if match_decoded(decoded, match):
        return hash_160_to_pubkey_address(decoded[2][1])

    # strange tx
    match = [opcodes.OP_DUP, opcodes.OP_HASH160, opcodes.OP_PUSHDATA4, opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG, opcodes.OP_NOP]
    if match_decoded(decoded, match):
        return hash_160_to_pubkey_address(decoded[2][1])

    # p2sh
    match = [ opcodes.OP_HASH160, opcodes.OP_PUSHDATA4, opcodes.OP_EQUAL ]
    if match_decoded(decoded, match):
        addr = hash_160_to_script_address(decoded[1][1])
        return addr

    # name new
    match = [ opcodes.OP_NAME_NEW, opcodes.OP_PUSHDATA4, opcodes.OP_2DROP, opcodes.OP_DUP, opcodes.OP_HASH160, opcodes.OP_PUSHDATA4, opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG ]
    if match_decoded(decoded, match):
        addr = hash_160_to_pubkey_address(decoded[5][1])
        return addr

    # name firstupdate
    match = [ opcodes.OP_NAME_FIRSTUPDATE, opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4, opcodes.OP_2DROP, opcodes.OP_2DROP, opcodes.OP_DUP, opcodes.OP_HASH160, opcodes.OP_PUSHDATA4, opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG ]
    if match_decoded(decoded, match):
        addr = hash_160_to_pubkey_address(decoded[8][1])
        return addr

    # name update
    match = [ opcodes.OP_NAME_UPDATE, opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4, opcodes.OP_2DROP, opcodes.OP_DROP, opcodes.OP_DUP, opcodes.OP_HASH160, opcodes.OP_PUSHDATA4, opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG ]
    if match_decoded(decoded, match):
        addr = hash_160_to_pubkey_address(decoded[7][1])
        return addr

    return None
Esempio n. 2
0
def get_address_from_output_script(_bytes):
    try:
        decoded = [x for x in list(script_GetOp(_bytes))]
    except Exception:
        return None

    # The Genesis Block, self-payments,
    # and pay-by-IP-address payments look like:
    # 65 BYTES:... CHECKSIG
    match = [opcodes.OP_PUSHDATA4, opcodes.OP_CHECKSIG]
    if match_decoded(decoded, match):
        return public_key_to_pubkey_address(decoded[0][1])

    # coins sent to black hole
    # DUP HASH160 20 BYTES:... EQUALVERIFY CHECKSIG
    match = [
        opcodes.OP_DUP, opcodes.OP_HASH160, opcodes.OP_0,
        opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG
    ]
    if match_decoded(decoded, match):
        return None

    # Pay-by-Bitcoin-address TxOuts look like:
    # DUP HASH160 20 BYTES:... EQUALVERIFY CHECKSIG
    match = [
        opcodes.OP_DUP, opcodes.OP_HASH160, opcodes.OP_PUSHDATA4,
        opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG
    ]
    if match_decoded(decoded, match):
        return hash_160_to_pubkey_address(decoded[2][1])

    # strange tx
    match = [
        opcodes.OP_DUP, opcodes.OP_HASH160, opcodes.OP_PUSHDATA4,
        opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG, opcodes.OP_NOP
    ]
    if match_decoded(decoded, match):
        return hash_160_to_pubkey_address(decoded[2][1])

    # p2sh
    match = [opcodes.OP_HASH160, opcodes.OP_PUSHDATA4, opcodes.OP_EQUAL]
    if match_decoded(decoded, match):
        addr = hash_160_to_script_address(decoded[1][1])
        return addr

    return None
Esempio n. 3
0
def try_output_matches(decoded, matches):
    for ops, data_format, address_index in matches:
        if match_decoded(decoded, ops):
            if data_format is None:
                return None
            elif data_format == 'pubkey':
                return public_key_to_pubkey_address(decoded[address_index][1])
            elif data_format == 'hash160p2pkh':
                return hash_160_to_pubkey_address(decoded[address_index][1])
            elif data_format == 'hash160p2sh':
                return hash_160_to_script_address(decoded[address_index][1])
    return None
Esempio n. 4
0
def try_output_matches(decoded, matches):
    for ops, data_format, address_index in matches:
        if match_decoded(decoded, ops):
            if data_format is None:
                return None
            elif data_format == 'pubkey':
                return public_key_to_pubkey_address(decoded[address_index][1])
            elif data_format == 'hash160p2pkh':
                return hash_160_to_pubkey_address(decoded[address_index][1])
            elif data_format == 'hash160p2sh':
                return hash_160_to_script_address(decoded[address_index][1])
    return None
Esempio n. 5
0
def get_address_from_output_script(bytes):
    try:
        decoded = [ x for x in script_GetOp(bytes) ]
    except:
        return None
    r = decode_claim_script(decoded)
    if r is not False:
        claim_name, claim_value, decoded = r

    # The Genesis Block, self-payments, and pay-by-IP-address payments look like:
    # 65 BYTES:... CHECKSIG
    match = [opcodes.OP_PUSHDATA4, opcodes.OP_CHECKSIG]
    if match_decoded(decoded, match):
        return public_key_to_pubkey_address(decoded[0][1])

    # coins sent to black hole
    # DUP HASH160 20 BYTES:... EQUALVERIFY CHECKSIG
    match = [opcodes.OP_DUP, opcodes.OP_HASH160, opcodes.OP_0, opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG]
    if match_decoded(decoded, match):
        return None

    # Pay-by-Bitcoin-address TxOuts look like:
    # DUP HASH160 20 BYTES:... EQUALVERIFY CHECKSIG
    match = [opcodes.OP_DUP, opcodes.OP_HASH160, opcodes.OP_PUSHDATA4, opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG]
    if match_decoded(decoded, match):
        return hash_160_to_pubkey_address(decoded[2][1])

    # strange tx
    match = [opcodes.OP_DUP, opcodes.OP_HASH160, opcodes.OP_PUSHDATA4, opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG, opcodes.OP_NOP]
    if match_decoded(decoded, match):
        return hash_160_to_pubkey_address(decoded[2][1])

    # p2sh
    match = [ opcodes.OP_HASH160, opcodes.OP_PUSHDATA4, opcodes.OP_EQUAL ]
    if match_decoded(decoded, match):
        addr = hash_160_to_script_address(decoded[1][1])
        return addr

    return None
Esempio n. 6
0
 def key_to_address(self, addr):
     return hash_160_to_pubkey_address(addr)
 def key_to_address(self, addr):
     return hash_160_to_pubkey_address(addr)