mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
cmd/evm: fixups for json logger
This commit is contained in:
parent
373f587d8a
commit
0e250abf32
3 changed files with 19 additions and 25 deletions
|
|
@ -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})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue