(settings, max_blocks_per_call=10000)
| 64 | return 'error' in resp_obj and resp_obj['error'] is not None |
| 65 | |
| 66 | def 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 | |
| 93 | def get_rpc_cookie(): |
| 94 | # Open the cookie file |
no test coverage detected