forked from PLEBNET-PLAYGROUND/plebnet-playground-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetcoins.py
executable file
·49 lines (41 loc) · 1.9 KB
/
getcoins.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
# Copyright (c) 2021 Richard Safier
# 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
import json
from pprint import pprint
sys.path.append('.')
sys.path.append("/usr/local/lib/python3.8/site-packages")
sys.path.append("/usr/local/lib/python3.9/site-packages")
parser = argparse.ArgumentParser(description='Script to get coins from a faucet.')
parser.add_argument('-c', '--cmd', dest='cmd', default='docker', help='bitcoin-cli command to use')
parser.add_argument('-f', '--faucet', dest='faucet', default='http://signet.xenon.fun:5000/faucet', help='URL of the faucet')
parser.add_argument('-a', '--address', dest='address', default='', help='Bitcoin address to which the faucet should send')
parser.add_argument('-r', '--report', dest='report', default='false', help='Return session data')
parser.add_argument('-s', '--success', dest='success', default='false', help='return 0 if true')
args = parser.parse_args()
def print_report():
if args.report == 'true':
print(args.address)
# NOTE: jq expected syntax
# echo {\"address\": \"tb1qhjd4lxv7vkqp7pen34t8zfxvvc8f8eqpppug26\"} | jq .
#print(data) #return session data first!
else:
print(res.text)
if args.address == '':
# get address for receiving coins
args.address = json.loads(subprocess.check_output([args.cmd] + ['exec','-it','playground-lnd', 'lncli', '--macaroonpath', '/root/.lnd/data/chain/bitcoin/signet/admin.macaroon', 'newaddress', 'p2wkh']))["address"]
data = {'address': args.address}
else:
data = {'address': args.address}
try:
res = requests.get(args.faucet, params=data)
print_report()
except:
print('Unexpected error when contacting faucet:', sys.exc_info()[0])
exit()