Skip to content

Commit

Permalink
convert amount in Lightning backend for later validation
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Mar 22, 2024
1 parent 15abec5 commit 5107a85
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/regtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
MINT_PORT: 3337
MINT_TEST_DATABASE: ${{ inputs.mint-database }}
TOR: false
MINT_LIGHTNING_BACKEND: ${{ inputs.backend-wallet-class }}
MINT_BACKEND_BOLT11_SAT: ${{ inputs.backend-wallet-class }}
MINT_LNBITS_ENDPOINT: http://localhost:5001
MINT_LNBITS_KEY: d08a3313322a4514af75d488bcc27eee
MINT_LND_REST_ENDPOINT: https://localhost:8081/
Expand Down
6 changes: 5 additions & 1 deletion cashu/lightning/blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,11 @@ 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)
return PaymentQuoteResponse(checking_id=bolt11, fee=fees, amount=amount)
return PaymentQuoteResponse(
checking_id=bolt11,
fee=fees.to(self.unit, round="up"),
amount=amount.to(self.unit, round="up"),
)


async def main():
Expand Down
4 changes: 3 additions & 1 deletion cashu/lightning/corelightningrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,5 +320,7 @@ 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)
return PaymentQuoteResponse(
checking_id=invoice_obj.payment_hash, fee=fees, amount=amount
checking_id=invoice_obj.payment_hash,
fee=fees.to(self.unit, round="up"),
amount=amount.to(self.unit, round="up"),
)
4 changes: 3 additions & 1 deletion cashu/lightning/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,7 @@ async def get_payment_quote(self, bolt11: str) -> PaymentQuoteResponse:
raise NotImplementedError()

return PaymentQuoteResponse(
checking_id=invoice_obj.payment_hash, fee=fees, amount=amount
checking_id=invoice_obj.payment_hash,
fee=fees.to(self.unit, round="up"),
amount=amount.to(self.unit, round="up"),
)
4 changes: 3 additions & 1 deletion cashu/lightning/lnbits.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,7 @@ 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)
return PaymentQuoteResponse(
checking_id=invoice_obj.payment_hash, fee=fees, amount=amount
checking_id=invoice_obj.payment_hash,
fee=fees.to(self.unit, round="up"),
amount=amount.to(self.unit, round="up"),
)
4 changes: 3 additions & 1 deletion cashu/lightning/lndrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,7 @@ 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)
return PaymentQuoteResponse(
checking_id=invoice_obj.payment_hash, fee=fees, amount=amount
checking_id=invoice_obj.payment_hash,
fee=fees.to(self.unit, round="up"),
amount=amount.to(self.unit, round="up"),
)
24 changes: 0 additions & 24 deletions cashu/lightning/strike.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,27 +195,3 @@ async def get_payment_status(self, checking_id: str) -> PaymentStatus:
fee_msat=data["details"]["fee"],
preimage=data["preimage"],
)

# async def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
# url = f"{self.endpoint}/api/v1/payments/sse"

# while True:
# try:
# async with requests.stream("GET", url) as r:
# async for line in r.aiter_lines():
# if line.startswith("data:"):
# try:
# data = json.loads(line[5:])
# except json.decoder.JSONDecodeError:
# continue

# if type(data) is not dict:
# continue

# yield data["payment_hash"] # payment_hash

# except:
# pass

# print("lost connection to lnbits /payments/sse, retrying in 5 seconds")
# await asyncio.sleep(5)
3 changes: 2 additions & 1 deletion cashu/mint/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,8 @@ async def melt_quote(
payment_quote.fee.unit == unit
), "payment quote fee units do not match"

# Lightning bolt11 idiosyncrasy below
# We assume that the request is a bolt11 invoice, this works since we
# support only the bol11 method for now.
invoice_obj = bolt11.decode(melt_quote.request)
assert invoice_obj.amount_msat, "invoice has no amount."
# we set the expiry of this quote to the expiry of the bolt11 invoice
Expand Down

0 comments on commit 5107a85

Please sign in to comment.