Ejemplo n.º 1
0
        private static ParityTraceAction DecodeAction(RlpStream rlpStream)
        {
            ParityTraceAction action = new ParityTraceAction();
            int sequenceLength       = rlpStream.ReadSequenceLength();

            if (rlpStream.ReadNumberOfItemsRemaining(rlpStream.Position + sequenceLength) == 3)
            {
                action.CallType     = "reward";
                action.RewardType   = rlpStream.DecodeString();
                action.Author       = rlpStream.DecodeAddress();
                action.Value        = rlpStream.DecodeUInt256();
                action.TraceAddress = Array.Empty <int>();
            }
            else
            {
                action.CallType       = rlpStream.DecodeString();
                action.From           = rlpStream.DecodeAddress();
                action.To             = rlpStream.DecodeAddress();
                action.Value          = rlpStream.DecodeUInt256();
                action.Gas            = rlpStream.DecodeLong();
                action.Input          = rlpStream.DecodeByteArray();
                action.Result         = new ParityTraceResult();
                action.Result.Output  = rlpStream.DecodeByteArray();
                action.Result.GasUsed = rlpStream.DecodeLong();
                action.TraceAddress   = rlpStream.DecodeArray(c => c.DecodeInt());
                int subtracesCount = rlpStream.DecodeInt();
                action.Subtraces = new List <ParityTraceAction>(subtracesCount);
                for (int i = 0; i < subtracesCount; i++)
                {
                    action.Subtraces.Add(DecodeAction(rlpStream));
                }
            }

            return(action);
        }
Ejemplo n.º 2
0
        public static T[] DecodeArray <T>(this IRlpStreamDecoder <T> decoder, RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            int checkPosition = rlpStream.ReadSequenceLength() + rlpStream.Position;

            T[] result = new T[rlpStream.ReadNumberOfItemsRemaining(checkPosition)];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = decoder.Decode(rlpStream, rlpBehaviors);
            }

            return(result);
        }
Ejemplo n.º 3
0
        private Dictionary <UInt256, ParityStateChange <byte[]> > DecodeStorageChange(RlpStream rlpStream)
        {
            int checkpoint = rlpStream.ReadSequenceLength();
            var change     = new Dictionary <UInt256, ParityStateChange <byte[]> >();
            int itemsCount = rlpStream.ReadNumberOfItemsRemaining(rlpStream.Position + checkpoint);

            if (itemsCount == 0)
            {
                return(null);
            }

            for (int i = 0; i < itemsCount; i = i + 2)
            {
                change[rlpStream.DecodeUInt256()] = DecodeByteChange(rlpStream);
            }

            return(change);
        }
Ejemplo n.º 4
0
        private Dictionary <Address, ParityAccountStateChange> DecodeStateDiff(RlpStream rlpStream)
        {
            var accountStateChange = new Dictionary <Address, ParityAccountStateChange>();
            int checkpoint         = rlpStream.ReadSequenceLength();
            int items = rlpStream.ReadNumberOfItemsRemaining(rlpStream.Position + checkpoint);

            if (items == 0)
            {
                return(null);
            }

            for (int i = 0; i < items; i = i + 2)
            {
                accountStateChange[rlpStream.DecodeAddress()] = DecodeAccountStateChange(rlpStream);
            }

            return(accountStateChange);
        }
Ejemplo n.º 5
0
        private void InitializeChain(string chainFile)
        {
            if (!File.Exists(chainFile))
            {
                if (_logger.IsInfo)
                {
                    _logger.Info($"HIVE Chain file does not exist: {chainFile}, skipping");
                }
                return;
            }

            var chainFileContent = File.ReadAllBytes(chainFile);
            var rlpStream        = new RlpStream(chainFileContent);
            var blocks           = new List <Block>();

            if (_logger.IsInfo)
            {
                _logger.Info($"HIVE Loading blocks from {chainFile}");
            }
            while (rlpStream.ReadNumberOfItemsRemaining() > 0)
            {
                rlpStream.PeekNextItem();
                Block block = Rlp.Decode <Block>(rlpStream);
                if (_logger.IsInfo)
                {
                    _logger.Info($"HIVE Reading a chain.rlp block {block.ToString(Block.Format.Short)}");
                }
                blocks.Add(block);
            }

            for (int i = 0; i < blocks.Count; i++)
            {
                Block block = blocks[i];
                if (_logger.IsInfo)
                {
                    _logger.Info($"HIVE Processing a chain.rlp block {block.ToString(Block.Format.Short)}");
                }
                ProcessBlock(block);
            }
        }