|
23 | 23 | if args.bitcoin_cli_args == []:
|
24 | 24 | args.bitcoin_cli_args = ['-signet']
|
25 | 25 |
|
26 |
| -if args.faucet.lower() == DEFAULT_GLOBAL_FAUCET: |
27 |
| - # Get the hash of the block at height 1 of the currently active signet chain |
| 26 | + |
| 27 | +def bitcoin_cli(rpc_command_and_params): |
| 28 | + argv = [args.cmd] + args.bitcoin_cli_args + rpc_command_and_params |
28 | 29 | try:
|
29 |
| - curr_signet_hash = subprocess.check_output([args.cmd] + args.bitcoin_cli_args + ['getblockhash', '1']).strip().decode() |
| 30 | + return subprocess.check_output(argv).strip().decode() |
30 | 31 | except FileNotFoundError:
|
31 | 32 | print('The binary', args.cmd, 'could not be found.')
|
32 |
| - exit() |
| 33 | + exit(1) |
| 34 | + except subprocess.CalledProcessError: |
| 35 | + cmdline = ' '.join(argv) |
| 36 | + print(f'-----\nError while calling "{cmdline}" (see output above).') |
| 37 | + exit(1) |
| 38 | + |
| 39 | + |
| 40 | +if args.faucet.lower() == DEFAULT_GLOBAL_FAUCET: |
| 41 | + # Get the hash of the block at height 1 of the currently active signet chain |
| 42 | + curr_signet_hash = bitcoin_cli(['getblockhash', '1']) |
33 | 43 | if curr_signet_hash != GLOBAL_FIRST_BLOCK_HASH:
|
34 | 44 | print('The global faucet cannot be used with a custom Signet network. Please use the global signet or setup your custom faucet to use this functionality.\n')
|
35 |
| - exit() |
| 45 | + exit(1) |
36 | 46 |
|
37 | 47 | if args.addr == '':
|
38 | 48 | # get address for receiving coins
|
39 |
| - try: |
40 |
| - args.addr = subprocess.check_output([args.cmd] + args.bitcoin_cli_args + ['getnewaddress', 'faucet', 'bech32']).strip() |
41 |
| - except FileNotFoundError: |
42 |
| - print('The binary', args.cmd, 'could not be found.') |
43 |
| - exit() |
| 49 | + args.addr = bitcoin_cli(['getnewaddress', 'faucet', 'bech32']) |
44 | 50 |
|
45 | 51 | data = {'address': args.addr, 'password': args.password}
|
46 | 52 | try:
|
47 | 53 | res = requests.post(args.faucet, data=data)
|
48 | 54 | except:
|
49 | 55 | print('Unexpected error when contacting faucet:', sys.exc_info()[0])
|
50 |
| - exit() |
| 56 | + exit(1) |
51 | 57 |
|
52 | 58 | # Display the output as per the returned status code
|
53 | 59 | if res:
|
|
0 commit comments