示例#1
0
 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);
     }
 }
示例#2
0
        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);
        }
示例#3
0
        public ParityLikeTxTrace Decode(Rlp.DecoderContext context, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            ParityLikeTxTrace trace = new ParityLikeTxTrace();

            context.ReadSequenceLength();
            trace.BlockHash       = context.DecodeKeccak();
            trace.BlockNumber     = context.DecodeUInt256();
            trace.TransactionHash = context.DecodeKeccak();
            byte[] txPosBytes = context.DecodeByteArray();
            trace.TransactionPosition = txPosBytes.Length == 0 ? (int?)null : txPosBytes.ToInt32();
            context.ReadSequenceLength();
            trace.Action       = DecodeAction(context);
            trace.StateChanges = DecodeStateDiff(context);
            // stateChanges

            return(trace);
        }
示例#4
0
        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);
        }
示例#5
0
        public Snapshot Decode(Rlp.DecoderContext context, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            context.ReadSequenceLength();

            // Block number
            UInt256 number = context.DecodeUInt256();
            // Hash
            Keccak hash = context.DecodeKeccak();
            // Signers
            SortedList <Address, UInt256> signers = DecodeSigners(context);
            // Votes
            List <Vote> votes = DecodeVotes(context);
            // Tally
            Dictionary <Address, Tally> tally = DecodeTally(context);
            Snapshot snapshot = new Snapshot(number, hash, signers, tally);

            snapshot.Votes = votes;

            return(snapshot);
        }
示例#6
0
        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);
        }
示例#7
0
        public Snapshot Decode(Rlp.DecoderContext context, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            context.ReadSequenceLength();

            // Config
            CliqueConfig config = new CliqueConfig(15, 30000);
            // Signature cache
            LruCache <Keccak, Address> sigCache = new LruCache <Keccak, Address>(Clique.InMemorySignatures);
            // Block number
            UInt256 number = context.DecodeUInt256();
            // Hash
            Keccak hash = context.DecodeKeccak();
            // Signers
            SortedList <Address, UInt256> signers = DecodeSigners(context);
            // Votes
            List <Vote> votes = DecodeVotes(context);
            // Tally
            Dictionary <Address, Tally> tally = DecodeTally(context);
            Snapshot snapshot = new Snapshot(config, sigCache, number, hash, signers, tally);

            snapshot.Votes = votes;

            return(snapshot);
        }
示例#8
0
 public GetBlockBodiesMessage Deserialize(byte[] bytes)
 {
     Rlp.DecoderContext context = bytes.AsRlpContext();
     Keccak[]           hashes  = context.DecodeArray(ctx => context.DecodeKeccak());
     return(new GetBlockBodiesMessage(hashes));
 }