mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-08-01 00:06:14 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35c9ce5699 |
+24
-2
@@ -142,6 +142,7 @@ async def refund_wallet_endpoint(
|
|||||||
authorization: Annotated[str, Header(...)],
|
authorization: Annotated[str, Header(...)],
|
||||||
session: AsyncSession = Depends(get_session),
|
session: AsyncSession = Depends(get_session),
|
||||||
) -> dict[str, str]:
|
) -> dict[str, str]:
|
||||||
|
logger.info("Refund request received", extra={"authorization": authorization})
|
||||||
if not authorization.startswith("Bearer "):
|
if not authorization.startswith("Bearer "):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=401,
|
status_code=401,
|
||||||
@@ -157,6 +158,7 @@ async def refund_wallet_endpoint(
|
|||||||
|
|
||||||
remaining_balance_msats: int = key.total_balance
|
remaining_balance_msats: int = key.total_balance
|
||||||
|
|
||||||
|
logger.info("Refunding key: %s", key.dict())
|
||||||
if key.refund_currency == "sat":
|
if key.refund_currency == "sat":
|
||||||
remaining_balance = remaining_balance_msats // 1000
|
remaining_balance = remaining_balance_msats // 1000
|
||||||
else:
|
else:
|
||||||
@@ -172,6 +174,15 @@ async def refund_wallet_endpoint(
|
|||||||
if key.refund_address:
|
if key.refund_address:
|
||||||
from .core.settings import settings as global_settings
|
from .core.settings import settings as global_settings
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
"Sending refund to lnurl",
|
||||||
|
extra={
|
||||||
|
"remaining_balance": remaining_balance,
|
||||||
|
"refund_currency": key.refund_currency,
|
||||||
|
"refund_mint_url": key.refund_mint_url,
|
||||||
|
"refund_address": key.refund_address,
|
||||||
|
},
|
||||||
|
)
|
||||||
await send_to_lnurl(
|
await send_to_lnurl(
|
||||||
remaining_balance,
|
remaining_balance,
|
||||||
key.refund_currency or "sat",
|
key.refund_currency or "sat",
|
||||||
@@ -180,7 +191,16 @@ async def refund_wallet_endpoint(
|
|||||||
)
|
)
|
||||||
result = {"recipient": key.refund_address}
|
result = {"recipient": key.refund_address}
|
||||||
else:
|
else:
|
||||||
|
logger.info(
|
||||||
|
"Sending refund as token",
|
||||||
|
extra={
|
||||||
|
"remaining_balance": remaining_balance,
|
||||||
|
"refund_currency": key.refund_currency,
|
||||||
|
"refund_mint_url": key.refund_mint_url,
|
||||||
|
},
|
||||||
|
)
|
||||||
refund_currency = key.refund_currency or "sat"
|
refund_currency = key.refund_currency or "sat"
|
||||||
|
|
||||||
token = await send_token(
|
token = await send_token(
|
||||||
remaining_balance, refund_currency, key.refund_mint_url
|
remaining_balance, refund_currency, key.refund_mint_url
|
||||||
)
|
)
|
||||||
@@ -191,10 +211,12 @@ async def refund_wallet_endpoint(
|
|||||||
else:
|
else:
|
||||||
result["msats"] = str(remaining_balance_msats)
|
result["msats"] = str(remaining_balance_msats)
|
||||||
|
|
||||||
except HTTPException:
|
except HTTPException as e:
|
||||||
|
logger.error("Refund failed", extra={"exception": e})
|
||||||
# Re-raise HTTP exceptions (like 400 for balance too small)
|
# Re-raise HTTP exceptions (like 400 for balance too small)
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
logger.error("Refund failed", extra={"exception": e})
|
||||||
# If refund fails, don't modify the database
|
# If refund fails, don't modify the database
|
||||||
error_msg = str(e)
|
error_msg = str(e)
|
||||||
if (
|
if (
|
||||||
@@ -205,7 +227,7 @@ async def refund_wallet_endpoint(
|
|||||||
):
|
):
|
||||||
raise HTTPException(status_code=503, detail="Mint service unavailable")
|
raise HTTPException(status_code=503, detail="Mint service unavailable")
|
||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=500, detail="Refund failed")
|
raise HTTPException(status_code=500, detail="Refund failed: " + error_msg)
|
||||||
|
|
||||||
await _refund_cache_set(bearer_value, result)
|
await _refund_cache_set(bearer_value, result)
|
||||||
|
|
||||||
|
|||||||
+8
-1
@@ -40,16 +40,23 @@ async def recieve_token(
|
|||||||
async def send(amount: int, unit: str, mint_url: str | None = None) -> tuple[int, str]:
|
async def send(amount: int, unit: str, mint_url: str | None = None) -> tuple[int, str]:
|
||||||
"""Internal send function - returns amount and serialized token"""
|
"""Internal send function - returns amount and serialized token"""
|
||||||
wallet: Wallet = await get_wallet(mint_url or settings.primary_mint, unit)
|
wallet: Wallet = await get_wallet(mint_url or settings.primary_mint, unit)
|
||||||
|
logger.info("Sending", extra={"amount": amount, "unit": unit, "mint_url": mint_url})
|
||||||
proofs = get_proofs_per_mint_and_unit(
|
proofs = get_proofs_per_mint_and_unit(
|
||||||
wallet, mint_url or settings.primary_mint, unit
|
wallet, mint_url or settings.primary_mint, unit
|
||||||
)
|
)
|
||||||
|
logger.info("Proofs", extra={"proofs": proofs})
|
||||||
|
logger.info(
|
||||||
|
"Selecting to send",
|
||||||
|
extra={"amount": amount, "unit": unit, "mint_url": mint_url},
|
||||||
|
)
|
||||||
send_proofs, _ = await wallet.select_to_send(
|
send_proofs, _ = await wallet.select_to_send(
|
||||||
proofs, amount, set_reserved=True, include_fees=False
|
proofs, amount, set_reserved=True, include_fees=False
|
||||||
)
|
)
|
||||||
|
logger.info("Send proofs", extra={"send_proofs": send_proofs})
|
||||||
token = await wallet.serialize_proofs(
|
token = await wallet.serialize_proofs(
|
||||||
send_proofs, include_dleq=False, legacy=False, memo=None
|
send_proofs, include_dleq=False, legacy=False, memo=None
|
||||||
)
|
)
|
||||||
|
logger.info("Token created", extra={"token": token})
|
||||||
return amount, token
|
return amount, token
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user