diff --git a/nostr_dvm/bot.py b/nostr_dvm/bot.py index ce26a3e..fa83f5d 100644 --- a/nostr_dvm/bot.py +++ b/nostr_dvm/bot.py @@ -189,7 +189,7 @@ class Bot: print(params_as_str) # and encrypt them encrypted_params = nip44_encrypt(self.keys.secret_key(), - PublicKey.from_hex( + PublicKey.parse( self.dvm_config.SUPPORTED_DVMS[ index].PUBLIC_KEY), params_as_str, Nip44Version.V2) @@ -675,16 +675,12 @@ class Bot: elif (input.startswith("nevent") or input.startswith("nostr:nevent") or input.startswith("note") or input.startswith("nostr:note")): input_type = "event" - if str(input).startswith('note'): - event_id = EventId.from_bech32(input) - elif str(input).startswith("nevent"): + if str(input).startswith("nevent"): event_id = Nip19Event.from_bech32(input).event_id() - elif str(input).startswith('nostr:note'): - event_id = EventId.from_nostr_uri(input) elif str(input).startswith("nostr:nevent"): event_id = Nip19Event.from_nostr_uri(input).event_id() else: - event_id = EventId.from_hex(input) + event_id = EventId.parse(input) i_tag = Tag.parse(["i", event_id.to_hex(), input_type]) tags.append(i_tag) else: diff --git a/nostr_dvm/dvm.py b/nostr_dvm/dvm.py index fba428b..bf36c71 100644 --- a/nostr_dvm/dvm.py +++ b/nostr_dvm/dvm.py @@ -17,7 +17,7 @@ from nostr_dvm.utils.dvmconfig import DVMConfig from nostr_dvm.utils.mediasource_utils import input_data_file_duration from nostr_dvm.utils.nip88_utils import nip88_has_active_subscription from nostr_dvm.utils.nostr_utils import get_event_by_id, get_referenced_event_by_id, check_and_decrypt_tags, \ - send_event_outbox + send_event_outbox, print_send_result from nostr_dvm.utils.nut_wallet_utils import NutZapWallet from nostr_dvm.utils.output_utils import build_status_reaction from nostr_dvm.utils.print_utils import bcolors @@ -432,7 +432,7 @@ class DVM: print(status) if job_event.kind() == EventDefinitions.KIND_NIP88_SUBSCRIBE_EVENT: await send_job_status_reaction(job_event, "subscription-success", client=self.client, - dvm_config=self.dvm_config, user=user) + dvm_config=self.dvm_config) @@ -579,8 +579,8 @@ class DVM: request_tag = Tag.parse(["request", original_event_as_str]) e_tag = Tag.parse(["e", original_event.id().to_hex()]) p_tag = Tag.parse(["p", original_event.author().to_hex()]) - alt_tag = Tag.parse(["alt", "This is the result of a NIP90 DVM AI task with kind " + str( - original_event.kind().as_u16()) + ". The task was: " + original_event.content()]) + alt_tag = Tag.parse(["alt", "This is the result of a NIP90 DVM task with kind " + str( + original_event.kind().as_u16())]) status_tag = Tag.parse(["status", "success"]) reply_tags = [request_tag, e_tag, p_tag, alt_tag, status_tag] @@ -624,12 +624,12 @@ class DVM: if encrypted: print(content) if is_legacy_encryption: - content = nip04_encrypt(self.keys.secret_key(), PublicKey.from_hex(original_event.author().to_hex()), + content = nip04_encrypt(self.keys.secret_key(), PublicKey.parse(original_event.author().to_hex()), content) else: content = nip44_encrypt(self.keys.secret_key(), - PublicKey.from_hex(original_event.author().to_hex()), + PublicKey.parse(original_event.author().to_hex()), content, Nip44Version.V2) reply_tags = encryption_tags @@ -639,13 +639,19 @@ class DVM: self.keys) #print(reply_event) # send_event(reply_event, client=self.client, dvm_config=self.dvm_config) - await send_event_outbox(reply_event, client=self.client, dvm_config=self.dvm_config) + response_status = await send_event_outbox(reply_event, client=self.client, dvm_config=self.dvm_config) + if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value: print(bcolors.GREEN + "[" + self.dvm_config.NIP89.NAME + "] " + str( - original_event.kind().as_u16() + 1000) + " Job Response event sent: " + reply_event.as_json() + bcolors.ENDC) + original_event.kind().as_u16() + 1000) + " Job Response event sent: " + reply_event.as_json() + ". Success: " + str( + response_status.success) + " Failed: " + str(response_status.failed) + " EventID: " + + response_status.id.to_hex() + " / " + response_status.id.to_bech32() + bcolors.ENDC) + elif self.dvm_config.LOGLEVEL.value >= LogLevel.INFO.value: print(bcolors.GREEN + "[" + self.dvm_config.NIP89.NAME + "] " + str( - original_event.kind().as_u16() + 1000) + " Job Response event sent: " + reply_event.id().to_hex() + bcolors.ENDC) + original_event.kind().as_u16() + 1000) + " Job Response event sent. Success: " + str( + response_status.success) + " Failed: " + str(response_status.failed) + " EventID: " + + response_status.id.to_hex() + " / " + response_status.id.to_bech32() + bcolors.ENDC) async def send_job_status_reaction(original_event, status, is_paid=True, amount=0, client=None, content=None, @@ -751,11 +757,11 @@ class DVM: content = json.dumps(str_tags) if is_legacy_encryption: - content = nip04_encrypt(self.keys.secret_key(), PublicKey.from_hex(original_event.author().to_hex()), + content = nip04_encrypt(self.keys.secret_key(), PublicKey.parse(original_event.author().to_hex()), content) else: content = nip44_encrypt(self.keys.secret_key(), - PublicKey.from_hex(original_event.author().to_hex()), + PublicKey.parse(original_event.author().to_hex()), content, version=Nip44Version.V2) reply_tags = encryption_tags @@ -768,14 +774,19 @@ class DVM: keys = Keys.parse(dvm_config.PRIVATE_KEY) reaction_event = EventBuilder(EventDefinitions.KIND_FEEDBACK, str(content)).tags(reply_tags).sign_with_keys(keys) # send_event(reaction_event, client=self.client, dvm_config=self.dvm_config) - await send_event_outbox(reaction_event, client=self.client, dvm_config=self.dvm_config) - + response_status = await send_event_outbox(reaction_event, client=self.client, dvm_config=self.dvm_config) if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value: - print(bcolors.YELLOW + "[" + self.dvm_config.NIP89.NAME + "]" + " Sent Kind " + str( - EventDefinitions.KIND_FEEDBACK.as_u16()) + " Reaction: " + status + " " + reaction_event.as_json() + bcolors.ENDC) + print(bcolors.YELLOW + "[" + self.dvm_config.NIP89.NAME + "] Sent Kind " + str( + EventDefinitions.KIND_FEEDBACK.as_u16()) + " Reaction: " + status + " " + reaction_event.as_json() + ". Success: " + str( + response_status.success) + " Failed: " + str(response_status.failed) + " EventID: " + + response_status.id.to_hex() + " / " + response_status.id.to_bech32() + bcolors.ENDC) + elif self.dvm_config.LOGLEVEL.value >= LogLevel.INFO.value: - print(bcolors.YELLOW + "[" + self.dvm_config.NIP89.NAME + "]" + " Sent Kind " + str( - EventDefinitions.KIND_FEEDBACK.as_u16()) + " Reaction: " + status + " " + reaction_event.id().to_hex() + bcolors.ENDC) + print(bcolors.YELLOW + "[" + self.dvm_config.NIP89.NAME + "] Sent Kind " + str( + EventDefinitions.KIND_FEEDBACK.as_u16()) + " Reaction: " + status + ". Success: " + str( + response_status.success) + " Failed: " + str(response_status.failed) + " EventID: " + + response_status.id.to_hex() + " / " + response_status.id.to_bech32() + bcolors.ENDC) + return reaction_event.as_json() diff --git a/nostr_dvm/subscription.py b/nostr_dvm/subscription.py index 646a5de..5cc09de 100644 --- a/nostr_dvm/subscription.py +++ b/nostr_dvm/subscription.py @@ -147,7 +147,7 @@ class Subscription: str_tags.append(element.as_vec()) content = json.dumps(str_tags) - content = nip44_encrypt(self.keys.secret_key(), PublicKey.from_hex(original_event.author().to_hex()), + content = nip44_encrypt(self.keys.secret_key(), PublicKey.parse(original_event.author().to_hex()), content, Nip44Version.V2) reply_tags = encryption_tags diff --git a/nostr_dvm/tasks/advanced_search.py b/nostr_dvm/tasks/advanced_search.py index 257418a..d5b0427 100644 --- a/nostr_dvm/tasks/advanced_search.py +++ b/nostr_dvm/tasks/advanced_search.py @@ -87,7 +87,7 @@ class AdvancedSearch(DVMTaskInterface): from nostr_sdk import Filter options = self.set_options(request_form) - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) cli = Client(NostrSigner.keys(keys)) @@ -110,12 +110,7 @@ class AdvancedSearch(DVMTaskInterface): user = tag.as_vec()[1] # user = user[1] user = str(user).lstrip("@") - if str(user).startswith('npub'): - userkey = PublicKey.from_bech32(user) - elif str(user).startswith("nostr:npub"): - userkey = PublicKey.from_nostr_uri(user) - else: - userkey = PublicKey.from_hex(user) + userkey = PublicKey.parse(user) userkeys.append(userkey) diff --git a/nostr_dvm/tasks/advanced_search_wine.py b/nostr_dvm/tasks/advanced_search_wine.py index 57e8fec..bf34dbd 100644 --- a/nostr_dvm/tasks/advanced_search_wine.py +++ b/nostr_dvm/tasks/advanced_search_wine.py @@ -89,12 +89,7 @@ class AdvancedSearchWine(DVMTaskInterface): tag = Tag.parse(user) user = tag.as_vec()[1] user = str(user).lstrip("@") - if str(user).startswith('npub'): - userkey = PublicKey.from_bech32(user) - elif str(user).startswith("nostr:npub"): - userkey = PublicKey.from_nostr_uri(user) - else: - userkey = PublicKey.from_hex(user) + userkey = PublicKey.parse(user) userkeys.append(userkey) diff --git a/nostr_dvm/tasks/content_discovery_currently_latest_longform.py b/nostr_dvm/tasks/content_discovery_currently_latest_longform.py index 79e5bff..d1b5b11 100644 --- a/nostr_dvm/tasks/content_discovery_currently_latest_longform.py +++ b/nostr_dvm/tasks/content_discovery_currently_latest_longform.py @@ -107,7 +107,7 @@ class DicoverContentLatestLongForm(DVMTaskInterface): options = self.set_options(request_form) - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb(self.db_name) @@ -172,7 +172,7 @@ class DicoverContentLatestLongForm(DVMTaskInterface): try: relaylimits = RelayLimits.disable() opts = (Options().relay_limits(relaylimits)) - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb(self.db_name) cli = ClientBuilder().signer(NostrSigner.keys(keys)).database(database).opts(opts).build() diff --git a/nostr_dvm/tasks/content_discovery_currently_latest_wiki.py b/nostr_dvm/tasks/content_discovery_currently_latest_wiki.py index e972574..fda0f22 100644 --- a/nostr_dvm/tasks/content_discovery_currently_latest_wiki.py +++ b/nostr_dvm/tasks/content_discovery_currently_latest_wiki.py @@ -107,7 +107,7 @@ class DicoverContentLatestWiki(DVMTaskInterface): options = self.set_options(request_form) - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb(self.db_name) @@ -172,7 +172,7 @@ class DicoverContentLatestWiki(DVMTaskInterface): try: relaylimits = RelayLimits.disable() opts = (Options().relay_limits(relaylimits)) - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb(self.db_name) cli = ClientBuilder().signer(NostrSigner.keys(keys)).database(database).opts(opts).build() diff --git a/nostr_dvm/tasks/content_discovery_currently_popular.py b/nostr_dvm/tasks/content_discovery_currently_popular.py index c69bd37..050f5fc 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular.py @@ -170,7 +170,7 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface): async def sync_db(self): try: - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb(self.db_name) diff --git a/nostr_dvm/tasks/content_discovery_currently_popular_by_top_zaps.py b/nostr_dvm/tasks/content_discovery_currently_popular_by_top_zaps.py index e0f8c7f..b3d3793 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular_by_top_zaps.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular_by_top_zaps.py @@ -213,7 +213,7 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface): async def sync_db(self): try: - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb(self.db_name) cli = ClientBuilder().signer(NostrSigner.keys(keys)).database(database).build() diff --git a/nostr_dvm/tasks/content_discovery_currently_popular_followers.py b/nostr_dvm/tasks/content_discovery_currently_popular_followers.py index 507a904..1fdd18b 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular_followers.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular_followers.py @@ -94,7 +94,7 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface): opts = ( Options().relay_limits( relaylimits)) - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb(self.db_name) @@ -189,7 +189,7 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface): async def sync_db(self): try: - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb(self.db_name) cli = ClientBuilder().signer(NostrSigner.keys(keys)).database(database).build() diff --git a/nostr_dvm/tasks/content_discovery_currently_popular_gallery.py b/nostr_dvm/tasks/content_discovery_currently_popular_gallery.py index c4ce0bf..0a76d27 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular_gallery.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular_gallery.py @@ -133,7 +133,7 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface): relaylimits = RelayLimits.disable() opts = (Options().relay_limits(relaylimits)) - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) cli = ClientBuilder().database(databasegallery).signer(NostrSigner.keys(keys)).opts(opts).build() @@ -233,7 +233,7 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface): async def sync_db(self): try: - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb(self.db_name) cli = ClientBuilder().signer(NostrSigner.keys(keys)).database(database).build() diff --git a/nostr_dvm/tasks/content_discovery_currently_popular_mostr.py b/nostr_dvm/tasks/content_discovery_currently_popular_mostr.py index eea4646..f3e0741 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular_mostr.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular_mostr.py @@ -176,7 +176,7 @@ class DicoverContentCurrentlyPopularMostr(DVMTaskInterface): async def sync_db(self): try: - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb(self.db_name) cli = ClientBuilder().signer(NostrSigner.keys(keys)).database(database).build() diff --git a/nostr_dvm/tasks/content_discovery_currently_popular_nonfollowers.py b/nostr_dvm/tasks/content_discovery_currently_popular_nonfollowers.py index 765fa04..2b9f429 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular_nonfollowers.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular_nonfollowers.py @@ -142,7 +142,7 @@ class DicoverContentCurrentlyPopularNonFollowers(DVMTaskInterface): relaylimits = RelayLimits.disable() opts = ( Options().relay_limits(relaylimits)) - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) if self.database is None: self.database = NostrDatabase.lmdb(self.db_name) @@ -225,7 +225,7 @@ class DicoverContentCurrentlyPopularNonFollowers(DVMTaskInterface): async def sync_db(self): try: - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb(self.db_name) cli = ClientBuilder().signer(NostrSigner.keys(keys)).database(database).build() diff --git a/nostr_dvm/tasks/content_discovery_currently_popular_topic.py b/nostr_dvm/tasks/content_discovery_currently_popular_topic.py index d002d10..1c4f01e 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular_topic.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular_topic.py @@ -202,7 +202,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface): async def sync_db(self): try: - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb(self.db_name) cli = ClientBuilder().signer(NostrSigner.keys(keys)).database(database).build() diff --git a/nostr_dvm/tasks/content_discovery_currently_popular_tweets.py b/nostr_dvm/tasks/content_discovery_currently_popular_tweets.py index eeb9944..9ee7857 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular_tweets.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular_tweets.py @@ -191,7 +191,7 @@ class DicoverContentCurrentlyPopularTweets(DVMTaskInterface): async def sync_db(self): try: - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb(self.db_name) cli = ClientBuilder().signer(NostrSigner.keys(keys)).database(database).build() diff --git a/nostr_dvm/tasks/content_discovery_latest_one_per_follower.py b/nostr_dvm/tasks/content_discovery_latest_one_per_follower.py index 8e39485..3b57916 100644 --- a/nostr_dvm/tasks/content_discovery_latest_one_per_follower.py +++ b/nostr_dvm/tasks/content_discovery_latest_one_per_follower.py @@ -69,7 +69,7 @@ class Discoverlatestperfollower(DVMTaskInterface): from types import SimpleNamespace ns = SimpleNamespace() - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) relaylimits = RelayLimits.disable() diff --git a/nostr_dvm/tasks/content_discovery_on_this_day.py b/nostr_dvm/tasks/content_discovery_on_this_day.py index 6b35c6a..8bed620 100644 --- a/nostr_dvm/tasks/content_discovery_on_this_day.py +++ b/nostr_dvm/tasks/content_discovery_on_this_day.py @@ -175,7 +175,7 @@ class DicoverContentOnThisDay(DVMTaskInterface): async def sync_db(self): try: - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb(self.db_name) diff --git a/nostr_dvm/tasks/content_discovery_update_db_only.py b/nostr_dvm/tasks/content_discovery_update_db_only.py index 74ddf4e..6c26521 100644 --- a/nostr_dvm/tasks/content_discovery_update_db_only.py +++ b/nostr_dvm/tasks/content_discovery_update_db_only.py @@ -137,7 +137,7 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface): opts = (Options().relay_limits(relaylimits)) if self.dvm_config.WOT_FILTERING: opts = opts.filtering_mode(RelayFilteringMode.WHITELIST) - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) if self.database is None: self.database = await init_db(self.db_name, True, self.max_db_size) diff --git a/nostr_dvm/tasks/discovery_bot_farms.py b/nostr_dvm/tasks/discovery_bot_farms.py index dee05d6..be23e2a 100644 --- a/nostr_dvm/tasks/discovery_bot_farms.py +++ b/nostr_dvm/tasks/discovery_bot_farms.py @@ -74,7 +74,7 @@ class DiscoveryBotFarms(DVMTaskInterface): from nostr_sdk import Filter options = self.set_options(request_form) - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb("db/nostr_profiles.db") @@ -134,7 +134,7 @@ class DiscoveryBotFarms(DVMTaskInterface): return 1 async def sync_db(self): - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb("db/nostr_profiles.db") cli = ClientBuilder().signer(NostrSigner.keys(keys)).database(database).build() diff --git a/nostr_dvm/tasks/discovery_censor_wot.py b/nostr_dvm/tasks/discovery_censor_wot.py index 9a72fee..876195a 100644 --- a/nostr_dvm/tasks/discovery_censor_wot.py +++ b/nostr_dvm/tasks/discovery_censor_wot.py @@ -71,7 +71,7 @@ class DiscoverReports(DVMTaskInterface): relaylimits = RelayLimits.disable() opts = ( Options().relay_limits(relaylimits)) - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) cli = ClientBuilder().signer(NostrSigner.keys(keys)).opts(opts).build() # cli.add_relay("wss://relay.nostr.band") diff --git a/nostr_dvm/tasks/discovery_inactive_follows.py b/nostr_dvm/tasks/discovery_inactive_follows.py index 5a34fb5..9cf841d 100644 --- a/nostr_dvm/tasks/discovery_inactive_follows.py +++ b/nostr_dvm/tasks/discovery_inactive_follows.py @@ -68,7 +68,7 @@ class DiscoverInactiveFollows(DVMTaskInterface): from types import SimpleNamespace ns = SimpleNamespace() - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) # relaylimits = RelayLimits().event_max_num_tags(max_num_tags=10000) # relaylimits.event_max_size(None) @@ -130,7 +130,7 @@ class DiscoverInactiveFollows(DVMTaskInterface): filters = [] for i in range(i, i + st): - filter1 = Filter().author(PublicKey.from_hex(users[i])).since(notactivesince).limit(1) + filter1 = Filter().author(PublicKey.parse(users[i])).since(notactivesince).limit(1) filters.append(filter1) event_from_authors = await cli.fetch_events(filters, relay_timeout_long) for author in event_from_authors.to_vec(): diff --git a/nostr_dvm/tasks/discovery_nonfollowers.py b/nostr_dvm/tasks/discovery_nonfollowers.py index c18673c..4c8474b 100644 --- a/nostr_dvm/tasks/discovery_nonfollowers.py +++ b/nostr_dvm/tasks/discovery_nonfollowers.py @@ -66,7 +66,7 @@ class DiscoverNonFollowers(DVMTaskInterface): opts = ( Options().relay_limits( relaylimits)) - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) cli= ClientBuilder().signer(NostrSigner.keys(keys)).opts(opts).build() @@ -81,7 +81,7 @@ class DiscoverNonFollowers(DVMTaskInterface): options = self.set_options(request_form) step = 20 - followers_filter = Filter().author(PublicKey.from_hex(options["user"])).kind(Kind(3)) + followers_filter = Filter().author(PublicKey.parse(options["user"])).kind(Kind(3)) followers = await cli.fetch_events([followers_filter], relay_timeout) if len(followers.to_vec()) > 0: @@ -113,7 +113,7 @@ class DiscoverNonFollowers(DVMTaskInterface): for i in range(i, i + st): filters = [] - filter1 = Filter().author(PublicKey.from_hex(users[i])).kind(Kind(3)) + filter1 = Filter().author(PublicKey.parse(users[i])).kind(Kind(3)) filters.append(filter1) followers = await cli.fetch_events(filters, relay_timeout) diff --git a/nostr_dvm/tasks/discovery_trending_notes_gleasonator.py b/nostr_dvm/tasks/discovery_trending_notes_gleasonator.py index ada5bfc..95012ba 100644 --- a/nostr_dvm/tasks/discovery_trending_notes_gleasonator.py +++ b/nostr_dvm/tasks/discovery_trending_notes_gleasonator.py @@ -70,7 +70,7 @@ class TrendingNotesGleasonator(DVMTaskInterface): async def process(self, request_form): options = self.set_options(request_form) - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) cli = Client(NostrSigner.keys(keys)) diff --git a/nostr_dvm/tasks/people_discovery_mywot.py b/nostr_dvm/tasks/people_discovery_mywot.py index 3f759c4..3182454 100644 --- a/nostr_dvm/tasks/people_discovery_mywot.py +++ b/nostr_dvm/tasks/people_discovery_mywot.py @@ -203,7 +203,7 @@ class DiscoverPeopleMyWOT(DVMTaskInterface): async def sync_db(self): - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb(self.db_name) cli = ClientBuilder().signer(NostrSigner.keys(keys)).database(database).build() diff --git a/nostr_dvm/tasks/people_discovery_wot.py b/nostr_dvm/tasks/people_discovery_wot.py index 6db6baf..4115363 100644 --- a/nostr_dvm/tasks/people_discovery_wot.py +++ b/nostr_dvm/tasks/people_discovery_wot.py @@ -207,7 +207,7 @@ class DiscoverPeopleWOT(DVMTaskInterface): return 1 async def sync_db(self): - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb(self.db_name) cli = ClientBuilder().signer(NostrSigner.keys(keys)).database(database).build() diff --git a/nostr_dvm/tasks/search_users.py b/nostr_dvm/tasks/search_users.py index 254113c..4971a0d 100644 --- a/nostr_dvm/tasks/search_users.py +++ b/nostr_dvm/tasks/search_users.py @@ -79,7 +79,7 @@ class SearchUser(DVMTaskInterface): from nostr_sdk import Filter options = self.set_options(request_form) - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb(self.db_name) cli = ClientBuilder().database(database).signer(NostrSigner.keys(keys)).build() @@ -140,7 +140,7 @@ class SearchUser(DVMTaskInterface): return 1 async def sync_db(self): - sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) database = NostrDatabase.lmdb(self.db_name) relaylimits = RelayLimits.disable() diff --git a/nostr_dvm/utils/admin_utils.py b/nostr_dvm/utils/admin_utils.py index 200e8e8..4d15c05 100644 --- a/nostr_dvm/utils/admin_utils.py +++ b/nostr_dvm/utils/admin_utils.py @@ -9,7 +9,7 @@ from nostr_dvm.utils.nip65_utils import nip65_announce_relays from nostr_dvm.utils.nip88_utils import nip88_announce_tier, fetch_nip88_parameters_for_deletion, fetch_nip88_event, \ check_and_set_tiereventid_nip88 from nostr_dvm.utils.nip89_utils import nip89_announce_tasks, fetch_nip89_parameters_for_deletion -from nostr_dvm.utils.nostr_utils import update_profile +from nostr_dvm.utils.nostr_utils import update_profile, print_send_result from nostr_dvm.utils.nut_wallet_utils import NutZapWallet @@ -128,5 +128,5 @@ async def admin_make_database_updates(adminconfig: AdminConfig = None, dvmconfig await fetch_nip88_event(keys, event_id, client, dvmconfig) if adminconfig.UPDATE_PROFILE: - event = await update_profile(dvmconfig, client, lud16=dvmconfig.LN_ADDRESS) - print(event.output) + event_result = await update_profile(dvmconfig, client, lud16=dvmconfig.LN_ADDRESS) + print_send_result(event_result) diff --git a/nostr_dvm/utils/external_dvm_utils.py b/nostr_dvm/utils/external_dvm_utils.py index 0f8c106..54cc805 100644 --- a/nostr_dvm/utils/external_dvm_utils.py +++ b/nostr_dvm/utils/external_dvm_utils.py @@ -22,7 +22,7 @@ async def build_client(config): def build_external_dvm(pubkey, task, kind, fix_cost, per_unit_cost, config, external_post_process=PostProcessFunctionType.NONE): - pubkey = PublicKey.from_hex(pubkey).to_hex() + pubkey = PublicKey.parse(pubkey).to_hex() dvm_config = DVMConfig() dvm_config.PUBLIC_KEY = pubkey dvm_config.FIX_COST = fix_cost diff --git a/nostr_dvm/utils/gallery_utils.py b/nostr_dvm/utils/gallery_utils.py index 4b0bd68..f123cb2 100644 --- a/nostr_dvm/utils/gallery_utils.py +++ b/nostr_dvm/utils/gallery_utils.py @@ -16,7 +16,7 @@ import requests from urllib.parse import urlparse -from nostr_dvm.utils.nostr_utils import send_event +from nostr_dvm.utils.nostr_utils import send_event, print_send_result from nostr_dvm.utils.print_utils import bcolors @@ -88,8 +88,9 @@ async def convert_nip93_to_nip68(private_key, relay_list, user_to_import_npub=No var = input("Convert and post this image? (y(es)/n(o)/d(elete): " + image_url + " Content: " + content + "\n") if var == "d" or var == "delete": delete_event = EventBuilder.delete([event.id()]).sign_with_keys(keys) - result = await client.send_event(delete_event) - print(result.output) + response_status = await client.send_event(delete_event) + print_send_result(response_status) + elif var == "y" or var == "yes": diff --git a/nostr_dvm/utils/nip65_utils.py b/nostr_dvm/utils/nip65_utils.py index 3393983..f8a684f 100644 --- a/nostr_dvm/utils/nip65_utils.py +++ b/nostr_dvm/utils/nip65_utils.py @@ -16,11 +16,12 @@ async def announce_dm_relays(dvm_config, client): content = "" event = EventBuilder(Kind(10050), content).tags(tags).sign_with_keys(keys) - eventid = await send_event(event, client=client, dvm_config=dvm_config, broadcast=True) - if eventid is not None: + response_status = await send_event(event, client=client, dvm_config=dvm_config, broadcast=True) + if response_status is not None: print( - bcolors.BLUE + "[" + dvm_config.NIP89.NAME + "] Announced DM relays for " + dvm_config.NIP89.NAME + " (EventID: " + str( - eventid.id.to_hex()) + ")" + bcolors.ENDC) + bcolors.BLUE + "[" + dvm_config.NIP89.NAME + "] Announced DM relays for " + dvm_config.NIP89.NAME + ". Success: " + str( + response_status.success) + " Failed: " + str(response_status.failed) + " EventID: " + + response_status.id.to_hex() + " / " + response_status.id.to_bech32()) else: print( bcolors.RED + "[" + dvm_config.NIP89.NAME + "] Could not announce DM relays for " + dvm_config.NIP89.NAME + bcolors.ENDC) @@ -40,11 +41,12 @@ async def nip65_announce_relays(dvm_config, client): content = "" event = EventBuilder(EventDefinitions.KIND_RELAY_ANNOUNCEMENT, content).tags(tags).sign_with_keys(keys) - eventid = await send_event(event, client=client, dvm_config=dvm_config, broadcast=True) - if eventid is not None: + response_status = await send_event(event, client=client, dvm_config=dvm_config, broadcast=True) + if response_status is not None: print( - bcolors.BLUE + "[" + dvm_config.NIP89.NAME + "] Announced NIP 65 for " + dvm_config.NIP89.NAME + " (EventID: " + str( - eventid.id.to_hex()) + ")" + bcolors.ENDC) + bcolors.BLUE + "[" + dvm_config.NIP89.NAME + "] Announced NIP 65 for " + dvm_config.NIP89.NAME + ". Success: " + str( + response_status.success) + " Failed: " + str(response_status.failed) + " EventID: " + + response_status.id.to_hex() + " / " + response_status.id.to_bech32()) else: print( bcolors.RED + "[" + dvm_config.NIP89.NAME + "] Could not announce NIP 65 for " + dvm_config.NIP89.NAME + bcolors.ENDC) diff --git a/nostr_dvm/utils/nip88_utils.py b/nostr_dvm/utils/nip88_utils.py index 6760dbd..0086627 100644 --- a/nostr_dvm/utils/nip88_utils.py +++ b/nostr_dvm/utils/nip88_utils.py @@ -35,7 +35,7 @@ def nip88_create_d_tag(name, pubkey, image): async def fetch_nip88_parameters_for_deletion(keys, eventid, client, dvmconfig): - idfilter = Filter().id(EventId.from_hex(eventid)).limit(1) + idfilter = Filter().id(EventId.parse(eventid)).limit(1) nip88events = await client.fetch_events([idfilter], relay_timeout) d_tag = "" if len(nip88events.to_vec()) == 0: diff --git a/nostr_dvm/utils/nip89_utils.py b/nostr_dvm/utils/nip89_utils.py index 68db320..c082ccb 100644 --- a/nostr_dvm/utils/nip89_utils.py +++ b/nostr_dvm/utils/nip89_utils.py @@ -6,7 +6,7 @@ import dotenv from nostr_sdk import Tag, Keys, EventBuilder, Filter, Alphabet, PublicKey, Client, EventId, SingleLetterTag, Kind from nostr_dvm.utils.definitions import EventDefinitions, relay_timeout -from nostr_dvm.utils.nostr_utils import send_event +from nostr_dvm.utils.nostr_utils import send_event, print_send_result from nostr_dvm.utils.print_utils import bcolors @@ -31,15 +31,15 @@ async def nip89_announce_tasks(dvm_config, client): content = dvm_config.NIP89.CONTENT event = EventBuilder(EventDefinitions.KIND_ANNOUNCEMENT, content).tags([k_tag, d_tag]).sign_with_keys(keys) - eventid = await send_event(event, client=client, dvm_config=dvm_config, broadcast=True) - print(eventid.output) + response_status = await send_event(event, client=client, dvm_config=dvm_config, broadcast=True) - print( - bcolors.BLUE + "[" + dvm_config.NIP89.NAME + "] Announced NIP 89 for " + dvm_config.NIP89.NAME + " (" + eventid.id.to_hex() + ")" + bcolors.ENDC) + + print(bcolors.BLUE + "[" + dvm_config.NIP89.NAME + "] Announced NIP 89 for " + dvm_config.NIP89.NAME + ". Success: " + str(response_status.success) + " Failed: " + str(response_status.failed) + " EventID: " + + response_status.id.to_hex() + " / " + response_status.id.to_bech32()) async def fetch_nip89_parameters_for_deletion(keys, eventid, client, dvmconfig, pow=False): - idfilter = Filter().id(EventId.from_hex(eventid)).limit(1) + idfilter = Filter().id(EventId.parse(eventid)).limit(1) nip89events = await client.fetch_events([idfilter], relay_timeout) d_tag = "" if len(nip89events.to_vec()) == 0: @@ -73,13 +73,8 @@ async def nip89_delete_announcement(eid: str, keys: Keys, dtag: str, client: Cli event = EventBuilder(Kind(5), "").tags([e_tag, a_tag]).sign_with_keys(keys) print(f"Deletion event: {event.as_json()}") - new_dvm_config = DVMConfig() - new_dvm_config.RELAY_LIST = new_dvm_config.ANNOUNCE_RELAY_LIST - for relay in config.RELAY_LIST: - if relay not in new_dvm_config.RELAY_LIST: - new_dvm_config.RELAY_LIST.append(relay) - await send_event(event, client, new_dvm_config) + await send_event(event, client, config, broadcast=True) async def nip89_delete_announcement_pow(eid: str, keys: Keys, dtag: str, client: Client, config): @@ -88,13 +83,7 @@ async def nip89_delete_announcement_pow(eid: str, keys: Keys, dtag: str, client: ["a", str(EventDefinitions.KIND_ANNOUNCEMENT.as_u16()) + ":" + keys.public_key().to_hex() + ":" + dtag]) event = EventBuilder(Kind(5), "").tags([e_tag, a_tag]).pow(28).sign_with_keys(keys) print(f"POW event: {event.as_json()}") - new_dvm_config = DVMConfig() - new_dvm_config.RELAY_LIST = new_dvm_config.ANNOUNCE_RELAY_LIST - for relay in config.RELAY_LIST: - if relay not in new_dvm_config.RELAY_LIST: - new_dvm_config.RELAY_LIST.append(relay) - - await send_event(event, client, new_dvm_config) + await send_event(event, client, config, broadcast=True) async def nip89_fetch_all_dvms(client): diff --git a/nostr_dvm/utils/nostr_utils.py b/nostr_dvm/utils/nostr_utils.py index ada7916..70f260d 100644 --- a/nostr_dvm/utils/nostr_utils.py +++ b/nostr_dvm/utils/nostr_utils.py @@ -15,7 +15,7 @@ from nostr_dvm.utils.definitions import EventDefinitions, relay_timeout async def get_event_by_id(event_id_str: str, client: Client, config=None) -> Event | None: split = event_id_str.split(":") if len(split) == 3: - pk = PublicKey.from_hex(split[1]) + pk = PublicKey.parse(split[1]) id_filter = Filter().author(pk).custom_tag(SingleLetterTag.lowercase(Alphabet.D), [split[2]]) events = await client.fetch_events([id_filter], relay_timeout) else: @@ -43,21 +43,17 @@ async def get_events_by_ids(event_ids, client: Client, config=None) -> List | No for event_id in event_ids: split = event_id.split(":") if len(split) == 3: - pk = PublicKey.from_hex(split[1]) + pk = PublicKey.parse(split[1]) id_filter = Filter().author(pk).custom_tag(SingleLetterTag.lowercase(Alphabet.D), [split[2]]) events = await client.fetch_events([id_filter], relay_timeout) else: - if str(event_id).startswith('note'): - event_id = EventId.from_bech32(event_id) - elif str(event_id).startswith("nevent"): + + if str(event_id).startswith("nevent"): event_id = Nip19Event.from_bech32(event_id).event_id() - elif str(event_id).startswith('nostr:note'): - event_id = EventId.from_nostr_uri(event_id) elif str(event_id).startswith("nostr:nevent"): event_id = Nip19Event.from_nostr_uri(event_id).event_id() - else: - event_id = EventId.from_hex(event_id) + event_id = EventId.parse(event_id) search_ids.append(event_id) id_filter = Filter().ids(search_ids) @@ -82,16 +78,12 @@ async def get_events_by_id(event_ids: list, client: Client, config=None) -> list async def get_referenced_event_by_id(event_id, client, dvm_config, kinds) -> Event | None: if kinds is None: kinds = [] - if str(event_id).startswith('note'): - event_id = EventId.from_bech32(event_id) - elif str(event_id).startswith("nevent"): + if str(event_id).startswith("nevent"): event_id = Nip19Event.from_bech32(event_id).event_id() - elif str(event_id).startswith('nostr:note'): - event_id = EventId.from_nostr_uri(event_id) elif str(event_id).startswith("nostr:nevent"): event_id = Nip19Event.from_nostr_uri(event_id).event_id() else: - event_id = EventId.from_hex(event_id) + event_id = EventId.parse(event_id) if len(kinds) > 0: job_id_filter = Filter().kinds(kinds).event(event_id).limit(1) @@ -219,10 +211,10 @@ async def send_event_outbox(event: Event, client, dvm_config) -> SendEventOutput # connection = Connection().addr("127.0.0.1:9050").target(ConnectionTarget.ONION) opts = Options().relay_limits(relaylimits).connection(connection) - sk = SecretKey.from_hex(dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) outboxclient = ClientBuilder().signer(NostrSigner.keys(keys)).opts(opts).build() - print("[" + dvm_config.NIP89.NAME + "] Receiver Inbox relays: " + str(relays)) + #print("[" + dvm_config.NIP89.NAME + "] Receiver Inbox relays: " + str(relays)) for relay in relays[:5]: try: @@ -233,14 +225,14 @@ async def send_event_outbox(event: Event, client, dvm_config) -> SendEventOutput await outboxclient.connect() try: #print("Connected, sending event") - event_id = await outboxclient.send_event(event) - print(event_id.output) + event_response = await outboxclient.send_event(event) + except Exception as e: - event_id = None + event_response = None print(e) # 5. Fallback, if we couldn't send the event to any relay, we try to send to generic relays instead. - if event_id is None: + if event_response is None: relays = await get_main_relays(event, client, dvm_config) if len(relays) == 0: return None @@ -248,15 +240,16 @@ async def send_event_outbox(event: Event, client, dvm_config) -> SendEventOutput await outboxclient.add_relay(relay) try: await outboxclient.connect() - event_id = await outboxclient.send_event(event) + event_response = await outboxclient.send_event(event) except Exception as e: # Love yourself then. - event_id = None + event_response = None print(e) + await outboxclient.shutdown() - return event_id + return event_response async def send_event(event: Event, client: Client, dvm_config, broadcast=False): @@ -280,7 +273,7 @@ async def send_event(event: Event, client: Client, dvm_config, broadcast=False): if len(relays) == 0: relays = relay_list - print(relays) + for relay in relays: if relay not in dvm_config.RELAY_LIST: await client.add_relay(relay) @@ -288,19 +281,24 @@ async def send_event(event: Event, client: Client, dvm_config, broadcast=False): await client.connect() try: - event_id = await client.send_event(event) + response_status = await client.send_event(event) except Exception as e: print(e) - event_id = None + response_status = None for relay in relays: if relay not in dvm_config.RELAY_LIST: await client.force_remove_relay(relay) - return event_id + return response_status except Exception as e: print(e) +def print_send_result(response_status): + print("Success: " + str(response_status.success) + " Failed: " + str(response_status.failed) + " EventID: " + + response_status.id.to_hex() + " / " + response_status.id.to_bech32()) + + def check_and_decrypt_tags(event, dvm_config): is_encrypted = False use_legacy_encryption = False @@ -364,10 +362,10 @@ def check_and_decrypt_own_tags(event, dvm_config): elif event.author().to_hex() == dvm_config.PUBLIC_KEY: try: tags_str = nip44_decrypt(Keys.parse(dvm_config.PRIVATE_KEY).secret_key(), - PublicKey.from_hex(p), event.content()) + PublicKey.parse(p), event.content()) except: tags_str = nip04_decrypt(Keys.parse(dvm_config.PRIVATE_KEY).secret_key(), - PublicKey.from_hex(p), event.content()) + PublicKey.parse(p), event.content()) params = json.loads(tags_str) params.append(Tag.parse(["p", p]).as_vec()) params.append(Tag.parse(["encrypted"]).as_vec()) diff --git a/nostr_dvm/utils/output_utils.py b/nostr_dvm/utils/output_utils.py index c91b0cb..f4517f0 100644 --- a/nostr_dvm/utils/output_utils.py +++ b/nostr_dvm/utils/output_utils.py @@ -107,7 +107,7 @@ def post_process_list_to_events(result): for tag in result_list: try: e_tag = Tag.parse(tag) - id = EventId.from_hex(e_tag.as_vec()[1]).to_bech32() + id = EventId.parse(e_tag.as_vec()[1]).to_bech32() result_str = result_str + "nostr:" + id + "\n" except Exception as e: print(e) diff --git a/setup.py b/setup.py index b827455..d308bc9 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -VERSION = '1.0.5' +VERSION = '1.0.6' DESCRIPTION = 'A framework to build and run Nostr NIP90 Data Vending Machines' LONG_DESCRIPTION = ('A framework to build and run Nostr NIP90 Data Vending Machines. See the github repository for more information') @@ -14,7 +14,7 @@ setup( long_description=LONG_DESCRIPTION, packages=find_packages(include=['nostr_dvm', 'nostr_dvm.*']), - install_requires=["nostr-sdk==0.37.0", + install_requires=["nostr-sdk==0.38.0", "bech32==1.2.0", "pycryptodome==3.20.0", "yt-dlp==2024.11.04", diff --git a/tests/generic_dvm_autotopic_feed.py b/tests/generic_dvm_autotopic_feed.py index b8491d6..5a2b9be 100644 --- a/tests/generic_dvm_autotopic_feed.py +++ b/tests/generic_dvm_autotopic_feed.py @@ -120,7 +120,7 @@ def playground(announce=False): async def process(request_form): since = 2 * 60 * 60 options = dvm.set_options(request_form) - sk = SecretKey.from_hex(dvm.dvm_config.PRIVATE_KEY) + sk = SecretKey.parse(dvm.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) relaylimits = RelayLimits.disable() diff --git a/tests/test_dvm_client.py b/tests/test_dvm_client.py index bb1b599..7a9c9a4 100644 --- a/tests/test_dvm_client.py +++ b/tests/test_dvm_client.py @@ -326,7 +326,7 @@ async def nostr_client_test_discovery_user(user, ptag): await client.add_relay(relay) await client.connect() config = DVMConfig - eventid = await send_event(event, client=client, dvm_config=config) + await send_event(event, client=client, dvm_config=config) return event.as_json() @@ -351,7 +351,7 @@ async def nostr_client_test_discovery_gallery(user, ptag): await client.add_relay(relay) await client.connect() config = DVMConfig - eventid = await send_event(event, client=client, dvm_config=config) + await send_event(event, client=client, dvm_config=config) return event.as_json() diff --git a/tests/test_events.py b/tests/test_events.py index b5e6844..c3bae76 100644 --- a/tests/test_events.py +++ b/tests/test_events.py @@ -28,14 +28,14 @@ async def test(): await test_referred_events(client, "5635e5dd930b3c831f6ab1e348bb488f3c9aca2f13190e93ab5e5e1e1ba1835e", definitions.EventDefinitions.ANY_RESULT) - bech32evnt = EventId.from_hex("5635e5dd930b3c831f6ab1e348bb488f3c9aca2f13190e93ab5e5e1e1ba1835e").to_bech32() + bech32evnt = EventId.parse("5635e5dd930b3c831f6ab1e348bb488f3c9aca2f13190e93ab5e5e1e1ba1835e").to_bech32() print(bech32evnt) test = Nip19Event.from_bech32( "nevent1qqsrjcpejsrlt3u7dy42y6rc97svrq9ver08xy4jr2ll55ynq3sxafcppamhxue69uhkummnw3ezumt0d5pzpmnqx2pla0zvxxcfjqeeysy29ll3mtmf4s3yff0y45r7egau080vqvzqqqqqqyu4q839") print(test.event_id().to_hex()) - nostruri = EventId.from_hex("5635e5dd930b3c831f6ab1e348bb488f3c9aca2f13190e93ab5e5e1e1ba1835e").to_nostr_uri() + nostruri = EventId.parse("5635e5dd930b3c831f6ab1e348bb488f3c9aca2f13190e93ab5e5e1e1ba1835e").to_nostr_uri() print(nostruri) await test_search_by_user_since_days(client, @@ -49,9 +49,9 @@ async def test_referred_events(client, event_id, kinds=None): kinds = [] if len(kinds) > 0: - job_id_filter = Filter().kinds(kinds).event(EventId.from_hex(event_id)) + job_id_filter = Filter().kinds(kinds).event(EventId.parse(event_id)) else: - job_id_filter = Filter().event(EventId.from_hex(event_id)) + job_id_filter = Filter().event(EventId.parse(event_id)) event_struct = await client.fetch_events([job_id_filter], relay_timeout) events = event_struct.to_vec() diff --git a/tutorials/03_client.py b/tutorials/03_client.py index 671da81..3d595de 100644 --- a/tutorials/03_client.py +++ b/tutorials/03_client.py @@ -11,7 +11,7 @@ from nostr_dvm.utils.print_utils import bcolors import dotenv from nostr_sdk import Keys, Client, Tag, EventBuilder, Filter, HandleNotification, Timestamp, nip04_decrypt, \ NostrSigner, Event, Kind, PublicKey -from nostr_dvm.utils.nostr_utils import send_event, check_and_set_private_key +from nostr_dvm.utils.nostr_utils import send_event, check_and_set_private_key, print_send_result from nostr_dvm.utils.definitions import EventDefinitions @@ -46,8 +46,8 @@ async def nostr_client_generic_test(ptag): # We connect the client await client.connect() # and send the Event. - result = await send_event(event, client=client, dvm_config=DVMConfig()) - print(result) + response_status = await send_event(event, client=client, dvm_config=DVMConfig()) + print_send_result(response_status) async def nostr_client(target_dvm_npub): diff --git a/tutorials/09_nutzap_client.py b/tutorials/09_nutzap_client.py index 4f1ab00..ea05635 100644 --- a/tutorials/09_nutzap_client.py +++ b/tutorials/09_nutzap_client.py @@ -14,7 +14,7 @@ from nostr_sdk import PublicKey, Client, NostrSigner, EventBuilder, Kind, Tag, K import asyncio from nostr_dvm.utils.definitions import EventDefinitions from nostr_dvm.utils.dvmconfig import DVMConfig -from nostr_dvm.utils.nostr_utils import send_event, check_and_set_private_key +from nostr_dvm.utils.nostr_utils import send_event, check_and_set_private_key, print_send_result from nostr_dvm.utils.nut_wallet_utils import NutZapWallet from nostr_dvm.utils.print_utils import bcolors @@ -36,8 +36,8 @@ async def nostr_client_generic_test(ptag): for relay in relay_list: await client.add_relay(relay) await client.connect() - result = await send_event(event, client=client, dvm_config=DVMConfig()) - print(result) + response_status = await send_event(event, client=client, dvm_config=DVMConfig()) + print_send_result(response_status) async def nostr_client(target_dvm_npub):