bump and adapt to nostr-sdk to 0.7.1

This commit is contained in:
Believethehype
2024-01-09 15:37:31 +01:00
parent 7f928ae767
commit 3812ffa02f
11 changed files with 35 additions and 20 deletions

View File

@@ -24,7 +24,7 @@ def nostr_client_test_llm(prompt):
relay_list = ["wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org", relay_list = ["wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org",
"wss://nostr-pub.wellorder.net"] "wss://nostr-pub.wellorder.net"]
signer = ClientSigner.KEYS(keys) signer = ClientSigner.keys(keys)
client = Client(signer) client = Client(signer)
for relay in relay_list: for relay in relay_list:

View File

@@ -42,7 +42,7 @@ def nostr_client():
sk = keys.secret_key() sk = keys.secret_key()
pk = keys.public_key() pk = keys.public_key()
print(f"Nostr Test Client public key: {pk.to_bech32()}, Hex: {pk.to_hex()} ") print(f"Nostr Test Client public key: {pk.to_bech32()}, Hex: {pk.to_hex()} ")
signer = ClientSigner.KEYS(keys) signer = ClientSigner.keys(keys)
client = Client(signer) client = Client(signer)
dvmconfig = DVMConfig() dvmconfig = DVMConfig()

View File

@@ -35,7 +35,7 @@ class Bot:
skip_disconnected_relays = True skip_disconnected_relays = True
opts = (Options().wait_for_send(wait_for_send).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)) opts = (Options().wait_for_send(wait_for_send).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))
.skip_disconnected_relays(skip_disconnected_relays)) .skip_disconnected_relays(skip_disconnected_relays))
signer = ClientSigner.KEYS(self.keys) signer = ClientSigner.keys(self.keys)
self.client = Client.with_opts(signer, opts) self.client = Client.with_opts(signer, opts)
pk = self.keys.public_key() pk = self.keys.public_key()

View File

@@ -43,7 +43,7 @@ class DVM:
opts = (Options().wait_for_send(wait_for_send).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)) opts = (Options().wait_for_send(wait_for_send).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))
.skip_disconnected_relays(skip_disconnected_relays)) .skip_disconnected_relays(skip_disconnected_relays))
signer = ClientSigner.KEYS(self.keys) signer = ClientSigner.keys(self.keys)
self.client = Client.with_opts(signer,opts) self.client = Client.with_opts(signer,opts)

View File

@@ -89,7 +89,7 @@ class AdvancedSearch(DVMTaskInterface):
opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))) opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)))
sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
keys = Keys.from_sk_str(sk.to_hex()) keys = Keys.from_sk_str(sk.to_hex())
signer = ClientSigner.KEYS(keys) signer = ClientSigner.keys(keys)
cli = Client.with_opts(signer, opts) cli = Client.with_opts(signer, opts)
cli.add_relay("wss://relay.nostr.band") cli.add_relay("wss://relay.nostr.band")

View File

@@ -20,7 +20,7 @@ def build_external_dvm(pubkey, task, kind, fix_cost, per_unit_cost, config,
opts = (Options().wait_for_send(True).send_timeout(timedelta(seconds=config.RELAY_TIMEOUT)) opts = (Options().wait_for_send(True).send_timeout(timedelta(seconds=config.RELAY_TIMEOUT))
.skip_disconnected_relays(True)) .skip_disconnected_relays(True))
keys = Keys.from_sk_str(config.PRIVATE_KEY) keys = Keys.from_sk_str(config.PRIVATE_KEY)
signer = ClientSigner.KEYS(keys) signer = ClientSigner.keys(keys)
client = Client.with_opts(signer, opts) client = Client.with_opts(signer, opts)

View File

@@ -20,7 +20,7 @@ def nwc_zap(connectionstr, bolt11, keys):
} }
} }
signer = ClientSigner.KEYS(keys) signer = ClientSigner.keys(keys)
client = Client(signer) client = Client(signer)
client.add_relay(relay) client.add_relay(relay)
client.connect() client.connect()

