Mint: blink fix fee estimation (#439)

* blink: fix fee esimation

* fix line length

* fix line length

* fix line length

* remove noqa
This commit is contained in:
callebtc
2024-02-18 12:24:41 +01:00
committed by GitHub
parent 48158cd497
commit ad906df788
3 changed files with 13 additions and 3 deletions

View File

@@ -327,7 +327,7 @@ class BlinkWallet(LightningBackend):
fees_response_msat = int(resp["data"]["lnInvoiceFeeProbe"]["amount"]) * 1000 fees_response_msat = int(resp["data"]["lnInvoiceFeeProbe"]["amount"]) * 1000
# we either take fee_msat_response or the BLINK_MAX_FEE_PERCENT, whichever is higher # we either take fee_msat_response or the BLINK_MAX_FEE_PERCENT, whichever is higher
fees_msat = max( fees_msat = max(
fees_response_msat, math.ceil(amount_msat * BLINK_MAX_FEE_PERCENT) fees_response_msat, math.ceil(amount_msat / 100 * BLINK_MAX_FEE_PERCENT)
) )
fees = Amount(unit=Unit.msat, amount=fees_msat) fees = Amount(unit=Unit.msat, amount=fees_msat)

View File

@@ -380,6 +380,7 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
method = Method[quote.method] method = Method[quote.method]
if not quote.paid: if not quote.paid:
assert quote.checking_id, "quote has no checking id"
logger.trace(f"Lightning: checking invoice {quote.checking_id}") logger.trace(f"Lightning: checking invoice {quote.checking_id}")
status: PaymentStatus = await self.backends[method][ status: PaymentStatus = await self.backends[method][
unit unit
@@ -482,6 +483,7 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
assert mint_quote.method == method.name, "methods do not match" assert mint_quote.method == method.name, "methods do not match"
assert not mint_quote.paid, "mint quote already paid" assert not mint_quote.paid, "mint quote already paid"
assert not mint_quote.issued, "mint quote already issued" assert not mint_quote.issued, "mint quote already issued"
assert mint_quote.checking_id, "mint quote has no checking id"
payment_quote = PaymentQuoteResponse( payment_quote = PaymentQuoteResponse(
checking_id=mint_quote.checking_id, checking_id=mint_quote.checking_id,
amount=Amount(unit, mint_quote.amount), amount=Amount(unit, mint_quote.amount),

View File

@@ -49,7 +49,6 @@ async def test_blink_create_invoice():
} }
} }
} }
respx.post(blink.endpoint).mock(return_value=Response(200, json=mock_response)) respx.post(blink.endpoint).mock(return_value=Response(200, json=mock_response))
invoice = await blink.create_invoice(Amount(Unit.sat, 1000)) invoice = await blink.create_invoice(Amount(Unit.sat, 1000))
assert invoice.checking_id == invoice.payment_request assert invoice.checking_id == invoice.payment_request
@@ -129,9 +128,18 @@ async def test_blink_get_payment_status():
@respx.mock @respx.mock
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_blink_get_payment_quote(): async def test_blink_get_payment_quote():
# response says 1 sat fees but invoice * 0.5% is 5 sat so we expect 5 sat
mock_response = {"data": {"lnInvoiceFeeProbe": {"amount": 1}}}
respx.post(blink.endpoint).mock(return_value=Response(200, json=mock_response))
quote = await blink.get_payment_quote(payment_request)
assert quote.checking_id == payment_request
assert quote.amount == Amount(Unit.msat, 1000000) # msat
assert quote.fee == Amount(Unit.msat, 5000) # msat
# response says 10 sat fees but invoice * 0.5% is 5 sat so we expect 10 sat
mock_response = {"data": {"lnInvoiceFeeProbe": {"amount": 10}}} mock_response = {"data": {"lnInvoiceFeeProbe": {"amount": 10}}}
respx.post(blink.endpoint).mock(return_value=Response(200, json=mock_response)) respx.post(blink.endpoint).mock(return_value=Response(200, json=mock_response))
quote = await blink.get_payment_quote(payment_request) quote = await blink.get_payment_quote(payment_request)
assert quote.checking_id == payment_request assert quote.checking_id == payment_request
assert quote.amount == Amount(Unit.msat, 1000000) # msat assert quote.amount == Amount(Unit.msat, 1000000) # msat
assert quote.fee == Amount(Unit.msat, 500000) # msat assert quote.fee == Amount(Unit.msat, 10000) # msat