mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-06-07 09:09:15 +02:00
some more code cleanup
This commit is contained in:
parent
76e8ab80a5
commit
17606e756b
@ -1,18 +1,14 @@
|
|||||||
# DATABASE LOGIC
|
# DATABASE LOGIC
|
||||||
import json
|
import json
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
from sqlite3 import Error
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import timedelta
|
|
||||||
from logging import Filter
|
from logging import Filter
|
||||||
|
from sqlite3 import Error
|
||||||
|
|
||||||
|
from nostr_sdk import Timestamp, Keys, PublicKey, Filter, Kind
|
||||||
from nostr_sdk import Timestamp, Keys, PublicKey, EventBuilder, Filter, Kind
|
|
||||||
|
|
||||||
from nostr_dvm.utils.definitions import relay_timeout
|
from nostr_dvm.utils.definitions import relay_timeout
|
||||||
|
from nostr_dvm.utils.nostr_utils import send_nip04_dm
|
||||||
from nostr_dvm.utils.nostr_utils import send_event, send_nip04_dm
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -190,17 +186,15 @@ async def update_user_balance(db, npub, additional_sats, client, config, giftwra
|
|||||||
|
|
||||||
if config is not None:
|
if config is not None:
|
||||||
keys = Keys.parse(config.PRIVATE_KEY)
|
keys = Keys.parse(config.PRIVATE_KEY)
|
||||||
# time.sleep(1.0)
|
|
||||||
|
|
||||||
message = ("Added " + str(additional_sats) + " Sats to balance. New balance is " + str(
|
message = ("Added " + str(additional_sats) + " Sats to balance. New balance is " + str(
|
||||||
new_balance) + " Sats.")
|
new_balance) + " Sats.")
|
||||||
|
|
||||||
if giftwrap:
|
# always send giftwrapped. sorry not sorry.
|
||||||
|
#if giftwrap:
|
||||||
await client.send_private_msg(PublicKey.parse(npub), message, None)
|
await client.send_private_msg(PublicKey.parse(npub), message, None)
|
||||||
else:
|
#else:
|
||||||
#await client.send_direct_msg(PublicKey.parse(npub), message, None)
|
# await send_nip04_dm(client, message, PublicKey.parse(npub), config)
|
||||||
#await client.send_private_msg(PublicKey.parse(npub), message, None)
|
|
||||||
await send_nip04_dm(client, message, PublicKey.parse(npub), config)
|
|
||||||
|
|
||||||
|
|
||||||
def update_user_subscription(npub, subscribed_until, client, dvm_config):
|
def update_user_subscription(npub, subscribed_until, client, dvm_config):
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import os
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
@ -63,7 +62,6 @@ class EventDefinitions:
|
|||||||
KIND_NIP88_TIER_EVENT = Kind(37001)
|
KIND_NIP88_TIER_EVENT = Kind(37001)
|
||||||
KIND_NUT_WALLET = Kind(37375)
|
KIND_NUT_WALLET = Kind(37375)
|
||||||
|
|
||||||
|
|
||||||
ANY_RESULT = [KIND_NIP90_RESULT_EXTRACT_TEXT,
|
ANY_RESULT = [KIND_NIP90_RESULT_EXTRACT_TEXT,
|
||||||
KIND_NIP90_RESULT_SUMMARIZE_TEXT,
|
KIND_NIP90_RESULT_SUMMARIZE_TEXT,
|
||||||
KIND_NIP90_RESULT_TRANSLATE_TEXT,
|
KIND_NIP90_RESULT_TRANSLATE_TEXT,
|
||||||
@ -97,6 +95,7 @@ class RequiredJobToWatch:
|
|||||||
event: Event
|
event: Event
|
||||||
timestamp: int
|
timestamp: int
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class InvoiceToWatch:
|
class InvoiceToWatch:
|
||||||
sender: str
|
sender: str
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from nostr_sdk import Keys, LogLevel, PublicKey
|
from nostr_sdk import Keys, LogLevel
|
||||||
|
|
||||||
from nostr_dvm.utils.nip88_utils import NIP88Config
|
from nostr_dvm.utils.nip88_utils import NIP88Config
|
||||||
from nostr_dvm.utils.nip89_utils import NIP89Config
|
from nostr_dvm.utils.nip89_utils import NIP89Config
|
||||||
@ -8,6 +8,7 @@ from nostr_dvm.utils.nostr_utils import check_and_set_private_key
|
|||||||
from nostr_dvm.utils.outbox_utils import AVOID_OUTBOX_RELAY_LIST
|
from nostr_dvm.utils.outbox_utils import AVOID_OUTBOX_RELAY_LIST
|
||||||
from nostr_dvm.utils.zap_utils import check_and_set_ln_bits_keys
|
from nostr_dvm.utils.zap_utils import check_and_set_ln_bits_keys
|
||||||
|
|
||||||
|
|
||||||
class DVMConfig:
|
class DVMConfig:
|
||||||
SUPPORTED_DVMS = []
|
SUPPORTED_DVMS = []
|
||||||
PRIVATE_KEY: str = ""
|
PRIVATE_KEY: str = ""
|
||||||
@ -21,7 +22,7 @@ class DVMConfig:
|
|||||||
]
|
]
|
||||||
|
|
||||||
RECONCILE_DB_RELAY_LIST = ["wss://relay.damus.io", "wss://nostr.oxtr.dev",
|
RECONCILE_DB_RELAY_LIST = ["wss://relay.damus.io", "wss://nostr.oxtr.dev",
|
||||||
"wss://relay.nostr.net" , "wss://relay.primal.net"]
|
"wss://relay.nostr.net", "wss://relay.primal.net"]
|
||||||
|
|
||||||
# Straight Censorship (reply guy spam)
|
# Straight Censorship (reply guy spam)
|
||||||
WOT_FILTERING = False
|
WOT_FILTERING = False
|
||||||
@ -31,10 +32,8 @@ class DVMConfig:
|
|||||||
]
|
]
|
||||||
WOT_DEPTH = 2
|
WOT_DEPTH = 2
|
||||||
|
|
||||||
|
|
||||||
AVOID_PAID_OUTBOX_RELAY_LIST = AVOID_OUTBOX_RELAY_LIST
|
AVOID_PAID_OUTBOX_RELAY_LIST = AVOID_OUTBOX_RELAY_LIST
|
||||||
#If a DVM has a paid subscription, overwrite list without the paid one.
|
# If a DVM has a paid subscription, overwrite list without the paid one.
|
||||||
|
|
||||||
|
|
||||||
RELAY_TIMEOUT = 5
|
RELAY_TIMEOUT = 5
|
||||||
RELAY_LONG_TIMEOUT = 30
|
RELAY_LONG_TIMEOUT = 30
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
from nostr_sdk import Tag, Keys, EventBuilder, Kind
|
from nostr_sdk import Keys, EventBuilder, Kind
|
||||||
|
|
||||||
from nostr_dvm.utils.nostr_utils import send_event
|
from nostr_dvm.utils.nostr_utils import send_event
|
||||||
from nostr_dvm.utils.print_utils import bcolors
|
from nostr_dvm.utils.print_utils import bcolors
|
||||||
|
|
||||||
|
|
||||||
async def gallery_announce_list(tags, dvm_config, client):
|
async def gallery_announce_list(tags, dvm_config, client):
|
||||||
|
|
||||||
|
|
||||||
keys = Keys.parse(dvm_config.NIP89.PK)
|
keys = Keys.parse(dvm_config.NIP89.PK)
|
||||||
content = ""
|
content = ""
|
||||||
event = EventBuilder(Kind(10011), content, tags).to_event(keys)
|
event = EventBuilder(Kind(10011), content, tags).to_event(keys)
|
||||||
eventid = await send_event(event, client=client, dvm_config=dvm_config, blastr=True)
|
eventid = await send_event(event, client=client, dvm_config=dvm_config, blastr=True)
|
||||||
|
|
||||||
print(bcolors.BLUE + "[" + dvm_config.NIP89.NAME + "] Announced Gallery for " + dvm_config.NIP89.NAME +" (EventID: " + str(eventid.to_hex()) +")" + bcolors.ENDC)
|
print(
|
||||||
|
bcolors.BLUE + "[" + dvm_config.NIP89.NAME + "] Announced Gallery for " + dvm_config.NIP89.NAME + " (EventID: " + str(
|
||||||
|
eventid.to_hex()) + ")" + bcolors.ENDC)
|
||||||
|
@ -2,9 +2,10 @@ import os
|
|||||||
import urllib
|
import urllib
|
||||||
from datetime import time
|
from datetime import time
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
import ffmpegio
|
|
||||||
|
|
||||||
|
import ffmpegio
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from nostr_dvm.utils.nostr_utils import get_event_by_id
|
from nostr_dvm.utils.nostr_utils import get_event_by_id
|
||||||
from nostr_dvm.utils.scrapper.media_scrapper import YTDownload, get_media_duration
|
from nostr_dvm.utils.scrapper.media_scrapper import YTDownload, get_media_duration
|
||||||
|
|
||||||
|
@ -5,14 +5,15 @@ from collections import namedtuple
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
import requests
|
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
|
||||||
|
|
||||||
from nostr_dvm.utils.database_utils import fetch_user_metadata
|
from nostr_dvm.utils.database_utils import fetch_user_metadata
|
||||||
from nostr_dvm.utils.definitions import EventDefinitions, relay_timeout, relay_timeout_long
|
from nostr_dvm.utils.definitions import EventDefinitions, relay_timeout, relay_timeout_long
|
||||||
from nostr_dvm.utils.dvmconfig import DVMConfig
|
from nostr_dvm.utils.dvmconfig import DVMConfig
|
||||||
from nostr_dvm.utils.nostr_utils import check_and_set_private_key
|
from nostr_dvm.utils.nostr_utils import check_and_set_private_key
|
||||||
from nostr_dvm.utils.zap_utils import pay_bolt11_ln_bits, zaprequest
|
|
||||||
from nostr_sdk import Tag, Keys, nip44_encrypt, nip44_decrypt, Nip44Version, EventBuilder, Client, Filter, Kind, \
|
|
||||||
EventId, nip04_decrypt, nip04_encrypt, Options, NostrSigner, PublicKey, init_logger, LogLevel, Metadata
|
|
||||||
from nostr_dvm.utils.print_utils import bcolors
|
from nostr_dvm.utils.print_utils import bcolors
|
||||||
|
from nostr_dvm.utils.zap_utils import pay_bolt11_ln_bits, zaprequest
|
||||||
|
|
||||||
|
|
||||||
class NutWallet(object):
|
class NutWallet(object):
|
||||||
@ -29,7 +30,7 @@ class NutWallet(object):
|
|||||||
self.a: str = ""
|
self.a: str = ""
|
||||||
self.legacy_encryption: bool = False # Use Nip04 instead of Nip44, for reasons, turn to False ASAP.
|
self.legacy_encryption: bool = False # Use Nip04 instead of Nip44, for reasons, turn to False ASAP.
|
||||||
self.trust_unknown_mints: bool = False
|
self.trust_unknown_mints: bool = False
|
||||||
self.missing_balance_strategy: str = "mint" #none to do nothing until manually minted, mint to mint from lightning or swap to use existing tokens from other mints (fees!) (not working yet!)
|
self.missing_balance_strategy: str = "mint" # none to do nothing until manually minted, mint to mint from lightning or swap to use existing tokens from other mints (fees!) (not working yet!)
|
||||||
|
|
||||||
|
|
||||||
class NutMint(object):
|
class NutMint(object):
|
||||||
@ -120,7 +121,7 @@ class NutZapWallet:
|
|||||||
nut_wallet = None
|
nut_wallet = None
|
||||||
|
|
||||||
wallet_filter = Filter().kind(EventDefinitions.KIND_NUT_WALLET).author(keys.public_key())
|
wallet_filter = Filter().kind(EventDefinitions.KIND_NUT_WALLET).author(keys.public_key())
|
||||||
#relay_timeout = EventSource.relays(timedelta(seconds=10))
|
# relay_timeout = EventSource.relays(timedelta(seconds=10))
|
||||||
wallets = await client.get_events_of([wallet_filter], relay_timeout_long)
|
wallets = await client.get_events_of([wallet_filter], relay_timeout_long)
|
||||||
|
|
||||||
if len(wallets) > 0:
|
if len(wallets) > 0:
|
||||||
@ -195,7 +196,7 @@ class NutZapWallet:
|
|||||||
|
|
||||||
# Now all proof events
|
# Now all proof events
|
||||||
proof_filter = Filter().kind(Kind(7375)).author(keys.public_key())
|
proof_filter = Filter().kind(Kind(7375)).author(keys.public_key())
|
||||||
#relay_timeout = EventSource.relays(timedelta(seconds=5))
|
# relay_timeout = EventSource.relays(timedelta(seconds=5))
|
||||||
proof_events = await client.get_events_of([proof_filter], relay_timeout)
|
proof_events = await client.get_events_of([proof_filter], relay_timeout)
|
||||||
|
|
||||||
latest_proof_sec = 0
|
latest_proof_sec = 0
|
||||||
@ -449,7 +450,7 @@ class NutZapWallet:
|
|||||||
|
|
||||||
async def fetch_mint_info_event(self, pubkey, client):
|
async def fetch_mint_info_event(self, pubkey, client):
|
||||||
mint_info_filter = Filter().kind(Kind(10019)).author(PublicKey.parse(pubkey))
|
mint_info_filter = Filter().kind(Kind(10019)).author(PublicKey.parse(pubkey))
|
||||||
#relay_timeout = EventSource.relays(timedelta(seconds=5))
|
# relay_timeout = EventSource.relays(timedelta(seconds=5))
|
||||||
preferences = await client.get_events_of([mint_info_filter], relay_timeout)
|
preferences = await client.get_events_of([mint_info_filter], relay_timeout)
|
||||||
mints = []
|
mints = []
|
||||||
relays = []
|
relays = []
|
||||||
@ -778,12 +779,11 @@ class NutZapWallet:
|
|||||||
+ bcolors.ENDC)
|
+ bcolors.ENDC)
|
||||||
|
|
||||||
async def swap(self, amountinsats, incoming_mint_url, outgoing_mint_url, nut_wallet):
|
async def swap(self, amountinsats, incoming_mint_url, outgoing_mint_url, nut_wallet):
|
||||||
#TODO this doesn't seem to work yet.
|
# TODO this doesn't seem to work yet.
|
||||||
from cashu.wallet.cli.cli_helpers import print_mint_balances
|
from cashu.wallet.cli.cli_helpers import print_mint_balances
|
||||||
from cashu.wallet.wallet import Wallet
|
from cashu.wallet.wallet import Wallet
|
||||||
from cashu.core.crypto.keys import PrivateKey
|
from cashu.core.crypto.keys import PrivateKey
|
||||||
|
|
||||||
|
|
||||||
outgoing_mint = self.get_mint(nut_wallet, outgoing_mint_url)
|
outgoing_mint = self.get_mint(nut_wallet, outgoing_mint_url)
|
||||||
|
|
||||||
outgoing_wallet = await Wallet.with_db(
|
outgoing_wallet = await Wallet.with_db(
|
||||||
@ -797,7 +797,6 @@ class NutZapWallet:
|
|||||||
|
|
||||||
print(outgoing_wallet.available_balance)
|
print(outgoing_wallet.available_balance)
|
||||||
|
|
||||||
|
|
||||||
incoming_mint = self.get_mint(nut_wallet, incoming_mint_url)
|
incoming_mint = self.get_mint(nut_wallet, incoming_mint_url)
|
||||||
incoming_wallet = await Wallet.with_db(
|
incoming_wallet = await Wallet.with_db(
|
||||||
url=incoming_mint_url,
|
url=incoming_mint_url,
|
||||||
@ -808,8 +807,6 @@ class NutZapWallet:
|
|||||||
await incoming_wallet.load_mint()
|
await incoming_wallet.load_mint()
|
||||||
incoming_wallet.proofs = incoming_mint.proofs
|
incoming_wallet.proofs = incoming_mint.proofs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if incoming_wallet.url == outgoing_wallet.url:
|
if incoming_wallet.url == outgoing_wallet.url:
|
||||||
raise Exception("mints for swap have to be different")
|
raise Exception("mints for swap have to be different")
|
||||||
|
|
||||||
|
@ -19,8 +19,6 @@ async def create_reaction(keys, title, dtag):
|
|||||||
emoji_tag1 = Tag.parse(["emoji", name, url])
|
emoji_tag1 = Tag.parse(["emoji", name, url])
|
||||||
emoji_tags.append(emoji_tag1)
|
emoji_tags.append(emoji_tag1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
keys = Keys.parse(keys)
|
keys = Keys.parse(keys)
|
||||||
content = ""
|
content = ""
|
||||||
event = EventBuilder(Kind(30030), content, [d_tag, title_tag] + emoji_tags).to_event(keys)
|
event = EventBuilder(Kind(30030), content, [d_tag, title_tag] + emoji_tags).to_event(keys)
|
||||||
@ -65,4 +63,4 @@ keys = check_and_set_private_key("test_client")
|
|||||||
eventid = "da05cefc512ad43363f84131343f5d2a80303ea3b9368b9ad7f010e07db37d90"
|
eventid = "da05cefc512ad43363f84131343f5d2a80303ea3b9368b9ad7f010e07db37d90"
|
||||||
|
|
||||||
asyncio.run(create_reaction(keys=keys, title="ThugAmy", dtag="ThugAmy"))
|
asyncio.run(create_reaction(keys=keys, title="ThugAmy", dtag="ThugAmy"))
|
||||||
#asyncio.run(delete_reaction(keys=keys, eid=eventid, dtag="ThugAmy"))
|
# asyncio.run(delete_reaction(keys=keys, eid=eventid, dtag="ThugAmy"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user