Skip to content

Commit

Permalink
add deletion tutorial, improve logs
Browse files Browse the repository at this point in the history
  • Loading branch information
believethehype committed Dec 3, 2024
1 parent 58d3ef9 commit fa40e31
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
7 changes: 5 additions & 2 deletions nostr_dvm/utils/nip89_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ async def fetch_nip89_parameters_for_deletion(keys, eventid, client, dvmconfig,
return

if event.author().to_hex() == keys.public_key().to_hex():
await nip89_delete_announcement(event.id().to_hex(), keys, d_tag, client, dvmconfig)
if pow:
await nip89_delete_announcement_pow(event.id().to_hex(), keys, d_tag, client, dvmconfig)
else:
print("Delete with POW, this might take a while, please wait until finished")
await nip89_delete_announcement(event.id().to_hex(), keys, d_tag, client, dvmconfig)

print("NIP89 announcement deleted from known relays!")
else:
print("Privatekey does not belong to event")
Expand All @@ -66,7 +69,7 @@ async def nip89_delete_announcement(eid: str, keys: Keys, dtag: str, client: Cli
a_tag = Tag.parse(
["a", str(EventDefinitions.KIND_ANNOUNCEMENT.as_u16()) + ":" + keys.public_key().to_hex() + ":" + dtag])
event = EventBuilder(Kind(5), "").tags([e_tag, a_tag]).sign_with_keys(keys)
print(f"POW event: {event.as_json()}")
print(f"Deletion event: {event.as_json()}")
await send_event(event, client, config)


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

VERSION = '1.0.2'
VERSION = '1.0.3'
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')

Expand Down
4 changes: 4 additions & 0 deletions tests/generic_dvm_autotopic_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ def playground(announce=False):
# Add NIP89
nip89info = {
"name": name,
"image": "https://i.nostr.build/I8fJo0n355cbNEbS.png",
"picture": "https://i.nostr.build/I8fJo0n355cbNEbS.png", # "https://image.nostr.build/28da676a19841dcfa7dcf7124be6816842d14b84f6046462d2a3f1268fe58d03.png",
"about": "I create a personalized feed based on topics you were writing about recently",
"supportsEncryption": True,
"acceptsNutZaps": dvm_config.ENABLE_NUTZAP,
"personalized": True,
"amount": "free",
"nip90Params": {
}
}
Expand All @@ -103,6 +106,7 @@ def playground(announce=False):
async def process_request(options, prompt):
result = ""
try:
# pip install -U https://github.com/mrgick/duckduckgo-chat-ai/archive/master.zip
from duck_chat import DuckChat
async with DuckChat(model=ModelType.GPT4o) as chat:
query = prompt
Expand Down
61 changes: 61 additions & 0 deletions tutorials/10_delete_nip89.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

# Welcome Back. So you were playing around with a DVM and announced it to the world, but now you rather would like
# to remove it, because you don't want to run it anymore or you did it by accident. In this tutorial we look at how to
# remove NIP89 announcements, so our DVM doesn't appear in clients anymore.
# Check the main function for more instructions.



import asyncio
from nostr_sdk import EventId, Keys, Client, NostrSigner

from nostr_dvm.utils.dvmconfig import DVMConfig
from nostr_dvm.utils.nip89_utils import fetch_nip89_parameters_for_deletion

# Method to delete the NIP89, don't worry, you don't have to touch this, take a look in the main function.
async def delete_nip_89(event_id, private_key, relay_list, pow=True):
event_id = EventId.parse(event_id).to_hex()
keys = Keys.parse(private_key)
dvm_config = DVMConfig()
dvm_config.RELAY_LIST = relay_list


client = Client(NostrSigner.keys(keys))
for relay in dvm_config.RELAY_LIST:
await client.add_relay(relay)
await client.connect()

await fetch_nip89_parameters_for_deletion(keys, event_id, client, dvm_config, pow)



if __name__ == '__main__':

# What do you need to delete an event?

# First, you need the event id of the announcement. You can copy the json of the announcement from various clients,
# like Amethyst or you should also see it at noogle.lol/nip89. Copy the json to a text editor and in the first line
# you should see an entry "id":"someid". Copy the id and enter it in the event_id field below:
evend_id = "6f91dce309e....."

# The second thing you need is the private key of the DVM the announcement was made for.
# NostrDVM stores all your keys in the .env file. Open the .env file and search for
# DVM_PRIVATE_KEY_{IDENTIFIER_OF_YOUR_DVM}. Enter it below in the field private_key:

private_key = "6221e3181....."

# You can either use Proof of Work to send the delete event or not. Some relays require you to use POW in order to write.
# Sending a POW event might take up to a couple of minutes, so if you decide to use it, have some patience in the progress.
# If you know the relays you published your announcements to do not require POW, you can also set it to False which speeds up the progress.
pow = True

# And finally set the relay list you want to send the deletion request to. Ideally, you use the same relays that you use
# in your DVM's config. Maybe announcements also got propagated to other relays, so you might need to play around a bit until it's gone everywhere.
RELAY_LIST = ["wss://relay.primal.net",
"wss://nostr.mom",
"wss://nostr.oxtr.dev",
]

# That's it. Once you entered the info, run the script and if your private key matches the ID and the event can be found it should be deleted.
# Otherwise you'll get a warning
asyncio.run(delete_nip_89(evend_id, private_key, RELAY_LIST, pow))

0 comments on commit fa40e31

Please sign in to comment.