/usr/share/doc/python3-bitcoinlib/examples/make-bootstrap-rpc.py is in python3-bitcoinlib 0.9.0-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #!/usr/bin/env python3
# Copyright (C) 2013-2014 The python-bitcoinlib developers
#
# This file is part of python-bitcoinlib.
#
# It is subject to the license terms in the LICENSE file found in the top-level
# directory of this distribution.
#
# No part of python-bitcoinlib, including this file, may be copied, modified,
# propagated, or distributed except according to the terms contained in the
# LICENSE file.
"""Make a boostrap.dat file by getting the blocks from the RPC interface."""
import sys
if sys.version_info.major < 3:
sys.stderr.write('Sorry, Python 3.x required by this example.\n')
sys.exit(1)
import bitcoin
import bitcoin.rpc
import struct
import sys
import time
try:
if len(sys.argv) not in (2, 3):
raise Exception
n = int(sys.argv[1])
if len(sys.argv) == 3:
bitcoin.SelectParams(sys.argv[2])
except Exception as ex:
print('Usage: %s <block-height> [network=(mainnet|testnet|regtest)] > bootstrap.dat' % sys.argv[0], file=sys.stderr)
sys.exit(1)
proxy = bitcoin.rpc.Proxy()
total_bytes = 0
start_time = time.time()
fd = sys.stdout.buffer
for i in range(n + 1):
block = proxy.getblock(proxy.getblockhash(i))
block_bytes = block.serialize()
total_bytes += len(block_bytes)
print('%.2f KB/s, height %d, %d bytes' %
((total_bytes / 1000) / (time.time() - start_time),
i, len(block_bytes)),
file=sys.stderr)
fd.write(bitcoin.params.MESSAGE_START)
fd.write(struct.pack('<i', len(block_bytes)))
fd.write(block_bytes)
|