class TxOut: def serialize(self): result = int_to_little_endian(self.amount, 8) result += self.script_pubkey.serialize() return result class TxIn: def serialize(self): result = self.prev_tx[::-1] result += int_to_little_endian(self.prev_index, 4) result += self.script_sig.serialize() result += int_to_little_endian(self.sequence, 4) return result class Tx: def serialize(self) result = int_to_little_endian(self.version, 4) result += encode_varint(len(self.tx_ins)) for tx_in in self.tx_ins: result += tx_in.serialize() result += encode_varint(len(self.tx_outs)) for tx_out in self.tx_outs: result += tx_out.serialize() result += int_to_little_endian(self.locktime, 4) return result