From bf6659bbbdfa486211bbf5ffe883f4e2e74c6d1e Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 4 Apr 2023 12:52:10 +0200 Subject: [PATCH] remove the need for nostrclient --- README.md | 1 + __init__.py | 15 ++++++--------- config.json | 8 ++------ lnurl.py | 13 ++++--------- manifest.json | 15 +++++++-------- tasks.py | 20 ++++++++------------ 6 files changed, 28 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 8957dff..fc683b8 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ LNURL is a range of lightning-network standards that allow us to use lightning-n 2. Use the shareable link or view the LNURLp you just created\ ![LNURLp](https://i.imgur.com/C8s1P0Q.jpg) + - you can now open your LNURLp and copy the LNURL, get the shareable link or print it\ ![view lnurlp](https://i.imgur.com/4n41S7T.jpg) diff --git a/__init__.py b/__init__.py index 7a466ba..0c69f78 100644 --- a/__init__.py +++ b/__init__.py @@ -9,16 +9,13 @@ from lnbits.helpers import template_renderer from lnbits.tasks import catch_everything_and_restart from loguru import logger -try: - from ..nostrclient.nostr.event import Event - from ..nostrclient.nostr.key import PrivateKey, PublicKey - nostrclient_present = True - nostr_privatekey = PrivateKey() - nostr_publickey: PublicKey = nostr_privatekey.public_key - logger.debug(f"LNURLP Zaps Nostr pubkey: {nostr_publickey.hex()}") -except ImportError: - nostrclient_present = False +from .nostr.event import Event +from .nostr.key import PrivateKey, PublicKey + +nostr_privatekey = PrivateKey() +nostr_publickey: PublicKey = nostr_privatekey.public_key +logger.debug(f"LNURLP Zaps Nostr pubkey: {nostr_publickey.hex()}") db = Database("ext_lnurlp") diff --git a/config.json b/config.json index d3e046d..8e0ee88 100644 --- a/config.json +++ b/config.json @@ -1,10 +1,6 @@ { "name": "LNURLp", "short_description": "Make reusable LNURL pay links", - "tile": "/lnurlp/static/image/lnurl-pay.png", - "contributors": [ - "arcbtc", - "eillarra", - "fiatjaf" - ] + "tile": "/lnurlp/static/image/lnurl-pay.png", + "contributors": ["arcbtc", "eillarra", "fiatjaf", "callebtc"] } diff --git a/lnurl.py b/lnurl.py index 00ca97d..38fd911 100644 --- a/lnurl.py +++ b/lnurl.py @@ -12,13 +12,9 @@ from .crud import increment_pay_link, get_pay_link, get_address_data from loguru import logger from urllib.parse import urlparse import json -from . import nostrclient_present, nostr_publickey +from . import nostr_publickey -if nostrclient_present: - try: - from ..nostrclient.nostr.key import PrivateKey, PublicKey - except ImportError: - nostrclient_present = False +from ..nostrclient.nostr.key import PrivateKey, PublicKey @lnurlp_ext.get( @@ -151,7 +147,6 @@ async def api_lnurl_response(request: Request, link_id, lnaddress=False): if link.comment_chars > 0: params["commentAllowed"] = link.comment_chars - if nostrclient_present: - params["allowsNostr"] = True - params["nostrPubkey"] = nostr_publickey.hex() + params["allowsNostr"] = True + params["nostrPubkey"] = nostr_publickey.hex() return params diff --git a/manifest.json b/manifest.json index 508a576..cc0c3d2 100644 --- a/manifest.json +++ b/manifest.json @@ -1,10 +1,9 @@ - { - "repos": [ - { - "id": "lnurlp", - "organisation": "lnbits", - "repository": "lnurlp" - } - ] + "repos": [ + { + "id": "lnurlp", + "organisation": "lnbits", + "repository": "lnurlp" + } + ] } diff --git a/tasks.py b/tasks.py index 12fdfa4..ca77b16 100644 --- a/tasks.py +++ b/tasks.py @@ -12,16 +12,12 @@ from websocket import WebSocketApp from lnbits.settings import settings from .crud import get_pay_link from threading import Thread -from . import nostrclient_present, nostr_privatekey +from . import nostr_privatekey from typing import List import time -if nostrclient_present: - try: - from ..nostrclient.nostr.event import Event - from ..nostrclient.nostr.key import PrivateKey, PublicKey - except ImportError: - nostrclient_present = False +from .nostr.event import Event +from .nostr.key import PrivateKey, PublicKey async def wait_for_paid_invoices(): @@ -77,7 +73,7 @@ async def on_invoice_paid(payment: Payment): # NIP-57 nostr = payment.extra.get("nostr") - if nostrclient_present and nostr: + if nostr: event_json = json.loads(nostr) @@ -117,10 +113,10 @@ async def on_invoice_paid(payment: Payment): # list of all threads for these websockets wsts: List[Thread] = [] - # send zap via nostrclient - ws, wst = send_zap(f"ws://localhost:{settings.port}/nostrclient/api/v1/relay") - wss += [ws] - wsts += [wst] + # # send zap via nostrclient + # ws, wst = send_zap(f"ws://localhost:{settings.port}/nostrclient/api/v1/relay") + # wss += [ws] + # wsts += [wst] # send zap receipt to relays in zap request relays = get_tag(event_json, "relays")