github.com/AlohaMobile/go-ethereum@v1.9.7/core/types/gen_receipt_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  	"math/big"
     9  
    10  	"github.com/ethereum/go-ethereum/common"
    11  	"github.com/ethereum/go-ethereum/common/hexutil"
    12  )
    13  
    14  var _ = (*receiptMarshaling)(nil)
    15  
    16  // MarshalJSON marshals as JSON.
    17  func (r Receipt) MarshalJSON() ([]byte, error) {
    18  	type Receipt struct {
    19  		PostState         hexutil.Bytes  `json:"root"`
    20  		Status            hexutil.Uint64 `json:"status"`
    21  		CumulativeGasUsed hexutil.Uint64 `json:"cumulativeGasUsed" gencodec:"required"`
    22  		Bloom             Bloom          `json:"logsBloom"         gencodec:"required"`
    23  		Logs              []*Log         `json:"logs"              gencodec:"required"`
    24  		TxHash            common.Hash    `json:"transactionHash" gencodec:"required"`
    25  		ContractAddress   common.Address `json:"contractAddress"`
    26  		GasUsed           hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
    27  		BlockHash         common.Hash    `json:"blockHash,omitempty"`
    28  		BlockNumber       *hexutil.Big   `json:"blockNumber,omitempty"`
    29  		TransactionIndex  hexutil.Uint   `json:"transactionIndex"`
    30  	}
    31  	var enc Receipt
    32  	enc.PostState = r.PostState
    33  	enc.Status = hexutil.Uint64(r.Status)
    34  	enc.CumulativeGasUsed = hexutil.Uint64(r.CumulativeGasUsed)
    35  	enc.Bloom = r.Bloom
    36  	enc.Logs = r.Logs
    37  	enc.TxHash = r.TxHash
    38  	enc.ContractAddress = r.ContractAddress
    39  	enc.GasUsed = hexutil.Uint64(r.GasUsed)
    40  	enc.BlockHash = r.BlockHash
    41  	enc.BlockNumber = (*hexutil.Big)(r.BlockNumber)
    42  	enc.TransactionIndex = hexutil.Uint(r.TransactionIndex)
    43  	return json.Marshal(&enc)
    44  }
    45  
    46  // UnmarshalJSON unmarshals from JSON.
    47  func (r *Receipt) UnmarshalJSON(input []byte) error {
    48  	type Receipt struct {
    49  		PostState         *hexutil.Bytes  `json:"root"`
    50  		Status            *hexutil.Uint64 `json:"status"`
    51  		CumulativeGasUsed *hexutil.Uint64 `json:"cumulativeGasUsed" gencodec:"required"`
    52  		Bloom             *Bloom          `json:"logsBloom"         gencodec:"required"`
    53  		Logs              []*Log          `json:"logs"              gencodec:"required"`
    54  		TxHash            *common.Hash    `json:"transactionHash" gencodec:"required"`
    55  		ContractAddress   *common.Address `json:"contractAddress"`
    56  		GasUsed           *hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
    57  		BlockHash         *common.Hash    `json:"blockHash,omitempty"`
    58  		BlockNumber       *hexutil.Big    `json:"blockNumber,omitempty"`
    59  		TransactionIndex  *hexutil.Uint   `json:"transactionIndex"`
    60  	}
    61  	var dec Receipt
    62  	if err := json.Unmarshal(input, &dec); err != nil {
    63  		return err
    64  	}
    65  	if dec.PostState != nil {
    66  		r.PostState = *dec.PostState
    67  	}
    68  	if dec.Status != nil {
    69  		r.Status = uint64(*dec.Status)
    70  	}
    71  	if dec.CumulativeGasUsed == nil {
    72  		return errors.New("missing required field 'cumulativeGasUsed' for Receipt")
    73  	}
    74  	r.CumulativeGasUsed = uint64(*dec.CumulativeGasUsed)
    75  	if dec.Bloom == nil {
    76  		return errors.New("missing required field 'logsBloom' for Receipt")
    77  	}
    78  	r.Bloom = *dec.Bloom
    79  	if dec.Logs == nil {
    80  		return errors.New("missing required field 'logs' for Receipt")
    81  	}
    82  	r.Logs = dec.Logs
    83  	if dec.TxHash == nil {
    84  		return errors.New("missing required field 'transactionHash' for Receipt")
    85  	}
    86  	r.TxHash = *dec.TxHash
    87  	if dec.ContractAddress != nil {
    88  		r.ContractAddress = *dec.ContractAddress
    89  	}
    90  	if dec.GasUsed == nil {
    91  		return errors.New("missing required field 'gasUsed' for Receipt")
    92  	}
    93  	r.GasUsed = uint64(*dec.GasUsed)
    94  	if dec.BlockHash != nil {
    95  		r.BlockHash = *dec.BlockHash
    96  	}
    97  	if dec.BlockNumber != nil {
    98  		r.BlockNumber = (*big.Int)(dec.BlockNumber)
    99  	}
   100  	if dec.TransactionIndex != nil {
   101  		r.TransactionIndex = uint(*dec.TransactionIndex)
   102  	}
   103  	return nil
   104  }