github.com/ethereum/go-ethereum@v1.16.1/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  		AuthorizationList    []*stAuthorization    `json:"authorizationList,omitempty"`
    34  	}
    35  	var enc stTransaction
    36  	enc.GasPrice = (*math.HexOrDecimal256)(s.GasPrice)
    37  	enc.MaxFeePerGas = (*math.HexOrDecimal256)(s.MaxFeePerGas)
    38  	enc.MaxPriorityFeePerGas = (*math.HexOrDecimal256)(s.MaxPriorityFeePerGas)
    39  	enc.Nonce = math.HexOrDecimal64(s.Nonce)
    40  	enc.To = s.To
    41  	enc.Data = s.Data
    42  	enc.AccessLists = s.AccessLists
    43  	if s.GasLimit != nil {
    44  		enc.GasLimit = make([]math.HexOrDecimal64, len(s.GasLimit))
    45  		for k, v := range s.GasLimit {
    46  			enc.GasLimit[k] = math.HexOrDecimal64(v)
    47  		}
    48  	}
    49  	enc.Value = s.Value
    50  	enc.PrivateKey = s.PrivateKey
    51  	enc.Sender = s.Sender
    52  	enc.BlobVersionedHashes = s.BlobVersionedHashes
    53  	enc.BlobGasFeeCap = (*math.HexOrDecimal256)(s.BlobGasFeeCap)
    54  	enc.AuthorizationList = s.AuthorizationList
    55  	return json.Marshal(&enc)
    56  }
    57  
    58  // UnmarshalJSON unmarshals from JSON.
    59  func (s *stTransaction) UnmarshalJSON(input []byte) error {
    60  	type stTransaction struct {
    61  		GasPrice             *math.HexOrDecimal256 `json:"gasPrice"`
    62  		MaxFeePerGas         *math.HexOrDecimal256 `json:"maxFeePerGas"`
    63  		MaxPriorityFeePerGas *math.HexOrDecimal256 `json:"maxPriorityFeePerGas"`
    64  		Nonce                *math.HexOrDecimal64  `json:"nonce"`
    65  		To                   *string               `json:"to"`
    66  		Data                 []string              `json:"data"`
    67  		AccessLists          []*types.AccessList   `json:"accessLists,omitempty"`
    68  		GasLimit             []math.HexOrDecimal64 `json:"gasLimit"`
    69  		Value                []string              `json:"value"`
    70  		PrivateKey           *hexutil.Bytes        `json:"secretKey"`
    71  		Sender               *common.Address       `json:"sender"`
    72  		BlobVersionedHashes  []common.Hash         `json:"blobVersionedHashes,omitempty"`
    73  		BlobGasFeeCap        *math.HexOrDecimal256 `json:"maxFeePerBlobGas,omitempty"`
    74  		AuthorizationList    []*stAuthorization    `json:"authorizationList,omitempty"`
    75  	}
    76  	var dec stTransaction
    77  	if err := json.Unmarshal(input, &dec); err != nil {
    78  		return err
    79  	}
    80  	if dec.GasPrice != nil {
    81  		s.GasPrice = (*big.Int)(dec.GasPrice)
    82  	}
    83  	if dec.MaxFeePerGas != nil {
    84  		s.MaxFeePerGas = (*big.Int)(dec.MaxFeePerGas)
    85  	}
    86  	if dec.MaxPriorityFeePerGas != nil {
    87  		s.MaxPriorityFeePerGas = (*big.Int)(dec.MaxPriorityFeePerGas)
    88  	}
    89  	if dec.Nonce != nil {
    90  		s.Nonce = uint64(*dec.Nonce)
    91  	}
    92  	if dec.To != nil {
    93  		s.To = *dec.To
    94  	}
    95  	if dec.Data != nil {
    96  		s.Data = dec.Data
    97  	}
    98  	if dec.AccessLists != nil {
    99  		s.AccessLists = dec.AccessLists
   100  	}
   101  	if dec.GasLimit != nil {
   102  		s.GasLimit = make([]uint64, len(dec.GasLimit))
   103  		for k, v := range dec.GasLimit {
   104  			s.GasLimit[k] = uint64(v)
   105  		}
   106  	}
   107  	if dec.Value != nil {
   108  		s.Value = dec.Value
   109  	}
   110  	if dec.PrivateKey != nil {
   111  		s.PrivateKey = *dec.PrivateKey
   112  	}
   113  	if dec.Sender != nil {
   114  		s.Sender = dec.Sender
   115  	}
   116  	if dec.BlobVersionedHashes != nil {
   117  		s.BlobVersionedHashes = dec.BlobVersionedHashes
   118  	}
   119  	if dec.BlobGasFeeCap != nil {
   120  		s.BlobGasFeeCap = (*big.Int)(dec.BlobGasFeeCap)
   121  	}
   122  	if dec.AuthorizationList != nil {
   123  		s.AuthorizationList = dec.AuthorizationList
   124  	}
   125  	return nil
   126  }