Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
patch gas used api for block less than upgrade height
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Dec 16, 2022
1 parent dda1267 commit d83daef
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions rpc/backend/tx_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package backend

import (
"fmt"
"math/big"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -126,7 +127,7 @@ func (b *Backend) GetTransactionReceipt(hash common.Hash) (map[string]interface{
b.logger.Debug("tx not found", "hash", hexTx, "error", err.Error())
return nil, nil
}

gasUsed := res.GasUsed
resBlock, err := b.TendermintBlockByNumber(rpctypes.BlockNumber(res.Height))
if err != nil {
b.logger.Debug("block not found", "height", res.Height, "error", err.Error())
Expand Down Expand Up @@ -162,7 +163,13 @@ func (b *Backend) GetTransactionReceipt(hash common.Hash) (map[string]interface{
} else {
status = hexutil.Uint(ethtypes.ReceiptStatusSuccessful)
}

// FIXME: config based on diff chain and env
isHeightBeforeUpgrade := true
if status == 0 && isHeightBeforeUpgrade {
price := txData.GetGasPrice()
gas := txData.GetGas()
gasUsed = new(big.Int).Mul(price, new(big.Int).SetUint64(gas)).Uint64()
}
chainID, err := b.ChainID()
if err != nil {
return nil, err
Expand Down Expand Up @@ -205,7 +212,7 @@ func (b *Backend) GetTransactionReceipt(hash common.Hash) (map[string]interface{
// They are stored in the chain database.
"transactionHash": hash,
"contractAddress": nil,
"gasUsed": hexutil.Uint64(res.GasUsed),
"gasUsed": hexutil.Uint64(gasUsed),

// Inclusion information: These fields provide information about the inclusion of the
// transaction corresponding to this receipt.
Expand Down

0 comments on commit d83daef

Please sign in to comment.