@@ -4,101 +4,70 @@ import Table, { VerticalTable } from 'cli-table3';
44import colors from 'colors/safe' ;
55import { GetInfoRequest , GetInfoResponse , LndInfo , RaidenInfo } from '../../proto/xudrpc_pb' ;
66
7- const displayChannels = ( channels : any , asset : string ) => {
8- const table = new Table ( ) as VerticalTable ;
9- Object . keys ( channels ) . forEach ( ( key : any ) => {
10- table . push ( {
11- [ colors . blue ( key ) ] : channels [ key ] ,
12- } ) ;
13- } ) ;
14- console . log ( colors . underline ( colors . bold ( `\nLnd ${ asset } channels:` ) ) ) ;
15- console . log ( table . toString ( ) , '\n' ) ;
16- } ;
17-
18- const displayChainsList = ( list : any [ ] , asset : string ) => {
19- const table = new Table ( ) as VerticalTable ;
20- list . forEach ( ( asset , i ) => {
21- if ( asset ) {
22- table . push ( { [ colors . blue ( `${ i + 1 } .` ) ] : `${ asset . chain } -${ asset . network } ` } ) ;
23- }
24- } ) ;
25- if ( table . length !== 0 ) {
26- console . log ( colors . underline ( colors . bold ( `\nLnd ${ asset } chains:` ) ) ) ;
27- console . log ( table . toString ( ) , '\n' ) ;
28- }
29- } ;
30-
31- const displayUriList = ( uris : string [ ] , asset : string ) => {
32- const table = new Table ( ) as VerticalTable ;
33- uris . forEach ( ( uri , i ) => table . push ( { [ `${ i + 1 } .` ] : uri } ) ) ;
34- console . log ( colors . underline ( colors . bold ( `\nLnd ${ asset } uris:` ) ) ) ;
35- console . log ( table . toString ( ) , '\n' ) ;
36- } ;
37-
387const displayLndInfo = ( asset : string , info : LndInfo . AsObject ) => {
398 const basicInfotable = new Table ( ) as VerticalTable ;
409 basicInfotable . push (
41- { [ colors . blue ( 'Error ' ) ] : info . error } ,
10+ { [ colors . blue ( 'Status ' ) ] : info . status } ,
4211 ) ;
43- if ( info . blockheight ) {
44- basicInfotable . push ( { [ colors . blue ( 'Block Height' ) ] : info . blockheight } ) ;
45- }
46- if ( info . version ) {
47- basicInfotable . push ( { [ colors . blue ( 'Version' ) ] : info . version } ) ;
48- }
49- if ( info . alias ) {
50- basicInfotable . push ( { [ colors . blue ( 'Alias' ) ] : info . alias } ) ;
51- }
5212
53- console . log ( colors . underline ( colors . bold ( `\nLnd ${ asset } info:` ) ) ) ;
54- console . log ( basicInfotable . toString ( ) , '\n' ) ;
13+ const address = info . urisList [ 0 ] ? ` ${ info . urisList [ 0 ] . substring ( 0 , info . urisList [ 0 ] . indexOf ( '@' ) ) }
14+ ${ info . urisList [ 0 ] . substring ( info . urisList [ 0 ] . indexOf ( '@' ) ) } ` : '' ;
5515
56- if ( info . channels ) {
57- displayChannels ( info . channels , asset ) ;
58- }
59-
60- if ( ! info . error ) {
61- displayChainsList ( info . chainsList , asset ) ;
62- }
16+ basicInfotable . push (
17+ { [ colors . blue ( 'Version' ) ] : info . version || '' } ,
18+ { [ colors . blue ( 'Address' ) ] : address } ,
19+ { [ colors . blue ( 'Alias' ) ] : info . alias || '' } ,
20+ { [ colors . blue ( 'Channels' ) ] :
21+ `Active: ${ info . channels ? info . channels [ 'active' ] : 0 } \
22+ | Pending: ${ info . channels ? info . channels [ 'pending' ] : 0 } \
23+ | Closed: ${ info . channels ? info . channels [ 'closed' ] : 0 } ` ,
24+ } ,
25+ { [ colors . blue ( 'Network' ) ] : info . chainsList && info . chainsList . length > 0 ? `${ info . chainsList [ 0 ] . chain } ${ info . chainsList [ 0 ] . network } ` : '' } ,
26+ ) ;
6327
64- if ( info . urisList . length > 0 ) {
65- displayUriList ( info . urisList , asset ) ;
66- }
28+ console . log ( colors . underline ( colors . bold ( `\nLND-${ asset } Info:` ) ) ) ;
29+ console . log ( basicInfotable . toString ( ) , '\n' ) ;
6730} ;
6831
6932const displayGeneral = ( info : GetInfoResponse . AsObject ) => {
7033 const table = new Table ( ) as VerticalTable ;
34+ const address = info . urisList [ 0 ] ? `${ info . urisList [ 0 ] . substring ( 0 , info . urisList [ 0 ] . indexOf ( '@' ) ) }
35+ ${ info . urisList [ 0 ] . substring ( info . urisList [ 0 ] . indexOf ( '@' ) ) } ` : '' ;
36+
7137 table . push (
38+ { [ colors . blue ( 'Alias' ) ] : info . alias } ,
39+ { [ colors . blue ( 'Node Key' ) ] : info . nodePubKey } ,
40+ { [ colors . blue ( 'Address' ) ] : address } ,
41+ { [ colors . blue ( 'Network' ) ] : info . network } ,
7242 { [ colors . blue ( 'Version' ) ] : info . version } ,
73- { [ colors . blue ( 'Pairs' ) ] : info . numPairs } ,
7443 { [ colors . blue ( 'Peers' ) ] : info . numPeers } ,
75- { [ colors . blue ( 'Node key' ) ] : info . nodePubKey } ,
44+ { [ colors . blue ( 'Pairs' ) ] : info . numPairs } ,
45+ { [ colors . blue ( 'Own orders' ) ] : info . orders ? info . orders . own : '0' } ,
46+ { [ colors . blue ( 'Peer orders' ) ] : info . orders ? info . orders . peer : '0' } ,
47+ { [ colors . blue ( 'Pending swaps' ) ] : info . pendingSwapHashesList ? JSON . stringify ( info . pendingSwapHashesList , undefined , 1 ) : '' } ,
7648 ) ;
77- if ( info . orders ) {
78- table . push (
79- { [ colors . blue ( 'Own orders' ) ] : info . orders . own } ,
80- { [ colors . blue ( 'Peer orders' ) ] : info . orders . peer } ,
81- ) ;
82- }
83- if ( info . pendingSwapHashesList ) {
84- table . push (
85- { [ colors . blue ( 'Pending swaps' ) ] : JSON . stringify ( info . pendingSwapHashesList ) } ,
86- ) ;
87- }
8849 console . log ( colors . underline ( colors . bold ( '\nGeneral XUD Info' ) ) ) ;
8950 console . log ( table . toString ( ) , '\n' ) ;
9051} ;
9152
9253const displayRaiden = ( info : RaidenInfo . AsObject ) => {
9354 const table = new Table ( ) as VerticalTable ;
55+
9456 table . push (
57+ { [ colors . blue ( 'Status' ) ] : info . status } ,
9558 { [ colors . blue ( 'Version' ) ] : info . version } ,
9659 { [ colors . blue ( 'Address' ) ] : info . address } ,
97- { [ colors . blue ( 'Channels' ) ] : info . channels } ,
98- { [ colors . blue ( 'Error' ) ] : info . error } ,
60+ { [ colors . blue ( 'Channels' ) ] :
61+ `Active: ${ info . channels ? info . channels [ 'active' ] : 0 } \
62+ | Pending: 0\
63+ | Closed: ${ info . channels ? info . channels [ 'closed' ] : 0 } ` ,
64+ } ,
65+ { [ colors . blue ( 'Network' ) ] : info . chain } ,
9966 ) ;
67+
10068 console . log ( colors . underline ( colors . bold ( '\nRaiden info:' ) ) ) ;
10169 console . log ( table . toString ( ) , '\n' ) ;
70+
10271} ;
10372
10473const displayGetInfo = ( response : GetInfoResponse . AsObject ) => {
0 commit comments