Example #1
0
        /// <summary>
        /// Deserializes the given RLP serialized receipt and sets all values accordingly.
        /// </summary>
        /// <param name="item">The RLP item to deserialize and obtain values from.</param>
        public void Deserialize(RLPItem item)
        {
            // Verify this is a list
            if (!item.IsList)
            {
                throw new ArgumentException();
            }

            // Verify it has 4 items.
            RLPList rlpReceipt = (RLPList)item;

            if (rlpReceipt.Items.Count != 4)
            {
                throw new ArgumentException();
            }

            // Verify the types of all items
            if (!rlpReceipt.Items[0].IsByteArray ||
                !rlpReceipt.Items[1].IsByteArray ||
                !rlpReceipt.Items[2].IsByteArray ||
                !rlpReceipt.Items[3].IsList)
            {
                throw new ArgumentException();
            }

            // Set our state root
            RLPByteArray rlpStateRoot = (RLPByteArray)rlpReceipt.Items[0];

            StateRoot = rlpStateRoot.Data.ToArray();

            // Set our gas used
            RLPByteArray rlpGasUsed = (RLPByteArray)rlpReceipt.Items[1];

            GasUsed = RLP.ToInteger(rlpGasUsed, EVMDefinitions.WORD_SIZE);

            // Set our bloom
            RLPByteArray rlpBloom = (RLPByteArray)rlpReceipt.Items[2];

            Bloom = RLP.ToInteger(rlpBloom, EVMDefinitions.BLOOM_FILTER_SIZE);

            // Obtain our logs
            RLPList rlpLogs = (RLPList)rlpReceipt.Items[3];

            Logs = new List <Log>();
            foreach (RLPItem rlpLog in rlpLogs.Items)
            {
                // Add our log
                Logs.Add(new Log(rlpLog));
            }
        }
Example #2
0
File: Log.cs Project: zutobg/Meadow
        /// <summary>
        /// Deserializes the given RLP serialized log and sets all values accordingly.
        /// </summary>
        /// <param name="item">The RLP item to deserialize and obtain values from.</param>
        public void Deserialize(RLPItem item)
        {
            // Verify this is a list
            if (!item.IsList)
            {
                throw new ArgumentException();
            }

            // Verify it has 3 items.
            RLPList rlpLog = (RLPList)item;

            if (rlpLog.Items.Count != 3)
            {
                throw new ArgumentException();
            }

            // Verify the types of all items
            if (!rlpLog.Items[0].IsByteArray ||
                !rlpLog.Items[1].IsList ||
                !rlpLog.Items[2].IsByteArray)
            {
                throw new ArgumentException();
            }

            // Set our address
            RLPByteArray rlpAddress = (RLPByteArray)rlpLog.Items[0];

            Address = new Address(rlpAddress.Data.Span);

            // Obtain our topics
            RLPList rlpTopicsList = (RLPList)rlpLog.Items[1];

            Topics = new List <BigInteger>();
            foreach (RLPItem rlpTopic in rlpTopicsList.Items)
            {
                // Verify all of our items are data
                if (rlpTopic.GetType() != typeof(RLPByteArray))
                {
                    throw new ArgumentException();
                }

                // Add our topic.
                Topics.Add(RLP.ToInteger((RLPByteArray)rlpTopic, EVMDefinitions.WORD_SIZE));
            }

            // Obtain our data
            RLPByteArray rlpData = (RLPByteArray)rlpLog.Items[2];

            Data = rlpData.Data.ToArray();
        }
Example #3
0
        private void RLPListEncodeDecodeTest(int items)
        {
            RLPList list = new RLPList();

            for (int i = 0; i < items; i++)
            {
                if (i % 2 == 0)
                {
                    list.Items.Add(new byte[] { (byte)(i % 256) });
                }
                else
                {
                    list.Items.Add(new RLPList());
                }
            }

            byte[]  encoded = RLP.Encode(list);
            RLPList list2   = (RLPList)RLP.Decode(encoded);

            Assert.Equal(list.Items.Count, list2.Items.Count);

            for (int i = 0; i < list.Items.Count; i++)
            {
                if (i % 2 == 0)
                {
                    Assert.IsType <RLPByteArray>(list2.Items[i]);
                    RLPByteArray b1 = ((RLPByteArray)list.Items[i]);
                    RLPByteArray b2 = ((RLPByteArray)list2.Items[i]);
                    Assert.True(MemoryExtensions.SequenceEqual(b1.Data.Span, b2.Data.Span));
                }
                else
                {
                    Assert.IsType <RLPList>(list2.Items[i]);
                }
            }
        }