2020 Activated protocol features\n \
2121 Preview of MI and KV tables on each account\n "
2222
23+
2324def getJSONResp (conn , rpc , req_body = "" , exitOnError = True ):
2425 conn .request ("POST" , rpc , body = req_body )
2526 resp = conn .getresponse ()
27+
2628 json_resp = resp .read ()
2729 json_data = json .loads (json_resp )
2830 if 'code' in json_data :
@@ -34,11 +36,12 @@ def getJSONResp(conn, rpc, req_body="", exitOnError=True):
3436
3537 return json_data
3638
39+
3740if __name__ == "__main__" :
3841 rpc_endpt = "127.0.0.1:8888"
3942 nArg = len (sys .argv )
40- if nArg > 2 :
41- print (f"ERROR At most one argument expected, got { nArg } " )
43+ if nArg > 5 :
44+ print (f"ERROR At most four arguments expected, got { nArg } " )
4245 print (USAGE )
4346 exit (1 )
4447 if nArg > 1 :
@@ -58,13 +61,19 @@ def getJSONResp(conn, rpc, req_body="", exitOnError=True):
5861 page_size = 1024
5962 if len (sys .argv ) > 2 :
6063 page_size = int (sys .argv [2 ])
64+ scope_limit = 10
65+ if len (sys .argv ) > 3 :
66+ scope_limit = int (sys .argv [3 ])
67+ table_row_limit = 10
68+ if len (sys .argv ) > 4 :
69+ table_row_limit = int (sys .argv [4 ])
6170
6271 # get the server info
6372 conn = http .client .HTTPConnection (rpc_endpt )
6473 server_info_begin = getJSONResp (conn , "/v1/chain/get_info" )
6574
6675 # get all accounts on the chain
67- limit = 2
76+ limit = page_size
6877 moreAccounts = True
6978 all_accts = []
7079 req_body = '{"limit":' + str (limit ) + '}'
@@ -98,8 +107,6 @@ def getJSONResp(conn, rpc, req_body="", exitOnError=True):
98107
99108 accts_lst .append (e )
100109
101- scope_limit = 10
102- table_row_limit = 10
103110 for a in accts_lst :
104111 # get scopes and tables
105112 nm = a ['name' ]
@@ -134,7 +141,7 @@ def getJSONResp(conn, rpc, req_body="", exitOnError=True):
134141 table_rows = getJSONResp (conn , "/v1/chain/get_kv_table_rows" , req_body , exitOnError = False )
135142 a ['kv_tables' ][tbl_name + ":" + tbl_idx_nm ] = table_rows
136143
137- data = {'accounts' : accts_lst }
144+ data = {'accounts' : accts_lst , 'scope_limit' : scope_limit , 'table_row_limit' : table_row_limit }
138145
139146 prod_sched = getJSONResp (conn , "/v1/chain/get_producer_schedule" )
140147 data ['producer_schedule' ] = prod_sched
@@ -144,16 +151,20 @@ def getJSONResp(conn, rpc, req_body="", exitOnError=True):
144151 data ['activated_protocol_features' ] = prot_feats
145152
146153 # get deferred transactions
147- limit = 100
148- req_body = '{' + f'"limit" : { limit } ' + '}'
154+ limit = page_size
155+ req_body = '{ "json":true, ' + f'"limit": { limit } ' + '}'
149156 trx = getJSONResp (conn , "/v1/chain/get_scheduled_transactions" , req_body , exitOnError = False )
150157 deferred_trx = []
158+ deferred_trx .extend (trx ['transactions' ])
151159 while 'more' in trx and len (trx ['more' ]) > 0 :
152- deferred_trx .append (trx ['transactions' ])
153- req_body = '{' + f'"limit" : { limit } , "more" : { trx ["more" ]} ' + '}'
160+ deferred_trx .extend (trx ['transactions' ])
161+ more_trx = trx ["more" ]
162+ req_body = '{"json":true, ' + f'"limit":{ limit } , "more":"{ more_trx } "' + '}'
154163
155164 trx = getJSONResp (conn , "/v1/chain/get_scheduled_transactions" , req_body , exitOnError = False )
156165
166+ data ['deferred_transactions' ] = deferred_trx
167+
157168 # get the server info again
158169 server_info_end = getJSONResp (conn , "/v1/chain/get_info" )
159170
@@ -243,7 +254,7 @@ def getJSONResp(conn, rpc, req_body="", exitOnError=True):
243254 if 'rows' in tbl :
244255 print ('[' , end = "" )
245256 for v in tbl ['rows' ]:
246- print (v , end = ", " )
257+ print (v , end = ", " )
247258 if tbl ['more' ]:
248259 print ("(truncated)" , end = "" )
249260 print (']' )
@@ -253,8 +264,8 @@ def getJSONResp(conn, rpc, req_body="", exitOnError=True):
253264 if scopes ['more' ]:
254265 print (f"{ a ['name' ]:13} | (truncated)" )
255266 if not atLeastOne :
256- print ("(None)" )
257-
267+ print ("(None)" )
268+
258269 print ("\n \n ====== KV TABLES ======" )
259270 print ("Account Table:Primary Index Values" )
260271 print ("---------------------------------------------------------------------------------------------------------" )
@@ -266,7 +277,7 @@ def getJSONResp(conn, rpc, req_body="", exitOnError=True):
266277 for tbl_nm_idx , kv_tbl in kv_tables .items ():
267278 print (f"{ a ['name' ]:13} | { tbl_nm_idx :27} | [" , end = "" )
268279 for v in kv_tbl ['rows' ]:
269- print (v , end = ", " )
280+ print (v , end = ", " )
270281 if kv_tbl ['more' ]:
271282 print ("(truncated)" , end = "" )
272283 print (']' )
0 commit comments