diff --git a/mmgen/node_tools/BlocksInfo.py b/mmgen/node_tools/BlocksInfo.py index 4fbe371..46226c5 100644 --- a/mmgen/node_tools/BlocksInfo.py +++ b/mmgen/node_tools/BlocksInfo.py @@ -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): diff --git a/mmnode-blocks-info b/mmnode-blocks-info index 7fb9966..6a1b74d 100755 --- a/mmnode-blocks-info +++ b/mmnode-blocks-info @@ -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