mmnode-blocks-info: add --json-raw option
This commit is contained in:
parent
0dfdcf7372
commit
46bc925a5f
2 changed files with 10 additions and 2 deletions
|
|
@ -521,6 +521,8 @@ class JSONBlocksInfo(BlocksInfo):
|
|||
|
||||
def __init__(self,cmd_args,opt,rpc):
|
||||
super().__init__(cmd_args,opt,rpc)
|
||||
if opt.json_raw:
|
||||
self.output_block = self.output_block_raw
|
||||
Msg_r('{')
|
||||
|
||||
async def process_blocks(self):
|
||||
|
|
@ -528,12 +530,17 @@ class JSONBlocksInfo(BlocksInfo):
|
|||
await super().process_blocks()
|
||||
Msg_r(']')
|
||||
|
||||
def output_block_raw(self,data,n):
|
||||
Msg_r( (', ','')[n==0] + json.dumps(data._asdict()) )
|
||||
|
||||
def output_block(self,data,n):
|
||||
def gen():
|
||||
for k,v in data._asdict().items():
|
||||
vn = self.fields[k].varname
|
||||
yield ( k, (self.fmt_funcs[vn](v) if vn in self.fmt_funcs else v) )
|
||||
Msg_r(json.dumps(dict(gen())))
|
||||
Msg_r( (', ','')[n==0] + json.dumps(dict(gen())))
|
||||
|
||||
def print_header(self): pass
|
||||
|
||||
async def output_stats(self,res):
|
||||
def gen(data):
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ opts_data = {
|
|||
('hashes', True, 'stats', 'none'),
|
||||
('stats', 'none', 'stats_only', False),
|
||||
('stats_only', True, 'no_header', True),
|
||||
('json', True, 'no_header', True),
|
||||
('json_raw', True, 'json', True),
|
||||
],
|
||||
'text': {
|
||||
'desc': 'Display information about a block or range of blocks',
|
||||
|
|
@ -44,6 +44,7 @@ opts_data = {
|
|||
--, --longhelp Print help message for long options (common options)
|
||||
-H, --hashes Display only block numbers and hashes
|
||||
-j, --json Produce JSON output
|
||||
-J, --json-raw Produce JSON output with unformatted values
|
||||
-m, --miner-info Display miner info in coinbase transaction
|
||||
-M, --raw-miner-info Display miner info in uninterpreted form
|
||||
-n, --no-header Don’t print the column header
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue