diff --git a/cashu/lightning/fake.py b/cashu/lightning/fake.py index 7c50306c..6fca6ddf 100644 --- a/cashu/lightning/fake.py +++ b/cashu/lightning/fake.py @@ -45,7 +45,7 @@ class FakeWallet(LightningBackend): 32, ).hex() - supported_units = set([Unit.sat, Unit.msat, Unit.usd]) + supported_units = set([Unit.sat, Unit.msat, Unit.usd, Unit.eur]) unit = Unit.sat supports_incoming_payment_stream: bool = True @@ -113,7 +113,7 @@ async def create_invoice( amount_msat = 0 if self.unit == Unit.sat: amount_msat = MilliSatoshi(amount.to(Unit.msat, round="up").amount) - elif self.unit == Unit.usd: + elif self.unit == Unit.usd or self.unit == Unit.eur: amount_msat = MilliSatoshi( math.ceil(amount.amount / self.fake_btc_price * 1e9) ) @@ -194,10 +194,10 @@ async def get_payment_quote( fees_msat = fee_reserve(amount_msat) fees = Amount(unit=Unit.msat, amount=fees_msat) amount = Amount(unit=Unit.msat, amount=amount_msat) - elif self.unit == Unit.usd: + elif self.unit == Unit.usd or self.unit == Unit.eur: amount_usd = math.ceil(invoice_obj.amount_msat / 1e9 * self.fake_btc_price) - amount = Amount(unit=Unit.usd, amount=amount_usd) - fees = Amount(unit=Unit.usd, amount=2) + amount = Amount(unit=self.unit, amount=amount_usd) + fees = Amount(unit=self.unit, amount=2) else: raise NotImplementedError() diff --git a/cashu/lightning/strike.py b/cashu/lightning/strike.py index 35461362..15a47aa5 100644 --- a/cashu/lightning/strike.py +++ b/cashu/lightning/strike.py @@ -142,8 +142,7 @@ async def get_payment_quote( raise Exception(error_message) data = r.json() - # amount_cent = int(float(data.get("amount").get("amount")) * 100) - amount = Amount.from_float(data.get("amount").get("amount"), self.unit) + amount = Amount.from_float(float(data.get("amount").get("amount")), self.unit) quote = PaymentQuoteResponse( amount=amount, checking_id=data.get("paymentQuoteId"), diff --git a/cashu/mint/tasks.py b/cashu/mint/tasks.py index be80d63b..edd61a06 100644 --- a/cashu/mint/tasks.py +++ b/cashu/mint/tasks.py @@ -26,11 +26,15 @@ async def dispatch_listeners(self) -> None: asyncio.create_task(self.invoice_listener(backend)) async def invoice_listener(self, backend: LightningBackend) -> None: - try: - async for checking_id in backend.paid_invoices_stream(): - await self.invoice_callback_dispatcher(checking_id) - except Exception as e: - logger.error(f"Error in invoice listener: {e}") + if backend.supports_incoming_payment_stream: + while True: + try: + async for checking_id in backend.paid_invoices_stream(): + await self.invoice_callback_dispatcher(checking_id) + except Exception as e: + logger.error(f"Error in invoice listener: {e}") + logger.info("Restarting invoice listener...") + await asyncio.sleep(1) async def invoice_callback_dispatcher(self, checking_id: str) -> None: logger.debug(f"Invoice callback dispatcher: {checking_id}")