def to_bytes(self): return b''.join(( pack_le_int32(self.version), pack_list(self.inputs, XTxInput.to_bytes), pack_list(self.outputs, XTxOutput.to_bytes), pack_le_uint32(self.locktime), ))
def get_preimage(tx, input_index, utxo_value, utxo_script, sighash_flag=None): if not sighash_flag: sighash_flag = SigHash(SigHash.ALL | SigHash.FORKID) txin = tx.inputs[input_index] hash_prevouts = hash_sequence = hash_outputs = bitcoinx.consts.ZERO sighash_not_single_none = sighash_flag.base not in (SigHash.SINGLE, SigHash.NONE) if not sighash_flag.anyone_can_pay: hash_prevouts = tx._hash_prevouts() if sighash_not_single_none: hash_sequence = tx._hash_sequence() if sighash_not_single_none: hash_outputs = tx._hash_outputs() elif (sighash_flag.base == SigHash.SINGLE and input_index < len(tx.outputs)): hash_outputs = double_sha256(tx.outputs[input_index].to_bytes()) preimage = b''.join(( pack_le_int32(tx.version), hash_prevouts, hash_sequence, txin.to_bytes_for_signature(utxo_value, utxo_script), hash_outputs, pack_le_uint32(tx.locktime), pack_le_uint32(sighash_flag), )) return preimage