Beispiel #1
0
 def push_bytes(data):
     ms = StreamManager.get_stream()
     writer = BinaryWriter(ms)
     if len(data) == 0:
         raise ValueError("push data error: data is null")
     if len(data) <= int.from_bytes(PUSHBYTES75,
                                    'little') + 1 - int.from_bytes(
                                        PUSHBYTES1, 'little'):
         num = len(data) + int.from_bytes(PUSHBYTES1, 'little') - 1
         writer.write_byte(num)
     elif len(data) < 0x100:
         writer.write_byte(PUSHDATA1)
         writer.write_uint8(len(data))
     elif len(data) < 0x10000:
         writer.write_byte(PUSHDATA2)
         writer.write_uint16(len(data))
     else:
         writer.write_byte(PUSHDATA4)
         writer.write_uint32(len(data))
     writer.write_bytes(data)
     ms.flush()
     res = ms.to_bytes()
     StreamManager.release_stream(ms)
     res = bytes_reader(res)
     return res
 def serialize_unsigned(self) -> bytes:
     ms = StreamManager.GetStream()
     writer = BinaryWriter(ms)
     writer.write_uint8(self.version)
     writer.write_uint8(self.tx_type)
     writer.write_uint32(self.nonce)
     writer.write_uint64(self.gas_price)
     writer.write_uint64(self.gas_limit)
     writer.write_bytes(bytes(self.payer))
     self.serialize_exclusive_data(writer)
     if hasattr(self, "payload"):
         writer.write_var_bytes(bytes(self.payload))
     writer.write_var_int(len(self.attributes))
     ms.flush()
     res = ms.ToArray()
     StreamManager.ReleaseStream(ms)
     return res
 def serialize_unsigned(self) -> bytes or str:
     ms = StreamManager.get_stream()
     writer = BinaryWriter(ms)
     writer.write_uint8(self.version)
     writer.write_uint8(self.tx_type)
     writer.write_uint32(self.nonce)
     writer.write_uint64(self.gas_price)
     writer.write_uint64(self.gas_limit)
     writer.write_bytes(self.payer)
     self.serialize_exclusive_data(writer)
     if self.payload is not None and len(self.payload) != 0:
         writer.write_var_bytes(bytes(self.payload))
     writer.write_var_int(len(self.attributes))
     ms.flush()
     hex_bytes = ms.to_bytes()
     StreamManager.release_stream(ms)
     return hex_bytes