Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
believethehype committed Aug 19, 2024
1 parent c22d0e5 commit 0e3979a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 25 deletions.
4 changes: 2 additions & 2 deletions nostr_dvm/dvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class DVM:
job_list: list
jobs_on_hold_list: list

#def __init__(self, dvm_config, admin_config=None):
# asyncio.run(self.run_dvm(dvm_config, admin_config))
def __init__(self, dvm_config, admin_config=None):
asyncio.run(self.run_dvm(dvm_config, admin_config))

async def run_dvm(self, dvm_config, admin_config):

Expand Down
11 changes: 8 additions & 3 deletions nostr_dvm/interfaces/dvmtaskinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from nostr_sdk import Keys, Kind, LogLevel
from nostr_dvm.dvm import DVM
from nostr_dvm.utils.admin_utils import AdminConfig
from nostr_dvm.utils.backend_utils import keep_alive
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
from nostr_dvm.utils.nip88_utils import NIP88Config
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
Expand Down Expand Up @@ -107,9 +108,13 @@ async def run_dvm(self, dvm_config, admin_config):
print("Implement the run dvm function")
pass

def run(self):
dvm = DVM()
asyncio.run(dvm.run_dvm(self.dvm_config, self.admin_config))
def run(self, join=False):
#dvm = DVM(self.dvm_config, self.admin_config)
#asyncio.run(dvm.run_dvm(self.dvm_config, self.admin_config))
nostr_dvm_thread = Thread(target=self.DVM, args=[self.dvm_config, self.admin_config], daemon=False)
nostr_dvm_thread.start()
if join:
nostr_dvm_thread.join()

async def schedule(self, dvm_config):
"""schedule something, e.g. define some time to update or to post, does nothing by default"""
Expand Down
7 changes: 5 additions & 2 deletions nostr_dvm/utils/nut_wallet_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ async def add_proofs_to_wallet(self, nut_wallet, mint_url, new_proofs, marker, s

async def handle_low_balance_on_mint(self, nut_wallet, mint_url, mint, amount, client, keys):
mint_amount = amount - mint.available_balance()
reserved_fees = 3
reserved_fees = 0
await self.mint_cashu(nut_wallet, mint_url, client, keys, mint_amount+reserved_fees)


Expand Down Expand Up @@ -594,10 +594,13 @@ async def send_nut_zap(self, amount, comment, nut_wallet: NutWallet, zapped_even

try:
proofs, fees = await cashu_wallet.select_to_send(mint.proofs, amount)
_, send_proofs = await cashu_wallet.swap_to_send(
print(fees)
keep_proofs, send_proofs = await cashu_wallet.swap_to_send(
proofs, amount, secret_lock=secret_lock, set_reserved=True
)

print(keep_proofs)

for proof in send_proofs:
nut_proof = {
'id': proof.id,
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.8.0'
VERSION = '0.8.1'
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
18 changes: 8 additions & 10 deletions tests/dalle.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import json
import os
from pathlib import Path
Expand All @@ -16,18 +17,15 @@
from nostr_dvm.utils.nostr_utils import check_and_set_private_key
from nostr_dvm.utils.zap_utils import check_and_set_ln_bits_keys, get_price_per_sat

rebroadcast_NIP89 = False # Announce NIP89 on startup Only do this if you know what you're doing.
rebroadcast_NIP89 = False # Announce NIP89 on startup Only do this if you know what you're doing.
rebroadcast_NIP65_Relay_List = False
update_profile = False

#use_logger = True
use_logger = True
log_level = LogLevel.ERROR


#if use_logger:
# init_logger(log_level)


if use_logger:
init_logger(log_level)


def build_dalle(name, identifier):
Expand Down Expand Up @@ -56,15 +54,15 @@ def build_dalle(name, identifier):
nip89info["image"])
nip89config.CONTENT = json.dumps(nip89info)
aconfig = AdminConfig()
aconfig.REBROADCAST_NIP89 = False # We add an optional AdminConfig for this one, and tell the dvm to rebroadcast its NIP89
aconfig.REBROADCAST_NIP89 = False # We add an optional AdminConfig for this one, and tell the dvm to rebroadcast its NIP89
aconfig.LUD16 = dvm_config.LN_ADDRESS
return ImageGenerationDALLE(name=name, dvm_config=dvm_config, nip89config=nip89config, admin_config=aconfig)


def playground():
if os.getenv("OPENAI_API_KEY") is not None and os.getenv("OPENAI_API_KEY") != "":
dalle = build_dalle("Dall-E 3", "dalle3")
dalle.run()

dalle.run(True)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion tests/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

RECONCILE_DB_RELAY_LIST = [ "wss://relay.nostr.net", "wss://relay.nostr.bg", "wss://relay.damus.io", "wss://nostr.oxtr.dev"]
RELAY_LIST = ["wss://relay.primal.net",
"wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.bg",
"wss://nostr.mom", "wss://nostr.oxtr.dev",
"wss://relay.nostr.net"
]

Expand Down
29 changes: 23 additions & 6 deletions tests/test_dvm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
from threading import Thread

from nostr_dvm.utils.nip65_utils import nip65_announce_relays
from nostr_dvm.utils.nut_wallet_utils import NutZapWallet
from nostr_dvm.utils.print import bcolors

Expand Down Expand Up @@ -74,21 +75,21 @@ async def nostr_client_test_image(prompt):
iTag = Tag.parse(["i", prompt, "text"])
outTag = Tag.parse(["output", "image/png;format=url"])
paramTag1 = Tag.parse(["param", "size", "1024x1024"])
tTag = Tag.parse(["t", "bitcoin"])

bidTag = Tag.parse(['bid', str(1000 * 1000), str(1000 * 1000)])
relaysTag = Tag.parse(['relays', "wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org",
"wss://nostr-pub.wellorder.net"])
relaysTag = Tag.parse(['relays', "wss://relay.primal.net", "wss://nostr.oxtr.dev"])
alttag = Tag.parse(["alt", "This is a NIP90 DVM AI task to generate an Image from a given Input"])
event = EventBuilder(EventDefinitions.KIND_NIP90_GENERATE_IMAGE, str("Generate an Image."),
[iTag, outTag, tTag, paramTag1, bidTag, relaysTag, alttag]).to_event(keys)
[iTag, outTag, paramTag1, bidTag, relaysTag, alttag]).to_event(keys)

signer = NostrSigner.keys(keys)
client = Client(signer)
for relay in DVMConfig().RELAY_LIST:
await client.add_relay(relay)
await client.connect()
config = DVMConfig
#config.NIP89.PK = keys.secret_key().to_hex()
#await nip65_announce_relays(config, client=client)
await send_event(event, client=client, dvm_config=config)
return event.as_json()

Expand Down Expand Up @@ -340,6 +341,17 @@ async def nostr_client():

nutzap_wallet = NutZapWallet()
nut_wallet = await nutzap_wallet.get_nut_wallet(client, keys)
#dangerous, dont use this, except your wallet is messed up.
delete = False
if delete:
for mint in nut_wallet.nutmints:
await nutzap_wallet.update_spend_mint_proof_event(nut_wallet, mint.proofs, mint.mint_url, "", None,
None, client, keys)

nut_wallet.balance = 0
await nutzap_wallet.update_nut_wallet(nut_wallet, [], client, keys)
nut_wallet = await nutzap_wallet.get_nut_wallet(client, keys)


class NotificationHandler(HandleNotification):
async def handle(self, relay_url, subscription_id, event: Event):
Expand All @@ -348,11 +360,15 @@ async def handle(self, relay_url, subscription_id, event: Event):
if event.kind().as_u64() == 7000:
print("[Nostr Client]: " + event.as_json())
amount_sats = 0
status = ""
for tag in event.tags():
if tag.as_vec()[0] == "amount":
amount_sats = int(int(tag.as_vec()[1]) / 1000) # millisats
# THIS IS FO TESTING
if event.author().to_hex() == "89669b03bb25232f33192fdda77b8e36e3d3886e9b55b3c74b95091e916c8f98":
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":

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")
Expand All @@ -366,6 +382,7 @@ async def handle(self, relay_url, subscription_id, event: Event):
event.author().to_hex(), client,
keys)


elif 6000 < event.kind().as_u64() < 6999:
print("[Nostr Client]: " + event.as_json())
print("[Nostr Client]: " + event.content())
Expand Down

0 comments on commit 0e3979a

Please sign in to comment.