diff --git a/crud.py b/crud.py index 61cd865..b1916b7 100644 --- a/crud.py +++ b/crud.py @@ -7,14 +7,14 @@ from .models import Relay, RelayList async def get_relays() -> RelayList: - row = await db.fetchall("SELECT * FROM nostradmin.relays") + row = await db.fetchall("SELECT * FROM nostrclient.relays") return RelayList(__root__=row) async def add_relay(relay: Relay) -> None: await db.execute( f""" - INSERT INTO nostradmin.relays ( + INSERT INTO nostrclient.relays ( id, url, active @@ -26,4 +26,4 @@ async def add_relay(relay: Relay) -> None: async def delete_relay(relay: Relay) -> None: - await db.execute("DELETE FROM nostradmin.relays WHERE id = ?", (relay.id,)) + await db.execute("DELETE FROM nostrclient.relays WHERE url = ?", (relay.url,)) diff --git a/nostr/__pycache__/__init__.cpython-39.pyc b/nostr/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index ce5da3f..0000000 Binary files a/nostr/__pycache__/__init__.cpython-39.pyc and /dev/null differ diff --git a/nostr/__pycache__/bech32.cpython-39.pyc b/nostr/__pycache__/bech32.cpython-39.pyc deleted file mode 100644 index aad1954..0000000 Binary files a/nostr/__pycache__/bech32.cpython-39.pyc and /dev/null differ diff --git a/nostr/__pycache__/delegation.cpython-39.pyc b/nostr/__pycache__/delegation.cpython-39.pyc deleted file mode 100644 index 4490a0c..0000000 Binary files a/nostr/__pycache__/delegation.cpython-39.pyc and /dev/null differ diff --git a/nostr/__pycache__/event.cpython-39.pyc b/nostr/__pycache__/event.cpython-39.pyc deleted file mode 100644 index 2c5abc3..0000000 Binary files a/nostr/__pycache__/event.cpython-39.pyc and /dev/null differ diff --git a/nostr/__pycache__/filter.cpython-39.pyc b/nostr/__pycache__/filter.cpython-39.pyc deleted file mode 100644 index 1005def..0000000 Binary files a/nostr/__pycache__/filter.cpython-39.pyc and /dev/null differ diff --git a/nostr/__pycache__/key.cpython-39.pyc b/nostr/__pycache__/key.cpython-39.pyc deleted file mode 100644 index 28bd3ae..0000000 Binary files a/nostr/__pycache__/key.cpython-39.pyc and /dev/null differ diff --git a/nostr/__pycache__/message_pool.cpython-39.pyc b/nostr/__pycache__/message_pool.cpython-39.pyc deleted file mode 100644 index f9d222d..0000000 Binary files a/nostr/__pycache__/message_pool.cpython-39.pyc and /dev/null differ diff --git a/nostr/__pycache__/message_type.cpython-39.pyc b/nostr/__pycache__/message_type.cpython-39.pyc deleted file mode 100644 index 9f8a0c3..0000000 Binary files a/nostr/__pycache__/message_type.cpython-39.pyc and /dev/null differ diff --git a/nostr/__pycache__/relay.cpython-39.pyc b/nostr/__pycache__/relay.cpython-39.pyc deleted file mode 100644 index c7b3818..0000000 Binary files a/nostr/__pycache__/relay.cpython-39.pyc and /dev/null differ diff --git a/nostr/__pycache__/relay_manager.cpython-39.pyc b/nostr/__pycache__/relay_manager.cpython-39.pyc deleted file mode 100644 index d7a15a0..0000000 Binary files a/nostr/__pycache__/relay_manager.cpython-39.pyc and /dev/null differ diff --git a/nostr/__pycache__/subscription.cpython-39.pyc b/nostr/__pycache__/subscription.cpython-39.pyc deleted file mode 100644 index 7bcbe75..0000000 Binary files a/nostr/__pycache__/subscription.cpython-39.pyc and /dev/null differ diff --git a/nostr/client/__pycache__/__init__.cpython-39.pyc b/nostr/client/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index d98ac41..0000000 Binary files a/nostr/client/__pycache__/__init__.cpython-39.pyc and /dev/null differ diff --git a/nostr/client/__pycache__/cbc.cpython-39.pyc b/nostr/client/__pycache__/cbc.cpython-39.pyc deleted file mode 100644 index 38e4e35..0000000 Binary files a/nostr/client/__pycache__/cbc.cpython-39.pyc and /dev/null differ diff --git a/nostr/client/__pycache__/client.cpython-39.pyc b/nostr/client/__pycache__/client.cpython-39.pyc deleted file mode 100644 index dd9935c..0000000 Binary files a/nostr/client/__pycache__/client.cpython-39.pyc and /dev/null differ diff --git a/nostr/client/client.py b/nostr/client/client.py index 169ccc1..7d54d47 100644 --- a/nostr/client/client.py +++ b/nostr/client/client.py @@ -21,10 +21,10 @@ from . import cbc class NostrClient: relays = [ - "wss://lnbits.link/nostrrelay/client", "wss://nostr-pub.wellorder.net", "wss://nostr.zebedee.cloud", "wss://nodestr.fmt.wiz.biz", + "wss://nostr.oxtr.dev", ] # ["wss://nostr.oxtr.dev"] # ["wss://relay.nostr.info"] "wss://nostr-pub.wellorder.net" "ws://91.237.88.218:2700", "wss://nostrrr.bublina.eu.org", ""wss://nostr-relay.freeberty.net"", , "wss://nostr.oxtr.dev", "wss://relay.nostr.info", "wss://nostr-pub.wellorder.net" , "wss://relayer.fiatjaf.com", "wss://nodestr.fmt.wiz.biz/", "wss://no.str.cr" relay_manager = RelayManager() private_key: PrivateKey diff --git a/tasks.py b/tasks.py index 00dc987..083c234 100644 --- a/tasks.py +++ b/tasks.py @@ -34,7 +34,7 @@ from .crud import get_relays async def init_relays(): relays = await get_relays() - client.relays = [r.url for r in relays.__root__] + client.relays = set([r.url for r in relays.__root__]) client.connect() return @@ -73,8 +73,7 @@ async def init_relays(): async def subscribe_events(): while not any([r.connected for r in client.relay_manager.relays.values()]): - print("no relays connected yet") - await asyncio.sleep(1) + await asyncio.sleep(2) def callback(event: Event): print(f"From {event.public_key[:3]}..{event.public_key[-3:]}: {event.content}") diff --git a/views_api.py b/views_api.py index 4a42abc..e127d12 100644 --- a/views_api.py +++ b/views_api.py @@ -60,6 +60,8 @@ async def api_get_relays(): # type: ignore @nostrclient_ext.post("/api/v1/relay") async def api_add_relay(relay: Relay): # type: ignore assert relay.url, "no URL" + if relay.url in client.relay_manager.relays: + return relay.id = urlsafe_short_hash() await add_relay(relay) await init_relays() @@ -67,6 +69,8 @@ async def api_add_relay(relay: Relay): # type: ignore @nostrclient_ext.delete("/api/v1/relay") async def api_delete_relay(relay: Relay): # type: ignore + assert relay.url + client.relay_manager.remove_relay(relay.url) await delete_relay(relay)