diff options
author | NikhilBartwal <nikhilbartwal1234@gmail.com> | 2021-07-29 15:29:27 +0530 |
---|---|---|
committer | NikhilBartwal <nikhilbartwal1234@gmail.com> | 2021-08-05 02:57:58 +0530 |
commit | 1c612b274b1587c43ee6e6a486aed653b9ca5f70 (patch) | |
tree | e9ee7f630ba841b93a6ced740e6e3d0b8a51c6f1 | |
parent | 3308c61091b6b7cb22569f3abadea6d001295c90 (diff) | |
download | bitcoin-1c612b274b1587c43ee6e6a486aed653b9ca5f70.tar.xz |
[script] Update signet getcoins.py for custom network
Currently, using the getcoins.py with a custom signet executes successfully and shows the transaction as complete, however for obvious reasons, it should not.
This PR adds a sanity check for custom signet by comparing the current network's first block hash with global signet's respective hash.
-rwxr-xr-x | contrib/signet/getcoins.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/contrib/signet/getcoins.py b/contrib/signet/getcoins.py index 691f0bb1b6..0a8e762ff0 100755 --- a/contrib/signet/getcoins.py +++ b/contrib/signet/getcoins.py @@ -5,21 +5,36 @@ import argparse import subprocess -import requests import sys +import requests + +DEFAULT_GLOBAL_FAUCET = 'https://signetfaucet.com/claim' +GLOBAL_FIRST_BLOCK_HASH = '00000086d6b2636cb2a392d45edc4ec544a10024d30141c9adf4bfd9de533b53' parser = argparse.ArgumentParser(description='Script to get coins from a faucet.', epilog='You may need to start with double-dash (--) when providing bitcoin-cli arguments.') parser.add_argument('-c', '--cmd', dest='cmd', default='bitcoin-cli', help='bitcoin-cli command to use') -parser.add_argument('-f', '--faucet', dest='faucet', default='https://signetfaucet.com/claim', help='URL of the faucet') +parser.add_argument('-f', '--faucet', dest='faucet', default=DEFAULT_GLOBAL_FAUCET, help='URL of the faucet') parser.add_argument('-a', '--addr', dest='addr', default='', help='Bitcoin address to which the faucet should send') parser.add_argument('-p', '--password', dest='password', default='', help='Faucet password, if any') parser.add_argument('bitcoin_cli_args', nargs='*', help='Arguments to pass on to bitcoin-cli (default: -signet)') 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 + try: + curr_signet_hash = subprocess.check_output([args.cmd] + args.bitcoin_cli_args + ['getblockhash', '1']).strip().decode() + except FileNotFoundError: + print('The binary', args.cmd, 'could not be found.') + exit() + 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 == '': - if args.bitcoin_cli_args == []: - args.bitcoin_cli_args = ['-signet'] # get address for receiving coins try: args.addr = subprocess.check_output([args.cmd] + args.bitcoin_cli_args + ['getnewaddress', 'faucet', 'bech32']).strip() |