aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@protonmail.com>2020-11-19 12:08:48 +0100
committerWladimir J. van der Laan <laanwj@protonmail.com>2020-11-19 12:09:19 +0100
commitd9180c50b689d2fc05662579d2e742e4cc49ac5e (patch)
tree35d36467abd87b663493bae391d872da959f2133 /contrib
parent1cc5e693c1863fc758edcf43e68cdd256193b411 (diff)
parente9c8e6eea2dde6ccd5f685956392ee70c8cfefb7 (diff)
downloadbitcoin-d9180c50b689d2fc05662579d2e742e4cc49ac5e.tar.xz
Merge #20145: contrib: add getcoins.py script to get coins from (signet) faucet
e9c8e6eea2dde6ccd5f685956392ee70c8cfefb7 doc: add contrib/signet readme (Karl-Johan Alm) 355d0c4f6b8a7687a3940a2d90d66b08e560bfa7 contrib: add getcoins.py script to get coins from (signet) faucet (Karl-Johan Alm) Pull request description: This adds a small python script that can be used to fetch Signet coins from the default (or custom) faucet. ACKs for top commit: laanwj: Code and documentation review ACK e9c8e6eea2dde6ccd5f685956392ee70c8cfefb7 Tree-SHA512: 9aaeb96bf0c636a38e2dbe4cfc8b3ef907b1c05d0b782ee51223014952e07ce45a071c7e99aa9aa7700196a67f8a47d74d13e5e8d6890b9be503acd2bacd4d4f
Diffstat (limited to 'contrib')
-rw-r--r--contrib/signet/README.md19
-rwxr-xr-xcontrib/signet/getcoins.py36
2 files changed, 55 insertions, 0 deletions
diff --git a/contrib/signet/README.md b/contrib/signet/README.md
new file mode 100644
index 0000000000..c4aa5ae2f7
--- /dev/null
+++ b/contrib/signet/README.md
@@ -0,0 +1,19 @@
+Contents
+========
+This directory contains tools related to Signet, both for running a Signet yourself and for using one.
+
+getcoins.py
+===========
+
+A script to call a faucet to get Signet coins.
+
+Syntax: `getcoins.py [-h|--help] [-c|--cmd=<bitcoin-cli path>] [-f|--faucet=<faucet URL>] [-a|--addr=<signet bech32 address>] [-p|--password=<faucet password>] [--] [<bitcoin-cli args>]`
+
+* `--cmd` lets you customize the bitcoin-cli path. By default it will look for it in the PATH
+* `--faucet` lets you specify which faucet to use; the faucet is assumed to be compatible with https://github.com/kallewoof/bitcoin-faucet
+* `--addr` lets you specify a Signet address; by default, the address must be a bech32 address. This and `--cmd` above complement each other (i.e. you do not need `bitcoin-cli` if you use `--addr`)
+* `--password` lets you specify a faucet password; this is handy if you are in a classroom and set up your own faucet for your students; (above faucet does not limit by IP when password is enabled)
+
+If using the default network, invoking the script with no arguments should be sufficient under normal
+circumstances, but if multiple people are behind the same IP address, the faucet will by default only
+accept one claim per day. See `--password` above.
diff --git a/contrib/signet/getcoins.py b/contrib/signet/getcoins.py
new file mode 100755
index 0000000000..691f0bb1b6
--- /dev/null
+++ b/contrib/signet/getcoins.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python3
+# Copyright (c) 2020 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+import argparse
+import subprocess
+import requests
+import sys
+
+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('-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.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()
+ except FileNotFoundError:
+ print('The binary', args.cmd, 'could not be found.')
+ exit()
+
+data = {'address': args.addr, 'password': args.password}
+try:
+ res = requests.post(args.faucet, data=data)
+except:
+ print('Unexpected error when contacting faucet:', sys.exc_info()[0])
+ exit()
+print(res.text)