update default nz relays

This commit is contained in:
Believethehype
2024-11-06 10:54:09 +01:00
parent a142fb3e86
commit 3cdcf791ee
4 changed files with 44 additions and 39 deletions

View File

@@ -68,8 +68,8 @@ class DVMConfig:
# More info see here: https://github.com/cashubtc/nutshell
ENABLE_NUTZAP = False
NUTZAP_RELAYS = ["wss://relay.primal.net"]
NUZAP_MINTS = ["https://mint.minibits.cash/Bitcoin", "https://mint.gwoq.com"]
NUTZAP_RELAYS = ["wss://relay.nostr.net"]
NUZAP_MINTS = ["https://mint.gwoq.com"]
ENABLE_AUTO_MELT = False
AUTO_MELT_AMOUNT = 1000
REANNOUNCE_MINTS = True

View File

@@ -6,7 +6,7 @@ from datetime import timedelta
import requests
from nostr_sdk import Tag, Keys, nip44_encrypt, nip44_decrypt, Nip44Version, EventBuilder, Client, Filter, Kind, \
EventId, nip04_decrypt, nip04_encrypt, Options, NostrSigner, PublicKey, Metadata
EventId, nip04_decrypt, nip04_encrypt, PublicKey, Metadata
from nostr_dvm.utils.database_utils import fetch_user_metadata
from nostr_dvm.utils.definitions import EventDefinitions, relay_timeout, relay_timeout_long
@@ -50,13 +50,13 @@ class NutMint(object):
class NutZapWallet:
async def client_connect(self, relay_list):
keys = Keys.parse(check_and_set_private_key("TEST_ACCOUNT_PK"))
async def client_connect(self, relay_list, keys):
client = Client(keys)
for relay in relay_list:
await client.add_relay(relay)
await client.connect()
return client, keys
return client
async def create_new_nut_wallet(self, mint_urls, relays, client, keys, name, description):
new_nut_wallet = NutWallet()
@@ -115,16 +115,16 @@ class NutZapWallet:
nut_wallet = None
wallet_filter = Filter().kind(EventDefinitions.KIND_NUT_WALLET).author(keys.public_key())
wallets_struct = await client.fetch_events([wallet_filter], relay_timeout_long)
wallets = wallets_struct.to_vec()
# relay_timeout = EventSource.relays(timedelta(seconds=10))
wallets = await client.fetch_events([wallet_filter], timedelta(seconds=10))
if len(wallets) > 0:
if len(wallets.to_vec()) > 0:
nut_wallet = NutWallet()
latest = 0
best_wallet = None
for wallet_event in wallets:
for wallet_event in wallets.to_vec():
isdeleted = False
for tag in wallet_event.tags().to_vec():
@@ -190,18 +190,16 @@ class NutZapWallet:
# Now all proof events
proof_filter = Filter().kind(Kind(7375)).author(keys.public_key())
# relay_timeout = EventSource.relays(timedelta(seconds=5))
proof_events_struct = await client.fetch_events([proof_filter], relay_timeout)
proof_events = proof_events_struct.to_vec()
proof_events = await client.fetch_events([proof_filter], timedelta(seconds=5))
latest_proof_sec = 0
latest_proof_event_id = EventId
for proof_event in proof_events:
for proof_event in proof_events.to_vec():
if proof_event.created_at().as_secs() > latest_proof_sec:
latest_proof_sec = proof_event.created_at().as_secs()
latest_proof_event_id = proof_event.id()
for proof_event in proof_events:
for proof_event in proof_events.to_vec():
try:
content = nip44_decrypt(keys.secret_key(), keys.public_key(), proof_event.content())
except:
@@ -445,15 +443,13 @@ class NutZapWallet:
async def fetch_mint_info_event(self, pubkey, client):
mint_info_filter = Filter().kind(Kind(10019)).author(PublicKey.parse(pubkey))
# relay_timeout = EventSource.relays(timedelta(seconds=5))
events_struct = await client.fetch_events([mint_info_filter], relay_timeout)
preferences = events_struct.to_vec()
preferences = await client.fetch_events([mint_info_filter], timedelta(seconds=5))
mints = []
relays = []
pubkey = ""
if len(preferences) > 0:
preference = preferences[0]
if len(preferences.to_vec()) > 0:
preference = preferences.to_vec()[0]
for tag in preference.tags().to_vec():
if tag.as_vec()[0] == "pubkey":

View File

