github.com/YoungNK/go-ethereum@v1.9.7/core/types/gen_log_json.go (about)

     1  // Code generated by github.com/fjl/gencodec. DO NOT EDIT.
     2  
     3  package types
     4  
     5  import (
     6  	"encoding/json"
     7  	"errors"
     8  
     9  	"github.com/ethereum/go-ethereum/common"
    10  	"github.com/ethereum/go-ethereum/common/hexutil"
    11  )
    12  
    13  var _ = (*logMarshaling)(nil)
    14  
    15  // MarshalJSON marshals as JSON.
    16  func (l Log) MarshalJSON() ([]byte, error) {
    17  	type Log struct {
    18  		Address     common.Address `json:"address" gencodec:"required"`
    19  		Topics      []common.Hash  `json:"topics" gencodec:"required"`
    20  		Data        hexutil.Bytes  `json:"data" gencodec:"required"`
    21  		BlockNumber hexutil.Uint64 `json:"blockNumber"`
    22  		TxHash      common.Hash    `json:"transactionHash" gencodec:"required"`
    23  		TxIndex     hexutil.Uint   `json:"transactionIndex" gencodec:"required"`
    24  		BlockHash   common.Hash    `json:"blockHash"`
    25  		Index       hexutil.Uint   `json:"logIndex" gencodec:"required"`
    26  		Removed     bool           `json:"removed"`
    27  	}
    28  	var enc Log
    29  	enc.Address = l.Address
    30  	enc.Topics = l.Topics
    31  	enc.Data = l.Data
    32  	enc.BlockNumber = hexutil.Uint64(l.BlockNumber)
    33  	enc.TxHash = l.TxHash
    34  	enc.TxIndex = hexutil.Uint(l.TxIndex)
    35  	enc.BlockHash = l.BlockHash
    36  	enc.Index = hexutil.Uint(l.Index)
    37  	enc.Removed = l.Removed
    38  	return json.Marshal(&enc)
    39  }
    40  
    41  // UnmarshalJSON unmarshals from JSON.
    42  func (l *Log) UnmarshalJSON(input []byte) error {
    43  	type Log struct {
    44  		Address     *common.Address `json:"address" gencodec:"required"`
    45  		Topics      []common.Hash   `json:"topics" gencodec:"required"`
    46  		Data        *hexutil.Bytes  `json:"data" gencodec:"required"`
    47  		BlockNumber *hexutil.Uint64 `json:"blockNumber"`
    48  		TxHash      *common.Hash    `json:"transactionHash" gencodec:"required"`
    49  		TxIndex     *hexutil.Uint   `json:"transactionIndex" gencodec:"required"`
    50  		BlockHash   *common.Hash    `json:"blockHash"`
    51  		Index       *hexutil.Uint   `json:"logIndex" gencodec:"required"`
    52  		Removed     *bool           `json:"removed"`
    53  	}
    54  	var dec Log
    55  	if err := json.Unmarshal(input, &dec); err != nil {
    56  		return err
    57  	}
    58  	if dec.Address == nil {
    59  		return errors.New("missing required field 'address' for Log")
    60  	}
    61  	l.Address = *dec.Address
    62  	if dec.Topics == nil {
    63  		return errors.New("missing required field 'topics' for Log")
    64  	}
    65  	l.Topics = dec.Topics
    66  	if dec.Data == nil {
    67  		return errors.New("missing required field 'data' for Log")
    68  	}
    69  	l.Data = *dec.Data
    70  	if dec.BlockNumber != nil {
    71  		l.BlockNumber = uint64(*dec.BlockNumber)
    72  	}
    73  	if dec.TxHash == nil {
    74  		return errors.New("missing required field 'transactionHash' for Log")
    75  	}
    76  	l.TxHash = *dec.TxHash
    77  	if dec.TxIndex == nil {
    78  		return errors.New("missing required field 'transactionIndex' for Log")
    79  	}
    80  	l.TxIndex = uint(*dec.TxIndex)
    81  	if dec.BlockHash != nil {
    82  		l.BlockHash = *dec.BlockHash
    83  	}
    84  	if dec.Index == nil {
    85  		return errors.New("missing required field 'logIndex' for Log")
    86  	}
    87  	l.Index = uint(*dec.Index)
    88  	if dec.Removed != nil {
    89  		l.Removed = *dec.Removed
    90  	}
    91  	return nil
    92  }