Skip to content

Commit

Permalink
fix mypy type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gudnuf committed Jul 1, 2024
1 parent aab3856 commit 289f377
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions cashu/lightning/nwc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import AsyncGenerator
from typing import Optional, AsyncGenerator

from bolt11 import decode
from loguru import logger
Expand All @@ -25,20 +25,20 @@


class NWCWallet(LightningBackend):
supported_units = [Unit.sat]

supported_units = {Unit.sat}

def __init__(self, unit: Unit, **kwargs):
logger.debug(f"Initializing NWCWallet with unit: {unit}")
self.assert_unit_supported(unit)
self.unit = unit
self.supported_units = [Unit.sat, Unit.usd, Unit.msat]
self.client = NWCClient(nostrWalletConnectUrl=settings.mint_nwc_url)

async def status(self) -> StatusResponse:
try:
res = await self.client.get_balance()
balance_msat = res.balance
return StatusResponse(balance=balance_msat // 1000)
return StatusResponse(balance=balance_msat // 1000, error_message=None)
except Nip47Error as exc:
return StatusResponse(
error_message=str(exc),
Expand All @@ -53,8 +53,9 @@ async def status(self) -> StatusResponse:
async def create_invoice(
self,
amount: Amount,
memo: str | None = None,
description_hash: bytes | None = None,
memo: Optional[str] = None,
description_hash: Optional[bytes] = None,
unhashed_description: Optional[str] = None,
) -> InvoiceResponse:
try:
res = await self.client.create_invoice(
Expand All @@ -69,21 +70,11 @@ async def create_invoice(
except Nip47Error as exc:
return InvoiceResponse(
error_message=str(exc),
checking_id="",
bolt11="",
amount=0,
expires_at=0,
created_at=0,
ok=False,
)
except Exception as exc:
return InvoiceResponse(
error_message=f"Failed to create invoice due to: {exc}",
checking_id="",
bolt11="",
amount=0,
expires_at=0,
created_at=0,
ok=False,
)

Expand Down Expand Up @@ -168,4 +159,4 @@ async def get_payment_quote(
)

async def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
raise NotImplementedError("paid_invoices_stream not implemented")
raise NotImplementedError("paid_invoices_stream not implemented")

0 comments on commit 289f377

Please sign in to comment.