diff --git a/cmd/evm/json_logger.go b/cmd/evm/json_logger.go index 420b516763..a84d5daebd 100644 --- a/cmd/evm/json_logger.go +++ b/cmd/evm/json_logger.go @@ -26,23 +26,17 @@ import ( "github.com/ethereum/go-ethereum/core/vm" ) -// JSONLogger merely contains a writer, and immediately outputs to that channel, -// instead of collecting logs type JSONLogger struct { encoder *json.Encoder } -// NewJSONLogger returns a new JSON logger func NewJSONLogger(writer io.Writer) *JSONLogger { - logger := &JSONLogger{ - encoder: json.NewEncoder(writer), - } - return logger + return &JSONLogger{json.NewEncoder(writer)} } -// CaptureState outputs state information on the logger +// CaptureState outputs state information on the logger. func (l *JSONLogger) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, depth int, err error) error { - log := vm.StructLog{ + return l.encoder.Encode(vm.StructLog{ Pc: pc, Op: op, Gas: gas + cost, @@ -51,19 +45,16 @@ func (l *JSONLogger) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cos Stack: stack.Data(), Storage: nil, Depth: depth, - Err: err} - return l.encoder.Encode(log) + Err: err, + }) } -// CaptureEnd is triggered at end of execution +// CaptureEnd is triggered at end of execution. func (l *JSONLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration) error { type endLog struct { Output string `json:"output"` GasUsed math.HexOrDecimal64 `json:"gasUsed"` Time time.Duration `json:"time"` } - - log := endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), t} - return l.encoder.Encode(log) - + return l.encoder.Encode(endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), t}) } diff --git a/core/vm/gen_structlog.go b/core/vm/gen_structlog.go index fec0e36196..1c86b2256f 100644 --- a/core/vm/gen_structlog.go +++ b/core/vm/gen_structlog.go @@ -7,6 +7,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/math" ) @@ -16,13 +17,13 @@ func (s StructLog) MarshalJSON() ([]byte, error) { Op OpCode `json:"op"` Gas math.HexOrDecimal64 `json:"gas"` GasCost math.HexOrDecimal64 `json:"gasCost"` - Memory []byte `json:"memory"` + Memory hexutil.Bytes `json:"memory"` Stack []*math.HexOrDecimal256 `json:"stack"` - Storage map[common.Hash]common.Hash `json:-` + Storage map[common.Hash]common.Hash `json:"-"` Depth int `json:"depth"` Err error `json:"error"` OpName string `json:"opName"` - MemorySize string `json:"memSize"` + MemorySize int `json:"memSize"` } var enc StructLog enc.Pc = s.Pc @@ -50,9 +51,9 @@ func (s *StructLog) UnmarshalJSON(input []byte) error { Op *OpCode `json:"op"` Gas *math.HexOrDecimal64 `json:"gas"` GasCost *math.HexOrDecimal64 `json:"gasCost"` - Memory []byte `json:"memory"` + Memory hexutil.Bytes `json:"memory"` Stack []*math.HexOrDecimal256 `json:"stack"` - Storage map[common.Hash]common.Hash `json:-` + Storage map[common.Hash]common.Hash `json:"-"` Depth *int `json:"depth"` Err *error `json:"error"` } diff --git a/core/vm/logger.go b/core/vm/logger.go index df9e3a514e..d95f462bc2 100644 --- a/core/vm/logger.go +++ b/core/vm/logger.go @@ -24,6 +24,7 @@ import ( "time" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/core/types" ) @@ -58,7 +59,7 @@ type StructLog struct { GasCost uint64 `json:"gasCost"` Memory []byte `json:"memory"` Stack []*big.Int `json:"stack"` - Storage map[common.Hash]common.Hash `json:-` + Storage map[common.Hash]common.Hash `json:"-"` Depth int `json:"depth"` Err error `json:"error"` } @@ -67,16 +68,17 @@ func (s *StructLog) OpName() string { return s.Op.String() } -func (s *StructLog) MemorySize() string { - return fmt.Sprintf("%v", len(s.Memory)) +func (s *StructLog) MemorySize() int { + return len(s.Memory) } type structLogMarshaling struct { Stack []*math.HexOrDecimal256 Gas math.HexOrDecimal64 GasCost math.HexOrDecimal64 + Memory hexutil.Bytes OpName string `json:"opName"` - MemorySize string `json:"memSize"` + MemorySize int `json:"memSize"` } // Tracer is used to collect execution traces from an EVM transaction