View File

@@ -14,7 +14,7 @@ setup(
description=DESCRIPTION, description=DESCRIPTION,
long_description=LONG_DESCRIPTION, long_description=LONG_DESCRIPTION,
packages=find_packages(include=['nostr_dvm/**']), packages=find_packages(include=['nostr_dvm/**']),
install_requires=["nostr-sdk==0.7.0", install_requires=["nostr-sdk==0.7.1",
"bech32==1.2.0", "bech32==1.2.0",
"pycryptodome==3.19.0", "pycryptodome==3.19.0",
"python-dotenv==1.0.0", "python-dotenv==1.0.0",

View File

@@ -19,7 +19,7 @@ keys = Keys.from_sk_str(check_and_set_private_key("test_client"))
opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=2)) opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=2))
.skip_disconnected_relays(True)) .skip_disconnected_relays(True))
signer = ClientSigner.KEYS(keys) signer = ClientSigner.keys(keys)
client = Client.with_opts(signer, opts) client = Client.with_opts(signer, opts)
relay_list = ["wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org", "wss://nostr-pub.wellorder.net"] relay_list = ["wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org", "wss://nostr-pub.wellorder.net"]
@@ -65,6 +65,16 @@ def nostr_client_test_search(prompt, users=None, since="", until=""):
def handledvm(now): def handledvm(now):
response = False response = False
signer = ClientSigner.keys(keys)
cli = Client.with_opts(signer, opts)
relay_list = ["wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org",
"wss://nostr-pub.wellorder.net"]
for relay in relay_list:
cli.add_relay(relay)
cli.connect()
feedbackfilter = Filter().pubkey(keys.public_key()).kinds( feedbackfilter = Filter().pubkey(keys.public_key()).kinds(
[EventDefinitions.KIND_NIP90_RESULTS_CONTENT_SEARCH]).since(now) [EventDefinitions.KIND_NIP90_RESULTS_CONTENT_SEARCH]).since(now)
feedbackfilter2 = Filter().pubkey(keys.public_key()).kinds( feedbackfilter2 = Filter().pubkey(keys.public_key()).kinds(
@@ -72,8 +82,8 @@ def handledvm(now):
events = [] events = []
fevents = [] fevents = []
while not response: while not response:
events = client.get_events_of([feedbackfilter], timedelta(seconds=3)) events = cli.get_events_of([feedbackfilter], timedelta(seconds=3))
fevents = client.get_events_of([feedbackfilter2], timedelta(seconds=3)) fevents = cli.get_events_of([feedbackfilter2], timedelta(seconds=3))
if len(fevents) > 0: if len(fevents) > 0:
print(fevents[0].content()) print(fevents[0].content())
# ui.notify(fevents[0].content()) # ui.notify(fevents[0].content())
@@ -89,7 +99,8 @@ def handledvm(now):
event_ids.append(eventidob) event_ids.append(eventidob)
config = DVMConfig() config = DVMConfig()
events = get_events_by_id(event_ids, client, config) events = get_events_by_id(event_ids, cli, config)
print("HELLO")
listui = [] listui = []
for event in events: for event in events:
nip19event = Nip19Event(event.id(), event.pubkey(), dvmconfig.DVMConfig.RELAY_LIST) nip19event = Nip19Event(event.id(), event.pubkey(), dvmconfig.DVMConfig.RELAY_LIST)
@@ -104,11 +115,13 @@ def handledvm(now):
listui.append(new) listui.append(new)
print(event.as_json()) print(event.as_json())
# ui.update(table) # ui.update(table)
response = True
cli.disconnect()
cli.shutdown()
return listui return listui
async def search(): async def search():
data.clear()
table.clear()
table.visible = False table.visible = False
now = Timestamp.now() now = Timestamp.now()
taggedusersfrom = [str(word).lstrip('from:@') for word in prompt.value.split() if word.startswith('from:@')] taggedusersfrom = [str(word).lstrip('from:@') for word in prompt.value.split() if word.startswith('from:@')]
@@ -129,6 +142,8 @@ async def search():
print("Sent: " + ev) print("Sent: " + ev)
listui = [] listui = []
print(str(now.to_human_datetime())) print(str(now.to_human_datetime()))
data.clear()
table.clear()
listui = await run.cpu_bound(handledvm, now) listui = await run.cpu_bound(handledvm, now)
ui.notify("Received results from DVM") ui.notify("Received results from DVM")

View File

@@ -31,7 +31,7 @@ def nostr_client_test_translation(input, kind, lang, sats, satsmax):
relay_list = ["wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org", relay_list = ["wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org",
"wss://nostr-pub.wellorder.net"] "wss://nostr-pub.wellorder.net"]
signer = ClientSigner.KEYS(keys) signer = ClientSigner.keys(keys)
client = Client(signer) client = Client(signer)
for relay in relay_list: for relay in relay_list:
@@ -60,7 +60,7 @@ def nostr_client_test_image(prompt):
relay_list = ["wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org", relay_list = ["wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org",
"wss://nostr-pub.wellorder.net"] "wss://nostr-pub.wellorder.net"]
signer = ClientSigner.KEYS(keys) signer = ClientSigner.keys(keys)
client = Client(signer) client = Client(signer)
for relay in relay_list: for relay in relay_list:
client.add_relay(relay) client.add_relay(relay)
@@ -86,7 +86,7 @@ def nostr_client_test_tts(prompt):
relay_list = ["wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org", relay_list = ["wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org",
"wss://nostr-pub.wellorder.net"] "wss://nostr-pub.wellorder.net"]
signer = ClientSigner.KEYS(keys) signer = ClientSigner.keys(keys)
client = Client(signer) client = Client(signer)
for relay in relay_list: for relay in relay_list:
client.add_relay(relay) client.add_relay(relay)
@@ -125,7 +125,7 @@ def nostr_client_test_image_private(prompt, cashutoken):
nip90request = EventBuilder(EventDefinitions.KIND_NIP90_GENERATE_IMAGE, encrypted_params, nip90request = EventBuilder(EventDefinitions.KIND_NIP90_GENERATE_IMAGE, encrypted_params,
[pTag, encrypted_tag]).to_event(keys) [pTag, encrypted_tag]).to_event(keys)
signer = ClientSigner.KEYS(keys) signer = ClientSigner.keys(keys)
client = Client(signer) client = Client(signer)
for relay in relay_list: for relay in relay_list:
client.add_relay(relay) client.add_relay(relay)
@@ -140,7 +140,7 @@ def nostr_client():
sk = keys.secret_key() sk = keys.secret_key()
pk = keys.public_key() pk = keys.public_key()
print(f"Nostr Client public key: {pk.to_bech32()}, Hex: {pk.to_hex()} ") print(f"Nostr Client public key: {pk.to_bech32()}, Hex: {pk.to_hex()} ")
signer = ClientSigner.KEYS(keys) signer = ClientSigner.keys(keys)
client = Client(signer) client = Client(signer)
dvmconfig = DVMConfig() dvmconfig = DVMConfig()

View File

@@ -17,7 +17,7 @@ skip_disconnected_relays = True
opts = (Options().wait_for_send(wait_for_send).send_timeout(timedelta(seconds=5)) opts = (Options().wait_for_send(wait_for_send).send_timeout(timedelta(seconds=5))
.skip_disconnected_relays(skip_disconnected_relays)) .skip_disconnected_relays(skip_disconnected_relays))
signer = ClientSigner.KEYS(keys) signer = ClientSigner.keys(keys)
client = Client.with_opts(signer, opts) client = Client.with_opts(signer, opts)
for relay in relay_list: for relay in relay_list: