Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend fake wallet with eur unit #529

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cashu/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class MintBackends(MintSettings):
mint_lightning_backend: str = Field(default="") # deprecated
mint_backend_bolt11_sat: str = Field(default="")
mint_backend_bolt11_usd: str = Field(default="")
mint_backend_bolt11_eur: str = Field(default="")

mint_lnbits_endpoint: str = Field(default=None)
mint_lnbits_key: str = Field(default=None)
Expand Down
19 changes: 14 additions & 5 deletions cashu/lightning/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@


class FakeWallet(LightningBackend):
fake_btc_price = 1e8 / 1337
fake_btcusd_price = 1e8 / 1556
fake_btceur_price = 1e8 / 1672
queue: asyncio.Queue[Bolt11] = asyncio.Queue(0)
payment_secrets: Dict[str, str] = dict()
paid_invoices: Set[str] = set()
Expand All @@ -42,7 +43,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 +88,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 @@ -164,9 +168,14 @@ async def get_payment_quote(
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
5 changes: 5 additions & 0 deletions cashu/mint/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
unit=Unit.usd
)
backends.setdefault(Method.bolt11, {})[Unit.usd] = backend_bolt11_usd
if settings.mint_backend_bolt11_eur:
backend_bolt11_eur = getattr(wallets_module, settings.mint_backend_bolt11_eur)(
unit=Unit.eur
)
backends.setdefault(Method.bolt11, {})[Unit.eur] = backend_bolt11_eur
if not backends:
raise Exception("No backends are set.")

Expand Down
Loading