diff --git a/cashu/wallet/api/router.py b/cashu/wallet/api/router.py index 0065a50d..f5c771f6 100644 --- a/cashu/wallet/api/router.py +++ b/cashu/wallet/api/router.py @@ -194,7 +194,7 @@ async def swap( if outgoing_wallet.available_balance < total_amount: raise Exception("balance too low") - _, send_proofs = await outgoing_wallet.split_to_send( + _, send_proofs = await outgoing_wallet.swap_to_send( outgoing_wallet.proofs, total_amount, set_reserved=True ) await outgoing_wallet.melt( diff --git a/cashu/wallet/cli/cli.py b/cashu/wallet/cli/cli.py index 2a39a41f..c9b81cc3 100644 --- a/cashu/wallet/cli/cli.py +++ b/cashu/wallet/cli/cli.py @@ -548,6 +548,14 @@ async def balance(ctx: Context, verbose): help="Include fees for receiving token.", type=bool, ) +@click.option( + "--force-swap", + "-s", + default=False, + is_flag=True, + help="Force swap token.", + type=bool, +) @click.pass_context @coro async def send_command( @@ -562,6 +570,7 @@ async def send_command( yes: bool, offline: bool, include_fees: bool, + force_swap: bool, ): wallet: Wallet = ctx.obj["WALLET"] amount = int(amount * 100) if wallet.unit in [Unit.usd, Unit.eur] else int(amount) @@ -575,6 +584,7 @@ async def send_command( include_dleq=dleq, include_fees=include_fees, memo=memo, + force_swap=force_swap, ) else: await send_nostr(wallet, amount=amount, pubkey=nostr, verbose=verbose, yes=yes) diff --git a/cashu/wallet/helpers.py b/cashu/wallet/helpers.py index 834be839..627423d4 100644 --- a/cashu/wallet/helpers.py +++ b/cashu/wallet/helpers.py @@ -116,6 +116,7 @@ async def send( include_dleq: bool = False, include_fees: bool = False, memo: Optional[str] = None, + force_swap: bool = False, ): """ Prints token to send to stdout. @@ -144,13 +145,12 @@ async def send( await wallet.load_proofs() await wallet.load_mint() - if secret_lock: - _, send_proofs = await wallet.split_to_send( + if secret_lock or force_swap: + _, send_proofs = await wallet.swap_to_send( wallet.proofs, amount, set_reserved=False, # we set reserved later secret_lock=secret_lock, - include_fees=include_fees, ) else: send_proofs, fees = await wallet.select_to_send( diff --git a/cashu/wallet/lightning/lightning.py b/cashu/wallet/lightning/lightning.py index be6ef103..56ab06aa 100644 --- a/cashu/wallet/lightning/lightning.py +++ b/cashu/wallet/lightning/lightning.py @@ -61,7 +61,7 @@ async def pay_invoice(self, pr: str) -> PaymentResponse: if self.available_balance < total_amount: print("Error: Balance too low.") return PaymentResponse(ok=False) - _, send_proofs = await self.split_to_send(self.proofs, total_amount) + _, send_proofs = await self.swap_to_send(self.proofs, total_amount) try: resp = await self.melt(send_proofs, pr, quote.fee_reserve, quote.quote) if resp.change: diff --git a/cashu/wallet/nostr.py b/cashu/wallet/nostr.py index 217ed95a..bb989d03 100644 --- a/cashu/wallet/nostr.py +++ b/cashu/wallet/nostr.py @@ -62,7 +62,7 @@ async def send_nostr( pubkey = await nip5_to_pubkey(wallet, pubkey) await wallet.load_mint() await wallet.load_proofs() - _, send_proofs = await wallet.split_to_send( + _, send_proofs = await wallet.swap_to_send( wallet.proofs, amount, set_reserved=True, include_fees=False ) token = await wallet.serialize_proofs(send_proofs, include_dleq=include_dleq) diff --git a/cashu/wallet/proofs.py b/cashu/wallet/proofs.py index ae8b839c..c0169e18 100644 --- a/cashu/wallet/proofs.py +++ b/cashu/wallet/proofs.py @@ -148,6 +148,7 @@ async def serialize_proofs( try: _ = [bytes.fromhex(p.id) for p in proofs] except ValueError: + logger.debug("Proof with base64 keyset, using legacy token serialization") legacy = True if legacy: diff --git a/cashu/wallet/transactions.py b/cashu/wallet/transactions.py index 94c47c54..78251488 100644 --- a/cashu/wallet/transactions.py +++ b/cashu/wallet/transactions.py @@ -36,55 +36,63 @@ def get_fees_for_proofs(self, proofs: List[Proof]) -> int: def get_fees_for_proofs_ppk(self, proofs: List[Proof]) -> int: return sum([self.keysets[p.id].input_fee_ppk for p in proofs]) - async def _select_proofs_to_send_( - self, proofs: List[Proof], amount_to_send: int, tolerance: int = 0 - ) -> List[Proof]: - send_proofs: List[Proof] = [] - NO_SELECTION: List[Proof] = [] - - logger.trace(f"proofs: {[p.amount for p in proofs]}") - # sort proofs by amount (descending) - sorted_proofs = sorted(proofs, key=lambda p: p.amount, reverse=True) - # only consider proofs smaller than the amount we want to send (+ tolerance) for coin selection - fee_for_single_proof = self.get_fees_for_proofs([sorted_proofs[0]]) - sorted_proofs = [ - p - for p in sorted_proofs - if p.amount <= amount_to_send + tolerance + fee_for_single_proof - ] - if not sorted_proofs: - logger.info( - f"no small-enough proofs to send. Have: {[p.amount for p in proofs]}" - ) - return NO_SELECTION - - target_amount = amount_to_send - - # compose the target amount from the remaining_proofs - logger.debug(f"sorted_proofs: {[p.amount for p in sorted_proofs]}") - for p in sorted_proofs: - # logger.debug(f"send_proofs: {[p.amount for p in send_proofs]}") - # logger.debug(f"target_amount: {target_amount}") - # logger.debug(f"p.amount: {p.amount}") - if sum_proofs(send_proofs) + p.amount <= target_amount + tolerance: - send_proofs.append(p) - target_amount = amount_to_send + self.get_fees_for_proofs(send_proofs) - - if sum_proofs(send_proofs) < amount_to_send: - logger.info("could not select proofs to reach target amount (too little).") - return NO_SELECTION - - fees = self.get_fees_for_proofs(send_proofs) - logger.debug(f"Selected sum of proofs: {sum_proofs(send_proofs)}, fees: {fees}") - return send_proofs + # async def _select_proofs_to_send_legacy( + # self, proofs: List[Proof], amount_to_send: int, tolerance: int = 0 + # ) -> List[Proof]: + # send_proofs: List[Proof] = [] + # NO_SELECTION: List[Proof] = [] + + # logger.trace(f"proofs: {[p.amount for p in proofs]}") + # # sort proofs by amount (descending) + # sorted_proofs = sorted(proofs, key=lambda p: p.amount, reverse=True) + # # only consider proofs smaller than the amount we want to send (+ tolerance) for coin selection + # fee_for_single_proof = self.get_fees_for_proofs([sorted_proofs[0]]) + # sorted_proofs = [ + # p + # for p in sorted_proofs + # if p.amount <= amount_to_send + tolerance + fee_for_single_proof + # ] + # if not sorted_proofs: + # logger.info( + # f"no small-enough proofs to send. Have: {[p.amount for p in proofs]}" + # ) + # return NO_SELECTION + + # target_amount = amount_to_send + + # # compose the target amount from the remaining_proofs + # logger.debug(f"sorted_proofs: {[p.amount for p in sorted_proofs]}") + # for p in sorted_proofs: + # if sum_proofs(send_proofs) + p.amount <= target_amount + tolerance: + # send_proofs.append(p) + # target_amount = amount_to_send + self.get_fees_for_proofs(send_proofs) + + # if sum_proofs(send_proofs) < amount_to_send: + # logger.info("could not select proofs to reach target amount (too little).") + # return NO_SELECTION + + # fees = self.get_fees_for_proofs(send_proofs) + # logger.debug(f"Selected sum of proofs: {sum_proofs(send_proofs)}, fees: {fees}") + # return send_proofs async def _select_proofs_to_send( self, proofs: List[Proof], amount_to_send: Union[int, float], *, - include_fees: bool = True, + include_fees: bool = False, ) -> List[Proof]: + """Select proofs to send based on the amount to send and the proofs available. Implements a simple coin selection algorithm. + Can be used for selecting proofs to send an offline transaction. + + Args: + proofs (List[Proof]): List of proofs to select from + amount_to_send (Union[int, float]): Amount to select proofs for + include_fees (bool, optional): Whether to include fees necessary to redeem the tokens in the selection. Defaults to False. + + Returns: + List[Proof]: _description_ + """ # check that enough spendable proofs exist if sum_proofs(proofs) < amount_to_send: return [] @@ -147,9 +155,8 @@ async def _select_proofs_to_split( Rules: 1) Proofs that are not marked as reserved - 2) Proofs that have a different keyset than the activated keyset_id of the mint - 3) Include all proofs that have an older keyset than the current keyset of the mint (to get rid of old epochs). - 4) If the target amount is not reached, add proofs of the current keyset until it is. + 2) Include all proofs from inactive keysets (old epochs) to get rid of them + 3) If the target amount is not reached, add proofs of the current keyset until it is. Args: proofs (List[Proof]): List of proofs to select from @@ -171,11 +178,9 @@ async def _select_proofs_to_split( if sum_proofs(proofs) < amount_to_send: raise Exception("balance too low.") - # add all proofs that have an older keyset than the current keyset of the mint - proofs_old_epochs = [ - p for p in proofs if p.id != self.keysets[self.keyset_id].id - ] - send_proofs += proofs_old_epochs + # add all proofs from inactive keysets + proofs_inactive_keysets = [p for p in proofs if not self.keysets[p.id].active] + send_proofs += proofs_inactive_keysets # coinselect based on amount only from the current keyset # start with the proofs with the largest amount and add them until the target amount is reached diff --git a/cashu/wallet/wallet.py b/cashu/wallet/wallet.py index ad0c2a97..d09bdcb8 100644 --- a/cashu/wallet/wallet.py +++ b/cashu/wallet/wallet.py @@ -1049,7 +1049,7 @@ async def select_to_send( if not offline: logger.debug("Offline coin selection unsuccessful. Splitting proofs.") # we set the proofs as reserved later - _, send_proofs = await self.split_to_send( + _, send_proofs = await self.swap_to_send( proofs, amount, set_reserved=False ) else: @@ -1061,7 +1061,7 @@ async def select_to_send( await self.set_reserved(send_proofs, reserved=True) return send_proofs, fees - async def split_to_send( + async def swap_to_send( self, proofs: List[Proof], amount: int, diff --git a/tests/test_mint_api.py b/tests/test_mint_api.py index e1f69e29..494c27c5 100644 --- a/tests/test_mint_api.py +++ b/tests/test_mint_api.py @@ -422,7 +422,7 @@ async def test_melt_external(ledger: Ledger, wallet: Wallet): assert quote.amount == 62 assert quote.fee_reserve == 2 - keep, send = await wallet.split_to_send(wallet.proofs, 64) + keep, send = await wallet.swap_to_send(wallet.proofs, 64) inputs_payload = [p.to_dict() for p in send] # outputs for change diff --git a/tests/test_mint_init.py b/tests/test_mint_init.py index a33a6cf9..9c9ae7fa 100644 --- a/tests/test_mint_init.py +++ b/tests/test_mint_init.py @@ -252,7 +252,7 @@ async def test_startup_regtest_pending_quote_pending(wallet: Wallet, ledger: Led # wallet pays the invoice quote = await wallet.melt_quote(invoice_payment_request) total_amount = quote.amount + quote.fee_reserve - _, send_proofs = await wallet.split_to_send(wallet.proofs, total_amount) + _, send_proofs = await wallet.swap_to_send(wallet.proofs, total_amount) asyncio.create_task( wallet.melt( proofs=send_proofs, @@ -297,7 +297,7 @@ async def test_startup_regtest_pending_quote_success(wallet: Wallet, ledger: Led # wallet pays the invoice quote = await wallet.melt_quote(invoice_payment_request) total_amount = quote.amount + quote.fee_reserve - _, send_proofs = await wallet.split_to_send(wallet.proofs, total_amount) + _, send_proofs = await wallet.swap_to_send(wallet.proofs, total_amount) asyncio.create_task( wallet.melt( proofs=send_proofs, @@ -347,7 +347,7 @@ async def test_startup_regtest_pending_quote_failure(wallet: Wallet, ledger: Led # wallet pays the invoice quote = await wallet.melt_quote(invoice_payment_request) total_amount = quote.amount + quote.fee_reserve - _, send_proofs = await wallet.split_to_send(wallet.proofs, total_amount) + _, send_proofs = await wallet.swap_to_send(wallet.proofs, total_amount) asyncio.create_task( wallet.melt( proofs=send_proofs, diff --git a/tests/test_mint_operations.py b/tests/test_mint_operations.py index 518ae24a..23005653 100644 --- a/tests/test_mint_operations.py +++ b/tests/test_mint_operations.py @@ -60,7 +60,7 @@ async def test_melt_internal(wallet1: Wallet, ledger: Ledger): assert not melt_quote_pre_payment.paid, "melt quote should not be paid" assert melt_quote_pre_payment.state == MeltQuoteState.unpaid - keep_proofs, send_proofs = await wallet1.split_to_send(wallet1.proofs, 64) + keep_proofs, send_proofs = await wallet1.swap_to_send(wallet1.proofs, 64) await ledger.melt(proofs=send_proofs, quote=melt_quote.quote) melt_quote_post_payment = await ledger.get_melt_quote(melt_quote.quote) @@ -85,7 +85,7 @@ async def test_melt_external(wallet1: Wallet, ledger: Ledger): assert mint_quote.state == MeltQuoteState.unpaid.value total_amount = mint_quote.amount + mint_quote.fee_reserve - keep_proofs, send_proofs = await wallet1.split_to_send(wallet1.proofs, total_amount) + keep_proofs, send_proofs = await wallet1.swap_to_send(wallet1.proofs, total_amount) melt_quote = await ledger.melt_quote( PostMeltQuoteRequest(request=invoice_payment_request, unit="sat") ) @@ -169,7 +169,7 @@ async def test_split(wallet1: Wallet, ledger: Ledger): await pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) - keep_proofs, send_proofs = await wallet1.split_to_send(wallet1.proofs, 10) + keep_proofs, send_proofs = await wallet1.swap_to_send(wallet1.proofs, 10) secrets, rs, derivation_paths = await wallet1.generate_n_secrets(len(send_proofs)) outputs, rs = wallet1._construct_outputs( [p.amount for p in send_proofs], secrets, rs @@ -185,7 +185,7 @@ async def test_split_with_no_outputs(wallet1: Wallet, ledger: Ledger): invoice = await wallet1.request_mint(64) await pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) - _, send_proofs = await wallet1.split_to_send(wallet1.proofs, 10, set_reserved=False) + _, send_proofs = await wallet1.swap_to_send(wallet1.proofs, 10, set_reserved=False) await assert_err( ledger.split(proofs=send_proofs, outputs=[]), "no outputs provided", @@ -198,7 +198,7 @@ async def test_split_with_input_less_than_outputs(wallet1: Wallet, ledger: Ledge await pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) - keep_proofs, send_proofs = await wallet1.split_to_send( + keep_proofs, send_proofs = await wallet1.swap_to_send( wallet1.proofs, 10, set_reserved=False ) @@ -396,7 +396,7 @@ async def test_check_proof_state(wallet1: Wallet, ledger: Ledger): await pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) - keep_proofs, send_proofs = await wallet1.split_to_send(wallet1.proofs, 10) + keep_proofs, send_proofs = await wallet1.swap_to_send(wallet1.proofs, 10) proof_states = await ledger.db_read.get_proofs_states(Ys=[p.Y for p in send_proofs]) assert all([p.state.value == "UNSPENT" for p in proof_states]) diff --git a/tests/test_mint_regtest.py b/tests/test_mint_regtest.py index 8a934f0f..726dfcd5 100644 --- a/tests/test_mint_regtest.py +++ b/tests/test_mint_regtest.py @@ -43,7 +43,7 @@ async def test_regtest_pending_quote(wallet: Wallet, ledger: Ledger): # wallet pays the invoice quote = await wallet.melt_quote(invoice_payment_request) total_amount = quote.amount + quote.fee_reserve - _, send_proofs = await wallet.split_to_send(wallet.proofs, total_amount) + _, send_proofs = await wallet.swap_to_send(wallet.proofs, total_amount) asyncio.create_task(ledger.melt(proofs=send_proofs, quote=quote.quote)) # asyncio.create_task( # wallet.melt( diff --git a/tests/test_wallet.py b/tests/test_wallet.py index 78960908..8bb1a950 100644 --- a/tests/test_wallet.py +++ b/tests/test_wallet.py @@ -241,14 +241,14 @@ async def test_split(wallet1: Wallet): @pytest.mark.asyncio -async def test_split_to_send(wallet1: Wallet): +async def test_swap_to_send(wallet1: Wallet): invoice = await wallet1.request_mint(64) await pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) assert wallet1.balance == 64 # this will select 32 sats and them (nothing to keep) - keep_proofs, send_proofs = await wallet1.split_to_send( + keep_proofs, send_proofs = await wallet1.swap_to_send( wallet1.proofs, 32, set_reserved=True ) assert_amt(send_proofs, 32) @@ -307,7 +307,7 @@ async def test_melt(wallet1: Wallet): assert total_amount == 64 assert quote.fee_reserve == 0 - _, send_proofs = await wallet1.split_to_send(wallet1.proofs, total_amount) + _, send_proofs = await wallet1.swap_to_send(wallet1.proofs, total_amount) melt_response = await wallet1.melt( proofs=send_proofs, @@ -343,12 +343,12 @@ async def test_melt(wallet1: Wallet): @pytest.mark.asyncio -async def test_split_to_send_more_than_balance(wallet1: Wallet): +async def test_swap_to_send_more_than_balance(wallet1: Wallet): invoice = await wallet1.request_mint(64) await pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) await assert_err( - wallet1.split_to_send(wallet1.proofs, 128, set_reserved=True), + wallet1.swap_to_send(wallet1.proofs, 128, set_reserved=True), "balance too low.", ) assert wallet1.balance == 64 @@ -405,7 +405,7 @@ async def test_send_and_redeem(wallet1: Wallet, wallet2: Wallet): invoice = await wallet1.request_mint(64) await pay_if_regtest(invoice.bolt11) await wallet1.mint(64, id=invoice.id) - _, spendable_proofs = await wallet1.split_to_send( + _, spendable_proofs = await wallet1.swap_to_send( wallet1.proofs, 32, set_reserved=True ) await wallet2.redeem(spendable_proofs) diff --git a/tests/test_wallet_htlc.py b/tests/test_wallet_htlc.py index bda57263..0a36ecd1 100644 --- a/tests/test_wallet_htlc.py +++ b/tests/test_wallet_htlc.py @@ -74,7 +74,7 @@ async def test_htlc_split(wallet1: Wallet, wallet2: Wallet): preimage = "00000000000000000000000000000000" preimage_hash = hashlib.sha256(bytes.fromhex(preimage)).hexdigest() secret = await wallet1.create_htlc_lock(preimage=preimage) - _, send_proofs = await wallet1.split_to_send(wallet1.proofs, 8, secret_lock=secret) + _, send_proofs = await wallet1.swap_to_send(wallet1.proofs, 8, secret_lock=secret) for p in send_proofs: assert HTLCSecret.deserialize(p.secret).data == preimage_hash @@ -87,7 +87,7 @@ async def test_htlc_redeem_with_preimage(wallet1: Wallet, wallet2: Wallet): preimage = "00000000000000000000000000000000" # preimage_hash = hashlib.sha256(bytes.fromhex(preimage)).hexdigest() secret = await wallet1.create_htlc_lock(preimage=preimage) - _, send_proofs = await wallet1.split_to_send(wallet1.proofs, 8, secret_lock=secret) + _, send_proofs = await wallet1.swap_to_send(wallet1.proofs, 8, secret_lock=secret) for p in send_proofs: p.witness = HTLCWitness(preimage=preimage).json() await wallet2.redeem(send_proofs) @@ -103,7 +103,7 @@ async def test_htlc_redeem_with_wrong_preimage(wallet1: Wallet, wallet2: Wallet) secret = await wallet1.create_htlc_lock( preimage=preimage[:-5] + "11111" ) # wrong preimage - _, send_proofs = await wallet1.split_to_send(wallet1.proofs, 8, secret_lock=secret) + _, send_proofs = await wallet1.swap_to_send(wallet1.proofs, 8, secret_lock=secret) for p in send_proofs: p.witness = HTLCWitness(preimage=preimage).json() await assert_err( @@ -122,7 +122,7 @@ async def test_htlc_redeem_with_no_signature(wallet1: Wallet, wallet2: Wallet): secret = await wallet1.create_htlc_lock( preimage=preimage, hashlock_pubkey=pubkey_wallet1 ) - _, send_proofs = await wallet1.split_to_send(wallet1.proofs, 8, secret_lock=secret) + _, send_proofs = await wallet1.swap_to_send(wallet1.proofs, 8, secret_lock=secret) for p in send_proofs: p.witness = HTLCWitness(preimage=preimage).json() await assert_err( @@ -142,7 +142,7 @@ async def test_htlc_redeem_with_wrong_signature(wallet1: Wallet, wallet2: Wallet secret = await wallet1.create_htlc_lock( preimage=preimage, hashlock_pubkey=pubkey_wallet1 ) - _, send_proofs = await wallet1.split_to_send(wallet1.proofs, 8, secret_lock=secret) + _, send_proofs = await wallet1.swap_to_send(wallet1.proofs, 8, secret_lock=secret) signatures = await wallet1.sign_p2pk_proofs(send_proofs) for p, s in zip(send_proofs, signatures): p.witness = HTLCWitness( @@ -166,7 +166,7 @@ async def test_htlc_redeem_with_correct_signature(wallet1: Wallet, wallet2: Wall secret = await wallet1.create_htlc_lock( preimage=preimage, hashlock_pubkey=pubkey_wallet1 ) - _, send_proofs = await wallet1.split_to_send(wallet1.proofs, 8, secret_lock=secret) + _, send_proofs = await wallet1.swap_to_send(wallet1.proofs, 8, secret_lock=secret) signatures = await wallet1.sign_p2pk_proofs(send_proofs) for p, s in zip(send_proofs, signatures): @@ -192,7 +192,7 @@ async def test_htlc_redeem_hashlock_wrong_signature_timelock_correct_signature( locktime_seconds=2, locktime_pubkey=pubkey_wallet1, ) - _, send_proofs = await wallet1.split_to_send(wallet1.proofs, 8, secret_lock=secret) + _, send_proofs = await wallet1.swap_to_send(wallet1.proofs, 8, secret_lock=secret) signatures = await wallet1.sign_p2pk_proofs(send_proofs) for p, s in zip(send_proofs, signatures): @@ -226,7 +226,7 @@ async def test_htlc_redeem_hashlock_wrong_signature_timelock_wrong_signature( locktime_seconds=2, locktime_pubkey=pubkey_wallet1, ) - _, send_proofs = await wallet1.split_to_send(wallet1.proofs, 8, secret_lock=secret) + _, send_proofs = await wallet1.swap_to_send(wallet1.proofs, 8, secret_lock=secret) signatures = await wallet1.sign_p2pk_proofs(send_proofs) for p, s in zip(send_proofs, signatures): diff --git a/tests/test_wallet_p2pk.py b/tests/test_wallet_p2pk.py index ac236d5c..d3dcde53 100644 --- a/tests/test_wallet_p2pk.py +++ b/tests/test_wallet_p2pk.py @@ -74,7 +74,7 @@ async def test_p2pk(wallet1: Wallet, wallet2: Wallet): pubkey_wallet2 = await wallet2.create_p2pk_pubkey() # p2pk test secret_lock = await wallet1.create_p2pk_lock(pubkey_wallet2) # sender side - _, send_proofs = await wallet1.split_to_send( + _, send_proofs = await wallet1.swap_to_send( wallet1.proofs, 8, secret_lock=secret_lock ) await wallet2.redeem(send_proofs) @@ -100,7 +100,7 @@ async def test_p2pk_sig_all(wallet1: Wallet, wallet2: Wallet): secret_lock = await wallet1.create_p2pk_lock( pubkey_wallet2, sig_all=True ) # sender side - _, send_proofs = await wallet1.split_to_send( + _, send_proofs = await wallet1.swap_to_send( wallet1.proofs, 8, secret_lock=secret_lock ) await wallet2.redeem(send_proofs) @@ -114,7 +114,7 @@ async def test_p2pk_receive_with_wrong_private_key(wallet1: Wallet, wallet2: Wal pubkey_wallet2 = await wallet2.create_p2pk_pubkey() # receiver side # sender side secret_lock = await wallet1.create_p2pk_lock(pubkey_wallet2) # sender side - _, send_proofs = await wallet1.split_to_send( + _, send_proofs = await wallet1.swap_to_send( wallet1.proofs, 8, secret_lock=secret_lock ) # receiver side: wrong private key @@ -137,7 +137,7 @@ async def test_p2pk_short_locktime_receive_with_wrong_private_key( secret_lock = await wallet1.create_p2pk_lock( pubkey_wallet2, locktime_seconds=2 ) # sender side - _, send_proofs = await wallet1.split_to_send( + _, send_proofs = await wallet1.swap_to_send( wallet1.proofs, 8, secret_lock=secret_lock ) # receiver side: wrong private key @@ -167,7 +167,7 @@ async def test_p2pk_locktime_with_refund_pubkey(wallet1: Wallet, wallet2: Wallet locktime_seconds=2, # locktime tags=Tags([["refund", pubkey_wallet2]]), # refund pubkey ) # sender side - _, send_proofs = await wallet1.split_to_send( + _, send_proofs = await wallet1.swap_to_send( wallet1.proofs, 8, secret_lock=secret_lock ) send_proofs_copy = copy.deepcopy(send_proofs) @@ -198,7 +198,7 @@ async def test_p2pk_locktime_with_wrong_refund_pubkey(wallet1: Wallet, wallet2: locktime_seconds=2, # locktime tags=Tags([["refund", garbage_pubkey_2.serialize().hex()]]), # refund pubkey ) # sender side - _, send_proofs = await wallet1.split_to_send( + _, send_proofs = await wallet1.swap_to_send( wallet1.proofs, 8, secret_lock=secret_lock ) send_proofs_copy = copy.deepcopy(send_proofs) @@ -235,7 +235,7 @@ async def test_p2pk_locktime_with_second_refund_pubkey( [["refund", pubkey_wallet2, pubkey_wallet1]] ), # multiple refund pubkeys ) # sender side - _, send_proofs = await wallet1.split_to_send( + _, send_proofs = await wallet1.swap_to_send( wallet1.proofs, 8, secret_lock=secret_lock ) send_proofs_copy = copy.deepcopy(send_proofs) @@ -263,7 +263,7 @@ async def test_p2pk_multisig_2_of_2(wallet1: Wallet, wallet2: Wallet): pubkey_wallet2, tags=Tags([["pubkeys", pubkey_wallet1]]), n_sigs=2 ) - _, send_proofs = await wallet1.split_to_send( + _, send_proofs = await wallet1.swap_to_send( wallet1.proofs, 8, secret_lock=secret_lock ) # add signatures of wallet1 @@ -285,7 +285,7 @@ async def test_p2pk_multisig_duplicate_signature(wallet1: Wallet, wallet2: Walle pubkey_wallet2, tags=Tags([["pubkeys", pubkey_wallet1]]), n_sigs=2 ) - _, send_proofs = await wallet1.split_to_send( + _, send_proofs = await wallet1.swap_to_send( wallet1.proofs, 8, secret_lock=secret_lock ) # add signatures of wallet2 – this is a duplicate signature @@ -308,7 +308,7 @@ async def test_p2pk_multisig_quorum_not_met_1_of_2(wallet1: Wallet, wallet2: Wal secret_lock = await wallet1.create_p2pk_lock( pubkey_wallet2, tags=Tags([["pubkeys", pubkey_wallet1]]), n_sigs=2 ) - _, send_proofs = await wallet1.split_to_send( + _, send_proofs = await wallet1.swap_to_send( wallet1.proofs, 8, secret_lock=secret_lock ) await assert_err( @@ -330,7 +330,7 @@ async def test_p2pk_multisig_quorum_not_met_2_of_3(wallet1: Wallet, wallet2: Wal pubkey_wallet2, tags=Tags([["pubkeys", pubkey_wallet1]]), n_sigs=3 ) - _, send_proofs = await wallet1.split_to_send( + _, send_proofs = await wallet1.swap_to_send( wallet1.proofs, 8, secret_lock=secret_lock ) # add signatures of wallet1 @@ -352,7 +352,7 @@ async def test_p2pk_multisig_with_duplicate_publickey(wallet1: Wallet, wallet2: secret_lock = await wallet1.create_p2pk_lock( pubkey_wallet2, tags=Tags([["pubkeys", pubkey_wallet2]]), n_sigs=2 ) - _, send_proofs = await wallet1.split_to_send( + _, send_proofs = await wallet1.swap_to_send( wallet1.proofs, 8, secret_lock=secret_lock ) await assert_err(wallet2.redeem(send_proofs), "Mint Error: pubkeys must be unique.") @@ -377,7 +377,7 @@ async def test_p2pk_multisig_with_wrong_first_private_key( secret_lock = await wallet1.create_p2pk_lock( pubkey_wallet2, tags=Tags([["pubkeys", wrong_public_key_hex]]), n_sigs=2 ) - _, send_proofs = await wallet1.split_to_send( + _, send_proofs = await wallet1.swap_to_send( wallet1.proofs, 8, secret_lock=secret_lock ) # add signatures of wallet1 diff --git a/tests/test_wallet_regtest.py b/tests/test_wallet_regtest.py index 3e6d31bd..526fa119 100644 --- a/tests/test_wallet_regtest.py +++ b/tests/test_wallet_regtest.py @@ -45,7 +45,7 @@ async def test_regtest_pending_quote(wallet: Wallet, ledger: Ledger): # wallet pays the invoice quote = await wallet.melt_quote(invoice_payment_request) total_amount = quote.amount + quote.fee_reserve - _, send_proofs = await wallet.split_to_send(wallet.proofs, total_amount) + _, send_proofs = await wallet.swap_to_send(wallet.proofs, total_amount) asyncio.create_task( wallet.melt( proofs=send_proofs, @@ -85,7 +85,7 @@ async def test_regtest_failed_quote(wallet: Wallet, ledger: Ledger): # wallet pays the invoice quote = await wallet.melt_quote(invoice_payment_request) total_amount = quote.amount + quote.fee_reserve - _, send_proofs = await wallet.split_to_send(wallet.proofs, total_amount) + _, send_proofs = await wallet.swap_to_send(wallet.proofs, total_amount) asyncio.create_task( wallet.melt( proofs=send_proofs, diff --git a/tests/test_wallet_restore.py b/tests/test_wallet_restore.py index 4b92ca76..837d9657 100644 --- a/tests/test_wallet_restore.py +++ b/tests/test_wallet_restore.py @@ -185,7 +185,7 @@ async def test_restore_wallet_with_invalid_mnemonic(wallet3: Wallet): @pytest.mark.asyncio -async def test_restore_wallet_after_split_to_send(wallet3: Wallet): +async def test_restore_wallet_after_swap_to_send(wallet3: Wallet): await wallet3._init_private_key( "half depart obvious quality work element tank gorilla view sugar picture" " humble" @@ -197,7 +197,7 @@ async def test_restore_wallet_after_split_to_send(wallet3: Wallet): await wallet3.mint(64, id=invoice.id) assert wallet3.balance == 64 - _, spendable_proofs = await wallet3.split_to_send( + _, spendable_proofs = await wallet3.swap_to_send( wallet3.proofs, 32, set_reserved=True ) # type: ignore @@ -222,7 +222,7 @@ async def test_restore_wallet_after_send_and_receive(wallet3: Wallet, wallet2: W await wallet3.mint(64, id=invoice.id) assert wallet3.balance == 64 - _, spendable_proofs = await wallet3.split_to_send( + _, spendable_proofs = await wallet3.swap_to_send( wallet3.proofs, 32, set_reserved=True ) # type: ignore @@ -265,7 +265,7 @@ async def test_restore_wallet_after_send_and_self_receive(wallet3: Wallet): await wallet3.mint(64, id=invoice.id) assert wallet3.balance == 64 - _, spendable_proofs = await wallet3.split_to_send( + _, spendable_proofs = await wallet3.swap_to_send( wallet3.proofs, 32, set_reserved=True ) # type: ignore @@ -295,7 +295,7 @@ async def test_restore_wallet_after_send_twice( box.add(wallet3.proofs) assert wallet3.balance == 2 - keep_proofs, spendable_proofs = await wallet3.split_to_send( + keep_proofs, spendable_proofs = await wallet3.swap_to_send( wallet3.proofs, 1, set_reserved=True ) # type: ignore box.add(wallet3.proofs) @@ -317,7 +317,7 @@ async def test_restore_wallet_after_send_twice( # again - _, spendable_proofs = await wallet3.split_to_send( + _, spendable_proofs = await wallet3.swap_to_send( wallet3.proofs, 1, set_reserved=True ) # type: ignore box.add(wallet3.proofs) @@ -354,7 +354,7 @@ async def test_restore_wallet_after_send_and_self_receive_nonquadratic_value( box.add(wallet3.proofs) assert wallet3.balance == 64 - keep_proofs, spendable_proofs = await wallet3.split_to_send( + keep_proofs, spendable_proofs = await wallet3.swap_to_send( wallet3.proofs, 10, set_reserved=True ) # type: ignore box.add(wallet3.proofs) @@ -376,7 +376,7 @@ async def test_restore_wallet_after_send_and_self_receive_nonquadratic_value( # again - _, spendable_proofs = await wallet3.split_to_send( + _, spendable_proofs = await wallet3.swap_to_send( wallet3.proofs, 12, set_reserved=True ) # type: ignore diff --git a/tests/test_wallet_subscription.py b/tests/test_wallet_subscription.py index ce77a16f..ac4711fa 100644 --- a/tests/test_wallet_subscription.py +++ b/tests/test_wallet_subscription.py @@ -86,7 +86,7 @@ def callback(msg: JSONRPCNotficationParams): wallet.proofs, callback=callback ) - _ = await wallet.split_to_send(wallet.proofs, 64) + _ = await wallet.swap_to_send(wallet.proofs, 64) wait = 1 await asyncio.sleep(wait)