mirror of
https://github.com/lnbits/lnbits.git
synced 2025-07-17 00:12:34 +02:00
black formatting
This commit is contained in:
@ -285,7 +285,11 @@ async def create_payment(
|
|||||||
|
|
||||||
async def update_payment_status(checking_id: str, pending: bool) -> None:
|
async def update_payment_status(checking_id: str, pending: bool) -> None:
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"UPDATE apipayments SET pending = ? WHERE checking_id = ?", (int(pending), checking_id,),
|
"UPDATE apipayments SET pending = ? WHERE checking_id = ?",
|
||||||
|
(
|
||||||
|
int(pending),
|
||||||
|
checking_id,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,11 @@ class Wallet(NamedTuple):
|
|||||||
hashing_key = hashlib.sha256(self.id.encode("utf-8")).digest()
|
hashing_key = hashlib.sha256(self.id.encode("utf-8")).digest()
|
||||||
linking_key = hmac.digest(hashing_key, domain.encode("utf-8"), "sha256")
|
linking_key = hmac.digest(hashing_key, domain.encode("utf-8"), "sha256")
|
||||||
|
|
||||||
return SigningKey.from_string(linking_key, curve=SECP256k1, hashfunc=hashlib.sha256,)
|
return SigningKey.from_string(
|
||||||
|
linking_key,
|
||||||
|
curve=SECP256k1,
|
||||||
|
hashfunc=hashlib.sha256,
|
||||||
|
)
|
||||||
|
|
||||||
async def get_payment(self, payment_hash: str) -> Optional["Payment"]:
|
async def get_payment(self, payment_hash: str) -> Optional["Payment"]:
|
||||||
from .crud import get_wallet_payment
|
from .crud import get_wallet_payment
|
||||||
|
@ -133,7 +133,10 @@ async def pay_invoice(
|
|||||||
payment: PaymentResponse = WALLET.pay_invoice(payment_request)
|
payment: PaymentResponse = WALLET.pay_invoice(payment_request)
|
||||||
if payment.ok and payment.checking_id:
|
if payment.ok and payment.checking_id:
|
||||||
await create_payment(
|
await create_payment(
|
||||||
checking_id=payment.checking_id, fee=payment.fee_msat, preimage=payment.preimage, **payment_kwargs,
|
checking_id=payment.checking_id,
|
||||||
|
fee=payment.fee_msat,
|
||||||
|
preimage=payment.preimage,
|
||||||
|
**payment_kwargs,
|
||||||
)
|
)
|
||||||
await delete_payment(temp_id)
|
await delete_payment(temp_id)
|
||||||
else:
|
else:
|
||||||
@ -153,7 +156,8 @@ async def redeem_lnurl_withdraw(wallet_id: str, res: LnurlWithdrawResponse, memo
|
|||||||
|
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
await client.get(
|
await client.get(
|
||||||
res.callback.base, params={**res.callback.query_params, **{"k1": res.k1, "pr": payment_request}},
|
res.callback.base,
|
||||||
|
params={**res.callback.query_params, **{"k1": res.k1, "pr": payment_request}},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -210,7 +214,11 @@ async def perform_lnurlauth(callback: str) -> Optional[LnurlErrorResponse]:
|
|||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
r = await client.get(
|
r = await client.get(
|
||||||
callback,
|
callback,
|
||||||
params={"k1": k1.hex(), "key": key.verifying_key.to_string("compressed").hex(), "sig": sig.hex(),},
|
params={
|
||||||
|
"k1": k1.hex(),
|
||||||
|
"key": key.verifying_key.to_string("compressed").hex(),
|
||||||
|
"sig": sig.hex(),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
resp = json.loads(r.text)
|
resp = json.loads(r.text)
|
||||||
@ -219,7 +227,9 @@ async def perform_lnurlauth(callback: str) -> Optional[LnurlErrorResponse]:
|
|||||||
|
|
||||||
return LnurlErrorResponse(reason=resp["reason"])
|
return LnurlErrorResponse(reason=resp["reason"])
|
||||||
except (KeyError, json.decoder.JSONDecodeError):
|
except (KeyError, json.decoder.JSONDecodeError):
|
||||||
return LnurlErrorResponse(reason=r.text[:200] + "..." if len(r.text) > 200 else r.text,)
|
return LnurlErrorResponse(
|
||||||
|
reason=r.text[:200] + "..." if len(r.text) > 200 else r.text,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def check_invoice_status(wallet_id: str, payment_hash: str) -> PaymentStatus:
|
async def check_invoice_status(wallet_id: str, payment_hash: str) -> PaymentStatus:
|
||||||
|
@ -38,7 +38,11 @@ async def dispatch_webhook(payment: Payment):
|
|||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
data = payment._asdict()
|
data = payment._asdict()
|
||||||
try:
|
try:
|
||||||
r = await client.post(payment.webhook, json=data, timeout=40,)
|
r = await client.post(
|
||||||
|
payment.webhook,
|
||||||
|
json=data,
|
||||||
|
timeout=40,
|
||||||
|
)
|
||||||
await mark_webhook_sent(payment, r.status_code)
|
await mark_webhook_sent(payment, r.status_code)
|
||||||
except (httpx.ConnectError, httpx.RequestError):
|
except (httpx.ConnectError, httpx.RequestError):
|
||||||
await mark_webhook_sent(payment, -1)
|
await mark_webhook_sent(payment, -1)
|
||||||
|
@ -21,7 +21,13 @@ from ..tasks import sse_listeners
|
|||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
async def api_wallet():
|
async def api_wallet():
|
||||||
return (
|
return (
|
||||||
jsonify({"id": g.wallet.id, "name": g.wallet.name, "balance": g.wallet.balance_msat,}),
|
jsonify(
|
||||||
|
{
|
||||||
|
"id": g.wallet.id,
|
||||||
|
"name": g.wallet.name,
|
||||||
|
"balance": g.wallet.balance_msat,
|
||||||
|
}
|
||||||
|
),
|
||||||
HTTPStatus.OK,
|
HTTPStatus.OK,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -78,7 +84,11 @@ async def api_payments_create_invoice():
|
|||||||
if g.data.get("lnurl_callback"):
|
if g.data.get("lnurl_callback"):
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
try:
|
try:
|
||||||
r = await client.get(g.data["lnurl_callback"], params={"pr": payment_request}, timeout=10,)
|
r = await client.get(
|
||||||
|
g.data["lnurl_callback"],
|
||||||
|
params={"pr": payment_request},
|
||||||
|
timeout=10,
|
||||||
|
)
|
||||||
if r.is_error:
|
if r.is_error:
|
||||||
lnurl_response = r.text
|
lnurl_response = r.text
|
||||||
else:
|
else:
|
||||||
@ -154,7 +164,9 @@ async def api_payments_pay_lnurl():
|
|||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
try:
|
try:
|
||||||
r = await client.get(
|
r = await client.get(
|
||||||
g.data["callback"], params={"amount": g.data["amount"], "comment": g.data["comment"]}, timeout=40,
|
g.data["callback"],
|
||||||
|
params={"amount": g.data["amount"], "comment": g.data["comment"]},
|
||||||
|
timeout=40,
|
||||||
)
|
)
|
||||||
if r.is_error:
|
if r.is_error:
|
||||||
return jsonify({"message": "failed to connect"}), HTTPStatus.BAD_REQUEST
|
return jsonify({"message": "failed to connect"}), HTTPStatus.BAD_REQUEST
|
||||||
@ -194,7 +206,10 @@ async def api_payments_pay_lnurl():
|
|||||||
extra["comment"] = g.data["comment"]
|
extra["comment"] = g.data["comment"]
|
||||||
|
|
||||||
payment_hash = await pay_invoice(
|
payment_hash = await pay_invoice(
|
||||||
wallet_id=g.wallet.id, payment_request=params["pr"], description=g.data.get("description", ""), extra=extra,
|
wallet_id=g.wallet.id,
|
||||||
|
payment_request=params["pr"],
|
||||||
|
description=g.data.get("description", ""),
|
||||||
|
extra=extra,
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
await db.rollback()
|
await db.rollback()
|
||||||
@ -354,7 +369,9 @@ async def api_lnurlscan(code: str):
|
|||||||
@core_app.route("/api/v1/lnurlauth", methods=["POST"])
|
@core_app.route("/api/v1/lnurlauth", methods=["POST"])
|
||||||
@api_check_wallet_key("admin")
|
@api_check_wallet_key("admin")
|
||||||
@api_validate_post_request(
|
@api_validate_post_request(
|
||||||
schema={"callback": {"type": "string", "required": True},}
|
schema={
|
||||||
|
"callback": {"type": "string", "required": True},
|
||||||
|
}
|
||||||
)
|
)
|
||||||
async def api_perform_lnurlauth():
|
async def api_perform_lnurlauth():
|
||||||
err = await perform_lnurlauth(g.data["callback"])
|
err = await perform_lnurlauth(g.data["callback"])
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#async def m001_initial(db):
|
# async def m001_initial(db):
|
||||||
|
|
||||||
# await db.execute(
|
# await db.execute(
|
||||||
# """
|
# """
|
||||||
@ -8,4 +8,4 @@
|
|||||||
# time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
|
# time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
|
||||||
# );
|
# );
|
||||||
# """
|
# """
|
||||||
# )
|
# )
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#from sqlite3 import Row
|
# from sqlite3 import Row
|
||||||
#from typing import NamedTuple
|
# from typing import NamedTuple
|
||||||
|
|
||||||
|
|
||||||
#class Example(NamedTuple):
|
# class Example(NamedTuple):
|
||||||
# id: str
|
# id: str
|
||||||
# wallet: str
|
# wallet: str
|
||||||
#
|
#
|
||||||
# @classmethod
|
# @classmethod
|
||||||
# def from_row(cls, row: Row) -> "Example":
|
# def from_row(cls, row: Row) -> "Example":
|
||||||
# return cls(**dict(row))
|
# return cls(**dict(row))
|
||||||
|
@ -6,6 +6,7 @@ from . import db
|
|||||||
from .models import Tickets, Forms
|
from .models import Tickets, Forms
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
|
|
||||||
async def create_ticket(
|
async def create_ticket(
|
||||||
payment_hash: str,
|
payment_hash: str,
|
||||||
wallet: str,
|
wallet: str,
|
||||||
@ -52,19 +53,14 @@ async def set_ticket_paid(payment_hash: str) -> Tickets:
|
|||||||
""",
|
""",
|
||||||
(amount, row[1]),
|
(amount, row[1]),
|
||||||
)
|
)
|
||||||
|
|
||||||
ticket = await get_ticket(payment_hash)
|
ticket = await get_ticket(payment_hash)
|
||||||
if formdata.webhook:
|
if formdata.webhook:
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
try:
|
try:
|
||||||
r = await client.post(
|
r = await client.post(
|
||||||
formdata.webhook,
|
formdata.webhook,
|
||||||
json={
|
json={"form": ticket.form, "name": ticket.name, "email": ticket.email, "content": ticket.ltext},
|
||||||
"form": ticket.form,
|
|
||||||
"name": ticket.name,
|
|
||||||
"email": ticket.email,
|
|
||||||
"content": ticket.ltext
|
|
||||||
},
|
|
||||||
timeout=40,
|
timeout=40,
|
||||||
)
|
)
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
@ -96,7 +92,9 @@ async def delete_ticket(ticket_id: str) -> None:
|
|||||||
# FORMS
|
# FORMS
|
||||||
|
|
||||||
|
|
||||||
async def create_form(*, wallet: str, name: str, webhook: Optional[str] = None, description: str, costpword: int) -> Forms:
|
async def create_form(
|
||||||
|
*, wallet: str, name: str, webhook: Optional[str] = None, description: str, costpword: int
|
||||||
|
) -> Forms:
|
||||||
form_id = urlsafe_short_hash()
|
form_id = urlsafe_short_hash()
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
|
@ -102,7 +102,6 @@ async def m003_changed(db):
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
for row in [list(row) for row in await db.fetchall("SELECT * FROM forms")]:
|
for row in [list(row) for row in await db.fetchall("SELECT * FROM forms")]:
|
||||||
usescsv = ""
|
usescsv = ""
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import httpx
|
|||||||
|
|
||||||
from lnbits.extensions import subdomains
|
from lnbits.extensions import subdomains
|
||||||
|
|
||||||
|
|
||||||
async def create_subdomain(
|
async def create_subdomain(
|
||||||
payment_hash: str,
|
payment_hash: str,
|
||||||
wallet: str,
|
wallet: str,
|
||||||
@ -17,7 +18,7 @@ async def create_subdomain(
|
|||||||
ip: str,
|
ip: str,
|
||||||
sats: int,
|
sats: int,
|
||||||
duration: int,
|
duration: int,
|
||||||
record_type: str
|
record_type: str,
|
||||||
) -> Subdomains:
|
) -> Subdomains:
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
@ -33,7 +34,10 @@ async def create_subdomain(
|
|||||||
|
|
||||||
|
|
||||||
async def set_subdomain_paid(payment_hash: str) -> Subdomains:
|
async def set_subdomain_paid(payment_hash: str) -> Subdomains:
|
||||||
row = await db.fetchone("SELECT s.*, d.domain as domain_name FROM subdomain s INNER JOIN domain d ON (s.domain = d.id) WHERE s.id = ?", (payment_hash,))
|
row = await db.fetchone(
|
||||||
|
"SELECT s.*, d.domain as domain_name FROM subdomain s INNER JOIN domain d ON (s.domain = d.id) WHERE s.id = ?",
|
||||||
|
(payment_hash,),
|
||||||
|
)
|
||||||
if row[8] == False:
|
if row[8] == False:
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
@ -60,9 +64,9 @@ async def set_subdomain_paid(payment_hash: str) -> Subdomains:
|
|||||||
subdomain = await get_subdomain(payment_hash)
|
subdomain = await get_subdomain(payment_hash)
|
||||||
|
|
||||||
### SEND REQUEST TO CLOUDFLARE
|
### SEND REQUEST TO CLOUDFLARE
|
||||||
url="https://api.cloudflare.com/client/v4/zones/" + domaindata.cf_zone_id + "/dns_records"
|
url = "https://api.cloudflare.com/client/v4/zones/" + domaindata.cf_zone_id + "/dns_records"
|
||||||
header= {'Authorization': 'Bearer ' + domaindata.cf_token, 'Content-Type': 'application/json'}
|
header = {"Authorization": "Bearer " + domaindata.cf_token, "Content-Type": "application/json"}
|
||||||
aRecord=subdomain.subdomain + '.' + subdomain.domain_name
|
aRecord = subdomain.subdomain + "." + subdomain.domain_name
|
||||||
cf_response = ""
|
cf_response = ""
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
try:
|
try:
|
||||||
@ -74,7 +78,7 @@ async def set_subdomain_paid(payment_hash: str) -> Subdomains:
|
|||||||
"name": aRecord,
|
"name": aRecord,
|
||||||
"content": subdomain.ip,
|
"content": subdomain.ip,
|
||||||
"ttl": 0,
|
"ttl": 0,
|
||||||
"proxed": False
|
"proxed": False,
|
||||||
},
|
},
|
||||||
timeout=40,
|
timeout=40,
|
||||||
)
|
)
|
||||||
@ -96,7 +100,7 @@ async def set_subdomain_paid(payment_hash: str) -> Subdomains:
|
|||||||
"ip": subdomain.ip,
|
"ip": subdomain.ip,
|
||||||
"cost:": str(subdomain.sats) + " sats",
|
"cost:": str(subdomain.sats) + " sats",
|
||||||
"duration": str(subdomain.duration) + " days",
|
"duration": str(subdomain.duration) + " days",
|
||||||
"cf_response": cf_response
|
"cf_response": cf_response,
|
||||||
},
|
},
|
||||||
timeout=40,
|
timeout=40,
|
||||||
)
|
)
|
||||||
@ -108,7 +112,10 @@ async def set_subdomain_paid(payment_hash: str) -> Subdomains:
|
|||||||
|
|
||||||
|
|
||||||
async def get_subdomain(subdomain_id: str) -> Optional[Subdomains]:
|
async def get_subdomain(subdomain_id: str) -> Optional[Subdomains]:
|
||||||
row = await db.fetchone("SELECT s.*, d.domain as domain_name FROM subdomain s INNER JOIN domain d ON (s.domain = d.id) WHERE s.id = ?", (subdomain_id,))
|
row = await db.fetchone(
|
||||||
|
"SELECT s.*, d.domain as domain_name FROM subdomain s INNER JOIN domain d ON (s.domain = d.id) WHERE s.id = ?",
|
||||||
|
(subdomain_id,),
|
||||||
|
)
|
||||||
print(row)
|
print(row)
|
||||||
return Subdomains(**row) if row else None
|
return Subdomains(**row) if row else None
|
||||||
|
|
||||||
@ -118,7 +125,10 @@ async def get_subdomains(wallet_ids: Union[str, List[str]]) -> List[Subdomains]:
|
|||||||
wallet_ids = [wallet_ids]
|
wallet_ids = [wallet_ids]
|
||||||
|
|
||||||
q = ",".join(["?"] * len(wallet_ids))
|
q = ",".join(["?"] * len(wallet_ids))
|
||||||
rows = await db.fetchall(f"SELECT s.*, d.domain as domain_name FROM subdomain s INNER JOIN domain d ON (s.domain = d.id) WHERE s.wallet IN ({q})", (*wallet_ids,))
|
rows = await db.fetchall(
|
||||||
|
f"SELECT s.*, d.domain as domain_name FROM subdomain s INNER JOIN domain d ON (s.domain = d.id) WHERE s.wallet IN ({q})",
|
||||||
|
(*wallet_ids,),
|
||||||
|
)
|
||||||
|
|
||||||
return [Subdomains(**row) for row in rows]
|
return [Subdomains(**row) for row in rows]
|
||||||
|
|
||||||
@ -130,7 +140,17 @@ async def delete_subdomain(subdomain_id: str) -> None:
|
|||||||
# Domains
|
# Domains
|
||||||
|
|
||||||
|
|
||||||
async def create_domain(*, wallet: str, domain: str, cf_token: str, cf_zone_id: str, webhook: Optional[str] = None, description: str, cost: int, allowed_record_types: str) -> Domains:
|
async def create_domain(
|
||||||
|
*,
|
||||||
|
wallet: str,
|
||||||
|
domain: str,
|
||||||
|
cf_token: str,
|
||||||
|
cf_zone_id: str,
|
||||||
|
webhook: Optional[str] = None,
|
||||||
|
description: str,
|
||||||
|
cost: int,
|
||||||
|
allowed_record_types: str,
|
||||||
|
) -> Domains:
|
||||||
domain_id = urlsafe_short_hash()
|
domain_id = urlsafe_short_hash()
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
@ -170,6 +190,3 @@ async def get_domains(wallet_ids: Union[str, List[str]]) -> List[Domains]:
|
|||||||
|
|
||||||
async def delete_domain(domain_id: str) -> None:
|
async def delete_domain(domain_id: str) -> None:
|
||||||
await db.execute("DELETE FROM domain WHERE id = ?", (domain_id,))
|
await db.execute("DELETE FROM domain WHERE id = ?", (domain_id,))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,4 +34,4 @@ async def m001_initial(db):
|
|||||||
time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
|
time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
|
||||||
);
|
);
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
@ -6,18 +6,20 @@ from http import HTTPStatus
|
|||||||
from . import subdomains_ext
|
from . import subdomains_ext
|
||||||
from .crud import get_domain
|
from .crud import get_domain
|
||||||
|
|
||||||
|
|
||||||
@subdomains_ext.route("/")
|
@subdomains_ext.route("/")
|
||||||
@validate_uuids(["usr"], required=True)
|
@validate_uuids(["usr"], required=True)
|
||||||
@check_user_exists()
|
@check_user_exists()
|
||||||
async def index():
|
async def index():
|
||||||
return await render_template("subdomains/index.html", user=g.user)
|
return await render_template("subdomains/index.html", user=g.user)
|
||||||
|
|
||||||
|
|
||||||
@subdomains_ext.route("/<domain_id>")
|
@subdomains_ext.route("/<domain_id>")
|
||||||
async def display(domain_id):
|
async def display(domain_id):
|
||||||
domain = await get_domain(domain_id)
|
domain = await get_domain(domain_id)
|
||||||
if not domain:
|
if not domain:
|
||||||
abort(HTTPStatus.NOT_FOUND, "Domain does not exist.")
|
abort(HTTPStatus.NOT_FOUND, "Domain does not exist.")
|
||||||
allowed_records = domain.allowed_record_types.replace("\"","").replace(" ","").split(",")
|
allowed_records = domain.allowed_record_types.replace('"', "").replace(" ", "").split(",")
|
||||||
print(allowed_records)
|
print(allowed_records)
|
||||||
return await render_template(
|
return await render_template(
|
||||||
"subdomains/display.html",
|
"subdomains/display.html",
|
||||||
@ -25,5 +27,5 @@ async def display(domain_id):
|
|||||||
domain_domain=domain.domain,
|
domain_domain=domain.domain,
|
||||||
domain_desc=domain.description,
|
domain_desc=domain.description,
|
||||||
domain_cost=domain.cost,
|
domain_cost=domain.cost,
|
||||||
domain_allowed_record_types=allowed_records
|
domain_allowed_record_types=allowed_records,
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user