@@ -5,11 +5,8 @@ import (
5
5
"errors"
6
6
"fmt"
7
7
"math/big"
8
- "os"
9
- "os/signal"
10
8
"strings"
11
9
"sync"
12
- "syscall"
13
10
"time"
14
11
15
12
lru "github.com/hashicorp/golang-lru"
@@ -96,9 +93,6 @@ const (
96
93
)
97
94
98
95
func monitor (ctx context.Context ) error {
99
- ctx , cancel := setupCancelContext (ctx )
100
- defer cancel ()
101
-
102
96
rpc , err := ethrpc .DialContext (ctx , rpcUrl )
103
97
if err != nil {
104
98
log .Error ().Err (err ).Msg ("Unable to dial rpc" )
@@ -138,7 +132,6 @@ func monitor(ctx context.Context) error {
138
132
}()
139
133
select {
140
134
case <- ctx .Done ():
141
- log .Error ().Err (ctx .Err ()).Msg ("We are here" )
142
135
return
143
136
default :
144
137
for {
@@ -165,24 +158,6 @@ func monitor(ctx context.Context) error {
165
158
return err
166
159
}
167
160
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
-
186
161
func getChainState (ctx context.Context , ec * ethclient.Client ) (* chainState , error ) {
187
162
var err error
188
163
cs := new (chainState )
@@ -410,6 +385,43 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
410
385
var renderedBlocks rpctypes.SortableBlocks
411
386
412
387
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
+
413
425
log .Debug ().
414
426
Str ("TopDisplayedBlock" , ms .TopDisplayedBlock .String ()).
415
427
Int ("BatchSize" , batchSize .Get ()).
@@ -451,43 +463,6 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
451
463
ms .BlocksLock .RUnlock ()
452
464
renderedBlocks = renderedBlocksTemp
453
465
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
-
491
466
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" )
492
467
skeleton .Current .Text = ui .GetCurrentBlockInfo (ms .HeadBlock , ms .GasPrice , ms .PeerCount , ms .PendingCount , ms .ChainID , renderedBlocks , skeleton .Current .Inner .Dx (), skeleton .Current .Inner .Dy ())
493
468
skeleton .TxPerBlockChart .Data = metrics .GetTxsPerBlock (renderedBlocks )
0 commit comments