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

Emit eth tx hash in ante handler to support query failed transactions #1062

Merged
merged 14 commits into from
May 31, 2022
Merged
Prev Previous commit
Next Next commit
fix get tx by index
  • Loading branch information
yihuang committed May 24, 2022
commit ddf6424cd5612211644f398ac43c00e66f871df8
2 changes: 1 addition & 1 deletion rpc/namespaces/ethereum/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ func (e *PublicAPI) getTransactionByBlockAndIndex(block *tmrpctypes.ResultBlock,
return nil, fmt.Errorf("failed to parse tx events: %d, %v", idx, err)
}

parsedTx := parsedTxs.GetTxByIndex(int(idx))
parsedTx := parsedTxs.GetTxByTxIndex(int(idx))
if parsedTx == nil {
return nil, fmt.Errorf("ethereum tx not found in msgs: %d", idx)
}
Expand Down
17 changes: 14 additions & 3 deletions rpc/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,25 @@ func (p *ParsedTxs) GetTxByHash(hash common.Hash) *ParsedTx {
return nil
}

// GetTxByIndex returns ParsedTx by index
func (p *ParsedTxs) GetTxByIndex(i int) *ParsedTx {
if i >= len(p.Txs) {
// GetTxByMsgIndex returns ParsedTx by msg index
func (p *ParsedTxs) GetTxByMsgIndex(i int) *ParsedTx {
if i < 0 || i >= len(p.Txs) {
return nil
}
return &p.Txs[i]
}

// GetTxByTxIndex returns ParsedTx by tx index
func (p *ParsedTxs) GetTxByTxIndex(i int) *ParsedTx {
// assuming the `EthTxIndex` continuously increment.
if len(p.Txs) == 0 {
return nil
}
msgIndex := i - int(p.Txs[0].EthTxIndex)
// GetTxByMsgIndex will check the bound
return p.GetTxByMsgIndex(msgIndex)
}

// AccumulativeGasUsed calculate the accumulated gas used within the batch
func (p *ParsedTxs) AccumulativeGasUsed(msgIndex int) (result uint64) {
for i := 0; i <= msgIndex; i++ {
Expand Down