some more code cleanup

This commit is contained in:
Believethehype 2024-10-18 16:07:44 +02:00
parent 76e8ab80a5
commit 17606e756b
9 changed files with 73 additions and 85 deletions

View File

@ -1,18 +1,14 @@
# DATABASE LOGIC
import json
import sqlite3
from sqlite3 import Error
from dataclasses import dataclass
from datetime import timedelta
from logging import Filter
from sqlite3 import Error
from nostr_sdk import Timestamp, Keys, PublicKey, EventBuilder, Filter, Kind
from nostr_sdk import Timestamp, Keys, PublicKey, Filter, Kind
from nostr_dvm.utils.definitions import relay_timeout
from nostr_dvm.utils.nostr_utils import send_event, send_nip04_dm
from nostr_dvm.utils.nostr_utils import send_nip04_dm
@dataclass
@ -190,17 +186,15 @@ async def update_user_balance(db, npub, additional_sats, client, config, giftwra
if config is not None:
keys = Keys.parse(config.PRIVATE_KEY)
# time.sleep(1.0)
message = ("Added " + str(additional_sats) + " Sats to balance. New balance is " + str(
new_balance) + " Sats.")
if giftwrap:
await client.send_private_msg(PublicKey.parse(npub), message, None)
else:
#await client.send_direct_msg(PublicKey.parse(npub), message, None)
#await client.send_private_msg(PublicKey.parse(npub), message, None)
await send_nip04_dm(client, message, PublicKey.parse(npub), config)
# always send giftwrapped. sorry not sorry.
#if giftwrap:
await client.send_private_msg(PublicKey.parse(npub), message, None)
#else:
# await send_nip04_dm(client, message, PublicKey.parse(npub), config)
def update_user_subscription(npub, subscribed_until, client, dvm_config):

View File

@ -1,4 +1,3 @@
import os
from dataclasses import dataclass
from datetime import timedelta
@ -63,7 +62,6 @@ class EventDefinitions:
KIND_NIP88_TIER_EVENT = Kind(37001)
KIND_NUT_WALLET = Kind(37375)
ANY_RESULT = [KIND_NIP90_RESULT_EXTRACT_TEXT,
KIND_NIP90_RESULT_SUMMARIZE_TEXT,
KIND_NIP90_RESULT_TRANSLATE_TEXT,
@ -97,6 +95,7 @@ class RequiredJobToWatch:
event: Event
timestamp: int
@dataclass
class InvoiceToWatch:
sender: str
@ -108,4 +107,4 @@ class InvoiceToWatch:
relay_timeout = EventSource.relays(timedelta(seconds=5))
relay_timeout_long = EventSource.relays(timedelta(seconds=10))
relay_timeout_long = EventSource.relays(timedelta(seconds=10))

View File

@ -1,6 +1,6 @@
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.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.zap_utils import check_and_set_ln_bits_keys
class DVMConfig:
SUPPORTED_DVMS = []
PRIVATE_KEY: str = ""
@ -21,24 +22,22 @@ class DVMConfig:
]
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)
WOT_FILTERING = False
WOT_BASED_ON_NPUBS = ["99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64",
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
"3f770d65d3a764a9c5cb503ae123e62ec7598ad035d836e2a810f3877a745b24"
]
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
"3f770d65d3a764a9c5cb503ae123e62ec7598ad035d836e2a810f3877a745b24"
]
WOT_DEPTH = 2
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_LONG_TIMEOUT = 30
EXTERNAL_POST_PROCESS_TYPE = 0 # Leave this on None, except the DVM is external
EXTERNAL_POST_PROCESS_TYPE = 0 # Leave this on None, except the DVM is external
LNBITS_INVOICE_KEY = '' # Will all automatically generated by default, or read from .env
LNBITS_ADMIN_KEY = '' # In order to pay invoices, e.g. from the bot to DVMs, or reimburse users.
LNBITS_URL = 'https://lnbits.com'

View File

@ -24,7 +24,7 @@ async def build_client(config):
def build_external_dvm(pubkey, task, kind, fix_cost, per_unit_cost, config,
external_post_process=PostProcessFunctionType.NONE):
external_post_process=PostProcessFunctionType.NONE):
dvm_config = DVMConfig()
dvm_config.PUBLIC_KEY = PublicKey.from_hex(pubkey).to_hex()
dvm_config.FIX_COST = fix_cost

View File

@ -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.print_utils import bcolors
async def gallery_announce_list(tags, dvm_config, client):
keys = Keys.parse(dvm_config.NIP89.PK)
content = ""
event = EventBuilder(Kind(10011), content, tags).to_event(keys)
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)

View File

@ -2,9 +2,10 @@ import os
import urllib
from datetime import time
from urllib.parse import urlparse
import ffmpegio
import ffmpegio
import requests
from nostr_dvm.utils.nostr_utils import get_event_by_id
from nostr_dvm.utils.scrapper.media_scrapper import YTDownload, get_media_duration

View File

