Skip to content

Commit 0eca5eb

Browse files
committed
contrib: refactor: introduce bitcoin-cli RPC call helper in getcoins.py
1 parent b0c8246 commit 0eca5eb

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

contrib/signet/getcoins.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,26 @@
2323
if args.bitcoin_cli_args == []:
2424
args.bitcoin_cli_args = ['-signet']
2525

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
2829
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()
3031
except FileNotFoundError:
3132
print('The binary', args.cmd, 'could not be found.')
3233
exit()
34+
35+
36+
if args.faucet.lower() == DEFAULT_GLOBAL_FAUCET:
37+
# Get the hash of the block at height 1 of the currently active signet chain
38+
curr_signet_hash = bitcoin_cli(['getblockhash', '1'])
3339
if curr_signet_hash != GLOBAL_FIRST_BLOCK_HASH:
3440
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')
3541
exit()
3642

3743
if args.addr == '':
3844
# 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()
45+
args.addr = bitcoin_cli(['getnewaddress', 'faucet', 'bech32'])
4446

4547
data = {'address': args.addr, 'password': args.password}
4648
try:

0 commit comments

Comments
 (0)