forked from ethereum-optimism/op-geth
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CIP-64 / CIP-66 compatible
TransactionArgs
(#123)
Fixes #109 Add CIP-66 transaction type This introduces the CeloDenominatedTx type, which will when implemented allow for the fee-currency to be denominated in cel2 native token. Make the TransactionArgs CIP-64/CIP-66 compatible The TransactionArgs are used in some API endpoints to fill incomplete fields of passed in transactions and then convert this internally to an EVM-message or Transaction. This PR adds code that distinguishes some combination of passed in fields for the TransactionArgs between CIP-64 and CIP-66 transactions in order to create the concrete internal transaction type. The filling of missing required fields now considers wether the transaction is Celo-denominated or not. Additionally, the new MaxFeeInFeeCurrency field is passed along to the internal transaction representations Included commits: * Format comments in TransactionArgs fields * Add CIP-66 tx type (Celo denominated) Co-authored-by: bandu * Fix nil-deref in CIP-66 Transaction getter * Fix required RLP field for fee-currency in CIP66 * Fix initialize MaxFeePerFeeCurrency value upon copy * Convert TransactionArgs to CIP-64/66 transaction Closes #109 * Add MaxFeeInFeeCurrency to EVM Message * Fix CIP-64/66 related sanity checks The fee-currency conversion pre-London (legacy-tx) was unneccessary, since we don't allow celo transactions here. Additionally some sanity-checks regarding Celo related fields were missing * Add tests for CIP-64/66 compatible TransactionArgs * Fix call-arg naming for currency conversion * Fix comments and formatting
- Loading branch information
Showing
15 changed files
with
289 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package types | ||
|
||
import ( | ||
"bytes" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/rlp" | ||
) | ||
|
||
type CeloDenominatedTx struct { | ||
ChainID *big.Int | ||
Nonce uint64 | ||
GasTipCap *big.Int | ||
GasFeeCap *big.Int | ||
Gas uint64 | ||
To *common.Address `rlp:"nil"` // nil means contract creation | ||
Value *big.Int | ||
Data []byte | ||
AccessList AccessList | ||
|
||
FeeCurrency *common.Address | ||
MaxFeeInFeeCurrency *big.Int | ||
|
||
// Signature values | ||
V *big.Int `json:"v" gencodec:"required"` | ||
R *big.Int `json:"r" gencodec:"required"` | ||
S *big.Int `json:"s" gencodec:"required"` | ||
} | ||
|
||
// copy creates a deep copy of the transaction data and initializes all fields. | ||
func (tx *CeloDenominatedTx) copy() TxData { | ||
cpy := &CeloDenominatedTx{ | ||
Nonce: tx.Nonce, | ||
To: copyAddressPtr(tx.To), | ||
Data: common.CopyBytes(tx.Data), | ||
Gas: tx.Gas, | ||
FeeCurrency: copyAddressPtr(tx.FeeCurrency), | ||
// These are copied below. | ||
MaxFeeInFeeCurrency: new(big.Int), | ||
AccessList: make(AccessList, len(tx.AccessList)), | ||
Value: new(big.Int), | ||
ChainID: new(big.Int), | ||
GasTipCap: new(big.Int), | ||
GasFeeCap: new(big.Int), | ||
V: new(big.Int), | ||
R: new(big.Int), | ||
S: new(big.Int), | ||
} | ||
if tx.MaxFeeInFeeCurrency != nil { | ||
cpy.MaxFeeInFeeCurrency.Set(tx.MaxFeeInFeeCurrency) | ||
} | ||
copy(cpy.AccessList, tx.AccessList) | ||
if tx.Value != nil { | ||
cpy.Value.Set(tx.Value) | ||
} | ||
if tx.ChainID != nil { | ||
cpy.ChainID.Set(tx.ChainID) | ||
} | ||
if tx.GasTipCap != nil { | ||
cpy.GasTipCap.Set(tx.GasTipCap) | ||
} | ||
if tx.GasFeeCap != nil { | ||
cpy.GasFeeCap.Set(tx.GasFeeCap) | ||
} | ||
if tx.V != nil { | ||
cpy.V.Set(tx.V) | ||
} | ||
if tx.R != nil { | ||
cpy.R.Set(tx.R) | ||
} | ||
if tx.S != nil { | ||
cpy.S.Set(tx.S) | ||
} | ||
return cpy | ||
} | ||
|
||
// accessors for innerTx. | ||
func (tx *CeloDenominatedTx) txType() byte { return CeloDenominatedTxType } | ||
func (tx *CeloDenominatedTx) chainID() *big.Int { return tx.ChainID } | ||
func (tx *CeloDenominatedTx) accessList() AccessList { return tx.AccessList } | ||
func (tx *CeloDenominatedTx) data() []byte { return tx.Data } | ||
func (tx *CeloDenominatedTx) gas() uint64 { return tx.Gas } | ||
func (tx *CeloDenominatedTx) gasFeeCap() *big.Int { return tx.GasFeeCap } | ||
func (tx *CeloDenominatedTx) gasTipCap() *big.Int { return tx.GasTipCap } | ||
func (tx *CeloDenominatedTx) gasPrice() *big.Int { return tx.GasFeeCap } | ||
func (tx *CeloDenominatedTx) value() *big.Int { return tx.Value } | ||
func (tx *CeloDenominatedTx) nonce() uint64 { return tx.Nonce } | ||
func (tx *CeloDenominatedTx) to() *common.Address { return tx.To } | ||
func (tx *CeloDenominatedTx) isSystemTx() bool { return false } | ||
|
||
func (tx *CeloDenominatedTx) effectiveGasPrice(dst *big.Int, baseFee *big.Int) *big.Int { | ||
if baseFee == nil { | ||
return dst.Set(tx.GasFeeCap) | ||
} | ||
tip := dst.Sub(tx.GasFeeCap, baseFee) | ||
if tip.Cmp(tx.GasTipCap) > 0 { | ||
tip.Set(tx.GasTipCap) | ||
} | ||
return tip.Add(tip, baseFee) | ||
} | ||
|
||
func (tx *CeloDenominatedTx) rawSignatureValues() (v, r, s *big.Int) { | ||
return tx.V, tx.R, tx.S | ||
} | ||
|
||
func (tx *CeloDenominatedTx) setSignatureValues(chainID, v, r, s *big.Int) { | ||
tx.ChainID, tx.V, tx.R, tx.S = chainID, v, r, s | ||
} | ||
|
||
func (tx *CeloDenominatedTx) encode(b *bytes.Buffer) error { | ||
return rlp.Encode(b, tx) | ||
} | ||
|
||
func (tx *CeloDenominatedTx) decode(input []byte) error { | ||
return rlp.DecodeBytes(input, tx) | ||
} | ||
|
||
func (tx *CeloDenominatedTx) feeCurrency() *common.Address { return tx.FeeCurrency } | ||
|
||
func (tx *CeloDenominatedTx) maxFeeInFeeCurrency() *big.Int { return tx.MaxFeeInFeeCurrency } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.