mmnode-blocks-info 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2021 The MMGen Project <mmgen@tuta.io>
  5. #
  6. # This program is free software: you can redistribute it and/or modify it under
  7. # the terms of the GNU General Public License as published by the Free Software
  8. # Foundation, either version 3 of the License, or (at your option) any later
  9. # version.
  10. #
  11. # This program is distributed in the hope that it will be useful, but WITHOUT
  12. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  14. # details.
  15. #
  16. # You should have received a copy of the GNU General Public License along with
  17. # this program. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. mmnode-blocks-info: Display information about a block or range of blocks
  20. """
  21. from mmgen.common import *
  22. from mmgen.node_tools.BlocksInfo import BlocksInfo
  23. opts_data = {
  24. 'sets': [
  25. ('raw_miner_info', True, 'miner_info', True),
  26. ('summary', True, 'raw_miner_info', False),
  27. ('summary', True, 'miner_info', False),
  28. ('hashes', True, 'fields', 'block,hash'),
  29. ('hashes', True, 'no_summary', True),
  30. ],
  31. 'text': {
  32. 'desc': 'Display information about a block or range of blocks',
  33. 'usage': '[opts] blocknum [blocknum ...] | blocknum-blocknum[+step] | [blocknum|-nBlocks]+nBlocks[+step]',
  34. 'usage2': [
  35. '[opts] blocknum [blocknum ...]',
  36. '[opts] blocknum-blocknum[+step]',
  37. '[opts] [blocknum|-nBlocks]+nBlocks[+step]',
  38. ],
  39. 'options': """
  40. -h, --help Print this help message
  41. --, --longhelp Print help message for long options (common options)
  42. -D, --no-diff-stats Omit difficulty adjustment stats from summary
  43. -H, --hashes Display only block numbers and hashes
  44. -m, --miner-info Display miner info in coinbase transaction
  45. -M, --raw-miner-info Display miner info in uninterpreted form
  46. -n, --no-header Don’t print the column header
  47. -o, --fields= Display the specified fields (comma-separated list)
  48. See AVAILABLE FIELDS below. If the first character
  49. is '+', fields are appended to the defaults.
  50. -s, --summary Print the summary only
  51. -S, --no-summary Don’t print the summary
  52. """,
  53. 'notes': """
  54. If no block number is specified, the current block is assumed. The string
  55. 'cur' can be used in place of the current block number.
  56. If the requested range ends at the current chain tip, an estimate of the next
  57. difficulty adjustment is also displayed. The estimate is based on the average
  58. Block Discovery Interval from the beginning of the current 2016-block period.
  59. All fee fields except for 'totalfee' are in satoshis per virtual byte.
  60. AVAILABLE FIELDS: {f}
  61. EXAMPLES:
  62. # Display info for current block:
  63. {p}
  64. # Display info for the Genesis Block:
  65. {p} 0
  66. # Display info for the last 20 blocks:
  67. {p} +20
  68. # Display specified fields for blocks 165-190
  69. {p} -o block,date,size,inputs,nTx 165-190
  70. # Display info for 10 blocks beginning at block 600000:
  71. {p} 600000+10
  72. # Display info for every 5th block of 50-block range beginning at 1000
  73. # blocks from chain tip:
  74. {p} -- -1000+50+5
  75. # Display info for block 152817, adding miner field:
  76. {p} --miner-info 152817
  77. # Display specified fields for listed blocks:
  78. {p} -o block,date,hash 245798 170 624044
  79. # Display every difficulty adjustment from Genesis Block to chain tip:
  80. {p} -o +difficulty 0-cur+2016
  81. # Display roughly a block a day over the last two weeks. Note that
  82. # multiplication is allowed in the nBlocks spec:
  83. {p} +144*14+144
  84. This program requires a txindex-enabled daemon for correct operation.
  85. """.format(
  86. f = fmt_list(BlocksInfo.fields,fmt='bare'),
  87. p = g.prog_name )
  88. }
  89. }
  90. cmd_args = opts.init(opts_data)
  91. async def main():
  92. from mmgen.protocol import init_proto_from_opts
  93. proto = init_proto_from_opts()
  94. from mmgen.rpc import rpc_init
  95. m = BlocksInfo( cmd_args, opt, await rpc_init(proto) )
  96. if not (opt.summary or opt.no_header):
  97. m.print_header()
  98. await m.run()
  99. if m.last and not opt.no_summary:
  100. Msg('')
  101. await m.print_range_stats()
  102. if not opt.no_diff_stats:
  103. Msg('')
  104. await m.print_diff_stats()
  105. run_session(main())