SatSale

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

config.py (4838B)


      1 import sys
      2 import toml
      3 
      4 
      5 for i, arg in enumerate(sys.argv):
      6     if arg == "--conf":
      7         print("Using config file {}".format(sys.argv[i + 1]))
      8         conf_path = sys.argv[i + 1]
      9         break
     10 else:
     11     if "pytest" in sys.modules:
     12         conf_path = "test/config.toml"
     13     else:
     14         conf_path = "config.toml"
     15 
     16 with open(conf_path, "r") as config_file:
     17     config = toml.load(config_file)
     18 
     19 
     20 def get_opt(name, default):
     21     if name in config["satsale"]:
     22         return config["satsale"][name]
     23     else:
     24         return default
     25 
     26 
     27 def check_set_node_conf(name, default, node_conf):
     28     if name not in node_conf:
     29         if default is not None and default != "":
     30             print("using default {}: {}".format(name, default))
     31         node_conf[name] = default
     32     return
     33 
     34 
     35 payment_methods = []
     36 # This could be cleaned up into a single function that takes args, defaults, and required args.
     37 for method_name in config["payment_methods"]:
     38     method_config = config[method_name]
     39     if method_name == "bitcoind":
     40         method_config["name"] = "bitcoind"
     41         check_set_node_conf("rpcport", "8332", method_config)
     42         check_set_node_conf("username", "bitcoinrpc", method_config)
     43         check_set_node_conf("password", "", method_config)
     44         check_set_node_conf("rpc_cookie_file", "", method_config)
     45         check_set_node_conf("wallet", "", method_config)
     46         check_set_node_conf("tor_bitcoinrpc_host", None, method_config)
     47         if (method_config["password"] == "" or method_config["password"] is None) and (
     48             method_config["rpc_cookie_file"] == ""
     49             or method_config["rpc_cookie_file"] is None
     50         ):
     51             raise KeyError(
     52                 "Mising {} config: {} or {}".format(
     53                     method_name, "password", "rpc_cookie_file"
     54                 )
     55             )
     56 
     57     elif method_name == "lnd":
     58         method_config["name"] = "lnd"
     59         check_set_node_conf("lnd_dir", "~/.lnd/", method_config)
     60         check_set_node_conf("lnd_rpcport", "10009", method_config)
     61         check_set_node_conf("lnd_macaroon", "invoice.macaroon", method_config)
     62         check_set_node_conf("lightning_address", None, method_config)
     63         check_set_node_conf("lightning_address_comment", None, method_config)
     64 
     65     elif method_name == "clightning":
     66         method_config["name"] = "clightning"
     67         check_set_node_conf("clightning_rpc_file", None, method_config)
     68         check_set_node_conf("lightning_address", None, method_config)
     69         check_set_node_conf("lightning_address_comment", None, method_config)
     70         if (
     71             method_config["clightning_rpc_file"] == ""
     72             or method_config["clightning_rpc_file"] is None
     73         ):
     74             raise KeyError(
     75                 "Mising {}: config {}".format(method_name, "clightning_rpc_file")
     76             )
     77 
     78     elif method_name == "xpub":
     79         method_config["name"] = "xpub"
     80         check_set_node_conf("xpub", None, method_config)
     81         if method_config["xpub"] == "" or method_config["xpub"] is None:
     82             raise KeyError("Mising {}: config {}".format(method_name, "xpub"))
     83 
     84     else:
     85         raise Exception("Unknown payment method: {}".format(method_name))
     86 
     87     payment_methods.append(method_config)
     88 
     89 supported_currencies = get_opt("supported_currencies", ["USD"])
     90 if "BTC" in supported_currencies:
     91     supported_currencies.append("sats")
     92 
     93 base_currency = get_opt("base_currency", "USD")
     94 if base_currency not in supported_currencies:
     95     raise Exception("base_currency must be one of supported_currencies")
     96 
     97 currency_provider = get_opt("currency_provider", "COINGECKO")
     98 if currency_provider not in ["COINDESK", "COINGECKO"]:
     99     raise Exception("Unsupported currency price feed provider: {}".format(
    100         currency_provider))
    101 
    102 host = get_opt("host", "127.0.0.1")
    103 api_key_path = get_opt("api_key_path", "SatSale_API_key")
    104 tunnel_host = get_opt("tunnel_host", None)
    105 tunnel_port = get_opt("tunnel_port", 22)
    106 tor_proxy = get_opt("tor_proxy", None)
    107 onchain_dust_limit = get_opt("onchain_dust_limit", 0.00000546)
    108 node_info = get_opt("node_info", None)
    109 pollrate = get_opt("pollrate", 15)
    110 payment_timeout = get_opt("payment_timeout", 60 * 60)
    111 required_confirmations = get_opt("required_confirmations", 2)
    112 connection_attempts = get_opt("connection_attempts", 3)
    113 store_name = get_opt("store_name", "SatSale")
    114 redirect = get_opt("redirect", "https://github.com/nickfarrow/satsale")
    115 bitcoin_rate_multiplier = get_opt("bitcoin_rate_multiplier", 1.00)
    116 allowed_underpay_amount = get_opt("allowed_underpay_amount", 0.00000001)
    117 liquid_address = get_opt("liquid_address", None)
    118 paynym = get_opt("paynym", None)
    119 free_mode = get_opt("free_mode", False)
    120 loglevel = get_opt("loglevel", "DEBUG")
    121 
    122 if allowed_underpay_amount < 0:
    123     raise Exception("allowed_underpay_amount cannot be negative")
    124 
    125 #print(config)
    126 #print(tunnel_host)