public Account Decode(Rlp.DecoderContext context, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            context.ReadSequenceLength();
            UInt256 nonce       = context.DecodeUInt256();
            UInt256 balance     = context.DecodeUInt256();
            Keccak  storageRoot = context.DecodeKeccak();
            Keccak  codeHash    = context.DecodeKeccak();
            Account account     = new Account(nonce, balance, storageRoot, codeHash);

            return(account);
        }
        public Account Decode(Rlp.DecoderContext context, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            context.ReadSequenceLength();
            //long checkValue = context.ReadSequenceLength() + context.Position;

            UInt256 nonce       = context.DecodeUInt256();
            UInt256 balance     = context.DecodeUInt256();
            Keccak  storageRoot = context.DecodeKeccak();
            Keccak  codeHash    = context.DecodeKeccak();
            Account account     = new Account(nonce, balance, storageRoot, codeHash);

            //if (!rlpBehaviors.HasFlag(RlpBehaviors.AllowExtraData))
            //{
            //    context.Check(checkValue);
            //}

            return(account);
        }
        public LogEntry Decode(Rlp.DecoderContext context, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            context.ReadSequenceLength();
            Address address        = context.DecodeAddress();
            long    sequenceLength = context.ReadSequenceLength();

            Keccak[] topics = new Keccak[sequenceLength / 33];
            for (int i = 0; i < topics.Length; i++)
            {
                topics[i] = context.DecodeKeccak();
            }

            byte[] data = context.DecodeByteArray();

            return(new LogEntry(address, data, topics));
        }
Exemple #4
0
        public BlockHeader Decode(Rlp.DecoderContext context, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            if (context.Length == 1 && context.Data[0] == 192)
            {
                return(null);
            }

            var headerRlp = context.PeekNextItem();

            int headerSequenceLength = context.ReadSequenceLength();
            int headerCheck          = context.Position + headerSequenceLength;

            Keccak  parentHash       = context.DecodeKeccak();
            Keccak  ommersHash       = context.DecodeKeccak();
            Address beneficiary      = context.DecodeAddress();
            Keccak  stateRoot        = context.DecodeKeccak();
            Keccak  transactionsRoot = context.DecodeKeccak();
            Keccak  receiptsRoot     = context.DecodeKeccak();
            Bloom   bloom            = context.DecodeBloom();
            UInt256 difficulty       = context.DecodeUInt256();
            UInt256 number           = context.DecodeUInt256();
            UInt256 gasLimit         = context.DecodeUInt256();
            UInt256 gasUsed          = context.DecodeUInt256();
            UInt256 timestamp        = context.DecodeUInt256();

            byte[]     extraData = context.DecodeByteArray();
            Keccak     mixHash   = context.DecodeKeccak();
            BigInteger nonce     = context.DecodeUBigInt();

            if (!rlpBehaviors.HasFlag(RlpBehaviors.AllowExtraData))
            {
                context.Check(headerCheck);
            }

            BlockHeader blockHeader = new BlockHeader(
                parentHash,
                ommersHash,
                beneficiary,
                difficulty,
                number,
                (long)gasLimit,
                timestamp,
                extraData);

            blockHeader.StateRoot        = stateRoot;
            blockHeader.TransactionsRoot = transactionsRoot;
            blockHeader.ReceiptsRoot     = receiptsRoot;
            blockHeader.Bloom            = bloom;
            blockHeader.GasUsed          = (long)gasUsed;
            blockHeader.MixHash          = mixHash;
            blockHeader.Nonce            = (ulong)nonce;
            blockHeader.Hash             = Keccak.Compute(headerRlp);
            return(blockHeader);
        }
Exemple #5
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.DecodeUInt256();
            blockInfo.TotalTransactions = context.DecodeUInt256();

            if (!rlpBehaviors.HasFlag(RlpBehaviors.AllowExtraData))
            {
                context.Check(lastCheck);
            }

            return(blockInfo);
        }
        public TxReceipt Decode(Rlp.DecoderContext context, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            bool      isStorage = (rlpBehaviors & RlpBehaviors.Storage) != 0;
            TxReceipt txReceipt = new TxReceipt();

            context.ReadSequenceLength();
            byte[] firstItem = context.DecodeByteArray();
            if (firstItem.Length == 1)
            {
                txReceipt.StatusCode = firstItem[0];
            }
            else
            {
                txReceipt.PostTransactionState = firstItem.Length == 0 ? null : new Keccak(firstItem);
            }

            if (isStorage)
            {
                txReceipt.BlockHash = context.DecodeKeccak();
            }
            if (isStorage)
            {
                txReceipt.BlockNumber = (long)context.DecodeUInt256();
            }
            if (isStorage)
            {
                txReceipt.Index = context.DecodeInt();
            }
            if (isStorage)
            {
                txReceipt.Sender = context.DecodeAddress();
            }
            if (isStorage)
            {
                txReceipt.Recipient = context.DecodeAddress();
            }
            if (isStorage)
            {
                txReceipt.ContractAddress = context.DecodeAddress();
            }
            if (isStorage)
            {
                txReceipt.GasUsed = (long)context.DecodeUBigInt();
            }
            txReceipt.GasUsedTotal = (long)context.DecodeUBigInt();
            txReceipt.Bloom        = context.DecodeBloom();

            int             lastCheck  = context.ReadSequenceLength() + context.Position;
            List <LogEntry> logEntries = new List <LogEntry>();

            while (context.Position < lastCheck)
            {
                logEntries.Add(Rlp.Decode <LogEntry>(context, RlpBehaviors.AllowExtraData));
            }

            bool allowExtraData = (rlpBehaviors & RlpBehaviors.AllowExtraData) != 0;

            if (!allowExtraData)
            {
                context.Check(lastCheck);
            }

            // since error was added later we can only rely on it in cases where we read receipt only and no data follows
            if (isStorage && !allowExtraData && context.Position != context.Length)
            {
                txReceipt.Error = context.DecodeString();
            }

            txReceipt.Logs = logEntries.ToArray();
            return(txReceipt);
        }