mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-06-01 14:19:11 +02:00
optional: update profile on lnaddress change
This commit is contained in:
parent
92a993e184
commit
ed8c44977c
@ -12,7 +12,6 @@ from nostr_sdk import Filter, Client, Alphabet, EventId, Event, PublicKey, Tag,
|
|||||||
from nostr_dvm.utils.definitions import EventDefinitions, relay_timeout, relay_timeout_long
|
from nostr_dvm.utils.definitions import EventDefinitions, relay_timeout, relay_timeout_long
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def get_event_by_id(event_id: str, client: Client, config=None) -> Event | None:
|
async def get_event_by_id(event_id: str, client: Client, config=None) -> Event | None:
|
||||||
split = event_id.split(":")
|
split = event_id.split(":")
|
||||||
if len(split) == 3:
|
if len(split) == 3:
|
||||||
@ -358,6 +357,24 @@ def check_and_decrypt_own_tags(event, dvm_config):
|
|||||||
return event
|
return event
|
||||||
|
|
||||||
|
|
||||||
|
async def update_profile_lnaddress(private_key, dvm_config, lud16="",):
|
||||||
|
keys = Keys.parse(private_key)
|
||||||
|
opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=5))
|
||||||
|
.skip_disconnected_relays(True))
|
||||||
|
|
||||||
|
signer = NostrSigner.keys(keys)
|
||||||
|
client = Client.with_opts(signer, opts)
|
||||||
|
for relay in dvm_config.RELAY_LIST:
|
||||||
|
await client.add_relay(relay)
|
||||||
|
await client.connect()
|
||||||
|
|
||||||
|
metadata = Metadata() \
|
||||||
|
.set_lud16(lud16) \
|
||||||
|
.set_nip05(lud16)
|
||||||
|
|
||||||
|
await client.set_metadata(metadata)
|
||||||
|
|
||||||
|
|
||||||
async def update_profile(dvm_config, client, lud16=""):
|
async def update_profile(dvm_config, client, lud16=""):
|
||||||
keys = Keys.parse(dvm_config.PRIVATE_KEY)
|
keys = Keys.parse(dvm_config.PRIVATE_KEY)
|
||||||
try:
|
try:
|
||||||
|
@ -14,7 +14,8 @@ from bech32 import bech32_decode, convertbits, bech32_encode
|
|||||||
from nostr_sdk import PublicKey, SecretKey, Event, EventBuilder, Tag, Keys, generate_shared_key, Kind, \
|
from nostr_sdk import PublicKey, SecretKey, Event, EventBuilder, Tag, Keys, generate_shared_key, Kind, \
|
||||||
Timestamp
|
Timestamp
|
||||||
|
|
||||||
from nostr_dvm.utils.nostr_utils import get_event_by_id, check_and_decrypt_own_tags
|
from nostr_dvm.utils.nostr_utils import get_event_by_id, check_and_decrypt_own_tags, update_profile, \
|
||||||
|
update_profile_lnaddress
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
import dotenv
|
import dotenv
|
||||||
|
|
||||||
@ -417,7 +418,7 @@ def check_and_set_ln_bits_keys(identifier, npub):
|
|||||||
os.getenv("LNADDRESS_" + identifier.upper()))
|
os.getenv("LNADDRESS_" + identifier.upper()))
|
||||||
|
|
||||||
|
|
||||||
def change_ln_address(identifier, new_identifier):
|
async def change_ln_address(identifier, new_identifier, dvm_config, updateprofile=False):
|
||||||
previous_identifier = os.getenv("LNADDRESS_" + identifier.upper()).split("@")[0]
|
previous_identifier = os.getenv("LNADDRESS_" + identifier.upper()).split("@")[0]
|
||||||
pin = os.getenv("LNADDRESS_PIN_" + identifier.upper())
|
pin = os.getenv("LNADDRESS_PIN_" + identifier.upper())
|
||||||
npub = Keys.parse(os.getenv("DVM_PRIVATE_KEY_" + identifier.upper())).public_key().to_hex()
|
npub = Keys.parse(os.getenv("DVM_PRIVATE_KEY_" + identifier.upper())).public_key().to_hex()
|
||||||
@ -425,6 +426,9 @@ def change_ln_address(identifier, new_identifier):
|
|||||||
add_key_to_env_file("LNADDRESS_" + identifier.upper(), lnaddress)
|
add_key_to_env_file("LNADDRESS_" + identifier.upper(), lnaddress)
|
||||||
add_key_to_env_file("LNADDRESS_PIN_" + identifier.upper(), pin)
|
add_key_to_env_file("LNADDRESS_PIN_" + identifier.upper(), pin)
|
||||||
print("changed lnaddress")
|
print("changed lnaddress")
|
||||||
|
if updateprofile:
|
||||||
|
private_key = os.getenv("DVM_PRIVATE_KEY_" + identifier.upper())
|
||||||
|
await update_profile_lnaddress(private_key, dvm_config, lud16=lnaddress)
|
||||||
|
|
||||||
def add_key_to_env_file(value, oskey):
|
def add_key_to_env_file(value, oskey):
|
||||||
env_path = Path('.env')
|
env_path = Path('.env')
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
# On https://www.data-vending-machines.org/ there's an overview on all current kinds.
|
# On https://www.data-vending-machines.org/ there's an overview on all current kinds.
|
||||||
# On https://github.com/nostr-protocol/data-vending-machines/ you can make a PR for your own kind, if you come up with one later.
|
# On https://github.com/nostr-protocol/data-vending-machines/ you can make a PR for your own kind, if you come up with one later.
|
||||||
# Check the run_dvm function for more explanations
|
# Check the run_dvm function for more explanations
|
||||||
|
import asyncio
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ import dotenv
|
|||||||
from nostr_dvm.tasks.generic_dvm import GenericDVM
|
from nostr_dvm.tasks.generic_dvm import GenericDVM
|
||||||
from nostr_sdk import Kind, Keys
|
from nostr_sdk import Kind, Keys
|
||||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||||
from nostr_dvm.utils.dvmconfig import build_default_config
|
from nostr_dvm.utils.dvmconfig import build_default_config, DVMConfig
|
||||||
from nostr_dvm.utils.nip89_utils import NIP89Config
|
from nostr_dvm.utils.nip89_utils import NIP89Config
|
||||||
from nostr_dvm.utils.zap_utils import change_ln_address
|
from nostr_dvm.utils.zap_utils import change_ln_address
|
||||||
|
|
||||||
@ -77,6 +78,6 @@ if __name__ == '__main__':
|
|||||||
identifier = "tutorial01"
|
identifier = "tutorial01"
|
||||||
|
|
||||||
# psst, you can change your lightning address here:
|
# psst, you can change your lightning address here:
|
||||||
# change_ln_address(identifier, "a_cool_new_address")
|
#asyncio.run(change_ln_address(identifier, "test", DVMConfig(), True))
|
||||||
|
|
||||||
run_dvm(identifier)
|
run_dvm(identifier)
|
Loading…
x
Reference in New Issue
Block a user