mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-03-29 11:01:41 +01:00
use existing client for update profile
This commit is contained in:
parent
f9144a9820
commit
99eb655e2f
@ -89,4 +89,4 @@ def admin_make_database_updates(adminconfig: AdminConfig = None, dvmconfig: DVMC
|
||||
fetch_nip89_paramters_for_deletion(keys, event_id, client, dvmconfig)
|
||||
|
||||
if adminconfig.UPDATE_PROFILE:
|
||||
update_profile(dvmconfig, lud16=adminconfig.LUD16)
|
||||
update_profile(dvmconfig, client, lud16=adminconfig.LUD16)
|
||||
|
@ -183,7 +183,7 @@ def update_user_balance(db, npub, additional_sats, client, config):
|
||||
send_event(evt, client=client, dvm_config=config)
|
||||
|
||||
|
||||
def get_or_add_user(db, npub, client, config):
|
||||
def get_or_add_user(db, npub, client, config, update=False):
|
||||
user = get_from_sql_table(db, npub)
|
||||
if user is None:
|
||||
try:
|
||||
@ -195,9 +195,20 @@ def get_or_add_user(db, npub, client, config):
|
||||
return user
|
||||
except Exception as e:
|
||||
print("Error Adding User to DB: " + str(e))
|
||||
elif update:
|
||||
try:
|
||||
name, nip05, lud16 = fetch_user_metadata(npub, client)
|
||||
print("Updating User: " + npub + " (" + npub + ")")
|
||||
update_sql_table(db, user.npub, user.balance, user.iswhitelisted, user.isblacklisted, nip05,
|
||||
lud16, name, Timestamp.now().as_secs())
|
||||
user = get_from_sql_table(db, npub)
|
||||
return user
|
||||
except Exception as e:
|
||||
print("Error Updating User in DB: " + str(e))
|
||||
|
||||
return user
|
||||
|
||||
|
||||
def fetch_user_metadata(npub, client):
|
||||
name = ""
|
||||
nip05 = ""
|
||||
|
@ -135,16 +135,8 @@ def check_and_decrypt_own_tags(event, dvm_config):
|
||||
return event
|
||||
|
||||
|
||||
def update_profile(dvm_config, lud16=""):
|
||||
def update_profile(dvm_config, client, lud16=""):
|
||||
keys = Keys.from_sk_str(dvm_config.PRIVATE_KEY)
|
||||
opts = (Options().wait_for_send(True).send_timeout(timedelta(seconds=dvm_config.RELAY_TIMEOUT))
|
||||
.skip_disconnected_relays(True))
|
||||
|
||||
client = Client.with_opts(keys, opts)
|
||||
for relay in dvm_config.RELAY_LIST:
|
||||
client.add_relay(relay)
|
||||
client.connect()
|
||||
|
||||
nip89content = json.loads(dvm_config.NIP89.CONTENT)
|
||||
if nip89content.get("name"):
|
||||
name = nip89content.get("name")
|
||||
@ -165,7 +157,6 @@ def update_profile(dvm_config, lud16=""):
|
||||
print(f"Setting profile metadata for {keys.public_key().to_bech32()}...")
|
||||
print(metadata.as_json())
|
||||
client.set_metadata(metadata)
|
||||
client.disconnect()
|
||||
|
||||
|
||||
def check_and_set_private_key(identifier):
|
||||
|
@ -102,6 +102,7 @@ def create_bolt11_ln_bits(sats: int, config: DVMConfig) -> (str, str):
|
||||
|
||||
|
||||
def create_bolt11_lud16(lud16, amount):
|
||||
|
||||
if lud16.startswith("LNURL") or lud16.startswith("lnurl"):
|
||||
url = lnurl.decode(lud16)
|
||||
elif '@' in lud16: # LNaddress
|
||||
@ -109,6 +110,7 @@ def create_bolt11_lud16(lud16, amount):
|
||||
else: # No lud16 set or format invalid
|
||||
return None
|
||||
try:
|
||||
print(url)
|
||||
response = requests.get(url)
|
||||
ob = json.loads(response.content)
|
||||
callback = ob["callback"]
|
||||
@ -278,7 +280,7 @@ def parse_cashu(cashu_token: str):
|
||||
return None, None, None, None
|
||||
|
||||
|
||||
def redeem_cashu(cashu, required_amount, config, client) -> (bool, str):
|
||||
def redeem_cashu(cashu, required_amount, config, client, update_self=False) -> (bool, str):
|
||||
proofs, mint, redeem_invoice_amount, total_amount = parse_cashu(cashu)
|
||||
fees = total_amount - redeem_invoice_amount
|
||||
if redeem_invoice_amount < required_amount:
|
||||
@ -291,8 +293,9 @@ def redeem_cashu(cashu, required_amount, config, client) -> (bool, str):
|
||||
if config.LNBITS_INVOICE_KEY != "":
|
||||
invoice, paymenthash = create_bolt11_ln_bits(redeem_invoice_amount, config)
|
||||
else:
|
||||
|
||||
user = get_or_add_user(db=config.DB, npub=config.PUBLIC_KEY,
|
||||
client=client, config=config)
|
||||
client=client, config=config, update=update_self)
|
||||
invoice = create_bolt11_lud16(user.lud16, redeem_invoice_amount)
|
||||
print(invoice)
|
||||
if invoice is None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user