public BlockInfo Decode(Rlp.DecoderContext context, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { int lastCheck = context.ReadSequenceLength() + context.Position; BlockInfo blockInfo = new BlockInfo(); blockInfo.BlockHash = context.DecodeKeccak(); blockInfo.WasProcessed = context.DecodeBool(); blockInfo.TotalDifficulty = context.DecodeUBigInt(); blockInfo.TotalTransactions = context.DecodeUBigInt(); if (!rlpBehaviors.HasFlag(RlpBehaviors.AllowExtraData)) { context.Check(lastCheck); } return(blockInfo); }
public NewBlockMessage Deserialize(byte[] bytes) { Rlp.DecoderContext context = bytes.AsRlpContext(); NewBlockMessage message = new NewBlockMessage(); context.ReadSequenceLength(); message.Block = Rlp.Decode <Block>(context); message.TotalDifficulty = context.DecodeUBigInt(); return(message); }
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 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 = context.DecodeUBigInt(); } message.MaxHeaders = context.DecodeInt(); message.Skip = context.DecodeInt(); message.Reverse = context.DecodeInt(); return(message); }