From 1a75192a99c359f984c3181d2636c70a7b317156 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:51:32 +0100 Subject: [PATCH] clean up multinut --- cashu/core/base.py | 13 +- cashu/core/settings.py | 1 + cashu/lightning/base.py | 10 +- cashu/lightning/blink.py | 7 +- cashu/lightning/corelightningrest.py | 7 +- cashu/lightning/fake.py | 7 +- cashu/lightning/lnbits.py | 7 +- cashu/lightning/lndrest.py | 15 ++- cashu/lightning/strike.py | 7 +- cashu/mint/ledger.py | 3 +- cashu/wallet/api/router.py | 4 +- cashu/wallet/cli/cli.py | 18 ++- cashu/wallet/lightning/lightning.py | 6 +- cashu/wallet/wallet.py | 181 +++++++++++++-------------- cashu/wallet/wallet_deprecated.py | 2 +- tests/test_mint_lightning_blink.py | 27 +++- tests/test_mint_operations.py | 2 +- tests/test_wallet.py | 4 +- 18 files changed, 184 insertions(+), 137 deletions(-) diff --git a/cashu/core/base.py b/cashu/core/base.py index 88099a62..7cf0598f 100644 --- a/cashu/core/base.py +++ b/cashu/core/base.py @@ -101,12 +101,12 @@ class Proof(BaseModel): time_created: Union[None, str] = "" time_reserved: Union[None, str] = "" derivation_path: Union[None, str] = "" # derivation path of the proof - mint_id: Union[ - None, str - ] = None # holds the id of the mint operation that created this proof - melt_id: Union[ - None, str - ] = None # holds the id of the melt operation that destroyed this proof + mint_id: Union[None, str] = ( + None # holds the id of the mint operation that created this proof + ) + melt_id: Union[None, str] = ( + None # holds the id of the melt operation that destroyed this proof + ) def __init__(self, **data): super().__init__(**data) @@ -307,6 +307,7 @@ class MintMeltMethodSetting(BaseModel): unit: str min_amount: Optional[int] = None max_amount: Optional[int] = None + mpp: Optional[bool] = None class GetInfoResponse(BaseModel): diff --git a/cashu/core/settings.py b/cashu/core/settings.py index 1c0ee68b..83ef9f07 100644 --- a/cashu/core/settings.py +++ b/cashu/core/settings.py @@ -179,6 +179,7 @@ class LndRestFundingSource(MintSettings): mint_lnd_rest_macaroon: Optional[str] = Field(default=None) mint_lnd_rest_admin_macaroon: Optional[str] = Field(default=None) mint_lnd_rest_invoice_macaroon: Optional[str] = Field(default=None) + mint_lnd_enable_mpp_experimental: bool = Field(default=False) class CoreLightningRestFundingSource(MintSettings): diff --git a/cashu/lightning/base.py b/cashu/lightning/base.py index 6d7ddd99..8d35128e 100644 --- a/cashu/lightning/base.py +++ b/cashu/lightning/base.py @@ -3,7 +3,12 @@ from pydantic import BaseModel -from ..core.base import Amount, MeltQuote, Unit +from ..core.base import ( + Amount, + MeltQuote, + PostMeltQuoteRequest, + Unit, +) class StatusResponse(BaseModel): @@ -108,8 +113,7 @@ def get_payment_status( @abstractmethod async def get_payment_quote( self, - bolt11: str, - amount: Optional[Amount] = None, + melt_quote: PostMeltQuoteRequest, ) -> PaymentQuoteResponse: pass diff --git a/cashu/lightning/blink.py b/cashu/lightning/blink.py index 5c9f0dc4..e7ed2c60 100644 --- a/cashu/lightning/blink.py +++ b/cashu/lightning/blink.py @@ -11,7 +11,7 @@ ) from loguru import logger -from ..core.base import Amount, MeltQuote, Unit +from ..core.base import Amount, MeltQuote, PostMeltQuoteRequest, Unit from ..core.settings import settings from .base import ( InvoiceResponse, @@ -375,7 +375,10 @@ async def get_payment_status(self, checking_id: str) -> PaymentStatus: preimage=preimage, ) - async def get_payment_quote(self, bolt11: str) -> PaymentQuoteResponse: + async def get_payment_quote( + self, melt_quote: PostMeltQuoteRequest + ) -> PaymentQuoteResponse: + bolt11 = melt_quote.request variables = { "input": { "paymentRequest": bolt11, diff --git a/cashu/lightning/corelightningrest.py b/cashu/lightning/corelightningrest.py index da36cdc1..d1ffb23b 100644 --- a/cashu/lightning/corelightningrest.py +++ b/cashu/lightning/corelightningrest.py @@ -10,7 +10,7 @@ ) from loguru import logger -from ..core.base import Amount, MeltQuote, Unit +from ..core.base import Amount, MeltQuote, PostMeltQuoteRequest, Unit from ..core.helpers import fee_reserve from ..core.settings import settings from .base import ( @@ -312,7 +312,10 @@ async def paid_invoices_stream(self) -> AsyncGenerator[str, None]: ) await asyncio.sleep(0.02) - async def get_payment_quote(self, bolt11: str) -> PaymentQuoteResponse: + async def get_payment_quote( + self, melt_quote: PostMeltQuoteRequest + ) -> PaymentQuoteResponse: + bolt11 = melt_quote.request invoice_obj = decode(bolt11) assert invoice_obj.amount_msat, "invoice has no amount." amount_msat = int(invoice_obj.amount_msat) diff --git a/cashu/lightning/fake.py b/cashu/lightning/fake.py index f4c0f018..6ae85784 100644 --- a/cashu/lightning/fake.py +++ b/cashu/lightning/fake.py @@ -15,7 +15,7 @@ encode, ) -from ..core.base import Amount, MeltQuote, Unit +from ..core.base import Amount, MeltQuote, PostMeltQuoteRequest, Unit from ..core.helpers import fee_reserve from ..core.settings import settings from .base import ( @@ -152,7 +152,10 @@ async def paid_invoices_stream(self) -> AsyncGenerator[str, None]: # amount = invoice_obj.amount_msat # return InvoiceQuoteResponse(checking_id="", amount=amount) - async def get_payment_quote(self, bolt11: str) -> PaymentQuoteResponse: + async def get_payment_quote( + self, melt_quote: PostMeltQuoteRequest + ) -> PaymentQuoteResponse: + bolt11 = melt_quote.request invoice_obj = decode(bolt11) assert invoice_obj.amount_msat, "invoice has no amount." diff --git a/cashu/lightning/lnbits.py b/cashu/lightning/lnbits.py index 96dff6bb..b24cf74b 100644 --- a/cashu/lightning/lnbits.py +++ b/cashu/lightning/lnbits.py @@ -6,7 +6,7 @@ decode, ) -from ..core.base import Amount, MeltQuote, Unit +from ..core.base import Amount, MeltQuote, PostMeltQuoteRequest, Unit from ..core.helpers import fee_reserve from ..core.settings import settings from .base import ( @@ -157,7 +157,10 @@ async def get_payment_status(self, checking_id: str) -> PaymentStatus: preimage=data["preimage"], ) - async def get_payment_quote(self, bolt11: str) -> PaymentQuoteResponse: + async def get_payment_quote( + self, melt_quote: PostMeltQuoteRequest + ) -> PaymentQuoteResponse: + bolt11 = melt_quote.request invoice_obj = decode(bolt11) assert invoice_obj.amount_msat, "invoice has no amount." amount_msat = int(invoice_obj.amount_msat) diff --git a/cashu/lightning/lndrest.py b/cashu/lightning/lndrest.py index 970dc0bd..eab97b15 100644 --- a/cashu/lightning/lndrest.py +++ b/cashu/lightning/lndrest.py @@ -12,7 +12,7 @@ ) from loguru import logger -from ..core.base import Amount, MeltQuote, Unit +from ..core.base import Amount, MeltQuote, PostMeltQuoteRequest, Unit from ..core.helpers import fee_reserve from ..core.settings import settings from .base import ( @@ -29,7 +29,7 @@ class LndRestWallet(LightningBackend): """https://api.lightning.community/rest/index.html#lnd-rest-api-reference""" - supports_mpp = True + supports_mpp = settings.mint_lnd_enable_mpp_experimental supported_units = set([Unit.sat, Unit.msat]) unit = Unit.sat @@ -73,6 +73,8 @@ def __init__(self, unit: Unit = Unit.sat, **kwargs): self.client = httpx.AsyncClient( base_url=self.endpoint, headers=self.auth, verify=self.cert ) + if self.supports_mpp: + logger.info("LNDRestWallet enabling MPP experimental feature") async def status(self) -> StatusResponse: try: @@ -363,8 +365,15 @@ async def paid_invoices_stream(self) -> AsyncGenerator[str, None]: await asyncio.sleep(5) async def get_payment_quote( - self, bolt11: str, amount: Optional[Amount] = None + self, melt_quote: PostMeltQuoteRequest ) -> PaymentQuoteResponse: + # get amount from melt_quote or from bolt11 + amount = ( + Amount(Unit(melt_quote.unit), melt_quote.amount) + if melt_quote.amount + else None + ) + invoice_obj = decode(bolt11) assert invoice_obj.amount_msat, "invoice has no amount." diff --git a/cashu/lightning/strike.py b/cashu/lightning/strike.py index 1824c790..7149a582 100644 --- a/cashu/lightning/strike.py +++ b/cashu/lightning/strike.py @@ -4,7 +4,7 @@ import httpx -from ..core.base import Amount, MeltQuote, Unit +from ..core.base import Amount, MeltQuote, PostMeltQuoteRequest, Unit from ..core.settings import settings from .base import ( InvoiceResponse, @@ -118,7 +118,10 @@ async def create_invoice( error_message=None, ) - async def get_payment_quote(self, bolt11: str) -> PaymentQuoteResponse: + async def get_payment_quote( + self, melt_quote: PostMeltQuoteRequest + ) -> PaymentQuoteResponse: + bolt11 = melt_quote.request try: r = await self.client.post( url=f"{self.endpoint}/v1/payment-quotes/lightning", diff --git a/cashu/mint/ledger.py b/cashu/mint/ledger.py index d66ed4f4..2cd21e8d 100644 --- a/cashu/mint/ledger.py +++ b/cashu/mint/ledger.py @@ -505,9 +505,8 @@ async def melt_quote( ) else: # not internal, get quote by backend - amount = Amount(unit, melt_quote.amount) if melt_quote.amount else None payment_quote = await self.backends[method][unit].get_payment_quote( - melt_quote.request, amount=amount + melt_quote=melt_quote ) assert payment_quote.checking_id, "quote has no checking id" # make sure the backend returned the amount with a correct unit diff --git a/cashu/wallet/api/router.py b/cashu/wallet/api/router.py index bf8a0576..611ceaa9 100644 --- a/cashu/wallet/api/router.py +++ b/cashu/wallet/api/router.py @@ -189,7 +189,7 @@ async def swap( # pay invoice from outgoing mint await outgoing_wallet.load_proofs(reload=True) - quote = await outgoing_wallet.get_pay_amount_with_fees(invoice.bolt11) + quote = await outgoing_wallet.request_melt(invoice.bolt11) total_amount = quote.amount + quote.fee_reserve if outgoing_wallet.available_balance < total_amount: raise Exception("balance too low") @@ -197,7 +197,7 @@ async def swap( _, send_proofs = await outgoing_wallet.split_to_send( outgoing_wallet.proofs, total_amount, set_reserved=True ) - await outgoing_wallet.pay_lightning( + await outgoing_wallet.melt( send_proofs, invoice.bolt11, quote.fee_reserve, quote.quote ) diff --git a/cashu/wallet/cli/cli.py b/cashu/wallet/cli/cli.py index 671ec7cb..aa638485 100644 --- a/cashu/wallet/cli/cli.py +++ b/cashu/wallet/cli/cli.py @@ -177,17 +177,23 @@ async def cli(ctx: Context, host: str, walletname: str, unit: str, tests: bool): @cli.command("pay", help="Pay Lightning invoice.") @click.argument("invoice", type=str) -@click.argument("amount", type=int, required=False) +@click.argument( + "amount", + type=int, + required=False, +) @click.option( "--yes", "-y", default=False, is_flag=True, help="Skip confirmation.", type=bool ) @click.pass_context @coro -async def pay(ctx: Context, invoice: str, amount: Optional[int], yes: bool): +async def pay( + ctx: Context, invoice: str, amount: Optional[int] = None, yes: bool = False +): wallet: Wallet = ctx.obj["WALLET"] await wallet.load_mint() await print_balance(ctx) - quote = await wallet.get_pay_amount_with_fees(invoice, amount) + quote = await wallet.request_melt(invoice, amount) logger.debug(f"Quote: {quote}") total_amount = quote.amount + quote.fee_reserve if not yes: @@ -210,7 +216,7 @@ async def pay(ctx: Context, invoice: str, amount: Optional[int], yes: bool): return _, send_proofs = await wallet.split_to_send(wallet.proofs, total_amount) try: - melt_response = await wallet.pay_lightning( + melt_response = await wallet.melt( send_proofs, invoice, quote.fee_reserve, quote.quote ) except Exception as e: @@ -335,14 +341,14 @@ async def swap(ctx: Context): invoice = await incoming_wallet.request_mint(amount) # pay invoice from outgoing mint - quote = await outgoing_wallet.get_pay_amount_with_fees(invoice.bolt11) + quote = await outgoing_wallet.request_melt(invoice.bolt11) total_amount = quote.amount + quote.fee_reserve if outgoing_wallet.available_balance < total_amount: raise Exception("balance too low") _, send_proofs = await outgoing_wallet.split_to_send( outgoing_wallet.proofs, total_amount, set_reserved=True ) - await outgoing_wallet.pay_lightning( + await outgoing_wallet.melt( send_proofs, invoice.bolt11, quote.fee_reserve, quote.quote ) diff --git a/cashu/wallet/lightning/lightning.py b/cashu/wallet/lightning/lightning.py index c4b17d0b..6b23be5e 100644 --- a/cashu/wallet/lightning/lightning.py +++ b/cashu/wallet/lightning/lightning.py @@ -55,7 +55,7 @@ async def pay_invoice(self, pr: str) -> PaymentResponse: Returns: bool: True if successful """ - quote = await self.get_pay_amount_with_fees(pr) + quote = await self.request_melt(pr) total_amount = quote.amount + quote.fee_reserve assert total_amount > 0, "amount is not positive" if self.available_balance < total_amount: @@ -63,9 +63,7 @@ async def pay_invoice(self, pr: str) -> PaymentResponse: return PaymentResponse(ok=False) _, send_proofs = await self.split_to_send(self.proofs, total_amount) try: - resp = await self.pay_lightning( - send_proofs, pr, quote.fee_reserve, quote.quote - ) + resp = await self.melt(send_proofs, pr, quote.fee_reserve, quote.quote) if resp.change: fees_paid_sat = quote.fee_reserve - sum_promises(resp.change) else: diff --git a/cashu/wallet/wallet.py b/cashu/wallet/wallet.py index 0e924a16..c91c0f6e 100644 --- a/cashu/wallet/wallet.py +++ b/cashu/wallet/wallet.py @@ -595,7 +595,7 @@ def _meltrequest_include_fields( if resp.status_code == 404: invoice = await get_lightning_invoice(id=quote, db=self.db) assert invoice, f"no invoice found for id {quote}" - ret: PostMeltResponse_deprecated = await self.pay_lightning_deprecated( + ret: PostMeltResponse_deprecated = await self.melt_deprecated( proofs=proofs, outputs=outputs, invoice=invoice.bolt11 ) return PostMeltResponse( @@ -820,82 +820,6 @@ async def load_keysets(self) -> None: for keyset in keysets: self.keysets[keyset.id] = keyset - async def request_mint(self, amount: int) -> Invoice: - """Request a Lightning invoice for minting tokens. - - Args: - amount (int): Amount for Lightning invoice in satoshis - - Returns: - Invoice: Lightning invoice - """ - invoice = await super().mint_quote(amount) - await store_lightning_invoice(db=self.db, invoice=invoice) - return invoice - - async def mint( - self, - amount: int, - id: str, - split: Optional[List[int]] = None, - ) -> List[Proof]: - """Mint tokens of a specific amount after an invoice has been paid. - - Args: - amount (int): Total amount of tokens to be minted - id (str): Id for looking up the paid Lightning invoice. - split (Optional[List[str]], optional): List of desired amount splits to be minted. Total must sum to `amount`. - - Raises: - Exception: Raises exception if `amounts` does not sum to `amount` or has unsupported value. - Exception: Raises exception if no proofs have been provided - - Returns: - List[Proof]: Newly minted proofs. - """ - # specific split - if split: - logger.trace(f"Mint with split: {split}") - assert sum(split) == amount, "split must sum to amount" - allowed_amounts = [2**i for i in range(settings.max_order)] - for a in split: - if a not in allowed_amounts: - raise Exception( - f"Can only mint amounts with 2^n up to {2**settings.max_order}." - ) - - # if no split was specified, we use the canonical split - amounts = split or amount_split(amount) - - # quirk: we skip bumping the secret counter in the database since we are - # not sure if the minting will succeed. If it succeeds, we will bump it - # in the next step. - secrets, rs, derivation_paths = await self.generate_n_secrets( - len(amounts), skip_bump=True - ) - await self._check_used_secrets(secrets) - outputs, rs = self._construct_outputs(amounts, secrets, rs) - - # will raise exception if mint is unsuccessful - promises = await super().mint(outputs, id) - - promises_keyset_id = promises[0].id - await bump_secret_derivation( - db=self.db, keyset_id=promises_keyset_id, by=len(amounts) - ) - proofs = await self._construct_proofs(promises, secrets, rs, derivation_paths) - - if id: - await update_lightning_invoice( - db=self.db, id=id, paid=True, time_paid=int(time.time()) - ) - # store the mint_id in proofs - async with self.db.connect() as conn: - for p in proofs: - p.mint_id = id - await update_proof(p, mint_id=id, conn=conn) - return proofs - async def redeem( self, proofs: List[Proof], @@ -991,7 +915,95 @@ async def split( send_proofs = new_proofs[len(frst_outputs) :] return keep_proofs, send_proofs - async def pay_lightning( + async def request_mint(self, amount: int) -> Invoice: + """Request a Lightning invoice for minting tokens. + + Args: + amount (int): Amount for Lightning invoice in satoshis + + Returns: + Invoice: Lightning invoice + """ + invoice = await super().mint_quote(amount) + await store_lightning_invoice(db=self.db, invoice=invoice) + return invoice + + async def mint( + self, + amount: int, + id: str, + split: Optional[List[int]] = None, + ) -> List[Proof]: + """Mint tokens of a specific amount after an invoice has been paid. + + Args: + amount (int): Total amount of tokens to be minted + id (str): Id for looking up the paid Lightning invoice. + split (Optional[List[str]], optional): List of desired amount splits to be minted. Total must sum to `amount`. + + Raises: + Exception: Raises exception if `amounts` does not sum to `amount` or has unsupported value. + Exception: Raises exception if no proofs have been provided + + Returns: + List[Proof]: Newly minted proofs. + """ + # specific split + if split: + logger.trace(f"Mint with split: {split}") + assert sum(split) == amount, "split must sum to amount" + allowed_amounts = [2**i for i in range(settings.max_order)] + for a in split: + if a not in allowed_amounts: + raise Exception( + f"Can only mint amounts with 2^n up to {2**settings.max_order}." + ) + + # if no split was specified, we use the canonical split + amounts = split or amount_split(amount) + + # quirk: we skip bumping the secret counter in the database since we are + # not sure if the minting will succeed. If it succeeds, we will bump it + # in the next step. + secrets, rs, derivation_paths = await self.generate_n_secrets( + len(amounts), skip_bump=True + ) + await self._check_used_secrets(secrets) + outputs, rs = self._construct_outputs(amounts, secrets, rs) + + # will raise exception if mint is unsuccessful + promises = await super().mint(outputs, id) + + promises_keyset_id = promises[0].id + await bump_secret_derivation( + db=self.db, keyset_id=promises_keyset_id, by=len(amounts) + ) + proofs = await self._construct_proofs(promises, secrets, rs, derivation_paths) + + if id: + await update_lightning_invoice( + db=self.db, id=id, paid=True, time_paid=int(time.time()) + ) + # store the mint_id in proofs + async with self.db.connect() as conn: + for p in proofs: + p.mint_id = id + await update_proof(p, mint_id=id, conn=conn) + return proofs + + async def request_melt( + self, invoice: str, amount: Optional[int] = None + ) -> PostMeltQuoteResponse: + """ + Fetches a melt quote from the mint and either uses the amount in the invoice or the amount provided. + """ + melt_quote = await self.melt_quote(invoice, amount) + logger.debug( + f"Mint wants {self.unit.str(melt_quote.fee_reserve)} as fee reserve." + ) + return melt_quote + + async def melt( self, proofs: List[Proof], invoice: str, fee_reserve_sat: int, quote_id: str ) -> PostMeltResponse: """Pays a lightning invoice and returns the status of the payment. @@ -1524,19 +1536,6 @@ async def invalidate( # ---------- TRANSACTION HELPERS ---------- - async def get_pay_amount_with_fees( - self, invoice: str, amount: Optional[int] = None - ) -> PostMeltQuoteResponse: - """ - Decodes the amount from a Lightning invoice and returns the - total amount (amount+fees) to be paid. - """ - melt_quote = await self.melt_quote(invoice, amount) - logger.debug( - f"Mint wants {self.unit.str(melt_quote.fee_reserve)} as fee reserve." - ) - return melt_quote - async def split_to_send( self, proofs: List[Proof], diff --git a/cashu/wallet/wallet_deprecated.py b/cashu/wallet/wallet_deprecated.py index db5e927a..ea84aa2a 100644 --- a/cashu/wallet/wallet_deprecated.py +++ b/cashu/wallet/wallet_deprecated.py @@ -300,7 +300,7 @@ def _mintrequest_include_fields(outputs: List[BlindedMessage]): @async_set_httpx_client @async_ensure_mint_loaded_deprecated - async def pay_lightning_deprecated( + async def melt_deprecated( self, proofs: List[Proof], invoice: str, outputs: Optional[List[BlindedMessage]] ): """ diff --git a/tests/test_mint_lightning_blink.py b/tests/test_mint_lightning_blink.py index 85312e15..f4d882f3 100644 --- a/tests/test_mint_lightning_blink.py +++ b/tests/test_mint_lightning_blink.py @@ -2,7 +2,7 @@ import respx from httpx import Response -from cashu.core.base import Amount, MeltQuote, Unit +from cashu.core.base import Amount, MeltQuote, PostMeltQuoteRequest, Unit from cashu.core.settings import settings from cashu.lightning.blink import MINIMUM_FEE_MSAT, BlinkWallet @@ -192,7 +192,10 @@ async def test_blink_get_payment_quote(): # response says 1 sat fees but invoice (1000 sat) * 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) + melt_quote_request = PostMeltQuoteRequest( + unit=Unit.sat.name, request=payment_request + ) + quote = await blink.get_payment_quote(melt_quote_request) assert quote.checking_id == payment_request assert quote.amount == Amount(Unit.sat, 1000) # sat assert quote.fee == Amount(Unit.sat, 5) # sat @@ -200,7 +203,10 @@ async def test_blink_get_payment_quote(): # response says 10 sat fees but invoice (1000 sat) * 0.5% is 5 sat so we expect 10 sat mock_response = {"data": {"lnInvoiceFeeProbe": {"amount": 10}}} respx.post(blink.endpoint).mock(return_value=Response(200, json=mock_response)) - quote = await blink.get_payment_quote(payment_request) + melt_quote_request = PostMeltQuoteRequest( + unit=Unit.sat.name, request=payment_request + ) + quote = await blink.get_payment_quote(melt_quote_request) assert quote.checking_id == payment_request assert quote.amount == Amount(Unit.sat, 1000) # sat assert quote.fee == Amount(Unit.sat, 10) # sat @@ -208,7 +214,10 @@ async def test_blink_get_payment_quote(): # response says 10 sat fees but invoice (4973 sat) * 0.5% is 24.865 sat so we expect 25 sat mock_response = {"data": {"lnInvoiceFeeProbe": {"amount": 10}}} respx.post(blink.endpoint).mock(return_value=Response(200, json=mock_response)) - quote = await blink.get_payment_quote(payment_request_4973) + melt_quote_request_4973 = PostMeltQuoteRequest( + unit=Unit.sat.name, request=payment_request_4973 + ) + quote = await blink.get_payment_quote(melt_quote_request_4973) assert quote.checking_id == payment_request_4973 assert quote.amount == Amount(Unit.sat, 4973) # sat assert quote.fee == Amount(Unit.sat, 25) # sat @@ -216,7 +225,10 @@ async def test_blink_get_payment_quote(): # response says 0 sat fees but invoice (1 sat) * 0.5% is 0.005 sat so we expect MINIMUM_FEE_MSAT/1000 sat mock_response = {"data": {"lnInvoiceFeeProbe": {"amount": 0}}} respx.post(blink.endpoint).mock(return_value=Response(200, json=mock_response)) - quote = await blink.get_payment_quote(payment_request_1) + melt_quote_request_1 = PostMeltQuoteRequest( + unit=Unit.sat.name, request=payment_request_1 + ) + quote = await blink.get_payment_quote(melt_quote_request_1) assert quote.checking_id == payment_request_1 assert quote.amount == Amount(Unit.sat, 1) # sat assert quote.fee == Amount(Unit.sat, MINIMUM_FEE_MSAT // 1000) # msat @@ -228,7 +240,10 @@ async def test_blink_get_payment_quote_backend_error(): # response says error but invoice (1000 sat) * 0.5% is 5 sat so we expect 10 sat mock_response = {"data": {"lnInvoiceFeeProbe": {"errors": [{"message": "error"}]}}} respx.post(blink.endpoint).mock(return_value=Response(200, json=mock_response)) - quote = await blink.get_payment_quote(payment_request) + melt_quote_request = PostMeltQuoteRequest( + unit=Unit.sat.name, request=payment_request + ) + quote = await blink.get_payment_quote(melt_quote_request) assert quote.checking_id == payment_request assert quote.amount == Amount(Unit.sat, 1000) # sat assert quote.fee == Amount(Unit.sat, 5) # sat diff --git a/tests/test_mint_operations.py b/tests/test_mint_operations.py index faa58df5..22c44f18 100644 --- a/tests/test_mint_operations.py +++ b/tests/test_mint_operations.py @@ -73,7 +73,7 @@ async def test_melt_external(wallet1: Wallet, ledger: Ledger): invoice_dict = get_real_invoice(64) invoice_payment_request = invoice_dict["payment_request"] - mint_quote = await wallet1.get_pay_amount_with_fees(invoice_payment_request) + mint_quote = await wallet1.get_melt_quote(invoice_payment_request) total_amount = mint_quote.amount + mint_quote.fee_reserve keep_proofs, send_proofs = await wallet1.split_to_send(wallet1.proofs, total_amount) melt_quote = await ledger.melt_quote( diff --git a/tests/test_wallet.py b/tests/test_wallet.py index 78195f6d..60401a5e 100644 --- a/tests/test_wallet.py +++ b/tests/test_wallet.py @@ -274,7 +274,7 @@ async def test_melt(wallet1: Wallet): invoice_payment_hash = str(invoice.payment_hash) invoice_payment_request = invoice.bolt11 - quote = await wallet1.get_pay_amount_with_fees(invoice_payment_request) + quote = await wallet1.request_melt(invoice_payment_request) total_amount = quote.amount + quote.fee_reserve if is_regtest: @@ -288,7 +288,7 @@ async def test_melt(wallet1: Wallet): _, send_proofs = await wallet1.split_to_send(wallet1.proofs, total_amount) - melt_response = await wallet1.pay_lightning( + melt_response = await wallet1.melt( proofs=send_proofs, invoice=invoice_payment_request, fee_reserve_sat=quote.fee_reserve,