1414
1515def make_parser (parser ):
1616
17- parser .add_argument (
18- "-bh" ,
19- "--block_header_hash" ,
20- help = "Look up a block by block header hash string." ,
21- type = str ,
22- default = "" ,
23- )
24- parser .add_argument (
25- "-b" ,
26- "--block_by_header_hash" ,
27- help = "Look up a block by block header hash string." ,
28- type = str ,
29- default = "" ,
30- )
3117 parser .add_argument (
3218 "-s" ,
3319 "--state" ,
@@ -37,6 +23,7 @@ def make_parser(parser):
3723 const = True ,
3824 default = False ,
3925 )
26+
4027 parser .add_argument (
4128 "-c" ,
4229 "--connections" ,
@@ -48,21 +35,19 @@ def make_parser(parser):
4835 )
4936
5037 parser .add_argument (
51- "-p" ,
52- "--rpc-port" ,
53- help = f"Set the port where the Full Node is hosting the RPC interface. See the rpc_port "
54- f"under full_node in config.yaml. Defaults to 8555" ,
55- type = int ,
56- default = 8555 ,
38+ "-b" ,
39+ "--block-by-header-hash" ,
40+ help = "Look up a block by block header hash." ,
41+ type = str ,
42+ default = "" ,
5743 )
5844
5945 parser .add_argument (
60- "-e" ,
61- "--exit-node" ,
62- help = "Shut down the running Full Node" ,
63- nargs = "?" ,
64- const = True ,
65- default = False ,
46+ "-bh" ,
47+ "--block-header-hash-by-height" ,
48+ help = "Look up a block header hash by block height." ,
49+ type = str ,
50+ default = "" ,
6651 )
6752
6853 parser .add_argument (
@@ -80,18 +65,33 @@ def make_parser(parser):
8065 type = str ,
8166 default = "" ,
8267 )
68+
69+ parser .add_argument (
70+ "-e" ,
71+ "--exit-node" ,
72+ help = "Shut down the running Full Node" ,
73+ nargs = "?" ,
74+ const = True ,
75+ default = False ,
76+ )
77+
78+ parser .add_argument (
79+ "-p" ,
80+ "--rpc-port" ,
81+ help = f"Set the port where the Full Node is hosting the RPC interface. See the rpc_port "
82+ f"under full_node in config.yaml. Defaults to 8555" ,
83+ type = int ,
84+ default = 8555 ,
85+ )
8386 parser .set_defaults (function = show )
8487
8588
8689async def show_async (args , parser ):
8790
88- # print(args)
91+ # TODO read configuration for rpc_port instead of assuming default
8992 try :
9093 client = await RpcClient .create (args .rpc_port )
9194
92- # print (dir(client))
93- # TODO: Add other rpc calls
94- # TODO: pretty print response
9595 if args .state :
9696 blockchain_state = await client .get_blockchain_state ()
9797 lca_block = blockchain_state ["lca" ]
@@ -157,7 +157,7 @@ async def show_async(args, parser):
157157 )
158158 else :
159159 print ("" , latest_blocks_labels [i ])
160- # if called together with other arguments , leave a blank line
160+ # if called together with connections , leave a blank line
161161 if args .connections :
162162 print ("" )
163163 if args .connections :
@@ -182,7 +182,7 @@ async def show_async(args, parser):
182182 f"{ mb_down :7.1f} |{ mb_up :<7.1f} "
183183 )
184184 print (con_str )
185- # if called together with other arguments , leave a blank line
185+ # if called together with state , leave a blank line
186186 if args .state :
187187 print ("" )
188188 if args .exit_node :
@@ -227,17 +227,17 @@ async def show_async(args, parser):
227227 elif result_txt == "" :
228228 result_txt = f"NodeID { args .remove_connection } ... not found."
229229 print (result_txt )
230- if args .block_header_hash != "" :
231- block_header = await client .get_block (
232- hexstr_to_bytes ( args .block_header_hash )
230+ if args .block_header_hash_by_height != "" :
231+ block_header = await client .get_header_by_height (
232+ args .block_header_hash_by_height
233233 )
234234 if block_header is not None :
235- print ( "Block header:" )
236- print (block_header . header )
237- block_time = struct_time ( localtime ( block_header . header . data . timestamp ))
238- print ( "Block time:" , time . strftime ( "%a %b %d %Y %T %Z" , block_time ) )
235+ block_header_string = str ( block_header . get_hash () )
236+ print (
237+ f"Header hash of block { args . block_header_hash_by_height } : { block_header_string } "
238+ )
239239 else :
240- print ("Block hash " , args .block_header_hash , "not found." )
240+ print ("Block height " , args .block_header_hash_by_height , "not found." )
241241 if args .block_by_header_hash != "" :
242242 block = await client .get_block (hexstr_to_bytes (args .block_by_header_hash ))
243243 # Would like to have a verbose flag for this
0 commit comments