@ -5,14 +5,15 @@ from collections import namedtuple
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
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.dvmconfig import DVMConfig
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.zap_utils import pay_bolt11_ln_bits, zaprequest
class NutWallet(object):
@ -29,7 +30,7 @@ class NutWallet(object):
self.a: str = ""
self.legacy_encryption: bool = False # Use Nip04 instead of Nip44, for reasons, turn to False ASAP.
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):
@ -120,7 +121,7 @@ class NutZapWallet:
nut_wallet = None
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)
if len(wallets) > 0:
@ -195,7 +196,7 @@ class NutZapWallet:
# Now all proof events
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)
latest_proof_sec = 0
@ -449,7 +450,7 @@ 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))
# relay_timeout = EventSource.relays(timedelta(seconds=5))
preferences = await client.get_events_of([mint_info_filter], relay_timeout)
mints = []
relays = []
@ -778,12 +779,11 @@ class NutZapWallet:
+ bcolors.ENDC)
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.wallet import Wallet
from cashu.core.crypto.keys import PrivateKey
outgoing_mint = self.get_mint(nut_wallet, outgoing_mint_url)
outgoing_wallet = await Wallet.with_db(
@ -797,7 +797,6 @@ class NutZapWallet:
print(outgoing_wallet.available_balance)
incoming_mint = self.get_mint(nut_wallet, incoming_mint_url)
incoming_wallet = await Wallet.with_db(
url=incoming_mint_url,
@ -808,8 +807,6 @@ class NutZapWallet:
await incoming_wallet.load_mint()
incoming_wallet.proofs = incoming_mint.proofs
if incoming_wallet.url == outgoing_wallet.url:
raise Exception("mints for swap have to be different")

View File

@ -19,8 +19,6 @@ async def create_reaction(keys, title, dtag):
emoji_tag1 = Tag.parse(["emoji", name, url])
emoji_tags.append(emoji_tag1)
keys = Keys.parse(keys)
content = ""
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"
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"))

View File

@ -1,40 +1,40 @@
{
"features": {
"responsive_web_graphql_exclude_directive_enabled": true,
"verified_phone_label_enabled": false,
"responsive_web_graphql_timeline_navigation_enabled": true,
"responsive_web_graphql_skip_user_profile_image_extensions_enabled": false,
"tweetypie_unmention_optimization_enabled": true,
"vibe_api_enabled": false,
"responsive_web_edit_tweet_api_enabled": false,
"graphql_is_translatable_rweb_tweet_is_translatable_enabled": false,
"view_counts_everywhere_api_enabled": true,
"longform_notetweets_consumption_enabled": true,
"tweet_awards_web_tipping_enabled": false,
"freedom_of_speech_not_reach_fetch_enabled": false,
"standardized_nudges_misinfo": false,
"tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled": false,
"interactive_text_enabled": false,
"responsive_web_twitter_blue_verified_badge_is_enabled": true,
"responsive_web_text_conversations_enabled": false,
"longform_notetweets_richtext_consumption_enabled": false,
"responsive_web_enhance_cards_enabled": false,
"longform_notetweets_inline_media_enabled": true,
"longform_notetweets_rich_text_read_enabled": true,
"responsive_web_media_download_video_enabled": true,
"responsive_web_twitter_article_tweet_consumption_enabled": true,
"creator_subscriptions_tweet_preview_api_enabled": true
},
"variables": {
"with_rux_injections": false,
"includePromotedContent": true,
"withCommunity": true,
"withQuickPromoteEligibilityTweetFields": true,
"withBirdwatchNotes": true,
"withDownvotePerspective": false,
"withReactionsMetadata": false,
"withReactionsPerspective": false,
"withVoice": true,
"withV2Timeline": true
}
"features": {
"responsive_web_graphql_exclude_directive_enabled": true,
"verified_phone_label_enabled": false,
"responsive_web_graphql_timeline_navigation_enabled": true,
"responsive_web_graphql_skip_user_profile_image_extensions_enabled": false,
"tweetypie_unmention_optimization_enabled": true,
"vibe_api_enabled": false,
"responsive_web_edit_tweet_api_enabled": false,
"graphql_is_translatable_rweb_tweet_is_translatable_enabled": false,
"view_counts_everywhere_api_enabled": true,
"longform_notetweets_consumption_enabled": true,
"tweet_awards_web_tipping_enabled": false,
"freedom_of_speech_not_reach_fetch_enabled": false,
"standardized_nudges_misinfo": false,
"tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled": false,
"interactive_text_enabled": false,
"responsive_web_twitter_blue_verified_badge_is_enabled": true,
"responsive_web_text_conversations_enabled": false,
"longform_notetweets_richtext_consumption_enabled": false,
"responsive_web_enhance_cards_enabled": false,
"longform_notetweets_inline_media_enabled": true,
"longform_notetweets_rich_text_read_enabled": true,
"responsive_web_media_download_video_enabled": true,
"responsive_web_twitter_article_tweet_consumption_enabled": true,
"creator_subscriptions_tweet_preview_api_enabled": true
},
"variables": {
"with_rux_injections": false,
"includePromotedContent": true,
"withCommunity": true,
"withQuickPromoteEligibilityTweetFields": true,
"withBirdwatchNotes": true,
"withDownvotePerspective": false,
"withReactionsMetadata": false,
"withReactionsPerspective": false,
"withVoice": true,
"withV2Timeline": true
}
}