From 506921509e477445a95e1961a2557ef584d7caec Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 26 Sep 2022 12:04:19 +0200 Subject: [PATCH] Add effective gas price to tx view --- VERSION | 2 +- services/wallet/transfer/database.go | 4 ++-- services/wallet/transfer/downloader.go | 18 ++++++++++++++++-- services/wallet/transfer/view.go | 11 +++++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index 5ea3c7e09..b59780734 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.110.2 +0.110.3 diff --git a/services/wallet/transfer/database.go b/services/wallet/transfer/database.go index f08e537e9..bac4cb9c5 100644 --- a/services/wallet/transfer/database.go +++ b/services/wallet/transfer/database.go @@ -427,7 +427,7 @@ func insertBlocksWithTransactions(chainID uint64, creator statementCreator, acco func updateOrInsertTransfers(chainID uint64, creator statementCreator, transfers []Transfer) error { update, err := creator.Prepare(`UPDATE transfers - SET tx = ?, sender = ?, receipt = ?, timestamp = ?, loaded = 1 + SET tx = ?, sender = ?, receipt = ?, timestamp = ?, loaded = 1, base_gas_fee = ? WHERE address =? AND hash = ?`) if err != nil { return err @@ -441,7 +441,7 @@ func updateOrInsertTransfers(chainID uint64, creator statementCreator, transfers return err } for _, t := range transfers { - res, err := update.Exec(&JSONBlob{t.Transaction}, t.From, &JSONBlob{t.Receipt}, t.Timestamp, t.Address, t.ID) + res, err := update.Exec(&JSONBlob{t.Transaction}, t.From, &JSONBlob{t.Receipt}, t.Timestamp, t.BaseGasFees, t.Address, t.ID) if err != nil { return err diff --git a/services/wallet/transfer/downloader.go b/services/wallet/transfer/downloader.go index 8b0a1a964..e46c8ec67 100644 --- a/services/wallet/transfer/downloader.go +++ b/services/wallet/transfer/downloader.go @@ -115,6 +115,11 @@ func getTransferByHash(ctx context.Context, client *chain.Client, signer types.S return nil, err } + baseGasFee, err := client.GetBaseFeeFromBlock(big.NewInt(int64(transactionLog.BlockNumber))) + if err != nil { + return nil, err + } + transfer := &Transfer{Type: transferType, ID: hash, Address: address, @@ -124,7 +129,9 @@ func getTransferByHash(ctx context.Context, client *chain.Client, signer types.S Transaction: transaction, From: from, Receipt: receipt, - Log: transactionLog} + Log: transactionLog, + BaseGasFees: baseGasFee, + } return transfer, nil } @@ -355,6 +362,11 @@ func (d *ERC20TransfersDownloader) blocksFromLogs(parent context.Context, logs [ binary.BigEndian.PutUint32(index[:], uint32(l.Index)) id := crypto.Keccak256Hash(l.TxHash.Bytes(), index[:]) + baseGasFee, err := d.client.GetBaseFeeFromBlock(new(big.Int).SetUint64(l.BlockNumber)) + if err != nil { + return nil, err + } + header := &DBHeader{ Number: big.NewInt(int64(l.BlockNumber)), Hash: l.BlockHash, @@ -366,7 +378,9 @@ func (d *ERC20TransfersDownloader) blocksFromLogs(parent context.Context, logs [ From: address, Loaded: false, Type: erc20Transfer, - Log: &l}}} + Log: &l, + BaseGasFees: baseGasFee, + }}} concurrent.Add(func(ctx context.Context) error { concurrent.PushHeader(header) diff --git a/services/wallet/transfer/view.go b/services/wallet/transfer/view.go index 11f855231..ce4ef1015 100644 --- a/services/wallet/transfer/view.go +++ b/services/wallet/transfer/view.go @@ -21,6 +21,8 @@ type View struct { GasPrice *hexutil.Big `json:"gasPrice"` MaxFeePerGas *hexutil.Big `json:"maxFeePerGas"` MaxPriorityFeePerGas *hexutil.Big `json:"maxPriorityFeePerGas"` + EffectiveTip *hexutil.Big `json:"effectiveTip"` + EffectiveGasPrice *hexutil.Big `json:"effectiveGasPrice"` GasLimit hexutil.Uint64 `json:"gasLimit"` GasUsed hexutil.Uint64 `json:"gasUsed"` Nonce hexutil.Uint64 `json:"nonce"` @@ -53,6 +55,15 @@ func CastToTransferView(t Transfer) View { view.BlockHash = t.BlockHash view.Timestamp = hexutil.Uint64(t.Timestamp) view.GasPrice = (*hexutil.Big)(t.Transaction.GasPrice()) + if t.BaseGasFees != "" { + baseFee := new(big.Int) + baseFee.SetString(t.BaseGasFees[2:], 16) + tip := t.Transaction.EffectiveGasTipValue(baseFee) + + view.EffectiveTip = (*hexutil.Big)(tip) + price := new(big.Int).Add(baseFee, tip) + view.EffectiveGasPrice = (*hexutil.Big)(price) + } view.MaxFeePerGas = (*hexutil.Big)(t.Transaction.GasFeeCap()) view.MaxPriorityFeePerGas = (*hexutil.Big)(t.Transaction.GasTipCap()) view.GasLimit = hexutil.Uint64(t.Transaction.Gas())