-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core/types: add new sponsored transaction types
This commit adds new sponsored transaction type 0x64 (100) following EIP-2718: Typed Transaction Envelope. The new transaction type is the same as legacy with additional expiredTime and payer's signature field.
- Loading branch information
Showing
9 changed files
with
348 additions
and
39 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
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,89 @@ | ||
package types | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
type SponsoredTx struct { | ||
Nonce uint64 // nonce of sender account | ||
GasPrice *big.Int // wei per gas | ||
Gas uint64 // gas limit | ||
To *common.Address `rlp:"nil"` // nil means contract creation | ||
Value *big.Int // wei amount | ||
Data []byte // contract invocation input data | ||
ExpiredTime uint64 // the expired time of payer's signature | ||
PayerV, PayerR, PayerS *big.Int // payer's signature values | ||
V, R, S *big.Int // sender's signature values | ||
} | ||
|
||
func (tx *SponsoredTx) copy() TxData { | ||
cpy := &SponsoredTx{ | ||
Nonce: tx.Nonce, | ||
To: copyAddressPtr(tx.To), | ||
Data: common.CopyBytes(tx.Data), | ||
Gas: tx.Gas, | ||
ExpiredTime: tx.ExpiredTime, | ||
// These are initialized below. | ||
Value: new(big.Int), | ||
GasPrice: new(big.Int), | ||
PayerV: new(big.Int), | ||
PayerR: new(big.Int), | ||
PayerS: new(big.Int), | ||
V: new(big.Int), | ||
R: new(big.Int), | ||
S: new(big.Int), | ||
} | ||
if tx.Value != nil { | ||
cpy.Value.Set(tx.Value) | ||
} | ||
if tx.GasPrice != nil { | ||
cpy.GasPrice.Set(tx.GasPrice) | ||
} | ||
if tx.PayerV != nil { | ||
cpy.PayerV.Set(tx.PayerV) | ||
} | ||
if tx.PayerR != nil { | ||
cpy.PayerR.Set(tx.PayerR) | ||
} | ||
if tx.PayerS != nil { | ||
cpy.PayerS.Set(tx.PayerS) | ||
} | ||
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 *SponsoredTx) txType() byte { return SponsoredTxType } | ||
func (tx *SponsoredTx) chainID() *big.Int { return deriveChainId(tx.V) } | ||
func (tx *SponsoredTx) accessList() AccessList { return nil } | ||
func (tx *SponsoredTx) data() []byte { return tx.Data } | ||
func (tx *SponsoredTx) gas() uint64 { return tx.Gas } | ||
func (tx *SponsoredTx) gasPrice() *big.Int { return tx.GasPrice } | ||
func (tx *SponsoredTx) gasTipCap() *big.Int { return tx.GasPrice } | ||
func (tx *SponsoredTx) gasFeeCap() *big.Int { return tx.GasPrice } | ||
func (tx *SponsoredTx) value() *big.Int { return tx.Value } | ||
func (tx *SponsoredTx) nonce() uint64 { return tx.Nonce } | ||
func (tx *SponsoredTx) to() *common.Address { return tx.To } | ||
func (tx *SponsoredTx) expiredTime() uint64 { return tx.ExpiredTime } | ||
|
||
func (tx *SponsoredTx) rawPayerSignatureValues() (v, r, s *big.Int) { | ||
return tx.PayerV, tx.PayerR, tx.PayerS | ||
} | ||
|
||
func (tx *SponsoredTx) rawSignatureValues() (v, r, s *big.Int) { | ||
return tx.V, tx.R, tx.S | ||
} | ||
|
||
func (tx *SponsoredTx) setSignatureValues(chainID, v, r, s *big.Int) { | ||
tx.V, tx.R, tx.S = v, r, s | ||
} |
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.