示例#1
0
def compile_TxOutput(txout):
    ret = types.TxOutputBinType()
    ret.amount = txout.amount

    if len(list(txout.address_n)):
        raise Exception("address_n should be converted to address already")

    if txout.script_type == types.PAYTOADDRESS:
        script = '\x76\xa9'  # op_dup, op_hash_160
        script += '\x14'  # push 0x14 bytes
        script += tools.bc_address_to_hash_160(txout.address)
        script += '\x88\xac'  # op_equalverify, op_checksig
        ret.script_pubkey = script

    elif txout.script_type == types.PAYTOSCRIPTHASH:
        script = '\xa9'  # op_hash_160
        script += '\x14'  # push 0x14 bytes
        script += tools.bc_address_to_hash_160(txout.address)
        script += '\x87'  # op_equal
        ret.script_pubkey = script

    else:
        raise Exception("Unknown script type")

    return ret
示例#2
0
def compile_script_sig(address):
    # paytoaddress

    script = '\x76\xa9'  # op_dup, op_hash_160
    script += '\x14'  # push 0x14 bytes
    script += tools.bc_address_to_hash_160(address)
    script += '\x88\xac' # op_equalverify, op_checksig
    return script
示例#3
0
def compile_TxOutput(txout):
    ret = types.TxOutputBinType()
    ret.amount = txout.amount

    if len(list(txout.address_n)):
        raise Exception("address_n should be converted to address already")

    if txout.script_type == types.PAYTOADDRESS:
        script = '\x76\xa9'  # op_dup, op_hash_160
        script += '\x14'  # push 0x14 bytes
        script += tools.bc_address_to_hash_160(txout.address)
        script += '\x88\xac'  # op_equalverify, op_checksig
        ret.script_pubkey = script

    elif txout.script_type == types.PAYTOSCRIPTHASH:
        script = '\xa9'  # op_hash_160
        script += '\x14'  # push 0x14 bytes
        script += tools.bc_address_to_hash_160(txout.address)
        script += '\x87'  # op_equal
        ret.script_pubkey = script

    elif txout.script_type == types.PAYTOMULTISIG:
        s = compile_script_multisig(txout.multisig)
        h160 = tools.hash_160(s)
        script = '\xa9'  # op_hash_160
        script += '\x14'  # push 0x14 bytes
        script += h160
        script += '\x87'  # op_equal
        ret.script_pubkey = script

    elif txout.script_type == types.PAYTOOPRETURN:
        if txout.amount > 0:
            raise Exception("OP_RETURN output must not contain any satoshis")
        ret.script_pubkey = '\x6a' + op_push(len(txout.op_return_data)) + txout.op_return_data

    else:
        raise Exception("Unknown script type")

    return ret
示例#4
0
def compile_script_sig(address):
    def get_all_types():
        return [ t.address_type for t in coindef.types.values() ]

    # Compile address to paytoaddress script
    address_type = tools.bc_address_type(address)

    if address_type in get_all_types():  # paytoaddress
        script = '\x76\xa9'  # op_dup, op_hash_160
        script += '\x14'  # push 0x14 bytes
        script += tools.bc_address_to_hash_160(address)
        script += '\x88\xac' # op_equalverify, op_checksig
        return script

    elif address_type == 5:  # BTC, P2SH
        raise Exception("P2SH not implemented yet")

    raise Exception("Unsupported address type")
示例#5
0
def raw_tx_output(out):
    s = ''
    s += struct.pack('<Q', out.amount)  # amount

    if out.script_type == proto.PAYTOADDRESS:
        script = '\x76\xa9'  # op_dup, op_hash_160
        script += '\x14'  # push 0x14 bytes
        script += tools.bc_address_to_hash_160(out.address)
        script += '\x88\xac'  # op_equalverify, op_checksig

    elif out.script_type == proto.PAYTOSCRIPTHASH:
        raise Exception("P2SH not implemented yet!")

    else:
        raise Exception("Unknown script type!")

    s += tools.var_int(len(script))  # script length
    s += script  # script
    return s
示例#6
0
def raw_tx_output(out):
    s = ''
    s += struct.pack('<Q', out.amount)  # amount

    if out.script_type == proto.PAYTOADDRESS:
        script = '\x76\xa9'  # op_dup, op_hash_160
        script += '\x14'  # push 0x14 bytes
        script += tools.bc_address_to_hash_160(out.address)
        script += '\x88\xac'  # op_equalverify, op_checksig

    elif out.script_type == proto.PAYTOSCRIPTHASH:
        raise Exception("P2SH not implemented yet!")

    else:
        raise Exception("Unknown script type!")

    s += tools.var_int(len(script))  # script length
    s += script  # script
    return s