Skip to content

Commit

Permalink
fix(monitor): out of range panics (#375)
Browse files Browse the repository at this point in the history
* fix: memory panic when selecting txs

* fix: same fix

* chore: nit

* chore: lint
  • Loading branch information
leovct authored Sep 18, 2024
1 parent 0c533ee commit 9ab6f2a
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions cmd/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,21 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu

baseFee := ms.SelectedBlock.BaseFee()
if transactionList.SelectedRow != 0 {
ms.SelectedTransaction = ms.SelectedBlock.Transactions()[transactionList.SelectedRow-1]
transactions := ms.SelectedBlock.Transactions()
if len(transactions) > 0 {
index := transactionList.SelectedRow - 1
if index >= 0 && index < len(transactions) {
ms.SelectedTransaction = transactions[index]
} else {
log.Error().
Int("row", transactionList.SelectedRow).
Msg("Selected row is out of range for transactions")
}
} else {
log.Debug().
Int("block", int(ms.SelectedBlock.Number().Uint64())).
Msg("No transactions available in the selected block")
}
transactionInformationList.Rows = ui.GetSimpleTxFields(ms.SelectedTransaction, ms.ChainID, baseFee)
}
termui.Clear()
Expand All @@ -484,7 +498,22 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
return
} else if currentMode == monitorModeTransaction {
baseFee := ms.SelectedBlock.BaseFee()
skeleton.TxInfo.Rows = ui.GetSimpleTxFields(ms.SelectedBlock.Transactions()[transactionList.SelectedRow-1], ms.ChainID, baseFee)
transactions := ms.SelectedBlock.Transactions()
if len(transactions) > 0 {
index := transactionList.SelectedRow - 1
if index > 0 && index < len(transactions) {
tx := transactions[index]
skeleton.TxInfo.Rows = ui.GetSimpleTxFields(tx, ms.ChainID, baseFee)
} else {
log.Error().
Int("row", transactionList.SelectedRow).
Msg("Selected row is out of range for transactions")
}
} else {
log.Debug().
Int("block", int(ms.SelectedBlock.Number().Uint64())).
Msg("No transactions available in the selected block")
}
skeleton.Receipts.Rows = ui.GetSimpleReceipt(ctx, rpc, ms.SelectedTransaction)

termui.Clear()
Expand Down

0 comments on commit 9ab6f2a

Please sign in to comment.