github.com/beyonderyue/gochain@v2.2.26+incompatible/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  
     9  	"github.com/gochain-io/gochain/common"
    10  	"github.com/gochain-io/gochain/common/hexutil"
    11  )
    12  
    13  var _ = (*receiptMarshaling)(nil)
    14  
    15  // MarshalJSON marshals as JSON.
    16  func (r Receipt) MarshalJSON() ([]byte, error) {
    17  	type Receipt struct {
    18  		PostState         hexutil.Bytes  `json:"root"`
    19  		Status            hexutil.Uint64 `json:"status"`
    20  		CumulativeGasUsed hexutil.Uint64 `json:"cumulativeGasUsed" gencodec:"required"`
    21  		Bloom             Bloom          `json:"logsBloom"         gencodec:"required"`
    22  		Logs              []*Log         `json:"logs"              gencodec:"required"`
    23  		TxHash            common.Hash    `json:"transactionHash" gencodec:"required"`
    24  		ContractAddress   common.Address `json:"contractAddress"`
    25  		GasUsed           hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
    26  	}
    27  	var enc Receipt
    28  	enc.PostState = r.PostState
    29  	enc.Status = hexutil.Uint64(r.Status)
    30  	enc.CumulativeGasUsed = hexutil.Uint64(r.CumulativeGasUsed)
    31  	enc.Bloom = r.Bloom
    32  	enc.Logs = r.Logs
    33  	enc.TxHash = r.TxHash
    34  	enc.ContractAddress = r.ContractAddress
    35  	enc.GasUsed = hexutil.Uint64(r.GasUsed)
    36  	return json.Marshal(&enc)
    37  }
    38  
    39  // UnmarshalJSON unmarshals from JSON.
    40  func (r *Receipt) UnmarshalJSON(input []byte) error {
    41  	type Receipt struct {
    42  		PostState         *hexutil.Bytes  `json:"root"`
    43  		Status            *hexutil.Uint64 `json:"status"`
    44  		CumulativeGasUsed *hexutil.Uint64 `json:"cumulativeGasUsed" gencodec:"required"`
    45  		Bloom             *Bloom          `json:"logsBloom"         gencodec:"required"`
    46  		Logs              []*Log          `json:"logs"              gencodec:"required"`
    47  		TxHash            *common.Hash    `json:"transactionHash" gencodec:"required"`
    48  		ContractAddress   *common.Address `json:"contractAddress"`
    49  		GasUsed           *hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
    50  	}
    51  	var dec Receipt
    52  	if err := json.Unmarshal(input, &dec); err != nil {
    53  		return err
    54  	}
    55  	if dec.PostState != nil {
    56  		r.PostState = *dec.PostState
    57  	}
    58  	if dec.Status != nil {
    59  		r.Status = uint64(*dec.Status)
    60  	}
    61  	if dec.CumulativeGasUsed == nil {
    62  		return errors.New("missing required field 'cumulativeGasUsed' for Receipt")
    63  	}
    64  	r.CumulativeGasUsed = uint64(*dec.CumulativeGasUsed)
    65  	if dec.Bloom == nil {
    66  		return errors.New("missing required field 'logsBloom' for Receipt")
    67  	}
    68  	r.Bloom = *dec.Bloom
    69  	if dec.Logs == nil {
    70  		return errors.New("missing required field 'logs' for Receipt")
    71  	}
    72  	r.Logs = dec.Logs
    73  	if dec.TxHash == nil {
    74  		return errors.New("missing required field 'transactionHash' for Receipt")
    75  	}
    76  	r.TxHash = *dec.TxHash
    77  	if dec.ContractAddress != nil {
    78  		r.ContractAddress = *dec.ContractAddress
    79  	}
    80  	if dec.GasUsed == nil {
    81  		return errors.New("missing required field 'gasUsed' for Receipt")
    82  	}
    83  	r.GasUsed = uint64(*dec.GasUsed)
    84  	return nil
    85  }