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.id = uuid4().hex
|
||||||
|
|
||||||
account = await create_account(account, conn=conn)
|
account = await create_account(account, conn=conn)
|
||||||
await create_wallet(
|
wallet = await create_wallet(
|
||||||
user_id=account.id,
|
user_id=account.id,
|
||||||
wallet_name=wallet_name or settings.lnbits_default_wallet_name,
|
wallet_name=wallet_name or settings.lnbits_default_wallet_name,
|
||||||
conn=conn,
|
conn=conn,
|
||||||
|
|
@ -91,7 +91,7 @@ async def create_user_account_no_ckeck(
|
||||||
# Create default pay link for users with username
|
# Create default pay link for users with username
|
||||||
if account.username and "lnurlp" in user_extensions:
|
if account.username and "lnurlp" in user_extensions:
|
||||||
try:
|
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}")
|
logger.info(f"Created default pay link for user {account.username}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to create default pay link for user {account.username}: {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
|
# This handles cases where extensions are in /var/lib/lnbits/extensions
|
||||||
try:
|
try:
|
||||||
# Add extensions path to sys.path if not already there
|
# 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:
|
if extensions_path not in sys.path:
|
||||||
sys.path.insert(0, extensions_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)
|
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:
|
except Exception as e:
|
||||||
logger.error(f"Failed to create default pay link: {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
|
# 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:
|
async def _publish_nostr_metadata_event(account: Account) -> None:
|
||||||
"""Publish a Nostr kind 0 metadata event for a new user"""
|
"""Publish a Nostr kind 0 metadata event for a new user"""
|
||||||
try:
|
try:
|
||||||
|
|
@ -274,14 +279,14 @@ async def _publish_nostr_metadata_event(account: Account) -> None:
|
||||||
metadata = {
|
metadata = {
|
||||||
"name": account.username,
|
"name": account.username,
|
||||||
"display_name": account.username,
|
"display_name": account.username,
|
||||||
"about": f"LNbits user: {account.username}"
|
"about": f"LNbits user: {account.username}",
|
||||||
}
|
}
|
||||||
|
|
||||||
event = {
|
event = {
|
||||||
"kind": 0,
|
"kind": 0,
|
||||||
"created_at": int(time.time()),
|
"created_at": int(time.time()),
|
||||||
"tags": [],
|
"tags": [],
|
||||||
"content": json.dumps(metadata)
|
"content": json.dumps(metadata),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Sign the event using LNbits utilities
|
# 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
|
# 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:
|
async def _insert_event_into_nostrrelay(event: dict, username: str) -> None:
|
||||||
"""Directly insert Nostr event into nostrrelay database (hacky workaround)"""
|
"""Directly insert Nostr event into nostrrelay database (hacky workaround)"""
|
||||||
try:
|
try:
|
||||||
|
|
@ -313,26 +316,38 @@ async def _insert_event_into_nostrrelay(event: dict, username: str) -> None:
|
||||||
nostrrelay_crud = None
|
nostrrelay_crud = None
|
||||||
NostrEvent = None
|
NostrEvent = None
|
||||||
try:
|
try:
|
||||||
nostrrelay_crud = importlib.import_module("lnbits.extensions.nostrrelay.crud")
|
nostrrelay_crud = importlib.import_module(
|
||||||
NostrEvent = importlib.import_module("lnbits.extensions.nostrrelay.relay.event").NostrEvent
|
"lnbits.extensions.nostrrelay.crud"
|
||||||
|
)
|
||||||
|
NostrEvent = importlib.import_module(
|
||||||
|
"lnbits.extensions.nostrrelay.relay.event"
|
||||||
|
).NostrEvent
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
# Check if nostrrelay is in external extensions path
|
# 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:
|
if extensions_path not in sys.path:
|
||||||
sys.path.insert(0, extensions_path)
|
sys.path.insert(0, extensions_path)
|
||||||
nostrrelay_crud = importlib.import_module("nostrrelay.crud")
|
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:
|
except ImportError:
|
||||||
# Try from the lnbits-nostrmarket project path
|
# Try from the lnbits-nostrmarket project path
|
||||||
nostrmarket_path = "/home/padreug/Projects/lnbits-nostrmarket"
|
nostrmarket_path = "/home/padreug/Projects/lnbits-nostrmarket"
|
||||||
if nostrmarket_path not in sys.path:
|
if nostrmarket_path not in sys.path:
|
||||||
sys.path.insert(0, nostrmarket_path)
|
sys.path.insert(0, nostrmarket_path)
|
||||||
nostrrelay_crud = importlib.import_module("nostrrelay.crud")
|
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:
|
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
|
return
|
||||||
|
|
||||||
# Use a default relay_id for the proof of concept
|
# 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"],
|
kind=event["kind"],
|
||||||
tags=event.get("tags", []),
|
tags=event.get("tags", []),
|
||||||
content=event["content"],
|
content=event["content"],
|
||||||
sig=event["sig"]
|
sig=event["sig"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Insert directly into nostrrelay database
|
# Insert directly into nostrrelay database
|
||||||
await nostrrelay_crud.create_event(nostr_event)
|
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:
|
except Exception as e:
|
||||||
logger.error(f"Failed to insert event into nostrrelay database: {e}")
|
logger.error(f"Failed to insert event into nostrrelay database: {e}")
|
||||||
logger.debug(f"Exception details: {type(e).__name__}: {str(e)}")
|
logger.debug(f"Exception details: {type(e).__name__}: {str(e)}")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue