MCPcopy Create free account
hub / github.com/ElementsProject/elements / get_block_hashes

Function get_block_hashes

contrib/linearize/linearize-hashes.py:66–91  ·  view source on GitHub ↗
(settings, max_blocks_per_call=10000)

Source from the content-addressed store, hash-verified

64 return 'error' in resp_obj and resp_obj['error'] is not None
65
66def get_block_hashes(settings, max_blocks_per_call=10000):
67 rpc = BitcoinRPC(settings['host'], settings['port'],
68 settings['rpcuser'], settings['rpcpassword'])
69
70 height = settings['min_height']
71 while height < settings['max_height']+1:
72 num_blocks = min(settings['max_height']+1-height, max_blocks_per_call)
73 batch = []
74 for x in range(num_blocks):
75 batch.append(rpc.build_request(x, 'getblockhash', [height + x]))
76
77 reply = rpc.execute(batch)
78 if reply is None:
79 print('Cannot continue. Program will halt.')
80 return None
81
82 for x,resp_obj in enumerate(reply):
83 if rpc.response_is_error(resp_obj):
84 print('JSON-RPC: error at height', height+x, ': ', resp_obj['error'], file=sys.stderr)
85 sys.exit(1)
86 assert(resp_obj['id'] == x) # assume replies are in-sequence
87 if settings['rev_hash_bytes'] == 'true':
88 resp_obj['result'] = hex_switchEndian(resp_obj['result'])
89 print(resp_obj['result'])
90
91 height += num_blocks
92
93def get_rpc_cookie():
94 # Open the cookie file

Callers 1

Calls 6

build_requestMethod · 0.95
executeMethod · 0.95
response_is_errorMethod · 0.95
BitcoinRPCClass · 0.85
hex_switchEndianFunction · 0.70
enumerateFunction · 0.50

Tested by

no test coverage detected