mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-03-29 11:01:41 +01:00
fixes
This commit is contained in:
parent
c22d0e5c79
commit
0e3979aa9d
@ -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):
|
||||
|
||||
|
@ -11,6 +11,7 @@ from venv import create
|
||||
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
|
||||
@ -107,9 +108,13 @@ class DVMTaskInterface:
|
||||
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"""
|
||||
|
@ -518,7 +518,7 @@ class NutZapWallet:
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@ -594,10 +594,13 @@ class NutZapWallet:
|
||||
|
||||
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,
|
||||
|
2
setup.py
2
setup.py
@ -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')
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
@ -16,18 +17,15 @@ from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
||||
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):
|
||||
@ -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__':
|
||||
|
@ -42,7 +42,7 @@ log_level = LogLevel.INFO
|
||||
|
||||
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"
|
||||
]
|
||||
|
||||
|
@ -4,6 +4,7 @@ import time
|
||||
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
|
||||
|
||||
@ -74,14 +75,12 @@ 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)
|
||||
@ -89,6 +88,8 @@ async def nostr_client_test_image(prompt):
|
||||
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()
|
||||
|
||||
@ -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):
|
||||
@ -348,11 +360,15 @@ async def nostr_client():
|
||||
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")
|
||||
@ -366,6 +382,7 @@ async def nostr_client():
|
||||
event.author().to_hex(), client,
|
||||
keys)
|
||||
|
||||
|
||||
elif 6000 < event.kind().as_u64() < 6999:
|
||||
print("[Nostr Client]: " + event.as_json())
|
||||
print("[Nostr Client]: " + event.content())
|
||||
|
Loading…
x
Reference in New Issue
Block a user