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
Beispiel #2
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
Beispiel #3
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