Esempio n. 1
0
 def _serialize(self, with_inputs: bool = True) -> bytes:
     stream = BCDataStream()
     stream.write_uint32(self.version)
     if with_inputs:
         stream.write_compact_size(len(self._inputs))
         for txin in self._inputs:
             txin.serialize_to(stream)
     stream.write_compact_size(len(self._outputs))
     for txout in self._outputs:
         txout.serialize_to(stream)
     stream.write_uint32(self.locktime)
     return stream.get_bytes()
Esempio n. 2
0
 def _serialize_for_signature(self, signing_input: int) -> bytes:
     stream = BCDataStream()
     stream.write_uint32(self.version)
     stream.write_compact_size(len(self._inputs))
     for i, txin in enumerate(self._inputs):
         if signing_input == i:
             assert txin.txo_ref.txo is not None
             txin.serialize_to(stream, txin.txo_ref.txo.script.source)
         else:
             txin.serialize_to(stream, b'')
     stream.write_compact_size(len(self._outputs))
     for txout in self._outputs:
         txout.serialize_to(stream)
     stream.write_uint32(self.locktime)
     stream.write_uint32(self.signature_hash_type(1))  # signature hash type: SIGHASH_ALL
     return stream.get_bytes()