From 50f9b505cd6880c41cf23367a5c1370a41a58447 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Wed, 22 Mar 2023 00:47:37 +0100 Subject: [PATCH] allowNostr vs alllowsNostr --- lnurl.py | 27 ++++++++++++++------------- tasks.py | 7 ++++++- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lnurl.py b/lnurl.py index 7f08760..37c22f2 100644 --- a/lnurl.py +++ b/lnurl.py @@ -48,15 +48,15 @@ async def api_lnurl_callback( min = link.min * 1000 max = link.max * 1000 - amount_received = amount - if amount_received < min: + amount = amount + if amount < min: return LnurlErrorResponse( - reason=f"Amount {amount_received} is smaller than minimum {min}." + reason=f"Amount {amount} is smaller than minimum {min}." ).dict() - elif amount_received > max: + elif amount > max: return LnurlErrorResponse( - reason=f"Amount {amount_received} is greater than maximum {max}." + reason=f"Amount {amount} is greater than maximum {max}." ).dict() comment = request.query_params.get("comment") @@ -79,21 +79,22 @@ async def api_lnurl_callback( extra["comment"] = (comment,) nostr = request.query_params.get("nostr") + nostr_description = "" if nostr: extra["nostr"] = nostr + # print("HASHING THIS") + nostr_description = json.dumps(nostr)[1:-1] # remove leading and trailing " + # print(nostr_description) + import hashlib + + print(hashlib.sha256(nostr_description.encode()).hexdigest()) if lnaddress and link.username and link.domain: extra["lnaddress"] = f"{link.username}@{link.domain}" - print("HASHING THIS") - nostr_description = json.dumps(nostr)[1:-1] # remove leading and trailing " - print(nostr_description) - import hashlib - - print(hashlib.sha256(nostr_description.encode()).hexdigest()) payment_hash, payment_request = await create_invoice( wallet_id=link.wallet, - amount=int(amount_received / 1000), + amount=int(amount / 1000), memo=link.description, unhashed_description=nostr_description.encode() if nostr @@ -149,7 +150,7 @@ async def api_lnurl_response(request: Request, link_id, lnaddress=False): if link.comment_chars > 0: params["commentAllowed"] = link.comment_chars - params["allowNostr"] = True + params["allowsNostr"] = True params[ "nostrPubkey" ] = "749b4d4dfc6b00a5e6c9a88d8a220c46c069ff8f027dcf312f040475e059554a" # private: de1af06647137d49b2277faa86f96effc94257a7b7efd6f5dcc52bea08a4746b diff --git a/tasks.py b/tasks.py index 79385e9..698658f 100644 --- a/tasks.py +++ b/tasks.py @@ -65,6 +65,7 @@ async def on_invoice_paid(payment: Payment): payment.payment_hash, -1, False, "Unexpected Error", str(ex) ) + # NIP-57 nostr = payment.extra.get("nostr") if nostr: from ..nostrclient.nostr.event import Event @@ -92,11 +93,15 @@ async def on_invoice_paid(payment: Payment): tags.append([t, tag]) tags.append(["bolt11", payment.bolt11]) tags.append(["description", nostr]) - zap_receipt = Event(kind=9735, tags=tags, content="asd") + zap_receipt = Event( + kind=9735, tags=tags, content=payment.extra.get("comment") or "" + ) private_key.sign_event(zap_receipt) def send_event(_): + # logger.debug(f"Sending zap: {zap_receipt.to_message()}") ws.send(zap_receipt.to_message()) + ws.close() from lnbits.core import bolt11