add zaps
This commit is contained in:
parent
c51b849fe6
commit
fa3cb87ba0
2 changed files with 62 additions and 2 deletions
10
lnurl.py
10
lnurl.py
|
|
@ -77,6 +77,10 @@ async def api_lnurl_callback(
|
||||||
if comment:
|
if comment:
|
||||||
extra["comment"] = (comment,)
|
extra["comment"] = (comment,)
|
||||||
|
|
||||||
|
nostr = request.query_params.get("nostr")
|
||||||
|
if nostr:
|
||||||
|
extra["nostr"] = nostr
|
||||||
|
|
||||||
if lnaddress and link.username and link.domain:
|
if lnaddress and link.username and link.domain:
|
||||||
extra["lnaddress"] = f"{link.username}@{link.domain}"
|
extra["lnaddress"] = f"{link.username}@{link.domain}"
|
||||||
|
|
||||||
|
|
@ -84,7 +88,7 @@ async def api_lnurl_callback(
|
||||||
wallet_id=link.wallet,
|
wallet_id=link.wallet,
|
||||||
amount=int(amount_received / 1000),
|
amount=int(amount_received / 1000),
|
||||||
memo=link.description,
|
memo=link.description,
|
||||||
unhashed_description=link.lnurlpay_metadata.encode(),
|
unhashed_description=nostr.encode() or link.lnurlpay_metadata.encode(),
|
||||||
extra=extra,
|
extra=extra,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -136,4 +140,8 @@ async def api_lnurl_response(request: Request, link_id, lnaddress=False):
|
||||||
if link.comment_chars > 0:
|
if link.comment_chars > 0:
|
||||||
params["commentAllowed"] = link.comment_chars
|
params["commentAllowed"] = link.comment_chars
|
||||||
|
|
||||||
|
params["allowNostr"] = True
|
||||||
|
params[
|
||||||
|
"nostrPubkey"
|
||||||
|
] = "749b4d4dfc6b00a5e6c9a88d8a220c46c069ff8f027dcf312f040475e059554a" # private: de1af06647137d49b2277faa86f96effc94257a7b7efd6f5dcc52bea08a4746b
|
||||||
return params
|
return params
|
||||||
|
|
|
||||||
54
tasks.py
54
tasks.py
|
|
@ -8,8 +8,10 @@ from lnbits.core.crud import update_payment_extra
|
||||||
from lnbits.core.models import Payment
|
from lnbits.core.models import Payment
|
||||||
from lnbits.helpers import get_current_extension_name
|
from lnbits.helpers import get_current_extension_name
|
||||||
from lnbits.tasks import register_invoice_listener
|
from lnbits.tasks import register_invoice_listener
|
||||||
|
from websocket import WebSocketApp
|
||||||
|
from lnbits.settings import settings
|
||||||
from .crud import get_pay_link
|
from .crud import get_pay_link
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
|
|
||||||
async def wait_for_paid_invoices():
|
async def wait_for_paid_invoices():
|
||||||
|
|
@ -63,6 +65,56 @@ async def on_invoice_paid(payment: Payment):
|
||||||
payment.payment_hash, -1, False, "Unexpected Error", str(ex)
|
payment.payment_hash, -1, False, "Unexpected Error", str(ex)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
nostr = payment.extra.get("nostr")
|
||||||
|
if nostr:
|
||||||
|
from ..nostrclient.nostr.event import Event
|
||||||
|
from ..nostrclient.nostr.key import PrivateKey, PublicKey
|
||||||
|
|
||||||
|
event_json = json.loads(nostr)
|
||||||
|
|
||||||
|
def get_tag(event_json, tag):
|
||||||
|
res = [
|
||||||
|
event_tag[1] for event_tag in event_json["tags"] if event_tag[0] == tag
|
||||||
|
]
|
||||||
|
return res[0] if res else None
|
||||||
|
|
||||||
|
private_key = PrivateKey(
|
||||||
|
bytes.fromhex(
|
||||||
|
"de1af06647137d49b2277faa86f96effc94257a7b7efd6f5dcc52bea08a4746b"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
p_tag = get_tag(event_json, "p")
|
||||||
|
tags = []
|
||||||
|
for t in ["p", "e"]:
|
||||||
|
tag = get_tag(event_json, t)
|
||||||
|
if tag:
|
||||||
|
tags.append([t, tag])
|
||||||
|
tags.append(["bolt11", payment.bolt11])
|
||||||
|
tags.append(["description", json.dumps(event_json)])
|
||||||
|
zap_receipt = Event(
|
||||||
|
public_key="749b4d4dfc6b00a5e6c9a88d8a220c46c069ff8f027dcf312f040475e059554a",
|
||||||
|
kind=9735,
|
||||||
|
tags=tags,
|
||||||
|
)
|
||||||
|
private_key.sign_event(zap_receipt)
|
||||||
|
|
||||||
|
print(f"NOSTR STUFF: {event_json}")
|
||||||
|
print(f"Receipt: {zap_receipt}")
|
||||||
|
|
||||||
|
def send_event(class_obj):
|
||||||
|
ws.send(zap_receipt.to_message())
|
||||||
|
# nonlocal wst
|
||||||
|
# wst.join(timeout=1)
|
||||||
|
|
||||||
|
ws = WebSocketApp(
|
||||||
|
f"wss://localhost:{settings.port}/nostrclient/api/v1/relay",
|
||||||
|
on_open=send_event,
|
||||||
|
)
|
||||||
|
wst = Thread(target=ws.run_forever)
|
||||||
|
wst.daemon = True
|
||||||
|
wst.start()
|
||||||
|
|
||||||
|
|
||||||
async def mark_webhook_sent(
|
async def mark_webhook_sent(
|
||||||
payment_hash: str, status: int, is_success: bool, reason_phrase="", text=""
|
payment_hash: str, status: int, is_success: bool, reason_phrase="", text=""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue