github.com/ethw3/go-ethereuma@v0.0.0-20221013053120-c14602a4c23c/core/types/dynamic_fee_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 type DynamicFeeTx struct { 26 ChainID *big.Int 27 Nonce uint64 28 GasTipCap *big.Int // a.k.a. maxPriorityFeePerGas 29 GasFeeCap *big.Int // a.k.a. maxFeePerGas 30 Gas uint64 31 To *common.Address `rlp:"nil"` // nil means contract creation 32 Value *big.Int 33 Data []byte 34 AccessList AccessList 35 36 // Signature values 37 V *big.Int `json:"v" gencodec:"required"` 38 R *big.Int `json:"r" gencodec:"required"` 39 S *big.Int `json:"s" gencodec:"required"` 40 } 41 42 // copy creates a deep copy of the transaction data and initializes all fields. 43 func (tx *DynamicFeeTx) copy() TxData { 44 cpy := &DynamicFeeTx{ 45 Nonce: tx.Nonce, 46 To: copyAddressPtr(tx.To), 47 Data: common.CopyBytes(tx.Data), 48 Gas: tx.Gas, 49 // These are copied below. 50 AccessList: make(AccessList, len(tx.AccessList)), 51 Value: new(big.Int), 52 ChainID: new(big.Int), 53 GasTipCap: new(big.Int), 54 GasFeeCap: new(big.Int), 55 V: new(big.Int), 56 R: new(big.Int), 57 S: new(big.Int), 58 } 59 copy(cpy.AccessList, tx.AccessList) 60 if tx.Value != nil { 61 cpy.Value.Set(tx.Value) 62 } 63 if tx.ChainID != nil { 64 cpy.ChainID.Set(tx.ChainID) 65 } 66 if tx.GasTipCap != nil { 67 cpy.GasTipCap.Set(tx.GasTipCap) 68 } 69 if tx.GasFeeCap != nil { 70 cpy.GasFeeCap.Set(tx.GasFeeCap) 71 } 72 if tx.V != nil { 73 cpy.V.Set(tx.V) 74 } 75 if tx.R != nil { 76 cpy.R.Set(tx.R) 77 } 78 if tx.S != nil { 79 cpy.S.Set(tx.S) 80 } 81 return cpy 82 } 83 84 // accessors for innerTx. 85 func (tx *DynamicFeeTx) txType() byte { return DynamicFeeTxType } 86 func (tx *DynamicFeeTx) chainID() *big.Int { return tx.ChainID } 87 func (tx *DynamicFeeTx) accessList() AccessList { return tx.AccessList } 88 func (tx *DynamicFeeTx) data() []byte { return tx.Data } 89 func (tx *DynamicFeeTx) gas() uint64 { return tx.Gas } 90 func (tx *DynamicFeeTx) gasFeeCap() *big.Int { return tx.GasFeeCap } 91 func (tx *DynamicFeeTx) gasTipCap() *big.Int { return tx.GasTipCap } 92 func (tx *DynamicFeeTx) gasPrice() *big.Int { return tx.GasFeeCap } 93 func (tx *DynamicFeeTx) value() *big.Int { return tx.Value } 94 func (tx *DynamicFeeTx) nonce() uint64 { return tx.Nonce } 95 func (tx *DynamicFeeTx) to() *common.Address { return tx.To } 96 97 func (tx *DynamicFeeTx) rawSignatureValues() (v, r, s *big.Int) { 98 return tx.V, tx.R, tx.S 99 } 100 101 func (tx *DynamicFeeTx) setSignatureValues(chainID, v, r, s *big.Int) { 102 tx.ChainID, tx.V, tx.R, tx.S = chainID, v, r, s 103 }