@@ -2,7 +2,7 @@ from datetime import timedelta
from pathlib import Path
import dotenv
from nostr_sdk import PublicKey
from nostr_sdk import PublicKey, Keys
import asyncio
@@ -10,6 +10,7 @@ import argparse
from nostr_dvm.utils.dvmconfig import DVMConfig
from nostr_dvm.utils.nostr_utils import check_and_set_private_key
from nostr_dvm.utils.nut_wallet_utils import NutZapWallet
@@ -25,7 +26,8 @@ async def test(relays, mints):
nutzap_wallet = NutZapWallet()
update_wallet_info = False # leave this on false except when you manually changed relays/mints/keys
client, keys = await nutzap_wallet.client_connect(relays)
keys = Keys.parse(check_and_set_private_key("TEST_ACCOUNT_PK_TEST"))
client = await nutzap_wallet.client_connect(relays, keys)
set_profile = False # Attention, this overwrites your current profile if on True, do not set if you use an non-test account
if set_profile:
@@ -41,7 +43,7 @@ async def test(relays, mints):
send_test = args.zap # Send a Nutzap
send_zap_amount = 3
send_zap_message = "From my nutsack"
send_reveiver = "npub139nfkqamy53j7vce9lw6w7uwxm3a8zrwnd2m836tj5y3aytv37vqygz42j" # keys.public_key().to_bech32() # This is ourself, for testing purposes, some other people to nutzap: #npub1nxa4tywfz9nqp7z9zp7nr7d4nchhclsf58lcqt5y782rmf2hefjquaa6q8 # dbth #npub1l2vyh47mk2p0qlsku7hg0vn29faehy9hy34ygaclpn66ukqp3afqutajft # pablof7z
send_reveiver = "npub1dvwp6k3l4362ray6z3rk5u2va3ffstlsydqphj7ht6ca7s7kuy4syhug83" # keys.public_key().to_bech32() # This is ourself, for testing purposes, some other people to nutzap: #npub1nxa4tywfz9nqp7z9zp7nr7d4nchhclsf58lcqt5y782rmf2hefjquaa6q8 # dbth #npub1l2vyh47mk2p0qlsku7hg0vn29faehy9hy34ygaclpn66ukqp3afqutajft # pablof7z
send_zapped_event = None # None, or zap an event like this: Nip19Event.from_nostr_uri("nostr:nevent1qqsxq59mhz8s6aj9jzltcmqmmv3eutsfcpkeny2x755vdu5dtq44ldqpz3mhxw309ucnydewxqhrqt338g6rsd3e9upzp75cf0tahv5z7plpdeaws7ex52nmnwgtwfr2g3m37r844evqrr6jqvzqqqqqqyqtxyr6").event_id().to_hex()
# Test 3 Config: Melt to ln address

View File

@@ -394,7 +394,7 @@ async def nostr_client_test_image_private(prompt, cashutoken):
async def nostr_client():
keys = Keys.parse(check_and_set_private_key("test_client"))
keys = Keys.parse(check_and_set_private_key("test_client5"))
sk = keys.secret_key()
pk = keys.public_key()
print(f"Nostr Client public key: {pk.to_bech32()}, Hex: {pk.to_hex()} ")
@@ -406,7 +406,7 @@ async def nostr_client():
await client.connect()
dm_zap_filter = Filter().pubkey(pk).kinds([EventDefinitions.KIND_DM,
EventDefinitions.KIND_ZAP]).since(
EventDefinitions.KIND_ZAP, EventDefinitions.KIND_NIP61_NUT_ZAP]).since(
Timestamp.now()) # events to us specific
kinds = [EventDefinitions.KIND_NIP90_GENERIC]
#SUPPORTED_KINDS = [Kind(6100), Kind(7000)]
@@ -457,6 +457,16 @@ async def nostr_client():
nut_wallet.balance = 0
await nutzap_wallet.update_nut_wallet(nut_wallet, [], client, keys)
nut_wallet = await nutzap_wallet.get_nut_wallet(client, keys)
else:
nut_wallet = await nutzap_wallet.get_nut_wallet(client, keys)
if nut_wallet is None:
await nutzap_wallet.create_new_nut_wallet(dvmconfig.NUZAP_MINTS, dvmconfig.NUTZAP_RELAYS, client, keys,
"Test", "My Nutsack")
nut_wallet = await nutzap_wallet.get_nut_wallet(client, keys)
if nut_wallet is not None:
await nutzap_wallet.announce_nutzap_info_event(nut_wallet, client, keys)
else:
print("Couldn't fetch wallet, please restart and see if it is there")
@@ -476,20 +486,6 @@ async def nostr_client():
if tag.as_vec()[0] == "status":
status = tag.as_vec()[1]
# THIS IS FOR TESTING
if event.author().to_hex() == "89669b03bb25232f33192fdda77b8e36e3d3886e9b55b3c74b95091e916c8f98" and status == "payment-required" and event.created_at().as_secs() > self.last_event_time:
self.last_event_time = event.created_at().as_secs()
nut_wallet = await nutzap_wallet.get_nut_wallet(client, keys)
if nut_wallet is None:
await nutzap_wallet.create_new_nut_wallet(dvmconfig.NUZAP_MINTS, dvmconfig.NUTZAP_RELAYS, client, keys, "Test", "My Nutsack")
nut_wallet = await nutzap_wallet.get_nut_wallet(client, keys)
if nut_wallet is not None:
await nutzap_wallet.announce_nutzap_info_event(nut_wallet, client, keys)
else:
print("Couldn't fetch wallet, please restart and see if it is there")
await nutzap_wallet.send_nut_zap(amount_sats, "From my nutsack lol", nut_wallet, event.id().to_hex(),
event.author().to_hex(), client,
keys)
elif 6000 < event.kind().as_u16() < 6999:
@@ -503,6 +499,17 @@ async def nostr_client():
elif event.kind().as_u16() == 9735:
print("[Nostr Client]: " + f"Received new zap:")
print(event.as_json())
if event.kind().as_u16() == 9321:
print(bcolors.YELLOW + "[Client] NutZap 🥜️⚡ received" + event.as_json() + bcolors.ENDC)
# if event.author().to_hex() == keys.public_key().to_hex():
# #sleep to avoid event not being updated on self zap
# await asyncio.sleep(5)
nut_wallet = await nutzap_wallet.get_nut_wallet(client, keys)
if nut_wallet is not None:
await nutzap_wallet.reedeem_nutzap(event, nut_wallet, client, keys)
# await get_nut_wallet(client, keys)
async def handle_msg(self, relay_url, msg):
return