mirror of
https://github.com/lnbits/lnbits.git
synced 2025-04-15 07:19:25 +02:00
black formatting
This commit is contained in:
parent
128888be92
commit
c082c953f3
@ -285,7 +285,11 @@ async def create_payment(
|
||||
|
||||
async def update_payment_status(checking_id: str, pending: bool) -> None:
|
||||
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()
|
||||
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"]:
|
||||
from .crud import get_wallet_payment
|
||||
|
@ -133,7 +133,10 @@ async def pay_invoice(
|
||||
payment: PaymentResponse = WALLET.pay_invoice(payment_request)
|
||||
if payment.ok and payment.checking_id:
|
||||
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)
|
||||
else:
|
||||
@ -153,7 +156,8 @@ async def redeem_lnurl_withdraw(wallet_id: str, res: LnurlWithdrawResponse, memo
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
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:
|
||||
r = await client.get(
|
||||
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:
|
||||
resp = json.loads(r.text)
|
||||
@ -219,7 +227,9 @@ async def perform_lnurlauth(callback: str) -> Optional[LnurlErrorResponse]:
|
||||
|
||||
return LnurlErrorResponse(reason=resp["reason"])
|
||||
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:
|
||||
|
@ -38,7 +38,11 @@ async def dispatch_webhook(payment: Payment):
|
||||
async with httpx.AsyncClient() as client:
|
||||
data = payment._asdict()
|
||||
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)
|
||||
except (httpx.ConnectError, httpx.RequestError):
|
||||
await mark_webhook_sent(payment, -1)
|
||||
|
@ -21,7 +21,13 @@ from ..tasks import sse_listeners
|
||||
@api_check_wallet_key("invoice")
|
||||
async def api_wallet():
|
||||
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,
|
||||
)
|
||||
|
||||
@ -78,7 +84,11 @@ async def api_payments_create_invoice():
|
||||
if g.data.get("lnurl_callback"):
|
||||
async with httpx.AsyncClient() as client:
|
||||
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:
|
||||
lnurl_response = r.text
|
||||
else:
|
||||
@ -154,7 +164,9 @@ async def api_payments_pay_lnurl():
|
||||
async with httpx.AsyncClient() as client:
|
||||
try:
|
||||
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:
|
||||
return jsonify({"message": "failed to connect"}), HTTPStatus.BAD_REQUEST
|
||||
@ -194,7 +206,10 @@ async def api_payments_pay_lnurl():
|
||||
extra["comment"] = g.data["comment"]
|
||||
|
||||
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:
|
||||
await db.rollback()
|
||||
@ -354,7 +369,9 @@ async def api_lnurlscan(code: str):
|
||||
@core_app.route("/api/v1/lnurlauth", methods=["POST"])
|
||||
@api_check_wallet_key("admin")
|
||||
@api_validate_post_request(
|
||||
schema={"callback": {"type": "string", "required": True},}
|
||||
schema={
|
||||
"callback": {"type": "string", "required": True},
|
||||
}
|
||||
)
|
||||
async def api_perform_lnurlauth():
|
||||
err = await perform_lnurlauth(g.data["callback"])
|
||||
|
@ -1,4 +1,4 @@
|
||||
#async def m001_initial(db):
|
||||
# async def m001_initial(db):
|
||||
|
||||
# await db.execute(
|
||||
# """
|
||||
@ -8,4 +8,4 @@
|
||||
# time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
|
||||
# );
|
||||
# """
|
||||
# )
|
||||
# )
|
||||
|
@ -1,11 +1,11 @@
|
||||
#from sqlite3 import Row
|
||||
#from typing import NamedTuple
|
||||
# from sqlite3 import Row
|
||||
# from typing import NamedTuple
|
||||
|
||||
|
||||
#class Example(NamedTuple):
|
||||
# class Example(NamedTuple):
|
||||
# id: str
|
||||
# wallet: str
|
||||
#
|
||||
# @classmethod
|
||||
# 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
|
||||
import httpx
|
||||
|
||||
|
||||
async def create_ticket(
|
||||
payment_hash: str,
|
||||
wallet: str,
|
||||
@ -52,19 +53,14 @@ async def set_ticket_paid(payment_hash: str) -> Tickets:
|
||||
""",
|
||||
(amount, row[1]),
|
||||
)
|
||||
|
||||
|
||||
ticket = await get_ticket(payment_hash)
|
||||
if formdata.webhook:
|
||||
async with httpx.AsyncClient() as client:
|
||||
try:
|
||||
r = await client.post(
|
||||
formdata.webhook,
|
||||
json={
|
||||
"form": ticket.form,
|
||||
"name": ticket.name,
|
||||
"email": ticket.email,
|
||||
"content": ticket.ltext
|
||||
},
|
||||
json={"form": ticket.form, "name": ticket.name, "email": ticket.email, "content": ticket.ltext},
|
||||
timeout=40,
|
||||
)
|
||||
except AssertionError:
|
||||
@ -96,7 +92,9 @@ async def delete_ticket(ticket_id: str) -> None:
|
||||
# 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()
|
||||
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")]:
|
||||
usescsv = ""
|
||||
|
||||
|
@ -8,6 +8,7 @@ import httpx
|
||||
|
||||
from lnbits.extensions import subdomains
|
||||
|
||||
|
||||
async def create_subdomain(
|
||||
payment_hash: str,
|
||||
wallet: str,
|
||||
@ -17,7 +18,7 @@ async def create_subdomain(
|
||||
ip: str,
|
||||
sats: int,
|
||||
duration: int,
|
||||
record_type: str
|
||||
record_type: str,
|
||||
) -> Subdomains:
|
||||
await db.execute(
|
||||
"""
|
||||
@ -33,7 +34,10 @@ async def create_subdomain(
|
||||
|
||||
|
||||
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:
|
||||
await db.execute(
|
||||
"""
|
||||
@ -60,9 +64,9 @@ async def set_subdomain_paid(payment_hash: str) -> Subdomains:
|
||||
subdomain = await get_subdomain(payment_hash)
|
||||
|
||||
### SEND REQUEST TO CLOUDFLARE
|
||||
url="https://api.cloudflare.com/client/v4/zones/" + domaindata.cf_zone_id + "/dns_records"
|
||||
header= {'Authorization': 'Bearer ' + domaindata.cf_token, 'Content-Type': 'application/json'}
|
||||
aRecord=subdomain.subdomain + '.' + subdomain.domain_name
|
||||
url = "https://api.cloudflare.com/client/v4/zones/" + domaindata.cf_zone_id + "/dns_records"
|
||||
header = {"Authorization": "Bearer " + domaindata.cf_token, "Content-Type": "application/json"}
|
||||
aRecord = subdomain.subdomain + "." + subdomain.domain_name
|
||||
cf_response = ""
|
||||
async with httpx.AsyncClient() as client:
|
||||
try:
|
||||
@ -74,7 +78,7 @@ async def set_subdomain_paid(payment_hash: str) -> Subdomains:
|
||||
"name": aRecord,
|
||||
"content": subdomain.ip,
|
||||
"ttl": 0,
|
||||
"proxed": False
|
||||
"proxed": False,
|
||||
},
|
||||
timeout=40,
|
||||
)
|
||||
@ -96,7 +100,7 @@ async def set_subdomain_paid(payment_hash: str) -> Subdomains:
|
||||
"ip": subdomain.ip,
|
||||
"cost:": str(subdomain.sats) + " sats",
|
||||
"duration": str(subdomain.duration) + " days",
|
||||
"cf_response": cf_response
|
||||
"cf_response": cf_response,
|
||||
},
|
||||
timeout=40,
|
||||
)
|
||||
@ -108,7 +112,10 @@ async def set_subdomain_paid(payment_hash: str) -> 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)
|
||||
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]
|
||||
|
||||
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]
|
||||
|
||||
@ -130,7 +140,17 @@ async def delete_subdomain(subdomain_id: str) -> None:
|
||||
# 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()
|
||||
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:
|
||||
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'))
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
@ -6,18 +6,20 @@ from http import HTTPStatus
|
||||
from . import subdomains_ext
|
||||
from .crud import get_domain
|
||||
|
||||
|
||||
@subdomains_ext.route("/")
|
||||
@validate_uuids(["usr"], required=True)
|
||||
@check_user_exists()
|
||||
async def index():
|
||||
return await render_template("subdomains/index.html", user=g.user)
|
||||
|
||||
|
||||
@subdomains_ext.route("/<domain_id>")
|
||||
async def display(domain_id):
|
||||
domain = await get_domain(domain_id)
|
||||
if not domain:
|
||||
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)
|
||||
return await render_template(
|
||||
"subdomains/display.html",
|
||||
@ -25,5 +27,5 @@ async def display(domain_id):
|
||||
domain_domain=domain.domain,
|
||||
domain_desc=domain.description,
|
||||
domain_cost=domain.cost,
|
||||
domain_allowed_record_types=allowed_records
|
||||
domain_allowed_record_types=allowed_records,
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user