github.com/ethw3/go-ethereuma@v0.0.0-20221013053120-c14602a4c23c/core/types/access_list_tx.go (about)

     1  // Copyright 2021 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package types
    18  
    19  import (
    20  	"math/big"
    21  
    22  	"github.com/ethw3/go-ethereuma/common"
    23  )
    24  
    25  //go:generate go run github.com/fjl/gencodec -type AccessTuple -out gen_access_tuple.go
    26  
    27  // AccessList is an EIP-2930 access list.
    28  type AccessList []AccessTuple
    29  
    30  // AccessTuple is the element type of an access list.
    31  type AccessTuple struct {
    32  	Address     common.Address `json:"address"        gencodec:"required"`
    33  	StorageKeys []common.Hash  `json:"storageKeys"    gencodec:"required"`
    34  }
    35  
    36  // StorageKeys returns the total number of storage keys in the access list.
    37  func (al AccessList) StorageKeys() int {
    38  	sum := 0
    39  	for _, tuple := range al {
    40  		sum += len(tuple.StorageKeys)
    41  	}
    42  	return sum
    43  }
    44  
    45  // AccessListTx is the data of EIP-2930 access list transactions.
    46  type AccessListTx struct {
    47  	ChainID    *big.Int        // destination chain ID
    48  	Nonce      uint64          // nonce of sender account
    49  	GasPrice   *big.Int        // wei per gas
    50  	Gas        uint64          // gas limit
    51  	To         *common.Address `rlp:"nil"` // nil means contract creation
    52  	Value      *big.Int        // wei amount
    53  	Data       []byte          // contract invocation input data
    54  	AccessList AccessList      // EIP-2930 access list
    55  	V, R, S    *big.Int        // signature values
    56  }
    57  
    58  // copy creates a deep copy of the transaction data and initializes all fields.
    59  func (tx *AccessListTx) copy() TxData {
    60  	cpy := &AccessListTx{
    61  		Nonce: tx.Nonce,
    62  		To:    copyAddressPtr(tx.To),
    63  		Data:  common.CopyBytes(tx.Data),
    64  		Gas:   tx.Gas,
    65  		// These are copied below.
    66  		AccessList: make(AccessList, len(tx.AccessList)),
    67  		Value:      new(big.Int),
    68  		ChainID:    new(big.Int),
    69  		GasPrice:   new(big.Int),
    70  		V:          new(big.Int),
    71  		R:          new(big.Int),
    72  		S:          new(big.Int),
    73  	}
    74  	copy(cpy.AccessList, tx.AccessList)
    75  	if tx.Value != nil {
    76  		cpy.Value.Set(tx.Value)
    77  	}
    78  	if tx.ChainID != nil {
    79  		cpy.ChainID.Set(tx.ChainID)
    80  	}
    81  	if tx.GasPrice != nil {
    82  		cpy.GasPrice.Set(tx.GasPrice)
    83  	}
    84  	if tx.V != nil {
    85  		cpy.V.Set(tx.V)
    86  	}
    87  	if tx.R != nil {
    88  		cpy.R.Set(tx.R)
    89  	}
    90  	if tx.S != nil {
    91  		cpy.S.Set(tx.S)
    92  	}
    93  	return cpy
    94  }
    95  
    96  // accessors for innerTx.
    97  func (tx *AccessListTx) txType() byte           { return AccessListTxType }
    98  func (tx *AccessListTx) chainID() *big.Int      { return tx.ChainID }
    99  func (tx *AccessListTx) accessList() AccessList { return tx.AccessList }
   100  func (tx *AccessListTx) data() []byte           { return tx.Data }
   101  func (tx *AccessListTx) gas() uint64            { return tx.Gas }
   102  func (tx *AccessListTx) gasPrice() *big.Int     { return tx.GasPrice }
   103  func (tx *AccessListTx) gasTipCap() *big.Int    { return tx.GasPrice }
   104  func (tx *AccessListTx) gasFeeCap() *big.Int    { return tx.GasPrice }
   105  func (tx *AccessListTx) value() *big.Int        { return tx.Value }
   106  func (tx *AccessListTx) nonce() uint64          { return tx.Nonce }
   107  func (tx *AccessListTx) to() *common.Address    { return tx.To }
   108  
   109  func (tx *AccessListTx) rawSignatureValues() (v, r, s *big.Int) {
   110  	return tx.V, tx.R, tx.S
   111  }
   112  
   113  func (tx *AccessListTx) setSignatureValues(chainID, v, r, s *big.Int) {
   114  	tx.ChainID, tx.V, tx.R, tx.S = chainID, v, r, s
   115  }