Skip to content

Commit

Permalink
Extend fake wallet woth eur unit
Browse files Browse the repository at this point in the history
  • Loading branch information
minibits-cash committed May 7, 2024
1 parent 52fbfc4 commit 3e72c1a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cashu/lightning/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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

def __init__(self, unit: Unit = Unit.sat, **kwargs):
Expand Down Expand Up @@ -87,13 +87,16 @@ async def create_invoice(
tags.add(TagChar.payment_hash, payment_hash)

self.payment_secrets[payment_hash] = secret

amount_msat = 0
if self.unit == Unit.sat:
amount_msat = MilliSatoshi(amount.to(Unit.msat, round="up").amount)
elif self.unit == Unit.usd:
amount_msat = MilliSatoshi(
math.ceil(amount.amount / self.fake_btc_price * 1e9)
math.ceil(amount.amount / self.fake_btcusd_price * 1e9)
)
elif self.unit == Unit.eur:
amount_msat = MilliSatoshi(
math.ceil(amount.amount / self.fake_btceur_price * 1e9)
)
else:
raise NotImplementedError()
Expand Down Expand Up @@ -162,9 +165,14 @@ async def get_payment_quote(self, bolt11: str) -> PaymentQuoteResponse:
fees = Amount(unit=Unit.msat, amount=fees_msat)
amount = Amount(unit=Unit.msat, amount=amount_msat)
elif self.unit == Unit.usd:
amount_usd = math.ceil(invoice_obj.amount_msat / 1e9 * self.fake_btc_price)
amount_usd = math.ceil(invoice_obj.amount_msat / 1e9 * self.fake_btcusd_price)
amount = Amount(unit=Unit.usd, amount=amount_usd)
fees = Amount(unit=Unit.usd, amount=2)
elif self.unit == Unit.eur:
amount_eur = math.ceil(invoice_obj.amount_msat / 1e9 * self.fake_btceur_price)
amount = Amount(unit=Unit.eur, amount=amount_eur)
fees = Amount(unit=Unit.eur, amount=2)

else:
raise NotImplementedError()

Expand Down

0 comments on commit 3e72c1a

Please sign in to comment.