Ejemplo n.º 1
0
        public void StartOperation(int depth, long gas, Instruction opcode, int pc)
        {
            _cancellationToken.ThrowIfCancellationRequested();

            var previousTraceEntry = _traceEntry;

            _traceEntry           = new GethTxTraceEntry();
            _traceEntry.Pc        = pc;
            _traceEntry.Operation = Enum.GetName(typeof(Instruction), opcode);
            _traceEntry.Gas       = gas;
            _traceEntry.Depth     = depth;
            _trace.Entries.Add(_traceEntry);

            if (_traceEntry.Depth > (previousTraceEntry?.Depth ?? 0))
            {
                _traceEntry.Storage = new Dictionary <string, string>();
                _trace.StoragesByDepth.Push(previousTraceEntry != null ? previousTraceEntry.Storage : new Dictionary <string, string>());
            }
            else if (_traceEntry.Depth < (previousTraceEntry?.Depth ?? 0))
            {
                if (previousTraceEntry == null)
                {
                    throw new InvalidOperationException("Unexpected missing previous trace when leaving a call.");
                }

                _traceEntry.Storage = new Dictionary <string, string>(_trace.StoragesByDepth.Pop());
            }
            else
            {
                if (previousTraceEntry == null)
                {
                    throw new InvalidOperationException("Unexpected missing previous trace on continuation.");
                }

                _traceEntry.Storage = new Dictionary <string, string>(previousTraceEntry.Storage);
            }
        }