github.com/ontio/ontology@v1.14.4/vm/evm/gen_structlog.go (about)

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