Skip to content

Commit

Permalink
Add transaction fields for internal to external use in signer
Browse files Browse the repository at this point in the history
squash: drop merge commit and add panic

squash: fromChain fix
  • Loading branch information
alanorwick authored and wizeguyy committed Jan 25, 2023
1 parent 6d3921c commit cfaa79e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/types/external_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ func (tx *ExternalTx) value() *big.Int { return tx.Value }
func (tx *ExternalTx) nonce() uint64 { return tx.Nonce }
func (tx *ExternalTx) to() *common.Address { return tx.To }
func (tx *ExternalTx) fromChain() *common.Location { return tx.Sender.Location() }
func (tx *ExternalTx) etxGasLimit() uint64 { panic("external TX does not have etxGasLimit") }
func (tx *ExternalTx) etxGasPrice() *big.Int { panic("external TX does not have etxGasPrice") }
func (tx *ExternalTx) etxGasTip() *big.Int { panic("external TX does not have etxGasTip") }
func (tx *ExternalTx) etxData() []byte { panic("external TX does not have etxData") }
func (tx *ExternalTx) etxAccessList() AccessList { panic("external TX does not have etxAccessList") }


func (tx *ExternalTx) rawSignatureValues() (v, r, s *big.Int) {
// Signature values are ignored for external transactions
Expand Down
5 changes: 5 additions & 0 deletions core/types/internal_to_external_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ func (tx *InternalToExternalTx) value() *big.Int { return tx.Value }
func (tx *InternalToExternalTx) nonce() uint64 { return tx.Nonce }
func (tx *InternalToExternalTx) to() *common.Address { return tx.To }
func (tx *InternalToExternalTx) fromChain() *common.Location { return tx.to().Location() }
func (tx *InternalToExternalTx) etxGasLimit() uint64 { return tx.ETXGasLimit }
func (tx *InternalToExternalTx) etxGasPrice() *big.Int { return tx.ETXGasPrice }
func (tx *InternalToExternalTx) etxGasTip() *big.Int { return tx.ETXGasTip }
func (tx *InternalToExternalTx) etxData() []byte { return tx.ETXData }
func (tx *InternalToExternalTx) etxAccessList() AccessList { return tx.ETXAccessList }

func (tx *InternalToExternalTx) rawSignatureValues() (v, r, s *big.Int) {
return tx.V, tx.R, tx.S
Expand Down
5 changes: 5 additions & 0 deletions core/types/internal_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func (tx *InternalTx) value() *big.Int { return tx.Value }
func (tx *InternalTx) nonce() uint64 { return tx.Nonce }
func (tx *InternalTx) to() *common.Address { return tx.To }
func (tx *InternalTx) fromChain() *common.Location { return tx.to().Location() }
func (tx *InternalTx) etxGasLimit() uint64 { panic("internal TX does not have etxGasLimit") }
func (tx *InternalTx) etxGasPrice() *big.Int { panic("internal TX does not have etxGasPrice") }
func (tx *InternalTx) etxGasTip() *big.Int { panic("internal TX does not have etxGasTip") }
func (tx *InternalTx) etxData() []byte { panic("internal TX does not have etxData") }
func (tx *InternalTx) etxAccessList() AccessList { panic("internal TX does not have etxAccessList") }

func (tx *InternalTx) rawSignatureValues() (v, r, s *big.Int) {
return tx.V, tx.R, tx.S
Expand Down
20 changes: 20 additions & 0 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ type TxData interface {
nonce() uint64
to() *common.Address
fromChain() *common.Location
etxGasLimit() uint64
etxGasPrice() *big.Int
etxGasTip() *big.Int
etxData() []byte
etxAccessList() AccessList

rawSignatureValues() (v, r, s *big.Int)
setSignatureValues(chainID, v, r, s *big.Int)
Expand Down Expand Up @@ -252,6 +257,21 @@ func (tx *Transaction) GasFeeCap() *big.Int { return new(big.Int).Set(tx.inner.g
// Value returns the ether amount of the transaction.
func (tx *Transaction) Value() *big.Int { return new(big.Int).Set(tx.inner.value()) }

// ETXGasLimit returns the fee cap per gas of the transaction.
func (tx *Transaction) ETXGasLimit() uint64{ return tx.inner.etxGasLimit() }

// ETXGasPrice returns the gas price of the external transaction.
func (tx *Transaction) ETXGasPrice() *big.Int { return new(big.Int).Set(tx.inner.etxGasPrice()) }

// ETXGasTip returns the gasTipCap per gas of the external transaction.
func (tx *Transaction) ETXGasTip() *big.Int { return new(big.Int).Set(tx.inner.etxGasTip()) }

// ETXData returns the input data of the external transaction.
func (tx *Transaction) ETXData() []byte { return tx.inner.etxData() }

// ETXAccessList returns the access list of the transaction.
func (tx *Transaction) ETXAccessList() AccessList { return tx.inner.etxAccessList() }

// Nonce returns the sender account nonce of the transaction.
func (tx *Transaction) Nonce() uint64 { return tx.inner.nonce() }

Expand Down
20 changes: 20 additions & 0 deletions core/types/transaction_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,26 @@ func (s SignerV1) SignatureValues(tx *Transaction, sig []byte) (R, S, V *big.Int
// Hash returns the hash to be signed by the sender.
// It does not uniquely identify the transaction.
func (s SignerV1) Hash(tx *Transaction) common.Hash {
if tx.Type() == InternalToExternalTxType {
return prefixedRlpHash(
tx.Type(),
[]interface{}{
s.chainId,
tx.Nonce(),
tx.GasTipCap(),
tx.GasFeeCap(),
tx.Gas(),
tx.To(),
tx.Value(),
tx.Data(),
tx.AccessList(),
tx.ETXGasLimit(),
tx.ETXGasPrice(),
tx.ETXGasTip(),
tx.ETXData(),
tx.ETXAccessList(),
})
}
return prefixedRlpHash(
tx.Type(),
[]interface{}{
Expand Down

0 comments on commit cfaa79e

Please sign in to comment.