github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/core/vm/gen_structlog.go (about)

     1  
     2  //此源码被清华学神尹成大魔王专业翻译分析并修改
     3  //尹成QQ77025077
     4  //尹成微信18510341407
     5  //尹成所在QQ群721929980
     6  //尹成邮箱 yinc13@mails.tsinghua.edu.cn
     7  //尹成毕业于清华大学,微软区块链领域全球最有价值专家
     8  //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620
     9  //代码由github.com/fjl/gencodec生成。不要编辑。
    10  
    11  package vm
    12  
    13  import (
    14  	"encoding/json"
    15  	"math/big"
    16  
    17  	"github.com/ethereum/go-ethereum/common"
    18  	"github.com/ethereum/go-ethereum/common/hexutil"
    19  	"github.com/ethereum/go-ethereum/common/math"
    20  )
    21  
    22  var _ = (*structLogMarshaling)(nil)
    23  
    24  func (s StructLog) MarshalJSON() ([]byte, error) {
    25  	type StructLog struct {
    26  		Pc          uint64                      `json:"pc"`
    27  		Op          OpCode                      `json:"op"`
    28  		Gas         math.HexOrDecimal64         `json:"gas"`
    29  		GasCost     math.HexOrDecimal64         `json:"gasCost"`
    30  		Memory      hexutil.Bytes               `json:"memory"`
    31  		MemorySize  int                         `json:"memSize"`
    32  		Stack       []*math.HexOrDecimal256     `json:"stack"`
    33  		Storage     map[common.Hash]common.Hash `json:"-"`
    34  		Depth       int                         `json:"depth"`
    35  		Err         error                       `json:"-"`
    36  		OpName      string                      `json:"opName"`
    37  		ErrorString string                      `json:"error"`
    38  	}
    39  	var enc StructLog
    40  	enc.Pc = s.Pc
    41  	enc.Op = s.Op
    42  	enc.Gas = math.HexOrDecimal64(s.Gas)
    43  	enc.GasCost = math.HexOrDecimal64(s.GasCost)
    44  	enc.Memory = s.Memory
    45  	enc.MemorySize = s.MemorySize
    46  	if s.Stack != nil {
    47  		enc.Stack = make([]*math.HexOrDecimal256, len(s.Stack))
    48  		for k, v := range s.Stack {
    49  			enc.Stack[k] = (*math.HexOrDecimal256)(v)
    50  		}
    51  	}
    52  	enc.Storage = s.Storage
    53  	enc.Depth = s.Depth
    54  	enc.Err = s.Err
    55  	enc.OpName = s.OpName()
    56  	enc.ErrorString = s.ErrorString()
    57  	return json.Marshal(&enc)
    58  }
    59  
    60  func (s *StructLog) UnmarshalJSON(input []byte) error {
    61  	type StructLog struct {
    62  		Pc         *uint64                     `json:"pc"`
    63  		Op         *OpCode                     `json:"op"`
    64  		Gas        *math.HexOrDecimal64        `json:"gas"`
    65  		GasCost    *math.HexOrDecimal64        `json:"gasCost"`
    66  		Memory     *hexutil.Bytes              `json:"memory"`
    67  		MemorySize *int                        `json:"memSize"`
    68  		Stack      []*math.HexOrDecimal256     `json:"stack"`
    69  		Storage    map[common.Hash]common.Hash `json:"-"`
    70  		Depth      *int                        `json:"depth"`
    71  		Err        error                       `json:"-"`
    72  	}
    73  	var dec StructLog
    74  	if err := json.Unmarshal(input, &dec); err != nil {
    75  		return err
    76  	}
    77  	if dec.Pc != nil {
    78  		s.Pc = *dec.Pc
    79  	}
    80  	if dec.Op != nil {
    81  		s.Op = *dec.Op
    82  	}
    83  	if dec.Gas != nil {
    84  		s.Gas = uint64(*dec.Gas)
    85  	}
    86  	if dec.GasCost != nil {
    87  		s.GasCost = uint64(*dec.GasCost)
    88  	}
    89  	if dec.Memory != nil {
    90  		s.Memory = *dec.Memory
    91  	}
    92  	if dec.MemorySize != nil {
    93  		s.MemorySize = *dec.MemorySize
    94  	}
    95  	if dec.Stack != nil {
    96  		s.Stack = make([]*big.Int, len(dec.Stack))
    97  		for k, v := range dec.Stack {
    98  			s.Stack[k] = (*big.Int)(v)
    99  		}
   100  	}
   101  	if dec.Storage != nil {
   102  		s.Storage = dec.Storage
   103  	}
   104  	if dec.Depth != nil {
   105  		s.Depth = *dec.Depth
   106  	}
   107  	if dec.Err != nil {
   108  		s.Err = dec.Err
   109  	}
   110  	return nil
   111  }