FIX: create wallet variable to pass to lnurlp creation
This commit is contained in:
parent
7075abdbbd
commit
7f66c4b092
1 changed files with 38 additions and 22 deletions
|
|
@ -74,7 +74,7 @@ async def create_user_account_no_ckeck(
|
|||
account.id = uuid4().hex
|
||||
|
||||
account = await create_account(account, conn=conn)
|
||||
await create_wallet(
|
||||
wallet = await create_wallet(
|
||||
user_id=account.id,
|
||||
wallet_name=wallet_name or settings.lnbits_default_wallet_name,
|
||||
conn=conn,
|
||||
|
|
@ -91,7 +91,7 @@ async def create_user_account_no_ckeck(
|
|||
# Create default pay link for users with username
|
||||
if account.username and "lnurlp" in user_extensions:
|
||||
try:
|
||||
await _create_default_pay_link(account, wallet) # TODO: determine if this should pass `conn=conn`?
|
||||
await _create_default_pay_link(account, wallet)
|
||||
logger.info(f"Created default pay link for user {account.username}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to create default pay link for user {account.username}: {e}")
|
||||
|
|
@ -228,7 +228,9 @@ async def _create_default_pay_link(account: Account, wallet) -> None:
|
|||
# This handles cases where extensions are in /var/lib/lnbits/extensions
|
||||
try:
|
||||
# Add extensions path to sys.path if not already there
|
||||
extensions_path = settings.lnbits_extensions_path or "/var/lib/lnbits/extensions"
|
||||
extensions_path = (
|
||||
settings.lnbits_extensions_path or "/var/lib/lnbits/extensions"
|
||||
)
|
||||
if extensions_path not in sys.path:
|
||||
sys.path.insert(0, extensions_path)
|
||||
|
||||
|
|
@ -255,12 +257,15 @@ async def _create_default_pay_link(account: Account, wallet) -> None:
|
|||
|
||||
await create_pay_link(pay_link_data)
|
||||
|
||||
logger.info(f"Successfully created default pay link for user {account.username}")
|
||||
logger.info(
|
||||
f"Successfully created default pay link for user {account.username}"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to create default pay link: {e}")
|
||||
# Don't raise - we don't want user creation to fail if pay link creation fails
|
||||
|
||||
|
||||
async def _publish_nostr_metadata_event(account: Account) -> None:
|
||||
"""Publish a Nostr kind 0 metadata event for a new user"""
|
||||
try:
|
||||
|
|
@ -274,14 +279,14 @@ async def _publish_nostr_metadata_event(account: Account) -> None:
|
|||
metadata = {
|
||||
"name": account.username,
|
||||
"display_name": account.username,
|
||||
"about": f"LNbits user: {account.username}"
|
||||
"about": f"LNbits user: {account.username}",
|
||||
}
|
||||
|
||||
event = {
|
||||
"kind": 0,
|
||||
"created_at": int(time.time()),
|
||||
"tags": [],
|
||||
"content": json.dumps(metadata)
|
||||
"content": json.dumps(metadata),
|
||||
}
|
||||
|
||||
# Sign the event using LNbits utilities
|
||||
|
|
@ -301,8 +306,6 @@ async def _publish_nostr_metadata_event(account: Account) -> None:
|
|||
# Don't raise - we don't want user creation to fail if Nostr publishing fails
|
||||
|
||||
|
||||
|
||||
|
||||
async def _insert_event_into_nostrrelay(event: dict, username: str) -> None:
|
||||
"""Directly insert Nostr event into nostrrelay database (hacky workaround)"""
|
||||
try:
|
||||
|
|
@ -313,26 +316,38 @@ async def _insert_event_into_nostrrelay(event: dict, username: str) -> None:
|
|||
nostrrelay_crud = None
|
||||
NostrEvent = None
|
||||
try:
|
||||
nostrrelay_crud = importlib.import_module("lnbits.extensions.nostrrelay.crud")
|
||||
NostrEvent = importlib.import_module("lnbits.extensions.nostrrelay.relay.event").NostrEvent
|
||||
nostrrelay_crud = importlib.import_module(
|
||||
"lnbits.extensions.nostrrelay.crud"
|
||||
)
|
||||
NostrEvent = importlib.import_module(
|
||||
"lnbits.extensions.nostrrelay.relay.event"
|
||||
).NostrEvent
|
||||
except ImportError:
|
||||
try:
|
||||
# Check if nostrrelay is in external extensions path
|
||||
extensions_path = settings.lnbits_extensions_path or "/var/lib/lnbits/extensions"
|
||||
extensions_path = (
|
||||
settings.lnbits_extensions_path or "/var/lib/lnbits/extensions"
|
||||
)
|
||||
if extensions_path not in sys.path:
|
||||
sys.path.insert(0, extensions_path)
|
||||
nostrrelay_crud = importlib.import_module("nostrrelay.crud")
|
||||
NostrEvent = importlib.import_module("nostrrelay.relay.event").NostrEvent
|
||||
NostrEvent = importlib.import_module(
|
||||
"nostrrelay.relay.event"
|
||||
).NostrEvent
|
||||
except ImportError:
|
||||
# Try from the lnbits-nostrmarket project path
|
||||
nostrmarket_path = "/home/padreug/Projects/lnbits-nostrmarket"
|
||||
if nostrmarket_path not in sys.path:
|
||||
sys.path.insert(0, nostrmarket_path)
|
||||
nostrrelay_crud = importlib.import_module("nostrrelay.crud")
|
||||
NostrEvent = importlib.import_module("nostrrelay.relay.event").NostrEvent
|
||||
NostrEvent = importlib.import_module(
|
||||
"nostrrelay.relay.event"
|
||||
).NostrEvent
|
||||
|
||||
if not nostrrelay_crud or not NostrEvent:
|
||||
logger.warning("Could not import nostrrelay - skipping direct database insert")
|
||||
logger.warning(
|
||||
"Could not import nostrrelay - skipping direct database insert"
|
||||
)
|
||||
return
|
||||
|
||||
# Use a default relay_id for the proof of concept
|
||||
|
|
@ -349,15 +364,16 @@ async def _insert_event_into_nostrrelay(event: dict, username: str) -> None:
|
|||
kind=event["kind"],
|
||||
tags=event.get("tags", []),
|
||||
content=event["content"],
|
||||
sig=event["sig"]
|
||||
sig=event["sig"],
|
||||
)
|
||||
|
||||
# Insert directly into nostrrelay database
|
||||
await nostrrelay_crud.create_event(nostr_event)
|
||||
|
||||
logger.info(f"Successfully inserted Nostr metadata event for {username} into nostrrelay database")
|
||||
logger.info(
|
||||
f"Successfully inserted Nostr metadata event for {username} into nostrrelay database"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to insert event into nostrrelay database: {e}")
|
||||
logger.debug(f"Exception details: {type(e).__name__}: {str(e)}")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue