|
| 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/celo-org/celo-blockchain/common" |
| 23 | +) |
| 24 | + |
| 25 | +type CeloDynamicFeeTx struct { |
| 26 | + ChainID *big.Int |
| 27 | + Nonce uint64 |
| 28 | + GasTipCap *big.Int |
| 29 | + GasFeeCap *big.Int |
| 30 | + Gas uint64 |
| 31 | + FeeCurrency *common.Address `rlp:"nil"` // nil means native currency |
| 32 | + GatewayFeeRecipient *common.Address `rlp:"nil"` // nil means no gateway fee is paid |
| 33 | + GatewayFee *big.Int `rlp:"nil"` |
| 34 | + To *common.Address `rlp:"nil"` // nil means contract creation |
| 35 | + Value *big.Int |
| 36 | + Data []byte |
| 37 | + AccessList AccessList |
| 38 | + |
| 39 | + // Signature values |
| 40 | + V *big.Int `json:"v" gencodec:"required"` |
| 41 | + R *big.Int `json:"r" gencodec:"required"` |
| 42 | + S *big.Int `json:"s" gencodec:"required"` |
| 43 | +} |
| 44 | + |
| 45 | +// copy creates a deep copy of the transaction data and initializes all fields. |
| 46 | +func (tx *CeloDynamicFeeTx) copy() TxData { |
| 47 | + cpy := &CeloDynamicFeeTx{ |
| 48 | + Nonce: tx.Nonce, |
| 49 | + To: tx.To, // TODO: copy pointed-to address |
| 50 | + Data: common.CopyBytes(tx.Data), |
| 51 | + Gas: tx.Gas, |
| 52 | + FeeCurrency: tx.FeeCurrency, |
| 53 | + GatewayFeeRecipient: tx.GatewayFeeRecipient, |
| 54 | + // These are copied below. |
| 55 | + AccessList: make(AccessList, len(tx.AccessList)), |
| 56 | + GatewayFee: new(big.Int), |
| 57 | + Value: new(big.Int), |
| 58 | + ChainID: new(big.Int), |
| 59 | + GasTipCap: new(big.Int), |
| 60 | + GasFeeCap: new(big.Int), |
| 61 | + V: new(big.Int), |
| 62 | + R: new(big.Int), |
| 63 | + S: new(big.Int), |
| 64 | + } |
| 65 | + copy(cpy.AccessList, tx.AccessList) |
| 66 | + if tx.Value != nil { |
| 67 | + cpy.Value.Set(tx.Value) |
| 68 | + } |
| 69 | + if tx.ChainID != nil { |
| 70 | + cpy.ChainID.Set(tx.ChainID) |
| 71 | + } |
| 72 | + if tx.GasTipCap != nil { |
| 73 | + cpy.GasTipCap.Set(tx.GasTipCap) |
| 74 | + } |
| 75 | + if tx.GasFeeCap != nil { |
| 76 | + cpy.GasFeeCap.Set(tx.GasFeeCap) |
| 77 | + } |
| 78 | + if tx.GatewayFee != nil { |
| 79 | + cpy.GatewayFee.Set(tx.GatewayFee) |
| 80 | + } |
| 81 | + if tx.V != nil { |
| 82 | + cpy.V.Set(tx.V) |
| 83 | + } |
| 84 | + if tx.R != nil { |
| 85 | + cpy.R.Set(tx.R) |
| 86 | + } |
| 87 | + if tx.S != nil { |
| 88 | + cpy.S.Set(tx.S) |
| 89 | + } |
| 90 | + return cpy |
| 91 | +} |
| 92 | + |
| 93 | +// accessors for innerTx. |
| 94 | +func (tx *CeloDynamicFeeTx) txType() byte { return CeloDynamicFeeTxType } |
| 95 | +func (tx *CeloDynamicFeeTx) chainID() *big.Int { return tx.ChainID } |
| 96 | +func (tx *CeloDynamicFeeTx) protected() bool { return true } |
| 97 | +func (tx *CeloDynamicFeeTx) accessList() AccessList { return tx.AccessList } |
| 98 | +func (tx *CeloDynamicFeeTx) data() []byte { return tx.Data } |
| 99 | +func (tx *CeloDynamicFeeTx) gas() uint64 { return tx.Gas } |
| 100 | +func (tx *CeloDynamicFeeTx) gasFeeCap() *big.Int { return tx.GasFeeCap } |
| 101 | +func (tx *CeloDynamicFeeTx) gasTipCap() *big.Int { return tx.GasTipCap } |
| 102 | +func (tx *CeloDynamicFeeTx) gasPrice() *big.Int { return tx.GasFeeCap } |
| 103 | +func (tx *CeloDynamicFeeTx) value() *big.Int { return tx.Value } |
| 104 | +func (tx *CeloDynamicFeeTx) nonce() uint64 { return tx.Nonce } |
| 105 | +func (tx *CeloDynamicFeeTx) to() *common.Address { return tx.To } |
| 106 | +func (tx *CeloDynamicFeeTx) feeCurrency() *common.Address { return tx.FeeCurrency } |
| 107 | +func (tx *CeloDynamicFeeTx) gatewayFeeRecipient() *common.Address { return tx.GatewayFeeRecipient } |
| 108 | +func (tx *CeloDynamicFeeTx) gatewayFee() *big.Int { return tx.GatewayFee } |
| 109 | +func (tx *CeloDynamicFeeTx) ethCompatible() bool { return false } |
| 110 | + |
| 111 | +func (tx *CeloDynamicFeeTx) rawSignatureValues() (v, r, s *big.Int) { |
| 112 | + return tx.V, tx.R, tx.S |
| 113 | +} |
| 114 | + |
| 115 | +func (tx *CeloDynamicFeeTx) setSignatureValues(chainID, v, r, s *big.Int) { |
| 116 | + tx.ChainID, tx.V, tx.R, tx.S = chainID, v, r, s |
| 117 | +} |
0 commit comments