github.com/AlohaMobile/go-ethereum@v1.9.7/core/vm/gen_structlog.go (about)

     1  // Code generated by github.com/fjl/gencodec. DO NOT EDIT.
     2  
     3  package vm
     4  
     5  import (
     6  	"encoding/json"
     7  	"math/big"
     8  
     9  	"github.com/ethereum/go-ethereum/common"
    10  	"github.com/ethereum/go-ethereum/common/hexutil"
    11  	"github.com/ethereum/go-ethereum/common/math"
    12  )
    13  
    14  var _ = (*structLogMarshaling)(nil)
    15  
    16  // MarshalJSON marshals as JSON.
    17  func (s StructLog) MarshalJSON() ([]byte, error) {
    18  	type StructLog struct {
    19  		Pc            uint64                      `json:"pc"`
    20  		Op            OpCode                      `json:"op"`
    21  		Gas           math.HexOrDecimal64         `json:"gas"`
    22  		GasCost       math.HexOrDecimal64         `json:"gasCost"`
    23  		Memory        hexutil.Bytes               `json:"memory"`
    24  		MemorySize    int                         `json:"memSize"`
    25  		Stack         []*math.HexOrDecimal256     `json:"stack"`
    26  		Storage       map[common.Hash]common.Hash `json:"-"`
    27  		Depth         int                         `json:"depth"`
    28  		RefundCounter uint64                      `json:"refund"`
    29  		Err           error                       `json:"-"`
    30  		OpName        string                      `json:"opName"`
    31  		ErrorString   string                      `json:"error"`
    32  	}
    33  	var enc StructLog
    34  	enc.Pc = s.Pc
    35  	enc.Op = s.Op
    36  	enc.Gas = math.HexOrDecimal64(s.Gas)
    37  	enc.GasCost = math.HexOrDecimal64(s.GasCost)
    38  	enc.Memory = s.Memory
    39  	enc.MemorySize = s.MemorySize
    40  	if s.Stack != nil {
    41  		enc.Stack = make([]*math.HexOrDecimal256, len(s.Stack))
    42  		for k, v := range s.Stack {
    43  			enc.Stack[k] = (*math.HexOrDecimal256)(v)
    44  		}
    45  	}
    46  	enc.Storage = s.Storage
    47  	enc.Depth = s.Depth
    48  	enc.RefundCounter = s.RefundCounter
    49  	enc.Err = s.Err
    50  	enc.OpName = s.OpName()
    51  	enc.ErrorString = s.ErrorString()
    52  	return json.Marshal(&enc)
    53  }
    54  
    55  // UnmarshalJSON unmarshals from JSON.
    56  func (s *StructLog) UnmarshalJSON(input []byte) error {
    57  	type StructLog struct {
    58  		Pc            *uint64                     `json:"pc"`
    59  		Op            *OpCode                     `json:"op"`
    60  		Gas           *math.HexOrDecimal64        `json:"gas"`
    61  		GasCost       *math.HexOrDecimal64        `json:"gasCost"`
    62  		Memory        *hexutil.Bytes              `json:"memory"`
    63  		MemorySize    *int                        `json:"memSize"`
    64  		Stack         []*math.HexOrDecimal256     `json:"stack"`
    65  		Storage       map[common.Hash]common.Hash `json:"-"`
    66  		Depth         *int                        `json:"depth"`
    67  		RefundCounter *uint64                     `json:"refund"`
    68  		Err           error                       `json:"-"`
    69  	}
    70  	var dec StructLog
    71  	if err := json.Unmarshal(input, &dec); err != nil {
    72  		return err
    73  	}
    74  	if dec.Pc != nil {
    75  		s.Pc = *dec.Pc
    76  	}
    77  	if dec.Op != nil {
    78  		s.Op = *dec.Op
    79  	}
    80  	if dec.Gas != nil {
    81  		s.Gas = uint64(*dec.Gas)
    82  	}
    83  	if dec.GasCost != nil {
    84  		s.GasCost = uint64(*dec.GasCost)
    85  	}
    86  	if dec.Memory != nil {
    87  		s.Memory = *dec.Memory
    88  	}
    89  	if dec.MemorySize != nil {
    90  		s.MemorySize = *dec.MemorySize
    91  	}
    92  	if dec.Stack != nil {
    93  		s.Stack = make([]*big.Int, len(dec.Stack))
    94  		for k, v := range dec.Stack {
    95  			s.Stack[k] = (*big.Int)(v)
    96  		}
    97  	}
    98  	if dec.Storage != nil {
    99  		s.Storage = dec.Storage
   100  	}
   101  	if dec.Depth != nil {
   102  		s.Depth = *dec.Depth
   103  	}
   104  	if dec.RefundCounter != nil {
   105  		s.RefundCounter = *dec.RefundCounter
   106  	}
   107  	if dec.Err != nil {
   108  		s.Err = dec.Err
   109  	}
   110  	return nil
   111  }