commit 1dff2299371bc9c0493ad66f52a21217b660a4a5
parent bf8399f8448e11d77c483d5b4b3f376448fb1b21
Author: Kristaps Kaupe <kristaps@blogiem.lv>
Date: Wed, 18 May 2022 12:26:38 +0300
Fix flake8 errors
Diffstat:
14 files changed, 23 insertions(+), 60 deletions(-)
diff --git a/gateways/lightning_address.py b/gateways/lightning_address.py
@@ -1,5 +1,5 @@
from flask import request
-from flask_restplus import Resource, Api, Namespace, fields
+from flask_restplus import Resource
import hashlib
import logging
@@ -8,6 +8,7 @@ max_sats = 10 ** 6
# Following https://github.com/andrerfneves/lightning-address/blob/master/DIY.md
+
def add_ln_address_decorators(app, api, node):
description = node.config['lightning_address_comment']
address = node.config['lightning_address']
diff --git a/gateways/paynym.py b/gateways/paynym.py
@@ -59,12 +59,6 @@ def insert_paynym_html(nym):
</style>
"""
- paynym_name_html = """
- <small style="vertical-align:middle"><a href="{}" target="_blank">{}</a></small>
- """.format(
- paynym_site + nym, nym
- )
-
nym_html = (
"""
<div class="paynym">
diff --git a/gateways/ssh_tunnel.py b/gateways/ssh_tunnel.py
@@ -1,10 +1,8 @@
import subprocess
-import time
import os
import logging
import config
-from node import bitcoind
def open_tunnel(host, port):
@@ -19,12 +17,11 @@ def open_tunnel(host, port):
config.tunnel_host,
"-p {}".format(config.tunnel_port),
]
- print("Opening tunnel to {}.".format(" ".join(command)))
+ logging.info("Opening tunnel to {}.".format(" ".join(command)))
return subprocess.Popen(command)
-
except Exception as e:
- print("FAILED TO OPEN TUNNEL. Exception: {}".format(e))
+ logging.error("FAILED TO OPEN TUNNEL. Exception: {}".format(e))
return None
@@ -45,13 +42,12 @@ def clightning_unix_domain_socket_ssh(rpc_file, rpc_store_dir=None):
"{}".format(config.tunnel_host),
"-p {}".format(config.tunnel_port),
]
- print("Opening tunnel to {}.".format(" ".join(command)))
+ logging.info("Opening tunnel to {}.".format(" ".join(command)))
tunnel_proc = subprocess.Popen(command)
return tunnel_proc
-
except Exception as e:
- print(
+ logging.error(
"FAILED TO OPEN UNIX DOMAIN SOCKET OVER SSH. Exception: {}".format(e)
)
@@ -63,12 +59,13 @@ def rm_lightning_rpc_file():
os.remove("lightning-rpc")
return
+
def close_tunnels(ssh_processes):
if ssh_processes is not None:
for proc in ssh_processes:
try:
proc.kill()
- except Exception as e:
+ except Exception:
continue
if "clightning" in config.payment_methods:
diff --git a/gateways/tor.py b/gateways/tor.py
@@ -1,5 +1,3 @@
-import socks
-import json
import requests
import time
import logging
diff --git a/gunicorn.conf.py b/gunicorn.conf.py
@@ -1,11 +1,14 @@
from gateways import ssh_tunnel
+
def on_starting(server):
server.ssh_processes = ssh_tunnel.open_tunnels()
+
def on_reload(server):
ssh_tunnel.close_tunnels(server.ssh_processes)
server.ssh_processes = ssh_tunnel.open_tunnels()
+
def worker_exit(server, worker):
ssh_tunnel.close_tunnels(server.ssh_processes)
diff --git a/node/bitcoind.py b/node/bitcoind.py
@@ -3,12 +3,11 @@ import logging
import os
import qrcode
import time
-import uuid
import config
-from payments.price_feed import get_btc_value
from utils import btc_amount_format
+
class btcd:
def __init__(self, node_config):
from bitcoinrpc.authproxy import AuthServiceProxy
diff --git a/node/clightning.py b/node/clightning.py
@@ -1,14 +1,7 @@
-import subprocess
-import pathlib
import time
-import os
-import json
-import uuid
import qrcode
import logging
-
-from payments.price_feed import get_btc_value
import config
# if False: # config.tor_clightningrpc_host is not None:
diff --git a/node/lnd.py b/node/lnd.py
@@ -1,16 +1,12 @@
import subprocess
-import pathlib
import time
import os
import json
from base64 import b64decode
from google.protobuf.json_format import MessageToJson
-import uuid
import qrcode
import logging
-
-from payments.price_feed import get_btc_value
import config
diff --git a/node/xpub.py b/node/xpub.py
@@ -1,14 +1,9 @@
import time
-import uuid
import qrcode
-import json
-import os
import logging
import requests
from bip_utils import Bip84, Bip44Changes, Bip84Coins, Bip44, Bip44Coins
-import config
-from payments.price_feed import get_btc_value
from utils import btc_amount_format
from payments import database
diff --git a/payments/price_feed.py b/payments/price_feed.py
@@ -38,15 +38,15 @@ def get_price(currency, currency_provider=config.currency_provider):
)
else:
- raise ("Failed to reach {}.".format(price_feed))
+ raise ("Failed to reach {}.".format(provider["price_feed"]))
try:
price = prices[provider["ticker"]][provider["value_attribute"]]
return price
- except:
+ except Exception:
logging.error(
- "Failed to find currency {} from {}.".format(currency, price_feed)
+ "Failed to find currency {} from {}.".format(currency, provider["price_feed"])
)
return None
diff --git a/payments/weakhands.py b/payments/weakhands.py
@@ -1,9 +1,6 @@
import requests
import logging
-import config
-
-# import config
quote_url = "https://sideshift.ai/api/v1/quotes"
swap_url = "https://sideshift.ai/api/v1/orders"
diff --git a/satsale.py b/satsale.py
@@ -2,18 +2,13 @@ from flask import (
Flask,
render_template,
request,
- redirect,
- Blueprint,
- make_response,
- url_for,
+ make_response
)
-from flask_restplus import Resource, Api, Namespace, fields
+from flask_restplus import Resource, Api, fields
import time
import os
import uuid
-import sqlite3
from pprint import pprint
-import json
import qrcode
import logging
@@ -26,7 +21,6 @@ logging.basicConfig(
level=getattr(logging, config.loglevel),
)
-from gateways import ssh_tunnel
from gateways import paynym
from payments import database, weakhands
from payments.price_feed import get_btc_value
@@ -136,7 +130,6 @@ class create_payment(Resource):
"""Initiate a new payment with an `amount` in `config.base_currecy`."""
base_amount = request.args.get("amount")
currency = config.base_currency
- label = "" # request.args.get('label')
payment_method = request.args.get("method")
if payment_method is None:
payment_method = enabled_payment_methods[0]
@@ -260,7 +253,7 @@ class complete_payment(Resource):
)
# Call webhook to confirm payment with merchant
- if (invoice["webhook"] != None) and (invoice["webhook"] != ""):
+ if (invoice["webhook"] is not None) and (invoice["webhook"] != ""):
logging.info("Calling webhook {}".format(invoice["webhook"]))
response = woo_webhook.hook(app.config["SECRET_KEY"], invoice, order_id)
@@ -374,7 +367,7 @@ for method in config.payment_methods:
if config.node_info is not None:
@app.route("/node/")
def node():
- if config.node_info == True:
+ if config.node_info is True:
uri = lightning_node.get_uri()
else:
uri = config.node_info
@@ -385,7 +378,7 @@ if config.node_info is not None:
render_template("node.html", params={"uri": uri}), 200, headers
)
-# Add lightning address
+# Add lightning address
try:
if lightning_node.config['lightning_address'] is not None:
from gateways import lightning_address
diff --git a/scripts/generate_payment_report.py b/scripts/generate_payment_report.py
@@ -8,9 +8,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
import config
from payments import database
-from node import bitcoind
-from node import lnd
-from node import clightning
+from node import bitcoind, clightning, lnd, xpub
def valid_date(s):
@@ -26,9 +24,9 @@ def main():
description="Generate CSV report about received payments.")
parser.add_argument("report_file")
parser.add_argument("--date-from", required=False, dest="date_from",
- help="from date (YYYY-MM-DD)", type=valid_date)
+ help="from date (YYYY-MM-DD)", type=valid_date)
parser.add_argument("--date-to", required=False, dest="date_to",
- help="to date (YYYY-MM-DD)", type=valid_date)
+ help="to date (YYYY-MM-DD)", type=valid_date)
try:
args = parser.parse_args()
diff --git a/utils.py b/utils.py
@@ -1,4 +1,3 @@
def btc_amount_format(btc_amount):
return "%.8f" % float(btc_amount)
-