Skip to content

Commit

Permalink
Added txtype-specific fields to RPCTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
jdowning100 committed Jun 14, 2023
1 parent 82cd1e9 commit 7a42b30
Showing 1 changed file with 60 additions and 12 deletions.
72 changes: 60 additions & 12 deletions internal/quaiapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,14 @@ type RPCTransaction struct {
V *hexutil.Big `json:"v"`
R *hexutil.Big `json:"r"`
S *hexutil.Big `json:"s"`
// Optional fields only present for external transactions
Sender *common.Address `json:"sender,omitempty"`

ETXGasLimit hexutil.Uint64 `json:"etxGasLimit,omitempty"`
ETXGasPrice *hexutil.Big `json:"etxGasPrice,omitempty"`
ETXGasTip *hexutil.Big `json:"etxGasTip,omitempty"`
ETXData *hexutil.Bytes `json:"etxData,omitempty"`
ETXAccessList *types.AccessList `json:"etxAccessList,omitempty"`
}

// newRPCTransaction returns a transaction that will serialize to the RPC
Expand All @@ -983,18 +991,58 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber
var signer types.Signer
signer = types.LatestSignerForChainID(tx.ChainId())
from, _ := types.Sender(signer, tx)
result := &RPCTransaction{
Type: hexutil.Uint64(tx.Type()),
From: from,
Gas: hexutil.Uint64(tx.Gas()),
Hash: tx.Hash(),
Input: hexutil.Bytes(tx.Data()),
Nonce: hexutil.Uint64(tx.Nonce()),
To: tx.To(),
Value: (*hexutil.Big)(tx.Value()),
ChainID: (*hexutil.Big)(tx.ChainId()),
GasFeeCap: (*hexutil.Big)(tx.GasFeeCap()),
GasTipCap: (*hexutil.Big)(tx.GasTipCap()),
var result *RPCTransaction
switch tx.Type() {
case types.InternalTxType:
result = &RPCTransaction{
Type: hexutil.Uint64(tx.Type()),
From: from,
Gas: hexutil.Uint64(tx.Gas()),
Hash: tx.Hash(),
Input: hexutil.Bytes(tx.Data()),
Nonce: hexutil.Uint64(tx.Nonce()),
To: tx.To(),
Value: (*hexutil.Big)(tx.Value()),
ChainID: (*hexutil.Big)(tx.ChainId()),
GasFeeCap: (*hexutil.Big)(tx.GasFeeCap()),
GasTipCap: (*hexutil.Big)(tx.GasTipCap()),
}
case types.ExternalTxType:
result = &RPCTransaction{
Type: hexutil.Uint64(tx.Type()),
Gas: hexutil.Uint64(tx.Gas()),
Hash: tx.Hash(),
Input: hexutil.Bytes(tx.Data()),
Nonce: hexutil.Uint64(tx.Nonce()),
To: tx.To(),
Value: (*hexutil.Big)(tx.Value()),
ChainID: (*hexutil.Big)(tx.ChainId()),
GasFeeCap: (*hexutil.Big)(tx.GasFeeCap()),
GasTipCap: (*hexutil.Big)(tx.GasTipCap()),
}
sender := tx.ETXSender()
result.Sender = &sender
case types.InternalToExternalTxType:
result = &RPCTransaction{
Type: hexutil.Uint64(tx.Type()),
From: from,
Gas: hexutil.Uint64(tx.Gas()),
Hash: tx.Hash(),
Input: hexutil.Bytes(tx.Data()),
Nonce: hexutil.Uint64(tx.Nonce()),
To: tx.To(),
Value: (*hexutil.Big)(tx.Value()),
ChainID: (*hexutil.Big)(tx.ChainId()),
GasFeeCap: (*hexutil.Big)(tx.GasFeeCap()),
GasTipCap: (*hexutil.Big)(tx.GasTipCap()),
ETXGasLimit: (hexutil.Uint64)(tx.ETXGasLimit()),
ETXGasPrice: (*hexutil.Big)(tx.ETXGasPrice()),
ETXGasTip: (*hexutil.Big)(tx.ETXGasTip()),
}
data := tx.ETXData()
result.ETXData = (*hexutil.Bytes)(&data)
eal := tx.ETXAccessList()
result.ETXAccessList = &eal
}
if blockHash != (common.Hash{}) {
result.BlockHash = &blockHash
Expand Down

0 comments on commit 7a42b30

Please sign in to comment.