mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-11-19 23:16:27 +01:00
use existing client for update profile
This commit is contained in:
@@ -89,4 +89,4 @@ def admin_make_database_updates(adminconfig: AdminConfig = None, dvmconfig: DVMC
|
|||||||
fetch_nip89_paramters_for_deletion(keys, event_id, client, dvmconfig)
|
fetch_nip89_paramters_for_deletion(keys, event_id, client, dvmconfig)
|
||||||
|
|
||||||
if adminconfig.UPDATE_PROFILE:
|
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)
|
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)
|
user = get_from_sql_table(db, npub)
|
||||||
if user is None:
|
if user is None:
|
||||||
try:
|
try:
|
||||||
@@ -195,9 +195,20 @@ def get_or_add_user(db, npub, client, config):
|
|||||||
return user
|
return user
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Error Adding User to DB: " + str(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
|
return user
|
||||||
|
|
||||||
|
|
||||||
def fetch_user_metadata(npub, client):
|
def fetch_user_metadata(npub, client):
|
||||||
name = ""
|
name = ""
|
||||||
nip05 = ""
|
nip05 = ""
|
||||||
|
|||||||
@@ -135,16 +135,8 @@ def check_and_decrypt_own_tags(event, dvm_config):
|
|||||||
return event
|
return event
|
||||||
|
|
||||||
|
|
||||||
def update_profile(dvm_config, lud16=""):
|
def update_profile(dvm_config, client, lud16=""):
|
||||||
keys = Keys.from_sk_str(dvm_config.PRIVATE_KEY)
|
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)
|
nip89content = json.loads(dvm_config.NIP89.CONTENT)
|
||||||
if nip89content.get("name"):
|
if nip89content.get("name"):
|
||||||
name = 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(f"Setting profile metadata for {keys.public_key().to_bech32()}...")
|
||||||
print(metadata.as_json())
|
print(metadata.as_json())
|
||||||
client.set_metadata(metadata)
|
client.set_metadata(metadata)
|
||||||
client.disconnect()
|
|
||||||
|
|
||||||
|
|
||||||
def check_and_set_private_key(identifier):
|
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):
|
def create_bolt11_lud16(lud16, amount):
|
||||||
|
|
||||||
if lud16.startswith("LNURL") or lud16.startswith("lnurl"):
|
if lud16.startswith("LNURL") or lud16.startswith("lnurl"):
|
||||||
url = lnurl.decode(lud16)
|
url = lnurl.decode(lud16)
|
||||||
elif '@' in lud16: # LNaddress
|
elif '@' in lud16: # LNaddress
|
||||||
@@ -109,6 +110,7 @@ def create_bolt11_lud16(lud16, amount):
|
|||||||
else: # No lud16 set or format invalid
|
else: # No lud16 set or format invalid
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
|
print(url)
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
ob = json.loads(response.content)
|
ob = json.loads(response.content)
|
||||||
callback = ob["callback"]
|
callback = ob["callback"]
|
||||||
@@ -278,7 +280,7 @@ def parse_cashu(cashu_token: str):
|
|||||||
return None, None, None, None
|
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)
|
proofs, mint, redeem_invoice_amount, total_amount = parse_cashu(cashu)
|
||||||
fees = total_amount - redeem_invoice_amount
|
fees = total_amount - redeem_invoice_amount
|
||||||
if redeem_invoice_amount < required_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 != "":
|
if config.LNBITS_INVOICE_KEY != "":
|
||||||
invoice, paymenthash = create_bolt11_ln_bits(redeem_invoice_amount, config)
|
invoice, paymenthash = create_bolt11_ln_bits(redeem_invoice_amount, config)
|
||||||
else:
|
else:
|
||||||
|
|
||||||
user = get_or_add_user(db=config.DB, npub=config.PUBLIC_KEY,
|
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)
|
invoice = create_bolt11_lud16(user.lud16, redeem_invoice_amount)
|
||||||
print(invoice)
|
print(invoice)
|
||||||
if invoice is None:
|
if invoice is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user