SatSale

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit b77bece9c96da98b19100a7505831b314a9792e6
parent 0c043aaa931ff2cc784b34de1c669a5d6ebd9d2a
Author: Martin Habovštiak <martin.habovstiak@gmail.com>
Date:   Tue,  7 Dec 2021 06:39:39 +0100

Rudimentary support for config file (#4)

* rename config file in preparation for new loading method

* Add new config.py loader

Co-authored-by: Martin Habovstiak <martin.habovstiak@gmail.com>

* rename back to .toml

* Working toml config

* Add config cli arg

* Add latest config arguments

* Update docs to include new toml

* fixup .gitignore

* Add updating guidance (config gonna break)

Co-authored-by: nickfarrow <nicholas.w.farrow@gmail.com>
Diffstat:
M.gitignore | 5+++--
MREADME.md | 14++++++++++++--
Mconfig.py | 133+++++++++++++++++++++++++++----------------------------------------------------
Aconfig.toml | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdocs/lightning.md | 4++--
Mdocs/tor.md | 2+-
Mrequirements.txt | 2+-
7 files changed, 152 insertions(+), 95 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,10 +1,12 @@ *.macaroon *.cert config.py +config.toml +*.toml __pycache__/ gateways/__pycache__/ invoice/__pycache__/ pay/__pycache__/ SatSale_API_key .venv/ -database.db -\ No newline at end of file +database.db diff --git a/README.md b/README.md @@ -59,7 +59,7 @@ cd SatSale/ pip3 install -r requirements.txt ``` ### Connect to your Bitcoin Node -Edit the `config.py` configuration and point to your Bitcoin node: +Edit the `config.toml` configuration and point to your Bitcoin node: ```python host = "127.0.0.1" rpcport = "8332" @@ -114,14 +114,24 @@ Similarly, for lightning, use an `invoice.macaroon` not `admin.macaroon` unless Currently we have a plugin for Woocommerce in Wordpress that makes Bitcoin webstores extremely easy, [please click here for installation instructions](docs/woocommerce.md). SatSale acts as a custom payment gateway for Woocommerce via the php plugin found in `/gateways`. We have plans to extend to other web stores in the future. # Updating -When updating you want to you keep your config file changes but also receive new config options so it is often easiest to: +When updating we recommend to first backup your config: +``` +cp config.toml bk_config.toml + +# (previously) +cp config.py bk_config.py +``` +then stash your changes: ``` git stash git pull origin master git stash pop ``` +We're still in early development, so things are changing a lot. You may have to resolve changes or manually migrate to the `.toml` (if you used an earlier version of SatSale with the `.py` config.) + You can also just make commits to your modified fork. + # Docs * Basic [API docs](https://satsale.org/docs.html) * Example [configs, Tor, HTTPS, nginx, etc](docs/) diff --git a/config.py b/config.py @@ -1,87 +1,46 @@ -# SatSale needs to connect to your bitcoin/lnd node, -# with the correct RPC port(s) as set in this config. - -# Connecting through local host (see below if connecting to remote node): -host = "127.0.0.1" -rpcport = "8332" - -# From ~/.bitcoin/bitcoin.conf -username = "bitcoinrpc" -password = "rpcpassword" - -# Wallet (empty "" if your node has a single wallet, OR wallet name/path as shown in `biitcoin-cli listwallets`) -wallet = "" - -# File in which API key will be stored -api_key_path = "SatSale_API_key" - - -#### Connect To Remote Node #### -# Can use SSH or TOR -# to tunnel/relay ports required to talk to the node via RPC (gRPC for lightning) - -# SSH tunnel to node -# Make sure this command works `ssh HOST@IP -q -N -L 8332:localhost:8332` -# Use host = "127.0.0.1" and you will be able to see your node on 8332 -tunnel_host = None # "HOST@IP" - -# or tor hidden service for RPC (see docs for how to set up), need onion: -tor_bitcoinrpc_host = None # e.g. "http://if...dwr.onion" -# and a tor proxy, default 127.0.0.1:9050 (for Tor Browser use "127.0.0.1:9150") -tor_proxy = None - -#### Payment method #### -pay_method = "bitcoind" - -## Lightning -# Switch payment_method to lnd if you want to use lightning payments instead. And uncomment lnd_dir. -#pay_method = "lnd" - -# To find (or copy from remote nodes) the macaroon and TLS certs -#lnd_dir = "~/.lnd/" - -# lnd RPC port and lnd macaroon (uncomment) -#lnd_rpcport = "10009" -#lnd_macaroon = "invoice.macaroon" - -# Or clightning -#pay_method = "clightning" - -# If remote clightning, make sure `ssh -nNT -L lightning-rpc:{clightning_rpc_file} {tunnel_host}` -# creates a lightning-rpc unix domain socket -#clightning_rpc_file = "/home/user/.lightning/lightning-rpc" -####################### - -# Check for payment every xx seconds -pollrate = 15 - -# Payment expires after xx seconds -payment_timeout = 60*60 - -# Required confirmations for a payment -required_confirmations = 2 - -# Global connection attempts -connection_attempts = 3 - -# Generic redirect url after payment -redirect = "https://github.com/nickfarrow/satsale" - -# Currency and exchange rate provider -base_currency = "USD" -currency_provider = "COINGECKO" # Supported: COINDESK | COINGECKO - -# Lightning Address e.g. name@you.satsale.domain (think this requires https url) -lightning_address = None -lightning_address_comment = None # Defaults to: "Thank you for your support <3" - -# Weak Hands Mode - Automatically swap LN-BTC -> L-USDT using sideshift.ai -# https://blockstream.com/liquid/ -# Change lnd_macaroon='admin.macaroon', as you will also need to be able to spend with your lnd certificates. -# This is NOT a trustless swap. Exchange is carried out using sideshift.ai, you bear all associated exchange risks. -liquid_address = None - -# DO NOT CHANGE THIS TO TRUE UNLESS YOU WANT ALL PAYMENTS TO AUTOMATICALLY -# BE CONSIDERED AS PAID. -free_mode = False - +import sys +import toml + + +for i, arg in enumerate(sys.argv): + if arg == "--conf": + print("Using config file {}".format(sys.argv[i+1])) + conf_path = sys.argv[i+1] + break +else: + conf_path = "config.toml" + +with open(conf_path, "r") as config_file: + config = toml.load(config_file) + +def get_opt(name, default): + if name in config: + return config[name] + else: + return default + +host = get_opt("host", "127.0.0.1") +rpcport = get_opt("rpcport", "8332") +username = get_opt("username", "bitcoinrpc") +password = get_opt("password", "rpcpassword") +wallet = get_opt("wallet", "") +api_key_path = get_opt("api_key_path", "SatSale_API_key") +tunnel_host = get_opt("tunnel_host", None) +tor_bitcoinrpc_host = get_opt("tor_bitcoinrpc_host", None) +tor_proxy = get_opt("tor_proxy", None) +pay_method = get_opt("pay_method", "bitcoind") +lnd_dir = get_opt("lnd_dir", "~/.lnd/") +lnd_rpcport = get_opt("lnd_rpcport", "10009") +lnd_macaroon = get_opt("lnd_macaroon", "admin.macaroon") +clightning_rpc_file = get_opt("clightning_rpc_file", "/home/user/.lightning/lightning-rpc") +pollrate = get_opt("pollrate", 15) +payment_timeout = get_opt("payment_timeout", 60*60) +required_confirmations = get_opt("required_confirmations", 2) +connection_attempts = get_opt("connection_attempts", 3) +redirect = get_opt("redirect", "https://github.com/nickfarrow/satsale") +base_currency = get_opt("base_currency", "USD") +currency_provider = get_opt("currency_provider", "COINGECKO") +lightning_address = get_opt("lightning_address", None) +lightning_address_comment = get_opt("lightning_address_comment", None) +liquid_address = get_opt("liquid_address", None) +free_mode = get_opt("free_mode", False) diff --git a/config.toml b/config.toml @@ -0,0 +1,87 @@ +# SatSale needs to connect to your bitcoin/lnd node, +# with the correct RPC port(s) as set in this config. + +# Connecting through local host (see below if connecting to remote node): +host = "127.0.0.1" +rpcport = "8332" + +# From ~/.bitcoin/bitcoin.conf +username = "bitcoinrpc" +password = "rpcpassword" + +# Wallet (empty "" if your node has a single wallet, OR wallet name/path as shown in `biitcoin-cli listwallets`) +wallet = "" + +# File in which API key will be stored +api_key_path = "SatSale_API_key" + + +#### Connect To Remote Node #### +# Can use SSH or TOR +# to tunnel/relay ports required to talk to the node via RPC (gRPC for lightning) + +# SSH tunnel to node +# Make sure this command works `ssh HOST@IP -q -N -L 8332:localhost:8332` +# Combined with host = "127.0.0.1" and you will be able to see your node on 8332 +#tunnel_host = "HOST@IP" + +# or tor hidden service for RPC (see docs for how to set up), need onion: +#tor_bitcoinrpc_host = None # e.g. "http://if...dwr.onion" + +# and a tor proxy, default 127.0.0.1:9050 (for Tor Browser use "127.0.0.1:9150") +#tor_proxy = None + +#### Payment method #### +pay_method = "bitcoind" + +## Lightning +# Switch payment_method to lnd if you want to use lightning payments instead. And uncomment lnd_dir. +#pay_method = "lnd" + +# To find (or copy from remote nodes) the macaroon and TLS certs +#lnd_dir = "~/.lnd/" + +# lnd RPC port and lnd macaroon (uncomment) +#lnd_rpcport = "10009" +#lnd_macaroon = "invoice.macaroon" + +# Or clightning +#pay_method = "clightning" + +# If remote clightning, make sure `ssh -nNT -L lightning-rpc:{clightning_rpc_file} {tunnel_host}` +# creates a lightning-rpc unix domain socket +#clightning_rpc_file = "/home/user/.lightning/lightning-rpc" +####################### + +# Check for payment every xx seconds +pollrate = 1 + +# Payment expires after xx seconds +payment_timeout = 1800 + +# Required confirmations for a payment +required_confirmations = 2 + +# Global connection attempts +connection_attempts = 3 + +# Generic redirect url after payment +redirect = "https://github.com/nickfarrow/satsale" + +# Currency and exchange rate provider +base_currency = "USD" +currency_provider = "COINGECKO" # Supported: COINDESK | COINGECKO + +# Lightning Address e.g. name@you.satsale.domain (think this requires https url) +#lightning_address = None +#lightning_address_comment = None # Defaults to: "Thank you for your support <3" + +# Weak Hands Mode - Automatically swap LN-BTC -> L-USDT using sideshift.ai +# https://blockstream.com/liquid/ +# Change lnd_macaroon='admin.macaroon', as you will also need to be able to spend with your lnd certificates. +# This is NOT a trustless swap. Exchange is carried out using sideshift.ai, you bear all associated exchange risks. +#liquid_address = None + +# DO NOT CHANGE THIS TO TRUE UNLESS YOU WANT ALL PAYMENTS TO AUTOMATICALLY +# BE CONSIDERED AS PAID. +free_mode = false diff --git a/docs/lightning.md b/docs/lightning.md @@ -6,7 +6,7 @@ If installing the python library lndgrpc requirement failed, see this [solution] ## LND -To use lightning, you need to change your `pay_method` in `config.py`, and set your lightning directory on your node. +To use lightning, you need to change your `pay_method` in `config.toml`, and set your lightning directory on your node. ```python pay_method = "lnd" lnd_dir = "~/.lnd/" @@ -15,7 +15,7 @@ lnd_rpcport = "10009" ## clightning -To use lightning, you need to change your `pay_method` in `config.py`, and set your lightning directory on your node. +To use lightning, you need to change your `pay_method` in `config.toml`, and set your lightning directory on your node. ```python pay_method = "clightning" # If remote clightning, make sure `ssh -nNT -L lightning-rpc:{clightning_rpc_file} {tunnel_host}` diff --git a/docs/tor.md b/docs/tor.md @@ -14,7 +14,7 @@ then sudo systemctl restart tor cat /var/lib/tor/node_rpc/hostname ``` -to get the onion URL for your tor hidden service. Add this in `config.py` like `tor_bitcoinrpc_host = "http://u7...bid.onion"` +to get the onion URL for your tor hidden service. Add this in `config.toml` like `tor_bitcoinrpc_host = "http://u7...bid.onion"` On your SatSale machine, install tor and in `/etc/tor/torrc` (thanks @x_y:matrix.org): ``` diff --git a/requirements.txt b/requirements.txt @@ -9,7 +9,7 @@ protobuf==3.19.1 flask_restplus==0.13.0 Werkzeug==0.16.1 PySocks==1.7.1 - +toml==0.10.2 # For lightning (optional) setuptools==50.3.2