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
def get_address_from_input_script(bytes):
    try:
        decoded = [x for x in script_GetOp(bytes)]
    except:
        # coinbase transactions raise an exception
        return [], [], None

    # non-generated TxIn transactions push a signature
    # (seventy-something bytes) and then their public key
    # (33 or 65 bytes) onto the stack:

    match = [opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4]
    if match_decoded(decoded, match):
        return None, None, public_key_to_pubkey_address(decoded[1][1])

    # p2sh transaction, 2 of n
    match = [opcodes.OP_0]
    while len(match) < len(decoded):
        match.append(opcodes.OP_PUSHDATA4)

    if match_decoded(decoded, match):

        redeemScript = decoded[-1][1]
        num = len(match) - 2
        signatures = map(lambda x: x[1].encode('hex'), decoded[1:-1])
        dec2 = [x for x in script_GetOp(redeemScript)]

        # 2 of 2
        match2 = [
            opcodes.OP_NAME_FIRSTUPDATE, opcodes.OP_PUSHDATA4,
            opcodes.OP_PUSHDATA4, opcodes.OP_NAME_FIRSTUPDATE,
            opcodes.OP_CHECKMULTISIG
        ]
        if match_decoded(dec2, match2):
            pubkeys = [dec2[1][1].encode('hex'), dec2[2][1].encode('hex')]
            return pubkeys, signatures, hash_160_to_script_address(
                hash_160(redeemScript))

        # 2 of 3
        match2 = [
            opcodes.OP_NAME_FIRSTUPDATE, opcodes.OP_PUSHDATA4,
            opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4, opcodes.OP_NAME_UPDATE,
            opcodes.OP_CHECKMULTISIG
        ]
        if match_decoded(dec2, match2):
            pubkeys = [
                dec2[1][1].encode('hex'), dec2[2][1].encode('hex'),
                dec2[3][1].encode('hex')
            ]
            return pubkeys, signatures, hash_160_to_script_address(
                hash_160(redeemScript))

    return [], [], None
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
Example #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
Example #5
0
def get_address_from_input_script(bytes):
    try:
        decoded = [x for x in script_GetOp(bytes)]
    except:
        # coinbase transactions raise an exception
        return [], [], None

    # non-generated TxIn transactions push a signature
    # (seventy-something bytes) and then their public key
    # (33 or 65 bytes) onto the stack:

    match = [opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4]
    if match_decoded(decoded, match):
        return None, None, public_key_to_pubkey_address(decoded[1][1])

    # p2sh transaction, 2 of n
    match = [opcodes.OP_0]
    while len(match) < len(decoded):
        match.append(opcodes.OP_PUSHDATA4)

    if match_decoded(decoded, match):

        redeemScript = decoded[-1][1]
        num = len(match) - 2
        signatures = map(lambda x: x[1].encode("hex"), decoded[1:-1])
        dec2 = [x for x in script_GetOp(redeemScript)]

        # 2 of 2
        match2 = [opcodes.OP_2, opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4, opcodes.OP_2, opcodes.OP_CHECKMULTISIG]
        if match_decoded(dec2, match2):
            pubkeys = [dec2[1][1].encode("hex"), dec2[2][1].encode("hex")]
            return pubkeys, signatures, hash_160_to_script_address(hash_160(redeemScript))

        # 2 of 3
        match2 = [
            opcodes.OP_2,
            opcodes.OP_PUSHDATA4,
            opcodes.OP_PUSHDATA4,
            opcodes.OP_PUSHDATA4,
            opcodes.OP_3,
            opcodes.OP_CHECKMULTISIG,
        ]
        if match_decoded(dec2, match2):
            pubkeys = [dec2[1][1].encode("hex"), dec2[2][1].encode("hex"), dec2[3][1].encode("hex")]
            return pubkeys, signatures, hash_160_to_script_address(hash_160(redeemScript))

    return [], [], None
Example #6
0
def get_address_input_script(bytes):
    try:
        decoded = [x for x in script_GetOp(bytes)]
    except:
        # coinbase transactions raise an exception
        return [], [], None

    match = [opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4]
    if match_decoded(decoded, match):
        return None, None, public_key_to_pubkey_address(decoded[1][1])

    # p2sh transaction, 2 of n
    match = [opcodes.OP_0]
    while len(match) < len(decoded):
        match.append(opcodes.OP_PUSHDATA4)

    if match_decoded(decoded, match):

        redeemScript = decoded[-1][1]
        num = len(match) - 2
        signatures = map(lambda x: x[1].encode('hex'), decoded[1:-1])
        dec2 = [x for x in script_GetOp(redeemScript)]

        # 2 of 2
        match2 = [
            opcodes.OP_2, opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4,
            opcodes.OP_2, opcodes.OP_CHECKMULTISIG
        ]
        if match_decoded(dec2, match2):
            pubkeys = [dec2[1][1].encode('hex'), dec2[2][1].encode('hex')]
            return pubkeys, signatures, hash_160_to_script_address(
                hash_160(redeemScript))

        # 2 of 3
        match2 = [
            opcodes.OP_2, opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4,
            opcodes.OP_PUSHDATA4, opcodes.OP_3, opcodes.OP_CHECKMULTISIG
        ]
        if match_decoded(dec2, match2):
            pubkeys = [
                dec2[1][1].encode('hex'), dec2[2][1].encode('hex'),
                dec2[3][1].encode('hex')
            ]
            return pubkeys, signatures, hash_160_to_script_address(
                hash_160(redeemScript))

    return [], [], None
Example #7
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
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