gen_structlog.go 3.15 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.

package vm

import (
	"encoding/json"
	"math/big"

	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/common/hexutil"
	"github.com/ethereum/go-ethereum/common/math"
)

14 15
var _ = (*structLogMarshaling)(nil)

16
// MarshalJSON marshals as JSON.
17 18
func (s StructLog) MarshalJSON() ([]byte, error) {
	type StructLog struct {
19 20 21 22 23 24 25 26 27 28 29 30 31
		Pc            uint64                      `json:"pc"`
		Op            OpCode                      `json:"op"`
		Gas           math.HexOrDecimal64         `json:"gas"`
		GasCost       math.HexOrDecimal64         `json:"gasCost"`
		Memory        hexutil.Bytes               `json:"memory"`
		MemorySize    int                         `json:"memSize"`
		Stack         []*math.HexOrDecimal256     `json:"stack"`
		Storage       map[common.Hash]common.Hash `json:"-"`
		Depth         int                         `json:"depth"`
		RefundCounter uint64                      `json:"refund"`
		Err           error                       `json:"-"`
		OpName        string                      `json:"opName"`
		ErrorString   string                      `json:"error"`
32 33 34 35 36 37 38
	}
	var enc StructLog
	enc.Pc = s.Pc
	enc.Op = s.Op
	enc.Gas = math.HexOrDecimal64(s.Gas)
	enc.GasCost = math.HexOrDecimal64(s.GasCost)
	enc.Memory = s.Memory
39
	enc.MemorySize = s.MemorySize
40 41 42 43 44 45 46 47
	if s.Stack != nil {
		enc.Stack = make([]*math.HexOrDecimal256, len(s.Stack))
		for k, v := range s.Stack {
			enc.Stack[k] = (*math.HexOrDecimal256)(v)
		}
	}
	enc.Storage = s.Storage
	enc.Depth = s.Depth
48
	enc.RefundCounter = s.RefundCounter
49 50
	enc.Err = s.Err
	enc.OpName = s.OpName()
51
	enc.ErrorString = s.ErrorString()
52 53 54
	return json.Marshal(&enc)
}

55
// UnmarshalJSON unmarshals from JSON.
56 57
func (s *StructLog) UnmarshalJSON(input []byte) error {
	type StructLog struct {
58 59 60 61 62 63 64 65 66 67 68
		Pc            *uint64                     `json:"pc"`
		Op            *OpCode                     `json:"op"`
		Gas           *math.HexOrDecimal64        `json:"gas"`
		GasCost       *math.HexOrDecimal64        `json:"gasCost"`
		Memory        *hexutil.Bytes              `json:"memory"`
		MemorySize    *int                        `json:"memSize"`
		Stack         []*math.HexOrDecimal256     `json:"stack"`
		Storage       map[common.Hash]common.Hash `json:"-"`
		Depth         *int                        `json:"depth"`
		RefundCounter *uint64                     `json:"refund"`
		Err           error                       `json:"-"`
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
	}
	var dec StructLog
	if err := json.Unmarshal(input, &dec); err != nil {
		return err
	}
	if dec.Pc != nil {
		s.Pc = *dec.Pc
	}
	if dec.Op != nil {
		s.Op = *dec.Op
	}
	if dec.Gas != nil {
		s.Gas = uint64(*dec.Gas)
	}
	if dec.GasCost != nil {
		s.GasCost = uint64(*dec.GasCost)
	}
	if dec.Memory != nil {
87
		s.Memory = *dec.Memory
88
	}
89 90 91
	if dec.MemorySize != nil {
		s.MemorySize = *dec.MemorySize
	}
92 93 94 95 96 97 98 99 100 101 102 103
	if dec.Stack != nil {
		s.Stack = make([]*big.Int, len(dec.Stack))
		for k, v := range dec.Stack {
			s.Stack[k] = (*big.Int)(v)
		}
	}
	if dec.Storage != nil {
		s.Storage = dec.Storage
	}
	if dec.Depth != nil {
		s.Depth = *dec.Depth
	}
104 105 106
	if dec.RefundCounter != nil {
		s.RefundCounter = *dec.RefundCounter
	}
107
	if dec.Err != nil {
108
		s.Err = dec.Err
109 110 111
	}
	return nil
}