add zaps
This commit is contained in:
parent
c51b849fe6
commit
fa3cb87ba0
2 changed files with 62 additions and 2 deletions
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.helpers import get_current_extension_name
|
||||
from lnbits.tasks import register_invoice_listener
|
||||
|
||||
from websocket import WebSocketApp
|
||||
from lnbits.settings import settings
|
||||
from .crud import get_pay_link
|
||||
from threading import Thread
|
||||
|
||||
|
||||
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)
|
||||
)
|
||||
|
||||
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(
|
||||
payment_hash: str, status: int, is_success: bool, reason_phrase="", text=""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue