chore: update github workflows

This commit is contained in:
Eneko Illarramendi
2020-09-03 23:10:41 +02:00
parent a651f747ac
commit 23cfe0d417
23 changed files with 199 additions and 91 deletions
+7 -1
View File
@@ -29,7 +29,13 @@ Talisman(
app,
force_https=FORCE_HTTPS,
content_security_policy={
"default-src": ["'self'", "'unsafe-eval'", "'unsafe-inline'", "blob:", "api.opennode.co",]
"default-src": [
"'self'",
"'unsafe-eval'",
"'unsafe-inline'",
"blob:",
"api.opennode.co",
]
},
)
+2 -3
View File
@@ -2,7 +2,7 @@ import bitstring # type: ignore
import re
import hashlib
from typing import List, NamedTuple, Optional
from bech32 import bech32_decode, CHARSET
from bech32 import bech32_decode, CHARSET # type: ignore
from ecdsa import SECP256k1, VerifyingKey # type: ignore
from ecdsa.util import sigdecode_string # type: ignore
from binascii import unhexlify
@@ -115,8 +115,7 @@ def decode(pr: str) -> Invoice:
def _unshorten_amount(amount: str) -> int:
""" Given a shortened amount, return millisatoshis
"""
"""Given a shortened amount, return millisatoshis"""
# BOLT #11:
# The following `multiplier` letters are defined:
#
+7 -1
View File
@@ -268,7 +268,13 @@ def create_payment(
def update_payment_status(checking_id: str, pending: bool) -> None:
with open_db() as db:
db.execute("UPDATE apipayments SET pending = ? WHERE checking_id = ?", (int(pending), checking_id,))
db.execute(
"UPDATE apipayments SET pending = ? WHERE checking_id = ?",
(
int(pending),
checking_id,
),
)
def delete_payment(checking_id: str) -> None:
+6 -1
View File
@@ -9,7 +9,12 @@ from .crud import get_wallet, create_payment, delete_payment, check_internal, up
def create_invoice(
*, wallet_id: str, amount: int, memo: str, description_hash: Optional[bytes] = None, extra: Optional[Dict] = None,
*,
wallet_id: str,
amount: int,
memo: str,
description_hash: Optional[bytes] = None,
extra: Optional[Dict] = None,
) -> Tuple[str, str]:
invoice_memo = None if description_hash else memo
storeable_memo = memo
+12 -3
View File
@@ -16,7 +16,10 @@ def api_check_wallet_key(key_type: str = "invoice"):
try:
g.wallet = get_wallet_for_key(request.headers["X-Api-Key"], key_type)
except KeyError:
return jsonify({"message": "`X-Api-Key` header missing."}), HTTPStatus.BAD_REQUEST
return (
jsonify({"message": "`X-Api-Key` header missing."}),
HTTPStatus.BAD_REQUEST,
)
if not g.wallet:
return jsonify({"message": "Wrong keys."}), HTTPStatus.UNAUTHORIZED
@@ -33,13 +36,19 @@ def api_validate_post_request(*, schema: dict):
@wraps(view)
def wrapped_view(**kwargs):
if "application/json" not in request.headers["Content-Type"]:
return jsonify({"message": "Content-Type must be `application/json`."}), HTTPStatus.BAD_REQUEST
return (
jsonify({"message": "Content-Type must be `application/json`."}),
HTTPStatus.BAD_REQUEST,
)
v = Validator(schema)
g.data = {key: request.json[key] for key in schema.keys() if key in request.json}
if not v.validate(g.data):
return jsonify({"message": f"Errors in request data: {v.errors}"}), HTTPStatus.BAD_REQUEST
return (
jsonify({"message": f"Errors in request data: {v.errors}"}),
HTTPStatus.BAD_REQUEST,
)
return view(**kwargs)
+35 -5
View File
@@ -125,10 +125,22 @@ def get_diagonalleys_indexer(indexer_id: str) -> Optional[Indexers]:
print(x)
print("poo")
with open_ext_db("diagonalley") as db:
db.execute("UPDATE indexers SET online = ? WHERE id = ?", (True, indexer_id,))
db.execute(
"UPDATE indexers SET online = ? WHERE id = ?",
(
True,
indexer_id,
),
)
else:
with open_ext_db("diagonalley") as db:
db.execute("UPDATE indexers SET online = ? WHERE id = ?", (False, indexer_id,))
db.execute(
"UPDATE indexers SET online = ? WHERE id = ?",
(
False,
indexer_id,
),
)
except:
print("An exception occurred")
with open_ext_db("diagonalley") as db:
@@ -149,10 +161,22 @@ def get_diagonalleys_indexers(wallet_ids: Union[str, List[str]]) -> List[Indexer
x = requests.get(r["indexeraddress"] + "/" + r["ratingkey"])
if x.status_code == 200:
with open_ext_db("diagonalley") as db:
db.execute("UPDATE indexers SET online = ? WHERE id = ?", (True, r["id"],))
db.execute(
"UPDATE indexers SET online = ? WHERE id = ?",
(
True,
r["id"],
),
)
else:
with open_ext_db("diagonalley") as db:
db.execute("UPDATE indexers SET online = ? WHERE id = ?", (False, r["id"],))
db.execute(
"UPDATE indexers SET online = ? WHERE id = ?",
(
False,
r["id"],
),
)
except:
print("An exception occurred")
with open_ext_db("diagonalley") as db:
@@ -213,7 +237,13 @@ def get_diagonalleys_orders(wallet_ids: Union[str, List[str]]) -> List[Orders]:
PAID = WALLET.get_invoice_status(r["invoiceid"]).paid
if PAID:
with open_ext_db("diagonalley") as db:
db.execute("UPDATE orders SET paid = ? WHERE id = ?", (True, r["id"],))
db.execute(
"UPDATE orders SET paid = ? WHERE id = ?",
(
True,
r["id"],
),
)
rows = db.fetchall(f"SELECT * FROM orders WHERE wallet IN ({q})", (*wallet_ids,))
return [Orders(**row) for row in rows]
+14 -2
View File
@@ -198,7 +198,13 @@ def api_diagonalley_order_delete(order_id):
@api_check_wallet_key(key_type="invoice")
def api_diagonalleys_order_paid(order_id):
with open_ext_db("diagonalley") as db:
db.execute("UPDATE orders SET paid = ? WHERE id = ?", (True, order_id,))
db.execute(
"UPDATE orders SET paid = ? WHERE id = ?",
(
True,
order_id,
),
)
return "", HTTPStatus.OK
@@ -206,7 +212,13 @@ def api_diagonalleys_order_paid(order_id):
@api_check_wallet_key(key_type="invoice")
def api_diagonalleys_order_shipped(order_id):
with open_ext_db("diagonalley") as db:
db.execute("UPDATE orders SET shipped = ? WHERE id = ?", (True, order_id,))
db.execute(
"UPDATE orders SET shipped = ? WHERE id = ?",
(
True,
order_id,
),
)
order = db.fetchone("SELECT * FROM orders WHERE id = ?", (order_id,))
return jsonify([order._asdict() for order in get_diagonalleys_orders(order["wallet"])]), HTTPStatus.OK
+9 -1
View File
@@ -75,7 +75,15 @@ def m002_changed(db):
)
VALUES (?, ?, ?, ?, ?, ?, ?)
""",
(row[0], row[1], row[2], row[3], row[4], row[5], True,),
(
row[0],
row[1],
row[2],
row[3],
row[4],
row[5],
True,
),
)
db.execute("DROP TABLE tickets")
+15 -3
View File
@@ -18,9 +18,21 @@ from lnbits.extensions.example import example_ext
def api_example():
"""Try to add descriptions for others."""
tools = [
{"name": "Flask", "url": "https://flask.palletsprojects.com/", "language": "Python",},
{"name": "Vue.js", "url": "https://vuejs.org/", "language": "JavaScript",},
{"name": "Quasar Framework", "url": "https://quasar.dev/", "language": "JavaScript",},
{
"name": "Flask",
"url": "https://flask.palletsprojects.com/",
"language": "Python",
},
{
"name": "Vue.js",
"url": "https://vuejs.org/",
"language": "JavaScript",
},
{
"name": "Quasar Framework",
"url": "https://quasar.dev/",
"language": "JavaScript",
},
]
return jsonify(tools), HTTPStatus.OK
+10 -1
View File
@@ -74,7 +74,16 @@ def m002_changed(db):
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
""",
(row[0], row[1], row[2], row[3], row[4], row[5], row[6], True,),
(
row[0],
row[1],
row[2],
row[3],
row[4],
row[5],
row[6],
True,
),
)
db.execute("DROP TABLE tickets")
+4 -1
View File
@@ -106,7 +106,10 @@ def api_lnurl_response(link_id):
url = url_for("lnurlp.api_lnurl_callback", link_id=link.id, _external=True, _scheme=scheme)
resp = LnurlPayResponse(
callback=url, min_sendable=link.amount * 1000, max_sendable=link.amount * 1000, metadata=link.lnurlpay_metadata,
callback=url,
min_sendable=link.amount * 1000,
max_sendable=link.amount * 1000,
metadata=link.lnurlpay_metadata,
)
return jsonify(resp.dict()), HTTPStatus.OK
+5 -1
View File
@@ -22,7 +22,11 @@ class LNbitsWallet(Wallet):
else:
data["memo"] = memo or ""
r = post(url=f"{self.endpoint}/api/v1/payments", headers=self.auth_invoice, json=data,)
r = post(
url=f"{self.endpoint}/api/v1/payments",
headers=self.auth_invoice,
json=data,
)
ok, checking_id, payment_request, error_message = r.ok, None, None, None
if r.ok:
+3 -1
View File
@@ -55,7 +55,9 @@ class LndWallet(Wallet):
grpc_port=self.port,
)
payinvoice = lnd_rpc.pay_invoice(payment_request=bolt11,)
payinvoice = lnd_rpc.pay_invoice(
payment_request=bolt11,
)
ok, checking_id, fee_msat, error_message = True, None, 0, None
+21 -4
View File
@@ -30,7 +30,12 @@ class LndRestWallet(Wallet):
else:
data["memo"] = memo or ""
r = post(url=f"{self.endpoint}/v1/invoices", headers=self.auth_invoice, verify=self.auth_cert, json=data,)
r = post(
url=f"{self.endpoint}/v1/invoices",
headers=self.auth_invoice,
verify=self.auth_cert,
json=data,
)
ok, checking_id, payment_request, error_message = r.ok, None, None, None
@@ -38,7 +43,11 @@ class LndRestWallet(Wallet):
data = r.json()
payment_request = data["payment_request"]
r = get(url=f"{self.endpoint}/v1/payreq/{payment_request}", headers=self.auth_read, verify=self.auth_cert,)
r = get(
url=f"{self.endpoint}/v1/payreq/{payment_request}",
headers=self.auth_read,
verify=self.auth_cert,
)
print(r)
if r.ok:
checking_id = r.json()["payment_hash"].replace("/", "_")
@@ -56,7 +65,11 @@ class LndRestWallet(Wallet):
json={"payment_request": bolt11},
)
ok, checking_id, fee_msat, error_message = r.ok, None, 0, None
r = get(url=f"{self.endpoint}/v1/payreq/{bolt11}", headers=self.auth_admin, verify=self.auth_cert,)
r = get(
url=f"{self.endpoint}/v1/payreq/{bolt11}",
headers=self.auth_admin,
verify=self.auth_cert,
)
if r.ok:
checking_id = r.json()["payment_hash"]
@@ -68,7 +81,11 @@ class LndRestWallet(Wallet):
def get_invoice_status(self, checking_id: str) -> PaymentStatus:
checking_id = checking_id.replace("_", "/")
print(checking_id)
r = get(url=f"{self.endpoint}/v1/invoice/{checking_id}", headers=self.auth_invoice, verify=self.auth_cert,)
r = get(
url=f"{self.endpoint}/v1/invoice/{checking_id}",
headers=self.auth_invoice,
verify=self.auth_cert,
)
print(r.json()["settled"])
if not r or r.json()["settled"] == False:
return PaymentStatus(None)
+5 -1
View File
@@ -25,7 +25,11 @@ class LNPayWallet(Wallet):
else:
data["memo"] = memo or ""
r = post(url=f"{self.endpoint}/user/wallet/{self.auth_invoice}/invoice", headers=self.auth_api, json=data,)
r = post(
url=f"{self.endpoint}/user/wallet/{self.auth_invoice}/invoice",
headers=self.auth_api,
json=data,
)
ok, checking_id, payment_request, error_message = r.status_code == 201, None, None, r.text
if ok:
+5 -1
View File
@@ -23,7 +23,11 @@ class LntxbotWallet(Wallet):
else:
data["memo"] = memo or ""
r = post(url=f"{self.endpoint}/addinvoice", headers=self.auth_invoice, json=data,)
r = post(
url=f"{self.endpoint}/addinvoice",
headers=self.auth_invoice,
json=data,
)
ok, checking_id, payment_request, error_message = r.ok, None, None, None
if r.ok:
+3 -1
View File
@@ -48,7 +48,9 @@ class SparkWallet(Wallet):
try:
if description_hash:
r = self.invoicewithdescriptionhash(
msatoshi=amount * 1000, label=label, description_hash=description_hash.hex(),
msatoshi=amount * 1000,
label=label,
description_hash=description_hash.hex(),
)
else:
r = self.invoice(