github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/core/vm/gen_structlog.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 19:16:36</date>
    10  //</624450082363674624>
    11  
    12  //代码由github.com/fjl/gencodec生成。不要编辑。
    13  
    14  package vm
    15  
    16  import (
    17  	"encoding/json"
    18  	"math/big"
    19  
    20  	"github.com/ethereum/go-ethereum/common"
    21  	"github.com/ethereum/go-ethereum/common/hexutil"
    22  	"github.com/ethereum/go-ethereum/common/math"
    23  )
    24  
    25  var _ = (*structLogMarshaling)(nil)
    26  
    27  //marshaljson封送为json。
    28  func (s StructLog) MarshalJSON() ([]byte, error) {
    29  	type StructLog struct {
    30  		Pc            uint64                      `json:"pc"`
    31  		Op            OpCode                      `json:"op"`
    32  		Gas           math.HexOrDecimal64         `json:"gas"`
    33  		GasCost       math.HexOrDecimal64         `json:"gasCost"`
    34  		Memory        hexutil.Bytes               `json:"memory"`
    35  		MemorySize    int                         `json:"memSize"`
    36  		Stack         []*math.HexOrDecimal256     `json:"stack"`
    37  		Storage       map[common.Hash]common.Hash `json:"-"`
    38  		Depth         int                         `json:"depth"`
    39  		RefundCounter uint64                      `json:"refund"`
    40  		Err           error                       `json:"-"`
    41  		OpName        string                      `json:"opName"`
    42  		ErrorString   string                      `json:"error"`
    43  	}
    44  	var enc StructLog
    45  	enc.Pc = s.Pc
    46  	enc.Op = s.Op
    47  	enc.Gas = math.HexOrDecimal64(s.Gas)
    48  	enc.GasCost = math.HexOrDecimal64(s.GasCost)
    49  	enc.Memory = s.Memory
    50  	enc.MemorySize = s.MemorySize
    51  	if s.Stack != nil {
    52  		enc.Stack = make([]*math.HexOrDecimal256, len(s.Stack))
    53  		for k, v := range s.Stack {
    54  			enc.Stack[k] = (*math.HexOrDecimal256)(v)
    55  		}
    56  	}
    57  	enc.Storage = s.Storage
    58  	enc.Depth = s.Depth
    59  	enc.RefundCounter = s.RefundCounter
    60  	enc.Err = s.Err
    61  	enc.OpName = s.OpName()
    62  	enc.ErrorString = s.ErrorString()
    63  	return json.Marshal(&enc)
    64  }
    65  
    66  //取消标记JSON取消标记JSON。
    67  func (s *StructLog) UnmarshalJSON(input []byte) error {
    68  	type StructLog struct {
    69  		Pc            *uint64                     `json:"pc"`
    70  		Op            *OpCode                     `json:"op"`
    71  		Gas           *math.HexOrDecimal64        `json:"gas"`
    72  		GasCost       *math.HexOrDecimal64        `json:"gasCost"`
    73  		Memory        *hexutil.Bytes              `json:"memory"`
    74  		MemorySize    *int                        `json:"memSize"`
    75  		Stack         []*math.HexOrDecimal256     `json:"stack"`
    76  		Storage       map[common.Hash]common.Hash `json:"-"`
    77  		Depth         *int                        `json:"depth"`
    78  		RefundCounter *uint64                     `json:"refund"`
    79  		Err           error                       `json:"-"`
    80  	}
    81  	var dec StructLog
    82  	if err := json.Unmarshal(input, &dec); err != nil {
    83  		return err
    84  	}
    85  	if dec.Pc != nil {
    86  		s.Pc = *dec.Pc
    87  	}
    88  	if dec.Op != nil {
    89  		s.Op = *dec.Op
    90  	}
    91  	if dec.Gas != nil {
    92  		s.Gas = uint64(*dec.Gas)
    93  	}
    94  	if dec.GasCost != nil {
    95  		s.GasCost = uint64(*dec.GasCost)
    96  	}
    97  	if dec.Memory != nil {
    98  		s.Memory = *dec.Memory
    99  	}
   100  	if dec.MemorySize != nil {
   101  		s.MemorySize = *dec.MemorySize
   102  	}
   103  	if dec.Stack != nil {
   104  		s.Stack = make([]*big.Int, len(dec.Stack))
   105  		for k, v := range dec.Stack {
   106  			s.Stack[k] = (*big.Int)(v)
   107  		}
   108  	}
   109  	if dec.Storage != nil {
   110  		s.Storage = dec.Storage
   111  	}
   112  	if dec.Depth != nil {
   113  		s.Depth = *dec.Depth
   114  	}
   115  	if dec.RefundCounter != nil {
   116  		s.RefundCounter = *dec.RefundCounter
   117  	}
   118  	if dec.Err != nil {
   119  		s.Err = dec.Err
   120  	}
   121  	return nil
   122  }
   123