2019-02-15 15:49:55 +00:00
|
|
|
#!/usr/bin/env python3
|
2017-10-02 17:55:35 +03:00
|
|
|
#
|
|
|
|
|
# mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
|
2021-03-12 09:32:25 +00:00
|
|
|
# Copyright (C)2013-2021 The MMGen Project <mmgen@tuta.io>
|
2017-10-02 17:55:35 +03:00
|
|
|
#
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify it under
|
|
|
|
|
# the terms of the GNU General Public License as published by the Free Software
|
|
|
|
|
# Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
|
# version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
|
# details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
|
# this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
"""
|
2021-03-12 18:20:44 +00:00
|
|
|
mmnode-blocks-info: Display information about a block or range of blocks
|
2017-10-02 17:55:35 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from mmgen.common import *
|
2021-03-20 12:16:29 +00:00
|
|
|
from mmgen.node_tools.BlocksInfo import BlocksInfo,JSONBlocksInfo
|
2020-05-11 15:11:54 +00:00
|
|
|
|
2021-03-13 16:49:05 +00:00
|
|
|
opts_data = {
|
|
|
|
|
'sets': [
|
2021-03-22 14:32:58 +00:00
|
|
|
('header_info', True, 'fields', None),
|
|
|
|
|
('header_info', True, 'miner_info', None),
|
|
|
|
|
('header_info', True, 'stats', 'range'),
|
|
|
|
|
('json_raw', True, 'json', True),
|
|
|
|
|
('raw_miner_info', True, 'miner_info', True),
|
2021-03-23 20:46:34 +00:00
|
|
|
('stats_only', True, 'no_header', True),
|
2021-03-13 16:49:05 +00:00
|
|
|
],
|
|
|
|
|
'text': {
|
2021-03-13 17:03:06 +00:00
|
|
|
'desc': 'Display information about a block or range of blocks',
|
2021-03-16 16:25:48 +00:00
|
|
|
'usage': '[opts] blocknum [blocknum ...] | blocknum-blocknum[+step] | [blocknum|-nBlocks]+nBlocks[+step]',
|
|
|
|
|
'usage2': [
|
|
|
|
|
'[opts] blocknum [blocknum ...]',
|
|
|
|
|
'[opts] blocknum-blocknum[+step]',
|
|
|
|
|
'[opts] [blocknum|-nBlocks]+nBlocks[+step]',
|
|
|
|
|
],
|
2021-03-13 16:49:05 +00:00
|
|
|
'options': """
|
|
|
|
|
-h, --help Print this help message
|
|
|
|
|
--, --longhelp Print help message for long options (common options)
|
2021-03-22 14:32:58 +00:00
|
|
|
-H, --header-info Display information from block headers only
|
2021-03-20 12:16:29 +00:00
|
|
|
-j, --json Produce JSON output
|
2021-03-20 21:39:40 +00:00
|
|
|
-J, --json-raw Produce JSON output with unformatted values
|
2021-03-13 16:49:05 +00:00
|
|
|
-m, --miner-info Display miner info in coinbase transaction
|
|
|
|
|
-M, --raw-miner-info Display miner info in uninterpreted form
|
2021-03-13 17:03:06 +00:00
|
|
|
-n, --no-header Don’t print the column header
|
2021-03-19 14:09:01 +00:00
|
|
|
-o, --fields= Display the specified fields (comma-separated list).
|
2021-03-21 12:45:41 +00:00
|
|
|
See AVAILABLE FIELDS below. Prefix the list with '+'
|
|
|
|
|
to add the fields to the defaults, or '-' to remove
|
|
|
|
|
them. The special values 'all' and 'none' select all
|
|
|
|
|
available fields or none, respectively.
|
2021-03-19 14:09:01 +00:00
|
|
|
-s, --stats= Display the specified stats (comma-separated list).
|
2021-03-21 12:45:41 +00:00
|
|
|
See AVAILABLE STATS below. The prefixes and special
|
|
|
|
|
values available to the --fields option are recognized.
|
2021-03-23 20:46:34 +00:00
|
|
|
-S, --stats-only Display stats only. Suppress display of per-block data.
|
2021-03-13 16:49:05 +00:00
|
|
|
""",
|
|
|
|
|
'notes': """
|
2021-03-21 12:45:41 +00:00
|
|
|
If no block number is specified, the current chain tip is assumed.
|
|
|
|
|
|
|
|
|
|
The special value 'cur' can be used to designate the chain tip wherever a
|
|
|
|
|
block number is expected.
|
2021-03-13 16:49:05 +00:00
|
|
|
|
2021-03-13 17:03:06 +00:00
|
|
|
If the requested range ends at the current chain tip, an estimate of the next
|
|
|
|
|
difficulty adjustment is also displayed. The estimate is based on the average
|
|
|
|
|
Block Discovery Interval from the beginning of the current 2016-block period.
|
2021-03-13 16:49:05 +00:00
|
|
|
|
2021-03-16 16:08:00 +00:00
|
|
|
All fee fields except for 'totalfee' are in satoshis per virtual byte.
|
|
|
|
|
|
2021-03-14 11:47:19 +00:00
|
|
|
AVAILABLE FIELDS: {f}
|
|
|
|
|
|
2021-03-19 14:09:01 +00:00
|
|
|
AVAILABLE STATS: {s}
|
|
|
|
|
|
2021-03-14 11:47:19 +00:00
|
|
|
EXAMPLES:
|
|
|
|
|
|
2021-03-21 12:45:41 +00:00
|
|
|
Display info for current block:
|
|
|
|
|
$ {p}
|
|
|
|
|
|
|
|
|
|
Display info for the Genesis Block:
|
|
|
|
|
$ {p} 0
|
|
|
|
|
|
|
|
|
|
Display info for the last 20 blocks:
|
|
|
|
|
$ {p} +20
|
2021-03-14 11:47:19 +00:00
|
|
|
|
2021-03-21 12:45:41 +00:00
|
|
|
Display specified fields for blocks 165-190
|
|
|
|
|
$ {p} -o block,date,size,inputs,nTx 165-190
|
2021-03-14 11:47:19 +00:00
|
|
|
|
2021-03-21 12:45:41 +00:00
|
|
|
Display info for 10 blocks beginning at block 600000:
|
|
|
|
|
$ {p} 600000+10
|
2021-03-14 11:47:19 +00:00
|
|
|
|
2021-03-21 12:45:41 +00:00
|
|
|
Display info for every 5th block of 50-block range beginning at 1000
|
|
|
|
|
blocks from chain tip:
|
|
|
|
|
$ {p} -- -1000+50+5
|
2021-03-16 16:25:48 +00:00
|
|
|
|
2021-03-21 12:45:41 +00:00
|
|
|
Display info for block 152817, adding miner field:
|
|
|
|
|
$ {p} -o +miner 152817
|
2021-03-16 16:25:48 +00:00
|
|
|
|
2021-03-21 12:45:41 +00:00
|
|
|
Display specified fields for listed blocks:
|
|
|
|
|
$ {p} -o block,date,hash 245798 170 624044
|
2021-03-14 13:28:03 +00:00
|
|
|
|
2021-03-21 12:45:41 +00:00
|
|
|
Display every difficulty adjustment from Genesis Block to chain tip:
|
|
|
|
|
$ {p} -o +difficulty 0-cur+2016
|
2021-03-14 11:47:19 +00:00
|
|
|
|
2021-03-21 12:45:41 +00:00
|
|
|
Display roughly a block a day over the last two weeks. Note that
|
|
|
|
|
multiplication is allowed in the nBlocks spec:
|
|
|
|
|
$ {p} +144*14+144
|
2021-03-16 16:25:48 +00:00
|
|
|
|
2021-03-21 12:45:41 +00:00
|
|
|
Display only range stats for the last ten blocks:
|
|
|
|
|
$ {p} -o none -s range +10
|
2021-03-14 11:47:19 +00:00
|
|
|
|
2021-03-21 12:45:41 +00:00
|
|
|
Display data for the last ten blocks, skipping 'size' and 'subsidy'
|
|
|
|
|
fields and stats:
|
|
|
|
|
$ {p} -o -size,subsidy -s none +10
|
2021-03-13 17:03:06 +00:00
|
|
|
|
2021-03-21 12:45:41 +00:00
|
|
|
Display all fields and stats for the last ten blocks:
|
|
|
|
|
$ {p} -o all -s all +10
|
2021-03-19 14:09:01 +00:00
|
|
|
|
2021-03-23 20:46:34 +00:00
|
|
|
Same as above, but display stats only:
|
|
|
|
|
$ {p} -o all -s all -S +10
|
|
|
|
|
|
2021-03-22 14:32:58 +00:00
|
|
|
Display headers-only info for the last 1000 blocks. Speed up execution
|
|
|
|
|
using the async RPC backend:
|
|
|
|
|
$ {p} --rpc-backend=aio -H +1000
|
|
|
|
|
|
2021-03-13 17:03:06 +00:00
|
|
|
This program requires a txindex-enabled daemon for correct operation.
|
2021-03-14 11:47:19 +00:00
|
|
|
""".format(
|
|
|
|
|
f = fmt_list(BlocksInfo.fields,fmt='bare'),
|
2021-03-19 14:09:01 +00:00
|
|
|
s = fmt_list(BlocksInfo.all_stats,fmt='bare'),
|
2021-03-14 11:47:19 +00:00
|
|
|
p = g.prog_name )
|
2021-03-13 16:49:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 15:11:54 +00:00
|
|
|
cmd_args = opts.init(opts_data)
|
|
|
|
|
|
|
|
|
|
async def main():
|
2020-06-01 20:29:58 +00:00
|
|
|
|
|
|
|
|
from mmgen.protocol import init_proto_from_opts
|
2021-03-20 12:06:14 +00:00
|
|
|
from mmgen.rpc import rpc_init
|
|
|
|
|
|
2020-06-01 20:29:58 +00:00
|
|
|
proto = init_proto_from_opts()
|
|
|
|
|
|
2021-03-20 12:16:29 +00:00
|
|
|
cls = JSONBlocksInfo if opt.json else BlocksInfo
|
|
|
|
|
|
|
|
|
|
m = cls( cmd_args, opt, await rpc_init(proto) )
|
2020-05-11 15:11:54 +00:00
|
|
|
|
2021-03-21 12:45:41 +00:00
|
|
|
if m.fnames and not opt.no_header:
|
2021-03-12 10:32:25 +00:00
|
|
|
m.print_header()
|
|
|
|
|
|
2021-03-20 12:06:14 +00:00
|
|
|
await m.process_blocks()
|
2021-03-12 10:32:25 +00:00
|
|
|
|
2021-03-22 14:32:58 +00:00
|
|
|
if m.last:
|
2021-03-21 12:45:41 +00:00
|
|
|
for i,sname in enumerate(m.stats):
|
2021-03-20 12:06:14 +00:00
|
|
|
m.process_stats_pre(i)
|
2021-03-21 12:45:41 +00:00
|
|
|
await m.process_stats(sname)
|
2021-03-20 12:06:14 +00:00
|
|
|
|
|
|
|
|
m.finalize_output()
|
2020-05-11 15:11:54 +00:00
|
|
|
|
|
|
|
|
run_session(main())
|