Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: transactions #3502

Merged
11 commits merged into from Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions openapi/SwarmCommon.yaml
Expand Up @@ -655,6 +655,10 @@ components:
$ref: "#/components/schemas/BigInt"
gasLimit:
type: integer
gasTipCap:
This conversation was marked as resolved.
Show resolved Hide resolved
$ref: "#/components/schemas/BigInt"
gasFeeCap:
$ref: "#/components/schemas/BigInt"
data:
type: string
created:
Expand Down
6 changes: 6 additions & 0 deletions pkg/api/transaction.go
Expand Up @@ -32,6 +32,8 @@ type transactionInfo struct {
Nonce uint64 `json:"nonce"`
GasPrice *bigint.BigInt `json:"gasPrice"`
GasLimit uint64 `json:"gasLimit"`
GasTipCap int `json:"gasTipCap"`
This conversation was marked as resolved.
Show resolved Hide resolved
GasFeeCap *bigint.BigInt `json:"gasFeeCap"`
Data string `json:"data"`
Created time.Time `json:"created"`
Description string `json:"description"`
Expand Down Expand Up @@ -69,6 +71,8 @@ func (s *Service) transactionListHandler(w http.ResponseWriter, _ *http.Request)
Nonce: storedTransaction.Nonce,
GasPrice: bigint.Wrap(storedTransaction.GasPrice),
GasLimit: storedTransaction.GasLimit,
GasFeeCap: bigint.Wrap(storedTransaction.GasFeeCap),
GasTipCap: storedTransaction.GasTipBoost,
Data: hexutil.Encode(storedTransaction.Data),
Created: time.Unix(storedTransaction.Created, 0),
Description: storedTransaction.Description,
Expand Down Expand Up @@ -111,6 +115,8 @@ func (s *Service) transactionDetailHandler(w http.ResponseWriter, r *http.Reques
Nonce: storedTransaction.Nonce,
GasPrice: bigint.Wrap(storedTransaction.GasPrice),
GasLimit: storedTransaction.GasLimit,
GasFeeCap: bigint.Wrap(storedTransaction.GasFeeCap),
GasTipCap: storedTransaction.GasTipBoost,
Data: hexutil.Encode(storedTransaction.Data),
Created: time.Unix(storedTransaction.Created, 0),
Description: storedTransaction.Description,
Expand Down
32 changes: 22 additions & 10 deletions pkg/api/transaction_test.go
Expand Up @@ -36,7 +36,7 @@ func TestTransactionStoredTransaction(t *testing.T) {
value := big.NewInt(50)
nonce := uint64(12)
description := "test"

gasTipBoost := 10
t.Run("found", func(t *testing.T) {
t.Parallel()

Expand All @@ -50,6 +50,8 @@ func TestTransactionStoredTransaction(t *testing.T) {
Data: data,
GasPrice: gasPrice,
GasLimit: gasLimit,
GasFeeCap: gasPrice,
GasTipBoost: gasTipBoost,
Value: value,
Nonce: nonce,
Description: description,
Expand All @@ -66,6 +68,8 @@ func TestTransactionStoredTransaction(t *testing.T) {
To: &recipient,
GasPrice: bigint.Wrap(gasPrice),
GasLimit: gasLimit,
GasFeeCap: bigint.Wrap(gasPrice),
GasTipCap: gasTipBoost,
Value: bigint.Wrap(value),
Nonce: nonce,
Description: description,
Expand Down Expand Up @@ -121,19 +125,23 @@ func TestTransactionList(t *testing.T) {
storedTransactions := map[common.Hash]*transaction.StoredTransaction{
txHash1: {
To: &recipient,
Created: 1,
Data: []byte{1, 2, 3, 4},
GasPrice: big.NewInt(12),
GasLimit: 5345,
GasTipBoost: 10,
GasFeeCap: big.NewInt(12),
Value: big.NewInt(4),
Nonce: 3,
Created: 1,
Description: "test",
},
txHash2: {
To: &recipient,
Created: 2,
Data: []byte{3, 2, 3, 4},
GasPrice: big.NewInt(42),
GasTipBoost: 10,
GasFeeCap: big.NewInt(42),
GasLimit: 53451,
Value: big.NewInt(41),
Nonce: 32,
Expand All @@ -158,25 +166,29 @@ func TestTransactionList(t *testing.T) {
PendingTransactions: []api.TransactionInfo{
{
TransactionHash: txHash1,
Created: time.Unix(storedTransactions[txHash1].Created, 0),
Data: hexutil.Encode(storedTransactions[txHash1].Data),
To: storedTransactions[txHash1].To,
Nonce: storedTransactions[txHash1].Nonce,
GasPrice: bigint.Wrap(storedTransactions[txHash1].GasPrice),
GasLimit: storedTransactions[txHash1].GasLimit,
Value: bigint.Wrap(storedTransactions[txHash1].Value),
Nonce: storedTransactions[txHash1].Nonce,
GasTipCap: 10,
GasFeeCap: bigint.Wrap(storedTransactions[txHash1].GasPrice),
Data: hexutil.Encode(storedTransactions[txHash1].Data),
Created: time.Unix(storedTransactions[txHash1].Created, 0),
Description: storedTransactions[txHash1].Description,
Value: bigint.Wrap(storedTransactions[txHash1].Value),
},
{
TransactionHash: txHash2,
Created: time.Unix(storedTransactions[txHash2].Created, 0),
Data: hexutil.Encode(storedTransactions[txHash2].Data),
To: storedTransactions[txHash2].To,
Nonce: storedTransactions[txHash2].Nonce,
GasPrice: bigint.Wrap(storedTransactions[txHash2].GasPrice),
GasLimit: storedTransactions[txHash2].GasLimit,
Value: bigint.Wrap(storedTransactions[txHash2].Value),
Nonce: storedTransactions[txHash2].Nonce,
GasTipCap: 10,
GasFeeCap: bigint.Wrap(storedTransactions[txHash2].GasPrice),
This conversation was marked as resolved.
Show resolved Hide resolved
Data: hexutil.Encode(storedTransactions[txHash2].Data),
Created: time.Unix(storedTransactions[txHash2].Created, 0),
Description: storedTransactions[txHash2].Description,
Value: bigint.Wrap(storedTransactions[txHash2].Value),
},
},
}),
Expand Down
10 changes: 8 additions & 2 deletions pkg/transaction/transaction.go
Expand Up @@ -48,6 +48,8 @@ type TxRequest struct {
Data []byte // transaction data
GasPrice *big.Int // gas price or nil if suggested gas price should be used
GasLimit uint64 // gas limit or 0 if it should be estimated
GasTipBoost int // adds a tip for the miner for prioritizing transaction
This conversation was marked as resolved.
Show resolved Hide resolved
GasFeeCap *big.Int // adds a cap to maximum fee user is willing to pay
Value *big.Int // amount of wei to send
Description string // optional description
}
Expand All @@ -56,8 +58,9 @@ type StoredTransaction struct {
To *common.Address // recipient of the transaction
Data []byte // transaction data
GasPrice *big.Int // used gas price
GasTipBoost int // percentage used to boost the priority fee (eg: tip)
GasLimit uint64 // used gas limit
GasTipBoost int // adds a tip for the miner for prioritizing transaction
This conversation was marked as resolved.
Show resolved Hide resolved
GasFeeCap *big.Int // adds a cap to maximum fee user is willing to pay
Value *big.Int // amount of wei to send
Nonce uint64 // used nonce
Created int64 // creation timestamp
Expand Down Expand Up @@ -177,8 +180,9 @@ func (t *transactionService) Send(ctx context.Context, request *TxRequest, tipCa
To: signedTx.To(),
Data: signedTx.Data(),
GasPrice: signedTx.GasPrice(),
GasTipBoost: tipCapBoostPercent,
GasLimit: signedTx.Gas(),
GasTipBoost: tipCapBoostPercent,
GasFeeCap: signedTx.GasFeeCap(),
Value: signedTx.Value(),
Nonce: signedTx.Nonce(),
Created: time.Now().Unix(),
Expand Down Expand Up @@ -485,6 +489,8 @@ func (t *transactionService) CancelTransaction(ctx context.Context, originalTxHa
Data: signedTx.Data(),
GasPrice: signedTx.GasPrice(),
GasLimit: signedTx.Gas(),
GasFeeCap: signedTx.GasFeeCap(),
GasTipBoost: storedTransaction.GasTipBoost,
Value: signedTx.Value(),
Nonce: signedTx.Nonce(),
Created: time.Now().Unix(),
Expand Down