Skip to content

Commit 524cca2

Browse files
committed
fix order
1 parent 8b17cb4 commit 524cca2

File tree

1 file changed

+37
-62
lines changed

1 file changed

+37
-62
lines changed

cmd/monitor/monitor.go

+37-62
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import (
55
"errors"
66
"fmt"
77
"math/big"
8-
"os"
9-
"os/signal"
108
"strings"
119
"sync"
12-
"syscall"
1310
"time"
1411

1512
lru "github.com/hashicorp/golang-lru"
@@ -96,9 +93,6 @@ const (
9693
)
9794

9895
func monitor(ctx context.Context) error {
99-
ctx, cancel := setupCancelContext(ctx)
100-
defer cancel()
101-
10296
rpc, err := ethrpc.DialContext(ctx, rpcUrl)
10397
if err != nil {
10498
log.Error().Err(err).Msg("Unable to dial rpc")
@@ -138,7 +132,6 @@ func monitor(ctx context.Context) error {
138132
}()
139133
select {
140134
case <-ctx.Done():
141-
log.Error().Err(ctx.Err()).Msg("We are here")
142135
return
143136
default:
144137
for {
@@ -165,24 +158,6 @@ func monitor(ctx context.Context) error {
165158
return err
166159
}
167160

168-
func setupCancelContext(ctx context.Context) (context.Context, context.CancelFunc) {
169-
ctx, cancel := context.WithCancel(ctx)
170-
171-
sigChan := make(chan os.Signal, 1)
172-
signal.Notify(sigChan, os.Interrupt, syscall.SIGHUP,
173-
syscall.SIGINT,
174-
syscall.SIGTERM,
175-
syscall.SIGQUIT)
176-
177-
go func() {
178-
<-sigChan
179-
log.Error().Msg("WE ARE HERE")
180-
cancel()
181-
}()
182-
183-
return ctx, cancel
184-
}
185-
186161
func getChainState(ctx context.Context, ec *ethclient.Client) (*chainState, error) {
187162
var err error
188163
cs := new(chainState)
@@ -410,6 +385,43 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
410385
var renderedBlocks rpctypes.SortableBlocks
411386

412387
redraw := func(ms *monitorStatus, force ...bool) {
388+
if currentMode == monitorModeHelp {
389+
// TODO add some help context?
390+
} else if currentMode == monitorModeBlock {
391+
// render a block
392+
skeleton.BlockInfo.Rows = ui.GetSimpleBlockFields(ms.SelectedBlock)
393+
rows, title := ui.GetTransactionsList(ms.SelectedBlock, ms.ChainID)
394+
transactionList.Rows = rows
395+
transactionList.Title = title
396+
397+
baseFee := ms.SelectedBlock.BaseFee()
398+
if transactionList.SelectedRow != 0 {
399+
ms.SelectedTransaction = ms.SelectedBlock.Transactions()[transactionList.SelectedRow-1]
400+
transactionInformationList.Rows = ui.GetSimpleTxFields(ms.SelectedTransaction, ms.ChainID, baseFee)
401+
}
402+
termui.Clear()
403+
termui.Render(blockGrid)
404+
405+
log.Debug().
406+
Int("skeleton.TransactionList.SelectedRow", transactionList.SelectedRow).
407+
Msg("Redrawing block mode")
408+
409+
return
410+
} else if currentMode == monitorModeTransaction {
411+
baseFee := ms.SelectedBlock.BaseFee()
412+
skeleton.TxInfo.Rows = ui.GetSimpleTxFields(ms.SelectedBlock.Transactions()[transactionList.SelectedRow-1], ms.ChainID, baseFee)
413+
skeleton.Receipts.Rows = ui.GetSimpleReceipt(ctx, rpc, ms.SelectedTransaction)
414+
415+
termui.Clear()
416+
termui.Render(transactionGrid)
417+
418+
log.Debug().
419+
Int("skeleton.TransactionList.SelectedRow", transactionList.SelectedRow).
420+
Msg("Redrawing transaction mode")
421+
422+
return
423+
}
424+
413425
log.Debug().
414426
Str("TopDisplayedBlock", ms.TopDisplayedBlock.String()).
415427
Int("BatchSize", batchSize.Get()).
@@ -451,43 +463,6 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
451463
ms.BlocksLock.RUnlock()
452464
renderedBlocks = renderedBlocksTemp
453465

454-
if currentMode == monitorModeHelp {
455-
// TODO add some help context?
456-
} else if currentMode == monitorModeBlock {
457-
// render a block
458-
skeleton.BlockInfo.Rows = ui.GetSimpleBlockFields(ms.SelectedBlock)
459-
rows, title := ui.GetTransactionsList(ms.SelectedBlock, ms.ChainID)
460-
transactionList.Rows = rows
461-
transactionList.Title = title
462-
463-
baseFee := ms.SelectedBlock.BaseFee()
464-
if transactionList.SelectedRow != 0 {
465-
ms.SelectedTransaction = ms.SelectedBlock.Transactions()[transactionList.SelectedRow-1]
466-
transactionInformationList.Rows = ui.GetSimpleTxFields(ms.SelectedTransaction, ms.ChainID, baseFee)
467-
}
468-
termui.Clear()
469-
termui.Render(blockGrid)
470-
471-
log.Debug().
472-
Int("skeleton.TransactionList.SelectedRow", transactionList.SelectedRow).
473-
Msg("Redrawing block mode")
474-
475-
return
476-
} else if currentMode == monitorModeTransaction {
477-
baseFee := ms.SelectedBlock.BaseFee()
478-
skeleton.TxInfo.Rows = ui.GetSimpleTxFields(ms.SelectedBlock.Transactions()[transactionList.SelectedRow-1], ms.ChainID, baseFee)
479-
skeleton.Receipts.Rows = ui.GetSimpleReceipt(ctx, rpc, ms.SelectedTransaction)
480-
481-
termui.Clear()
482-
termui.Render(transactionGrid)
483-
484-
log.Debug().
485-
Int("skeleton.TransactionList.SelectedRow", transactionList.SelectedRow).
486-
Msg("Redrawing transaction mode")
487-
488-
return
489-
}
490-
491466
log.Debug().Int("skeleton.Current.Inner.Dy()", skeleton.Current.Inner.Dy()).Int("skeleton.Current.Inner.Dx()", skeleton.Current.Inner.Dx()).Msg("the dimension of the current box")
492467
skeleton.Current.Text = ui.GetCurrentBlockInfo(ms.HeadBlock, ms.GasPrice, ms.PeerCount, ms.PendingCount, ms.ChainID, renderedBlocks, skeleton.Current.Inner.Dx(), skeleton.Current.Inner.Dy())
493468
skeleton.TxPerBlockChart.Data = metrics.GetTxsPerBlock(renderedBlocks)

0 commit comments

Comments
 (0)