def _load_from_bytes(self, data: bytes) -> 'BaseTransaction':
        from hathor import protos
        from hathor.transaction.base_transaction import tx_or_block_from_proto

        tx_proto = protos.BaseTransaction()
        tx_proto.ParseFromString(data)
        return tx_or_block_from_proto(tx_proto, storage=self)
Example #2
0
 def to_proto(self,
              include_metadata: bool = True) -> protos.BaseTransaction:
     tx_proto = protos.Block(version=self.version,
                             weight=self.weight,
                             timestamp=self.timestamp,
                             parents=self.parents,
                             outputs=map(TxOutput.to_proto, self.outputs),
                             hash=self.hash,
                             data=self.data)
     tx_proto.nonce = int_to_bytes(self.nonce, 16)
     if include_metadata:
         tx_proto.metadata.CopyFrom(self.get_metadata().to_proto())
     return protos.BaseTransaction(block=tx_proto)
Example #3
0
 def to_proto(self, include_metadata: bool = True) -> protos.BaseTransaction:
     tx_proto = protos.TokenCreationTransaction(
         version=self.version,
         weight=self.weight,
         timestamp=self.timestamp,
         parents=self.parents,
         inputs=map(TxInput.to_proto, self.inputs),
         outputs=map(TxOutput.to_proto, self.outputs),
         token_info=self.serialize_token_info(),
         nonce=self.nonce,
         hash=self.hash,
     )
     if include_metadata:
         tx_proto.metadata.CopyFrom(self.get_metadata().to_proto())
     return protos.BaseTransaction(tokenCreationTransaction=tx_proto)