public StatusMessage Deserialize(byte[] bytes) { try { StatusMessage statusMessage = new StatusMessage(); Rlp.DecoderContext context = bytes.AsRlpContext(); context.ReadSequenceLength(); statusMessage.ProtocolVersion = context.DecodeByte(); statusMessage.ChainId = context.DecodeUInt256(); statusMessage.TotalDifficulty = context.DecodeUInt256(); statusMessage.BestHash = context.DecodeKeccak(); statusMessage.GenesisHash = context.DecodeKeccak(); return(statusMessage); } catch (Exception) { // TODO: still to be explained... StatusMessage statusMessage = new StatusMessage(); Rlp.DecoderContext context = bytes.AsSpan(3).ToArray().AsRlpContext(); context.ReadSequenceLength(); statusMessage.ProtocolVersion = context.DecodeByte(); statusMessage.ChainId = context.DecodeUInt256(); statusMessage.TotalDifficulty = context.DecodeUInt256(); statusMessage.BestHash = context.DecodeKeccak(); statusMessage.GenesisHash = context.DecodeKeccak(); statusMessage.StrangePrefix = bytes.AsSpan(0, 3).ToArray().ToHexString(); return(statusMessage); } }
private static HiMessage Deserialize(Rlp.DecoderContext context) { context.ReadSequenceLength(); var protocolVersion = context.DecodeByte(); var providerAddress = context.DecodeAddress(); var consumerAddress = context.DecodeAddress(); var nodeId = new PublicKey(context.DecodeByteArray()); var signature = SignatureDecoder.DecodeSignature(context); return(new HiMessage(protocolVersion, providerAddress, consumerAddress, nodeId, signature)); }
public StatusMessage Deserialize(byte[] bytes) { StatusMessage statusMessage = new StatusMessage(); Rlp.DecoderContext context = bytes.AsRlpContext(); context.ReadSequenceLength(); statusMessage.ProtocolVersion = context.DecodeByte(); statusMessage.ChainId = context.DecodeInt(); statusMessage.TotalDifficulty = context.DecodeUBigInt(); statusMessage.BestHash = context.DecodeKeccak(); statusMessage.GenesisHash = context.DecodeKeccak(); return(statusMessage); }
public HelloMessage Deserialize(byte[] bytes) { Rlp.DecoderContext context = bytes.AsRlpContext(); context.ReadSequenceLength(); HelloMessage helloMessage = new HelloMessage(); helloMessage.P2PVersion = context.DecodeByte(); helloMessage.ClientId = context.DecodeString(); helloMessage.Capabilities = context.DecodeArray(ctx => { ctx.ReadSequenceLength(); string protocolCode = ctx.DecodeString(); int version = ctx.DecodeByte(); return(new Capability(protocolCode, version)); }).ToList(); helloMessage.ListenPort = context.DecodeInt(); helloMessage.NodeId = new PublicKey(context.DecodeByteArray()); return(helloMessage); }
public GetBlockHeadersMessage Deserialize(byte[] bytes) { GetBlockHeadersMessage message = new GetBlockHeadersMessage(); Rlp.DecoderContext context = bytes.AsRlpContext(); context.ReadSequenceLength(); int position = context.Position; byte[] startingBytes = context.DecodeByteArray(); context.Position = position; if (startingBytes.Length == 32) { message.StartingBlockHash = context.DecodeKeccak(); } else { message.StartingBlockNumber = (long)context.DecodeUInt256(); } message.MaxHeaders = context.DecodeInt(); message.Skip = context.DecodeInt(); message.Reverse = context.DecodeByte(); return(message); }