Skip to content

Commit 1c612b2

Browse files
committed
[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.
1 parent 3308c61 commit 1c612b2

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

contrib/signet/getcoins.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,36 @@
55

66
import argparse
77
import subprocess
8-
import requests
98
import sys
9+
import requests
10+
11+
DEFAULT_GLOBAL_FAUCET = 'https://signetfaucet.com/claim'
12+
GLOBAL_FIRST_BLOCK_HASH = '00000086d6b2636cb2a392d45edc4ec544a10024d30141c9adf4bfd9de533b53'
1013

1114
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.')
1215
parser.add_argument('-c', '--cmd', dest='cmd', default='bitcoin-cli', help='bitcoin-cli command to use')
13-
parser.add_argument('-f', '--faucet', dest='faucet', default='https://signetfaucet.com/claim', help='URL of the faucet')
16+
parser.add_argument('-f', '--faucet', dest='faucet', default=DEFAULT_GLOBAL_FAUCET, help='URL of the faucet')
1417
parser.add_argument('-a', '--addr', dest='addr', default='', help='Bitcoin address to which the faucet should send')
1518
parser.add_argument('-p', '--password', dest='password', default='', help='Faucet password, if any')
1619
parser.add_argument('bitcoin_cli_args', nargs='*', help='Arguments to pass on to bitcoin-cli (default: -signet)')
1720

1821
args = parser.parse_args()
1922

23+
if args.bitcoin_cli_args == []:
24+
args.bitcoin_cli_args = ['-signet']
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
28+
try:
29+
curr_signet_hash = subprocess.check_output([args.cmd] + args.bitcoin_cli_args + ['getblockhash', '1']).strip().decode()
30+
except FileNotFoundError:
31+
print('The binary', args.cmd, 'could not be found.')
32+
exit()
33+
if curr_signet_hash != GLOBAL_FIRST_BLOCK_HASH:
34+
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()
36+
2037
if args.addr == '':
21-
if args.bitcoin_cli_args == []:
22-
args.bitcoin_cli_args = ['-signet']
2338
# get address for receiving coins
2439
try:
2540
args.addr = subprocess.check_output([args.cmd] + args.bitcoin_cli_args + ['getnewaddress', 'faucet', 'bech32']).strip()

0 commit comments

Comments
 (0)