github.com/ethereum/go-ethereum@v1.14.3/tests/gen_sttransaction.go (about)

     1  // Code generated by github.com/fjl/gencodec. DO NOT EDIT.
     2  
     3  package tests
     4  
     5  import (
     6  	"encoding/json"
     7  	"math/big"
     8  
     9  	"github.com/ethereum/go-ethereum/common"
    10  	"github.com/ethereum/go-ethereum/common/hexutil"
    11  	"github.com/ethereum/go-ethereum/common/math"
    12  	"github.com/ethereum/go-ethereum/core/types"
    13  )
    14  
    15  var _ = (*stTransactionMarshaling)(nil)
    16  
    17  // MarshalJSON marshals as JSON.
    18  func (s stTransaction) MarshalJSON() ([]byte, error) {
    19  	type stTransaction struct {
    20  		GasPrice             *math.HexOrDecimal256 `json:"gasPrice"`
    21  		MaxFeePerGas         *math.HexOrDecimal256 `json:"maxFeePerGas"`
    22  		MaxPriorityFeePerGas *math.HexOrDecimal256 `json:"maxPriorityFeePerGas"`
    23  		Nonce                math.HexOrDecimal64   `json:"nonce"`
    24  		To                   string                `json:"to"`
    25  		Data                 []string              `json:"data"`
    26  		AccessLists          []*types.AccessList   `json:"accessLists,omitempty"`
    27  		GasLimit             []math.HexOrDecimal64 `json:"gasLimit"`
    28  		Value                []string              `json:"value"`
    29  		PrivateKey           hexutil.Bytes         `json:"secretKey"`
    30  		Sender               *common.Address       `json:"sender"`
    31  		BlobVersionedHashes  []common.Hash         `json:"blobVersionedHashes,omitempty"`
    32  		BlobGasFeeCap        *math.HexOrDecimal256 `json:"maxFeePerBlobGas,omitempty"`
    33  	}
    34  	var enc stTransaction
    35  	enc.GasPrice = (*math.HexOrDecimal256)(s.GasPrice)
    36  	enc.MaxFeePerGas = (*math.HexOrDecimal256)(s.MaxFeePerGas)
    37  	enc.MaxPriorityFeePerGas = (*math.HexOrDecimal256)(s.MaxPriorityFeePerGas)
    38  	enc.Nonce = math.HexOrDecimal64(s.Nonce)
    39  	enc.To = s.To
    40  	enc.Data = s.Data
    41  	enc.AccessLists = s.AccessLists
    42  	if s.GasLimit != nil {
    43  		enc.GasLimit = make([]math.HexOrDecimal64, len(s.GasLimit))
    44  		for k, v := range s.GasLimit {
    45  			enc.GasLimit[k] = math.HexOrDecimal64(v)
    46  		}
    47  	}
    48  	enc.Value = s.Value
    49  	enc.PrivateKey = s.PrivateKey
    50  	enc.Sender = s.Sender
    51  	enc.BlobVersionedHashes = s.BlobVersionedHashes
    52  	enc.BlobGasFeeCap = (*math.HexOrDecimal256)(s.BlobGasFeeCap)
    53  	return json.Marshal(&enc)
    54  }
    55  
    56  // UnmarshalJSON unmarshals from JSON.
    57  func (s *stTransaction) UnmarshalJSON(input []byte) error {
    58  	type stTransaction struct {
    59  		GasPrice             *math.HexOrDecimal256 `json:"gasPrice"`
    60  		MaxFeePerGas         *math.HexOrDecimal256 `json:"maxFeePerGas"`
    61  		MaxPriorityFeePerGas *math.HexOrDecimal256 `json:"maxPriorityFeePerGas"`
    62  		Nonce                *math.HexOrDecimal64  `json:"nonce"`
    63  		To                   *string               `json:"to"`
    64  		Data                 []string              `json:"data"`
    65  		AccessLists          []*types.AccessList   `json:"accessLists,omitempty"`
    66  		GasLimit             []math.HexOrDecimal64 `json:"gasLimit"`
    67  		Value                []string              `json:"value"`
    68  		PrivateKey           *hexutil.Bytes        `json:"secretKey"`
    69  		Sender               *common.Address       `json:"sender"`
    70  		BlobVersionedHashes  []common.Hash         `json:"blobVersionedHashes,omitempty"`
    71  		BlobGasFeeCap        *math.HexOrDecimal256 `json:"maxFeePerBlobGas,omitempty"`
    72  	}
    73  	var dec stTransaction
    74  	if err := json.Unmarshal(input, &dec); err != nil {
    75  		return err
    76  	}
    77  	if dec.GasPrice != nil {
    78  		s.GasPrice = (*big.Int)(dec.GasPrice)
    79  	}
    80  	if dec.MaxFeePerGas != nil {
    81  		s.MaxFeePerGas = (*big.Int)(dec.MaxFeePerGas)
    82  	}
    83  	if dec.MaxPriorityFeePerGas != nil {
    84  		s.MaxPriorityFeePerGas = (*big.Int)(dec.MaxPriorityFeePerGas)
    85  	}
    86  	if dec.Nonce != nil {
    87  		s.Nonce = uint64(*dec.Nonce)
    88  	}
    89  	if dec.To != nil {
    90  		s.To = *dec.To
    91  	}
    92  	if dec.Data != nil {
    93  		s.Data = dec.Data
    94  	}
    95  	if dec.AccessLists != nil {
    96  		s.AccessLists = dec.AccessLists
    97  	}
    98  	if dec.GasLimit != nil {
    99  		s.GasLimit = make([]uint64, len(dec.GasLimit))
   100  		for k, v := range dec.GasLimit {
   101  			s.GasLimit[k] = uint64(v)
   102  		}
   103  	}
   104  	if dec.Value != nil {
   105  		s.Value = dec.Value
   106  	}
   107  	if dec.PrivateKey != nil {
   108  		s.PrivateKey = *dec.PrivateKey
   109  	}
   110  	if dec.Sender != nil {
   111  		s.Sender = dec.Sender
   112  	}
   113  	if dec.BlobVersionedHashes != nil {
   114  		s.BlobVersionedHashes = dec.BlobVersionedHashes
   115  	}
   116  	if dec.BlobGasFeeCap != nil {
   117  		s.BlobGasFeeCap = (*big.Int)(dec.BlobGasFeeCap)
   118  	}
   119  	return nil
   120  }