def raw_tx_input(inp, script_sig): s = '' s += inp.prev_hash[::-1] # prev hash s += struct.pack('<L', inp.prev_index) # prev index if script_sig != '': s += tools.var_int(len(script_sig)) # script length s += script_sig # script sig s += "\xff\xff\xff\xff" # sequence return s
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
def raw_tx_middle(outputs_count): s = '' s += tools.var_int(outputs_count) # number of outputs return s
def raw_tx_header(inputs_count): s = '' s += '\x01\x00\x00\x00' # version s += tools.var_int(inputs_count) # number of inputs return s