oops: formatting.
This commit is contained in:
parent
03706dcbad
commit
d84915cb00
16 changed files with 145 additions and 36 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,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:
|
||||||
|
|
@ -151,7 +154,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}},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -208,7 +212,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)
|
||||||
|
|
@ -217,7 +225,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:
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -71,7 +77,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:
|
||||||
|
|
@ -147,7 +157,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
|
||||||
|
|
@ -187,7 +199,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()
|
||||||
|
|
@ -347,7 +362,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"])
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,14 @@ async def m002_changed(db):
|
||||||
)
|
)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
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,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
await db.execute("DROP TABLE tickets")
|
await db.execute("DROP TABLE tickets")
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,21 @@ from . import example_ext
|
||||||
async def api_example():
|
async def api_example():
|
||||||
"""Try to add descriptions for others."""
|
"""Try to add descriptions for others."""
|
||||||
tools = [
|
tools = [
|
||||||
{"name": "Flask", "url": "https://flask.palletsprojects.com/", "language": "Python",},
|
{
|
||||||
{"name": "Vue.js", "url": "https://vuejs.org/", "language": "JavaScript",},
|
"name": "Flask",
|
||||||
{"name": "Quasar Framework", "url": "https://quasar.dev/", "language": "JavaScript",},
|
"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
|
return jsonify(tools), HTTPStatus.OK
|
||||||
|
|
|
||||||
|
|
@ -47,10 +47,19 @@ async def lndhub_auth():
|
||||||
async def lndhub_addinvoice():
|
async def lndhub_addinvoice():
|
||||||
try:
|
try:
|
||||||
_, pr = await create_invoice(
|
_, pr = await create_invoice(
|
||||||
wallet_id=g.wallet.id, amount=int(g.data["amt"]), memo=g.data["memo"], extra={"tag": "lndhub"},
|
wallet_id=g.wallet.id,
|
||||||
|
amount=int(g.data["amt"]),
|
||||||
|
memo=g.data["memo"],
|
||||||
|
extra={"tag": "lndhub"},
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({"error": True, "code": 7, "message": "Failed to create invoice: " + str(e),})
|
return jsonify(
|
||||||
|
{
|
||||||
|
"error": True,
|
||||||
|
"code": 7,
|
||||||
|
"message": "Failed to create invoice: " + str(e),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
invoice = bolt11.decode(pr)
|
invoice = bolt11.decode(pr)
|
||||||
return jsonify(
|
return jsonify(
|
||||||
|
|
@ -70,10 +79,18 @@ async def lndhub_addinvoice():
|
||||||
async def lndhub_payinvoice():
|
async def lndhub_payinvoice():
|
||||||
try:
|
try:
|
||||||
await pay_invoice(
|
await pay_invoice(
|
||||||
wallet_id=g.wallet.id, payment_request=g.data["invoice"], extra={"tag": "lndhub"},
|
wallet_id=g.wallet.id,
|
||||||
|
payment_request=g.data["invoice"],
|
||||||
|
extra={"tag": "lndhub"},
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({"error": True, "code": 10, "message": "Payment failed: " + str(e),})
|
return jsonify(
|
||||||
|
{
|
||||||
|
"error": True,
|
||||||
|
"code": 10,
|
||||||
|
"message": "Payment failed: " + str(e),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
invoice: bolt11.Invoice = bolt11.decode(g.data["invoice"])
|
invoice: bolt11.Invoice = bolt11.decode(g.data["invoice"])
|
||||||
return jsonify(
|
return jsonify(
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,13 @@ from .models import Tickets, Forms
|
||||||
|
|
||||||
|
|
||||||
async def create_ticket(
|
async def create_ticket(
|
||||||
payment_hash: str, wallet: str, form: str, name: str, email: str, ltext: str, sats: int,
|
payment_hash: str,
|
||||||
|
wallet: str,
|
||||||
|
form: str,
|
||||||
|
name: str,
|
||||||
|
email: str,
|
||||||
|
ltext: str,
|
||||||
|
sats: int,
|
||||||
) -> Tickets:
|
) -> Tickets:
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,15 @@ async def m002_changed(db):
|
||||||
)
|
)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
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,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
await db.execute("DROP TABLE tickets")
|
await db.execute("DROP TABLE tickets")
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,10 @@ async def api_ticket_make_ticket(form_id):
|
||||||
nwords = len(re.split(r"\s+", g.data["ltext"]))
|
nwords = len(re.split(r"\s+", g.data["ltext"]))
|
||||||
sats = nwords * form.costpword
|
sats = nwords * form.costpword
|
||||||
payment_hash, payment_request = await create_invoice(
|
payment_hash, payment_request = await create_invoice(
|
||||||
wallet_id=form.wallet, amount=sats, memo=f"ticket with {nwords} words on {form_id}", extra={"tag": "lnticket"},
|
wallet_id=form.wallet,
|
||||||
|
amount=sats,
|
||||||
|
memo=f"ticket with {nwords} words on {form_id}",
|
||||||
|
extra={"tag": "lnticket"},
|
||||||
)
|
)
|
||||||
|
|
||||||
ticket = await create_ticket(payment_hash=payment_hash, wallet=form.wallet, sats=sats, **g.data)
|
ticket = await create_ticket(payment_hash=payment_hash, wallet=form.wallet, sats=sats, **g.data)
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,17 @@ async def create_pay_link(
|
||||||
)
|
)
|
||||||
VALUES (?, ?, ?, ?, 0, 0, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, 0, 0, ?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(wallet_id, description, min, max, webhook_url, success_text, success_url, comment_chars, currency,),
|
(
|
||||||
|
wallet_id,
|
||||||
|
description,
|
||||||
|
min,
|
||||||
|
max,
|
||||||
|
webhook_url,
|
||||||
|
success_text,
|
||||||
|
success_url,
|
||||||
|
comment_chars,
|
||||||
|
currency,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
link_id = result._result_proxy.lastrowid
|
link_id = result._result_proxy.lastrowid
|
||||||
link = await get_pay_link(link_id)
|
link = await get_pay_link(link_id)
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,10 @@ async def api_lnurl_callback(link_id):
|
||||||
extra={"tag": "lnurlp", "link": link.id, "comment": comment},
|
extra={"tag": "lnurlp", "link": link.id, "comment": comment},
|
||||||
)
|
)
|
||||||
|
|
||||||
resp = LnurlPayActionResponse(pr=payment_request, success_action=link.success_action(payment_hash), routes=[],)
|
resp = LnurlPayActionResponse(
|
||||||
|
pr=payment_request,
|
||||||
|
success_action=link.success_action(payment_hash),
|
||||||
|
routes=[],
|
||||||
|
)
|
||||||
|
|
||||||
return jsonify(resp.dict()), HTTPStatus.OK
|
return jsonify(resp.dict()), HTTPStatus.OK
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@
|
||||||
<code>[<pay_link_object>, ...]</code>
|
<code>[<pay_link_object>, ...]</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X GET {{ request.url_root }}lnurlp/api/v1/links -H "X-Api-Key: {{
|
>curl -X GET {{ request.url_root }}lnurlp/api/v1/links -H "X-Api-Key:
|
||||||
g.user.wallets[0].inkey }}"
|
{{ g.user.wallets[0].inkey }}"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
@ -38,8 +38,8 @@
|
||||||
<code>{"lnurl": <string>}</code>
|
<code>{"lnurl": <string>}</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X GET {{ request.url_root }}lnurlp/api/v1/links/<pay_id> -H
|
>curl -X GET {{ request.url_root }}lnurlp/api/v1/links/<pay_id>
|
||||||
"X-Api-Key: {{ g.user.wallets[0].inkey }}"
|
-H "X-Api-Key: {{ g.user.wallets[0].inkey }}"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
@ -93,8 +93,8 @@
|
||||||
<code>{"lnurl": <string>}</code>
|
<code>{"lnurl": <string>}</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X PUT {{ request.url_root }}lnurlp/api/v1/links/<pay_id> -d
|
>curl -X PUT {{ request.url_root }}lnurlp/api/v1/links/<pay_id>
|
||||||
'{"description": <string>, "amount": <integer>}' -H
|
-d '{"description": <string>, "amount": <integer>}' -H
|
||||||
"Content-type: application/json" -H "X-Api-Key: {{
|
"Content-type: application/json" -H "X-Api-Key: {{
|
||||||
g.user.wallets[0].adminkey }}"
|
g.user.wallets[0].adminkey }}"
|
||||||
</code>
|
</code>
|
||||||
|
|
@ -120,8 +120,9 @@
|
||||||
<code></code>
|
<code></code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X DELETE {{ request.url_root }}lnurlp/api/v1/links/<pay_id>
|
>curl -X DELETE {{ request.url_root
|
||||||
-H "X-Api-Key: {{ g.user.wallets[0].adminkey }}"
|
}}lnurlp/api/v1/links/<pay_id> -H "X-Api-Key: {{
|
||||||
|
g.user.wallets[0].adminkey }}"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,15 @@ async def api_links():
|
||||||
wallet_ids = (await get_user(g.wallet.user)).wallet_ids
|
wallet_ids = (await get_user(g.wallet.user)).wallet_ids
|
||||||
try:
|
try:
|
||||||
return (
|
return (
|
||||||
jsonify([{**link._asdict(), **{"lnurl": link.lnurl},} for link in await get_withdraw_links(wallet_ids)]),
|
jsonify(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
**link._asdict(),
|
||||||
|
**{"lnurl": link.lnurl},
|
||||||
|
}
|
||||||
|
for link in await get_withdraw_links(wallet_ids)
|
||||||
|
]
|
||||||
|
),
|
||||||
HTTPStatus.OK,
|
HTTPStatus.OK,
|
||||||
)
|
)
|
||||||
except LnurlInvalidUrl:
|
except LnurlInvalidUrl:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue