From 0eca5ebaced264d041de815316eaca8cf6fef92f Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Fri, 6 Aug 2021 22:33:48 +0200 Subject: contrib: refactor: introduce bitcoin-cli RPC call helper in getcoins.py --- contrib/signet/getcoins.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'contrib') diff --git a/contrib/signet/getcoins.py b/contrib/signet/getcoins.py index c50c2cc16a..d0a12beb29 100755 --- a/contrib/signet/getcoins.py +++ b/contrib/signet/getcoins.py @@ -23,24 +23,26 @@ args = parser.parse_args() if args.bitcoin_cli_args == []: args.bitcoin_cli_args = ['-signet'] -if args.faucet.lower() == DEFAULT_GLOBAL_FAUCET: - # Get the hash of the block at height 1 of the currently active signet chain + +def bitcoin_cli(rpc_command_and_params): + argv = [args.cmd] + args.bitcoin_cli_args + rpc_command_and_params try: - curr_signet_hash = subprocess.check_output([args.cmd] + args.bitcoin_cli_args + ['getblockhash', '1']).strip().decode() + return subprocess.check_output(argv).strip().decode() except FileNotFoundError: print('The binary', args.cmd, 'could not be found.') exit() + + +if args.faucet.lower() == DEFAULT_GLOBAL_FAUCET: + # Get the hash of the block at height 1 of the currently active signet chain + curr_signet_hash = bitcoin_cli(['getblockhash', '1']) if curr_signet_hash != GLOBAL_FIRST_BLOCK_HASH: 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') exit() if args.addr == '': # get address for receiving coins - try: - args.addr = subprocess.check_output([args.cmd] + args.bitcoin_cli_args + ['getnewaddress', 'faucet', 'bech32']).strip() - except FileNotFoundError: - print('The binary', args.cmd, 'could not be found.') - exit() + args.addr = bitcoin_cli(['getnewaddress', 'faucet', 'bech32']) data = {'address': args.addr, 'password': args.password} try: -- cgit v1.2.3