@@ -105,7 +105,7 @@ func GetBlocksList(blocks []rpctypes.PolyBlock) ([]string, string) {
105105 zone , _ := time .Now ().Zone ()
106106 headerVariables := []string {"#" , fmt .Sprintf ("TIME (%s)" , zone ), "BLK TIME" , "TXN #" , "GAS USED" , "HASH" , "AUTHOR" }
107107
108- proportion := []int {10 , 10 , 2 , 2 , 10 , 12 }
108+ proportion := []int {10 , 20 , 10 , 10 , 10 , 80 }
109109
110110 header := ""
111111 for i , prop := range proportion {
@@ -146,14 +146,90 @@ func GetBlocksList(blocks []rpctypes.PolyBlock) ([]string, string) {
146146 blockTime = strconv .FormatUint (bs [j ].Time ()- bs [j - 1 ].Time (), 10 )
147147 }
148148
149+ // Default block info row should be full width
149150 recordVariables := []string {
150151 fmt .Sprintf ("%d" , bs [j ].Number ()),
151152 ut .Format ("02 Jan 06 15:04:05" ),
152153 fmt .Sprintf ("%ss" , blockTime ),
153154 fmt .Sprintf ("%d" , len (bs [j ].Transactions ())),
154155 fmt .Sprintf ("%d" , bs [j ].GasUsed ()),
155- metrics .TruncateHexString (bs [j ].Hash ().String (), 14 ),
156- metrics .TruncateHexString (author .String (), 14 ),
156+ bs [j ].Hash ().String (),
157+ author .String (),
158+ }
159+
160+ record := " "
161+ for i := 0 ; i < len (recordVariables )- 1 ; i ++ {
162+ spaceOffset := len (headerVariables [i ]) + proportion [i ] - len (recordVariables [i ])
163+ if spaceOffset < 0 {
164+ spaceOffset = 0
165+ log .Error ().Str ("record" , recordVariables [i ]).Str ("column" , headerVariables [i ]).Msg ("Column width exceed header width" )
166+ }
167+ record += recordVariables [i ] + strings .Repeat (" " , spaceOffset )
168+ }
169+ record += recordVariables [len (recordVariables )- 1 ]
170+
171+ records = append (records , record )
172+ }
173+ return records , header
174+ }
175+
176+ func GetSelectedBlocksList (blocks []rpctypes.PolyBlock ) ([]string , string ) {
177+ bs := rpctypes .SortableBlocks (blocks )
178+ sort .Sort (bs )
179+
180+ zone , _ := time .Now ().Zone ()
181+ headerVariables := []string {"#" , fmt .Sprintf ("TIME (%s)" , zone ), "BLK TIME" , "TXN #" , "GAS USED" , "HASH" , "AUTHOR" }
182+
183+ proportion := []int {10 , 20 , 10 , 10 , 10 , 25 }
184+
185+ header := ""
186+ for i , prop := range proportion {
187+ header += headerVariables [i ] + strings .Repeat ("─" , prop )
188+ }
189+ header += headerVariables [len (headerVariables )- 1 ]
190+
191+ if len (blocks ) < 1 {
192+ return nil , header
193+ }
194+
195+ isMined := true
196+
197+ if blocks [0 ].Miner ().String () == "0x0000000000000000000000000000000000000000" {
198+ isMined = false
199+ }
200+
201+ if ! isMined {
202+ header = strings .Replace (header , "AUTHOR" , "SIGNER" , 1 )
203+ }
204+
205+ // Set the first row to blank so that there is some space between the blocks
206+ // and the title.
207+ records := []string {"" }
208+
209+ for j := len (bs ) - 1 ; j >= 0 ; j = j - 1 {
210+ author := bs [j ].Miner ()
211+ ts := bs [j ].Time ()
212+ ut := time .Unix (int64 (ts ), 0 )
213+ if ! isMined {
214+ signer , err := metrics .Ecrecover (& bs [j ])
215+ if err == nil {
216+ author = ethcommon .HexToAddress ("0x" + hex .EncodeToString (signer ))
217+ }
218+ }
219+ blockTime := "-"
220+ if j > 0 {
221+ blockTime = strconv .FormatUint (bs [j ].Time ()- bs [j - 1 ].Time (), 10 )
222+ }
223+
224+ // Default block info row should be full width
225+ recordVariables := []string {
226+ fmt .Sprintf ("%d" , bs [j ].Number ()),
227+ ut .Format ("02 Jan 06 15:04:05" ),
228+ fmt .Sprintf ("%ss" , blockTime ),
229+ fmt .Sprintf ("%d" , len (bs [j ].Transactions ())),
230+ fmt .Sprintf ("%d" , bs [j ].GasUsed ()),
231+ metrics .TruncateHexString (bs [j ].Hash ().String (), 24 ),
232+ metrics .TruncateHexString (author .String (), 24 ),
157233 }
158234
159235 record := " "
@@ -382,7 +458,7 @@ func GetSimpleReceipt(ctx context.Context, rpc *ethrpc.Client, tx rpctypes.PolyT
382458 return fields
383459}
384460
385- func SetUISkeleton () (blockList * widgets.List , blockInfo * widgets.List , transactionList * widgets.List , transactionInformationList * widgets.List , transactionInfo * widgets.Table , grid * ui.Grid , blockGrid * ui.Grid , transactionGrid * ui.Grid , termUi UiSkeleton ) {
461+ func SetUISkeleton () (blockList * widgets.List , blockInfo * widgets.List , transactionList * widgets.List , transactionInformationList * widgets.List , transactionInfo * widgets.Table , grid * ui.Grid , selectGrid * ui. Grid , blockGrid * ui.Grid , transactionGrid * ui.Grid , termUi UiSkeleton ) {
386462 // help := widgets.NewParagraph()
387463 // help.Title = "Block Headers"
388464 // help.Text = "Use the arrow keys to scroll through the transactions. Press <Esc> to go back to the explorer view"
@@ -437,6 +513,7 @@ func SetUISkeleton() (blockList *widgets.List, blockInfo *widgets.List, transact
437513 slg4 .Title = "Gas Used"
438514
439515 grid = ui .NewGrid ()
516+ selectGrid = ui .NewGrid ()
440517 blockGrid = ui .NewGrid ()
441518 transactionGrid = ui .NewGrid ()
442519
@@ -480,6 +557,26 @@ func SetUISkeleton() (blockList *widgets.List, blockInfo *widgets.List, transact
480557 ui .NewCol (1.0 / 5 , slg4 ),
481558 ),
482559
560+ ui .NewRow (5.0 / 10 ,
561+ ui .NewCol (5.0 / 5 , blockList ),
562+ ),
563+
564+ ui .NewRow (2.0 / 10 ,
565+ ui .NewCol (5.0 / 5 , transactionInfo ),
566+ ),
567+ )
568+
569+ selectGrid .Set (
570+ ui .NewRow (1.0 / 10 , termUi .Current ),
571+
572+ ui .NewRow (2.0 / 10 ,
573+ ui .NewCol (1.0 / 5 , slg0 ),
574+ ui .NewCol (1.0 / 5 , slg1 ),
575+ ui .NewCol (1.0 / 5 , slg2 ),
576+ ui .NewCol (1.0 / 5 , slg3 ),
577+ ui .NewCol (1.0 / 5 , slg4 ),
578+ ),
579+
483580 ui .NewRow (5.0 / 10 ,
484581 ui .NewCol (3.0 / 5 , blockList ),
485582 ui .NewCol (2.0 / 5 , blockInfo ),
0 commit comments