def ToArray(self): """ Get the byte data of self. Returns: bytes: """ return Helper.ToArray(self)
def SendSerializedMessage(self, message): """ Send the `message` to the remote client. Args: message (neo.Network.Message): """ ba = Helper.ToArray(message) ba2 = binascii.unhexlify(ba) self.bytes_out += len(ba2) self.transport.write(ba2)
def get_blockheader_output(self, blockheader, params): if len(params) >= 2 and params[1]: jsn = blockheader.ToJson() jsn['confirmations'] = Blockchain.Default().Height - blockheader.Index + 1 hash = Blockchain.Default().GetNextBlockHash(blockheader.Hash) if hash: jsn['nextblockhash'] = '0x%s' % hash.decode('utf-8') return jsn return Helper.ToArray(blockheader).decode('utf-8')
def get_tx_output(self, tx, height, params): if len(params) >= 2 and params[1]: jsn = tx.ToJson() if height >= 0: header = Blockchain.Default().GetHeaderByHeight(height) jsn['blockhash'] = header.Hash.To0xString() jsn['confirmations'] = Blockchain.Default().Height - header.Index + 1 jsn['blocktime'] = header.Timestamp return jsn return Helper.ToArray(tx).decode('utf-8')
def __init__(self, command=None, payload=None): self.Command = command self.Magic = Settings.MAGIC if payload is None: payload = bytearray() else: payload = binascii.unhexlify(Helper.ToArray(payload)) self.Checksum = Message.GetChecksum(payload) self.Payload = payload
def SendSerializedMessage(self, message): """ Send the `message` to the remote client. Args: message (neo.Network.Message): """ try: ba = Helper.ToArray(message) ba2 = binascii.unhexlify(ba) self.bytes_out += len(ba2) self.transport.write(ba2) except Exception as e: self.Log("Could not send serialized message %s " % e)
def test_version_serialization(self): serialized = binascii.unhexlify( Helper.ToArray(self.payload)) deserialized_version = IOHelper.AsSerializableWithType(serialized, 'neo.Network.Payloads.VersionPayload.VersionPayload') v = deserialized_version self.assertEqual(v.Nonce, self.nonce) self.assertEqual(v.Port, self.port) self.assertEqual(v.UserAgent, self.ua) self.assertEqual(v.Timestamp, self.payload.Timestamp) self.assertEqual(v.StartHeight, self.payload.StartHeight) self.assertEqual(v.Version, self.payload.Version) self.assertEqual(v.Services, self.payload.Services) self.assertEqual(v.Relay, self.payload.Relay)
def __init__(self, command=None, payload=None, print_payload=False): """ Create an instance. Args: command (str): payload command i.e. "inv", "getdata". See NeoNode.MessageReceived() for more commands. payload (bytes): raw bytes of the payload. print_payload: UNUSED """ self.Command = command self.Magic = settings.MAGIC if payload is None: payload = bytearray() else: payload = binascii.unhexlify(Helper.ToArray(payload)) self.Checksum = Message.GetChecksum(payload) self.Payload = payload
def ToArray(self): return Helper.ToArray(self)
def SendSerializedMessage(self, message): ba = Helper.ToArray(message) ba2 = binascii.unhexlify(ba) self.bytes_out += len(ba2) self.transport.write(ba2)