Changeset View
Changeset View
Standalone View
Standalone View
contrib/linearize/linearize-hashes.py
Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | |||||
def get_block_hashes(settings, max_blocks_per_call=10000): | def get_block_hashes(settings, max_blocks_per_call=10000): | ||||
rpc = BitcoinRPC(settings['host'], settings['port'], | rpc = BitcoinRPC(settings['host'], settings['port'], | ||||
settings['rpcuser'], settings['rpcpassword']) | settings['rpcuser'], settings['rpcpassword']) | ||||
height = settings['min_height'] | height = settings['min_height'] | ||||
while height < settings['max_height'] + 1: | while height < settings['max_height'] + 1: | ||||
num_blocks = min(settings['max_height'] | num_blocks = min(settings['max_height'] + | ||||
+ 1 - height, max_blocks_per_call) | 1 - height, max_blocks_per_call) | ||||
batch = [] | batch = [] | ||||
for x in range(num_blocks): | for x in range(num_blocks): | ||||
batch.append(rpc.build_request(x, 'getblockhash', [height + x])) | batch.append(rpc.build_request(x, 'getblockhash', [height + x])) | ||||
reply = rpc.execute(batch) | reply = rpc.execute(batch) | ||||
if reply is None: | if reply is None: | ||||
print('Cannot continue. Program will halt.') | print('Cannot continue. Program will halt.') | ||||
return None | return None | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | if not use_userpass and not use_datadir: | ||||
print("Missing datadir or username and/or password in cfg file", | print("Missing datadir or username and/or password in cfg file", | ||||
file=sys.stderr) | file=sys.stderr) | ||||
sys.exit(1) | sys.exit(1) | ||||
settings['port'] = int(settings['port']) | settings['port'] = int(settings['port']) | ||||
settings['min_height'] = int(settings['min_height']) | settings['min_height'] = int(settings['min_height']) | ||||
settings['max_height'] = int(settings['max_height']) | settings['max_height'] = int(settings['max_height']) | ||||
# Force hash byte format setting to be lowercase to make comparisons easier. | # Force hash byte format setting to be lowercase to make comparisons | ||||
# easier. | |||||
settings['rev_hash_bytes'] = settings['rev_hash_bytes'].lower() | settings['rev_hash_bytes'] = settings['rev_hash_bytes'].lower() | ||||
# Get the rpc user and pass from the cookie if the datadir is set | # Get the rpc user and pass from the cookie if the datadir is set | ||||
if use_datadir: | if use_datadir: | ||||
get_rpc_cookie() | get_rpc_cookie() | ||||
get_block_hashes(settings) | get_block_hashes(settings) |