github.com/Inphi/go-ethereum@v1.9.7/core/types/gen_tx_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 _ = (*txdataMarshaling)(nil)
    15  
    16  // MarshalJSON marshals as JSON.
    17  func (t txdata) MarshalJSON() ([]byte, error) {
    18  	type txdata struct {
    19  		AccountNonce hexutil.Uint64  `json:"nonce"    gencodec:"required"`
    20  		Price        *hexutil.Big    `json:"gasPrice" gencodec:"required"`
    21  		GasLimit     hexutil.Uint64  `json:"gas"      gencodec:"required"`
    22  		Recipient    *common.Address `json:"to"       rlp:"nil"`
    23  		Amount       *hexutil.Big    `json:"value"    gencodec:"required"`
    24  		Payload      hexutil.Bytes   `json:"input"    gencodec:"required"`
    25  		V            *hexutil.Big    `json:"v" gencodec:"required"`
    26  		R            *hexutil.Big    `json:"r" gencodec:"required"`
    27  		S            *hexutil.Big    `json:"s" gencodec:"required"`
    28  		Hash         *common.Hash    `json:"hash" rlp:"-"`
    29  	}
    30  	var enc txdata
    31  	enc.AccountNonce = hexutil.Uint64(t.AccountNonce)
    32  	enc.Price = (*hexutil.Big)(t.Price)
    33  	enc.GasLimit = hexutil.Uint64(t.GasLimit)
    34  	enc.Recipient = t.Recipient
    35  	enc.Amount = (*hexutil.Big)(t.Amount)
    36  	enc.Payload = t.Payload
    37  	enc.V = (*hexutil.Big)(t.V)
    38  	enc.R = (*hexutil.Big)(t.R)
    39  	enc.S = (*hexutil.Big)(t.S)
    40  	enc.Hash = t.Hash
    41  	return json.Marshal(&enc)
    42  }
    43  
    44  // UnmarshalJSON unmarshals from JSON.
    45  func (t *txdata) UnmarshalJSON(input []byte) error {
    46  	type txdata struct {
    47  		AccountNonce *hexutil.Uint64 `json:"nonce"    gencodec:"required"`
    48  		Price        *hexutil.Big    `json:"gasPrice" gencodec:"required"`
    49  		GasLimit     *hexutil.Uint64 `json:"gas"      gencodec:"required"`
    50  		Recipient    *common.Address `json:"to"       rlp:"nil"`
    51  		Amount       *hexutil.Big    `json:"value"    gencodec:"required"`
    52  		Payload      *hexutil.Bytes  `json:"input"    gencodec:"required"`
    53  		V            *hexutil.Big    `json:"v" gencodec:"required"`
    54  		R            *hexutil.Big    `json:"r" gencodec:"required"`
    55  		S            *hexutil.Big    `json:"s" gencodec:"required"`
    56  		Hash         *common.Hash    `json:"hash" rlp:"-"`
    57  	}
    58  	var dec txdata
    59  	if err := json.Unmarshal(input, &dec); err != nil {
    60  		return err
    61  	}
    62  	if dec.AccountNonce == nil {
    63  		return errors.New("missing required field 'nonce' for txdata")
    64  	}
    65  	t.AccountNonce = uint64(*dec.AccountNonce)
    66  	if dec.Price == nil {
    67  		return errors.New("missing required field 'gasPrice' for txdata")
    68  	}
    69  	t.Price = (*big.Int)(dec.Price)
    70  	if dec.GasLimit == nil {
    71  		return errors.New("missing required field 'gas' for txdata")
    72  	}
    73  	t.GasLimit = uint64(*dec.GasLimit)
    74  	if dec.Recipient != nil {
    75  		t.Recipient = dec.Recipient
    76  	}
    77  	if dec.Amount == nil {
    78  		return errors.New("missing required field 'value' for txdata")
    79  	}
    80  	t.Amount = (*big.Int)(dec.Amount)
    81  	if dec.Payload == nil {
    82  		return errors.New("missing required field 'input' for txdata")
    83  	}
    84  	t.Payload = *dec.Payload
    85  	if dec.V == nil {
    86  		return errors.New("missing required field 'v' for txdata")
    87  	}
    88  	t.V = (*big.Int)(dec.V)
    89  	if dec.R == nil {
    90  		return errors.New("missing required field 'r' for txdata")
    91  	}
    92  	t.R = (*big.Int)(dec.R)
    93  	if dec.S == nil {
    94  		return errors.New("missing required field 's' for txdata")
    95  	}
    96  	t.S = (*big.Int)(dec.S)
    97  	if dec.Hash != nil {
    98  		t.Hash = dec.Hash
    99  	}
   100  	return nil
   101  }