Add effective gas price to tx view
This commit is contained in:
parent
bca26fbdd9
commit
506921509e
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue