refactor: extract nostr to __init__
This commit is contained in:
parent
e35dafe056
commit
99022f2b4a
4 changed files with 12 additions and 10 deletions
|
|
@ -8,6 +8,8 @@ from lnbits.db import Database
|
|||
from lnbits.helpers import template_renderer
|
||||
from lnbits.tasks import catch_everything_and_restart
|
||||
|
||||
from .nostr.client.client import NostrClient as NostrClientLib
|
||||
|
||||
db = Database("ext_nostrclient")
|
||||
|
||||
nostrclient_static_files = [
|
||||
|
|
@ -22,6 +24,13 @@ nostrclient_ext: APIRouter = APIRouter(prefix="/nostrclient", tags=["nostrclient
|
|||
|
||||
scheduled_tasks: List[asyncio.Task] = []
|
||||
|
||||
class NostrClient:
|
||||
def __init__(self):
|
||||
self.client: NostrClientLib = NostrClientLib(connect=False)
|
||||
|
||||
|
||||
nostr = NostrClient()
|
||||
|
||||
|
||||
def nostr_renderer():
|
||||
return template_renderer(["lnbits/extensions/nostrclient/templates"])
|
||||
|
|
|
|||
10
services.py
10
services.py
|
|
@ -7,21 +7,13 @@ from loguru import logger
|
|||
|
||||
from lnbits.helpers import urlsafe_short_hash
|
||||
|
||||
from . import nostr
|
||||
from .models import Event, Filter
|
||||
from .nostr.client.client import NostrClient as NostrClientLib
|
||||
from .nostr.filter import Filter as NostrFilter
|
||||
from .nostr.filter import Filters as NostrFilters
|
||||
from .nostr.message_pool import EndOfStoredEventsMessage, NoticeMessage
|
||||
|
||||
|
||||
class NostrClient:
|
||||
def __init__(self):
|
||||
self.client: NostrClientLib = NostrClientLib(connect=False)
|
||||
|
||||
|
||||
nostr = NostrClient()
|
||||
|
||||
|
||||
class NostrRouter:
|
||||
|
||||
received_subscription_events: dict[str, list[Event]] = {}
|
||||
|
|
|
|||
1
tasks.py
1
tasks.py
|
|
@ -1,6 +1,7 @@
|
|||
import asyncio
|
||||
import threading
|
||||
|
||||
from . import nostr
|
||||
from .crud import get_relays
|
||||
from .nostr.message_pool import EndOfStoredEventsMessage, EventMessage, NoticeMessage
|
||||
from .services import NostrRouter, nostr
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from starlette.exceptions import HTTPException
|
|||
from lnbits.decorators import check_admin
|
||||
from lnbits.helpers import urlsafe_short_hash
|
||||
|
||||
from . import nostrclient_ext, scheduled_tasks
|
||||
from . import nostr, nostrclient_ext, scheduled_tasks
|
||||
from .crud import add_relay, delete_relay, get_relays
|
||||
from .helpers import normalize_public_key
|
||||
from .models import Relay, RelayList, TestMessage, TestMessageResponse
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue