identified problem with cashu tokens from different mints

This commit is contained in:
GitHappens2Me
2025-05-25 14:51:53 +02:00
parent f9620458b5
commit 8de3bda191
2 changed files with 6 additions and 3 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ async def validate_bearer_key(bearer_key: str, session: AsyncSession) -> ApiKey:
if exsisting_key := await session.get(ApiKey, hashed_key):
return exsisting_key
new_key = ApiKey(hashed_key=hashed_key, balance=0)
await credit_balance(bearer_key, new_key, session)
await credit_balance(bearer_key, new_key, session) #TODO: see cashu.py "_initialize_wallet"
await session.refresh(new_key)
return new_key
except Exception as e:
+5 -2
View File
@@ -13,11 +13,13 @@ MINIMUM_PAYOUT = int(os.environ.get("MINIMUM_PAYOUT", 10))
DEVS_DONATION_RATE = 0 # 0.021 # 2.1%
WALLET = None
#TODO
# This causes problems when users send tokens from other mints
# WALLET is already set so it returns the specified wallet, but this wallet does not know the keyset of the token
async def _initialize_wallet(mint_url: str | None = None) -> Wallet:
"""Initializes and loads a Cashu wallet."""
global WALLET
if WALLET is not None:
if WALLET is not None and WALLET.mint_url == mint_url: # only return existing wallet if the mint_url matches the one of current WALLET
return WALLET
if mint_url is None:
mint_url = MINT
@@ -121,6 +123,7 @@ async def pay_out(session: AsyncSession) -> None:
async def credit_balance(cashu_token: str, key: ApiKey, session: AsyncSession) -> int:
token_obj: Token = deserialize_token_from_string(cashu_token)
token_mint = await _initialize_wallet(token_obj.mint)
wallet: Wallet = await _initialize_wallet(token_obj.mint)
amount_msats = await _handle_token_receive(wallet, token_obj)
key.balance += amount_msats