make simpler

This commit is contained in:
Arc
2026-07-13 13:17:29 +01:00
parent 1537027691
commit 0c60ad4f3b
3 changed files with 5 additions and 60 deletions
+5 -11
View File
@@ -65,7 +65,6 @@ class ExtensionHostAPI:
access_token: str | None = None,
context: str = "user",
owner_id: str | None = None,
wallet_id: str | None = None,
invocation_id: str | None = None,
runtime_limits: dict[str, int] | None = None,
) -> None:
@@ -75,7 +74,6 @@ class ExtensionHostAPI:
self.access_token = access_token
self.context = context
self.owner_id = sha256s(user_id) if user_id else owner_id
self.wallet_id = wallet_id
self.invocation_id = invocation_id
self.runtime_limits = runtime_limits or {}
from .utils import ExtensionAPIUtils
@@ -381,19 +379,15 @@ class ExtensionHostAPI:
from lnbits.core.services.payments import pay_invoice
from lnbits.exceptions import PaymentError
wallet = await get_wallet(request.wallet_id)
if wallet is None:
raise PermissionError("Paying invoices from this wallet is not allowed.")
if self.user_id:
if wallet.user != self.user_id:
raise PermissionError(
"Paying invoices from this wallet is not allowed."
)
elif not (self.context == "event" and request.wallet_id == self.wallet_id):
if not self.user_id:
raise PermissionError(
"Paying an invoice requires an authenticated user context."
)
wallet = await get_wallet(request.wallet_id)
if wallet is None or wallet.user != self.user_id:
raise PermissionError("Paying invoices from this wallet is not allowed.")
try:
payment_request = request.payment_request
if _looks_like_lnurl_pay_target(payment_request):
-1
View File
@@ -83,7 +83,6 @@ async def invoke_wasm_extension_export(
access_token=access_token,
context=context,
owner_id=owner_id,
wallet_id=wallet_id,
invocation_id=invocation.id,
runtime_limits=limits,
)
@@ -50,51 +50,3 @@ async def test_wasm_wallet_pay_invoice_resolves_ln_address(mocker):
assert calls["lnurl"] == ("alice@example.com", 21_000, "winner")
assert calls["pay_invoice"]["payment_request"] == "lnbc1resolved"
assert calls["pay_invoice"]["max_sat"] == 21
@pytest.mark.anyio
async def test_wasm_wallet_pay_invoice_allows_event_wallet_only(mocker):
async def get_wallet(wallet_id: str):
return SimpleNamespace(user="other-user")
async def pay_invoice(**kwargs):
return SimpleNamespace(
checking_id="checking",
payment_hash="hash",
status="success",
amount=-1_000,
fee=0,
pending=False,
success=True,
)
mocker.patch("lnbits.core.crud.wallets.get_wallet", get_wallet)
mocker.patch("lnbits.core.services.payments.pay_invoice", pay_invoice)
api = ExtensionHostAPI(
"demoext",
["wallet.pay_invoice"],
context="event",
owner_id="owner",
wallet_id="wallet1",
)
allowed = await api.wallet_pay_invoice(
PayInvoiceRequest(
wallet_id="wallet1",
payment_request="lnbc1invoice",
max_sat=None,
description="",
)
)
assert allowed.ok is True
with pytest.raises(PermissionError, match="authenticated user context"):
await api.wallet_pay_invoice(
PayInvoiceRequest(
wallet_id="wallet2",
payment_request="lnbc1invoice",
max_sat=None,
description="",
)
)