Skip to content

Commit

Permalink
use pow for deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
believethehype committed May 24, 2024
1 parent 128a5b1 commit a667aef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion nostr_dvm/utils/admin_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class AdminConfig:
DELETEUSER: bool = False
LISTDATABASE: bool = False
ClEANDB: bool = False
POW: bool = False
INDEX: str = "1"

USERNPUBS: list = []
Expand Down Expand Up @@ -93,7 +94,7 @@ def admin_make_database_updates(adminconfig: AdminConfig = None, dvmconfig: DVMC
event_id = adminconfig.EVENTID
keys = Keys.parse(
adminconfig.PRIVKEY) # Private key from sender of Event (e.g. the key of an nip89 announcement you want to delete)
fetch_nip89_parameters_for_deletion(keys, event_id, client, dvmconfig)
fetch_nip89_parameters_for_deletion(keys, event_id, client, dvmconfig, adminconfig.POW)

if adminconfig.DELETE_NIP88:
event_id = adminconfig.EVENTID
Expand Down
13 changes: 12 additions & 1 deletion nostr_dvm/utils/nip89_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def nip89_announce_tasks(dvm_config, client):
print("Announced NIP 89 for " + dvm_config.NIP89.NAME)


def fetch_nip89_parameters_for_deletion(keys, eventid, client, dvmconfig):
def fetch_nip89_parameters_for_deletion(keys, eventid, client, dvmconfig, pow=False):
idfilter = Filter().id(EventId.from_hex(eventid)).limit(1)
nip89events = client.get_events_of([idfilter], timedelta(seconds=dvmconfig.RELAY_TIMEOUT))
d_tag = ""
Expand All @@ -52,6 +52,8 @@ def fetch_nip89_parameters_for_deletion(keys, eventid, client, dvmconfig):

if event.author().to_hex() == keys.public_key().to_hex():
nip89_delete_announcement(event.id().to_hex(), keys, d_tag, client, dvmconfig)
if pow:
nip89_delete_announcement_pow(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 @@ -62,6 +64,15 @@ def nip89_delete_announcement(eid: str, keys: Keys, dtag: str, client: Client, c
a_tag = Tag.parse(
["a", str(EventDefinitions.KIND_ANNOUNCEMENT.as_u64()) + ":" + keys.public_key().to_hex() + ":" + dtag])
event = EventBuilder(Kind(5), "", [e_tag, a_tag]).to_event(keys)
print(f"POW event: {event.as_json()}")
send_event(event, client, config)

def nip89_delete_announcement_pow(eid: str, keys: Keys, dtag: str, client: Client, config):
e_tag = Tag.parse(["e", eid])
a_tag = Tag.parse(
["a", str(EventDefinitions.KIND_ANNOUNCEMENT.as_u64()) + ":" + keys.public_key().to_hex() + ":" + dtag])
event = EventBuilder(Kind(5), "", [e_tag, a_tag]).to_pow_event(keys, 28)
print(f"POW event: {event.as_json()}")
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 = '0.4.6'
VERSION = '0.4.7'
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

0 comments on commit a667aef

Please sign in to comment.