Skip to content

Commit

Permalink
strike works with eur
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Jun 26, 2024
1 parent 030347d commit bd5dc05
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
10 changes: 5 additions & 5 deletions cashu/lightning/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
)
Expand Down Expand Up @@ -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()

Expand Down
3 changes: 1 addition & 2 deletions cashu/lightning/strike.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
14 changes: 9 additions & 5 deletions cashu/mint/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down

0 comments on commit bd5dc05

Please sign in to comment.