diff --git a/crates/wallet/examples/compiler.rs b/crates/wallet/examples/compiler.rs index d0922fa4e..4221dc729 100644 --- a/crates/wallet/examples/compiler.rs +++ b/crates/wallet/examples/compiler.rs @@ -64,7 +64,7 @@ fn main() -> Result<(), Box> { println!( "First derived address from the descriptor: \n{}", - wallet.next_unused_address(KeychainKind::External), + wallet.last_unused_address(KeychainKind::External), ); // BDK also has it's own `Policy` structure to represent the spending condition in a more diff --git a/crates/wallet/src/descriptor/template.rs b/crates/wallet/src/descriptor/template.rs index ee9ec9aed..2e49b1d1e 100644 --- a/crates/wallet/src/descriptor/template.rs +++ b/crates/wallet/src/descriptor/template.rs @@ -87,7 +87,7 @@ impl IntoWalletDescriptor for T { /// /// assert_eq!( /// wallet -/// .next_unused_address(KeychainKind::External) +/// .last_unused_address(KeychainKind::External) /// .to_string(), /// "mwJ8hxFYW19JLuc65RCTaP4v1rzVU8cVMT" /// ); @@ -122,7 +122,7 @@ impl> DescriptorTemplate for P2Pkh { /// /// assert_eq!( /// wallet -/// .next_unused_address(KeychainKind::External) +/// .last_unused_address(KeychainKind::External) /// .to_string(), /// "2NB4ox5VDRw1ecUv6SnT3VQHPXveYztRqk5" /// ); @@ -158,7 +158,7 @@ impl> DescriptorTemplate for P2Wpkh_P2Sh { /// /// assert_eq!( /// wallet -/// .next_unused_address(KeychainKind::External) +/// .last_unused_address(KeychainKind::External) /// .to_string(), /// "tb1q4525hmgw265tl3drrl8jjta7ayffu6jf68ltjd" /// ); @@ -193,7 +193,7 @@ impl> DescriptorTemplate for P2Wpkh { /// /// assert_eq!( /// wallet -/// .next_unused_address(KeychainKind::External) +/// .last_unused_address(KeychainKind::External) /// .to_string(), /// "tb1pvjf9t34fznr53u5tqhejz4nr69luzkhlvsdsdfq9pglutrpve2xq7hps46" /// ); @@ -227,7 +227,7 @@ impl> DescriptorTemplate for P2TR { /// .network(Network::Testnet) /// .create_wallet_no_persist()?; /// -/// assert_eq!(wallet.next_unused_address(KeychainKind::External).to_string(), "mmogjc7HJEZkrLqyQYqJmxUqFaC7i4uf89"); +/// assert_eq!(wallet.last_unused_address(KeychainKind::External).to_string(), "mmogjc7HJEZkrLqyQYqJmxUqFaC7i4uf89"); /// assert_eq!(wallet.public_descriptor(KeychainKind::External).to_string(), "pkh([c55b303f/44'/1'/0']tpubDCuorCpzvYS2LCD75BR46KHE8GdDeg1wsAgNZeNr6DaB5gQK1o14uErKwKLuFmeemkQ6N2m3rNgvctdJLyr7nwu2yia7413Hhg8WWE44cgT/0/*)#5wrnv0xt"); /// # Ok::<_, Box>(()) /// ``` @@ -266,7 +266,7 @@ impl> DescriptorTemplate for Bip44 { /// .network(Network::Testnet) /// .create_wallet_no_persist()?; /// -/// assert_eq!(wallet.next_unused_address(KeychainKind::External).to_string(), "miNG7dJTzJqNbFS19svRdTCisC65dsubtR"); +/// assert_eq!(wallet.last_unused_address(KeychainKind::External).to_string(), "miNG7dJTzJqNbFS19svRdTCisC65dsubtR"); /// assert_eq!(wallet.public_descriptor(KeychainKind::External).to_string(), "pkh([c55b303f/44'/1'/0']tpubDDDzQ31JkZB7VxUr9bjvBivDdqoFLrDPyLWtLapArAi51ftfmCb2DPxwLQzX65iNcXz1DGaVvyvo6JQ6rTU73r2gqdEo8uov9QKRb7nKCSU/0/*)#cfhumdqz"); /// # Ok::<_, Box>(()) /// ``` @@ -304,7 +304,7 @@ impl> DescriptorTemplate for Bip44Public { /// .network(Network::Testnet) /// .create_wallet_no_persist()?; /// -/// assert_eq!(wallet.next_unused_address(KeychainKind::External).to_string(), "2N4zkWAoGdUv4NXhSsU8DvS5MB36T8nKHEB"); +/// assert_eq!(wallet.last_unused_address(KeychainKind::External).to_string(), "2N4zkWAoGdUv4NXhSsU8DvS5MB36T8nKHEB"); /// assert_eq!(wallet.public_descriptor(KeychainKind::External).to_string(), "sh(wpkh([c55b303f/49'/1'/0']tpubDDYr4kdnZgjjShzYNjZUZXUUtpXaofdkMaipyS8ThEh45qFmhT4hKYways7UXmg6V7het1QiFo9kf4kYUXyDvV4rHEyvSpys9pjCB3pukxi/0/*))#s9vxlc8e"); /// # Ok::<_, Box>(()) /// ``` @@ -343,7 +343,7 @@ impl> DescriptorTemplate for Bip49 { /// .network(Network::Testnet) /// .create_wallet_no_persist()?; /// -/// assert_eq!(wallet.next_unused_address(KeychainKind::External).to_string(), "2N3K4xbVAHoiTQSwxkZjWDfKoNC27pLkYnt"); +/// assert_eq!(wallet.last_unused_address(KeychainKind::External).to_string(), "2N3K4xbVAHoiTQSwxkZjWDfKoNC27pLkYnt"); /// assert_eq!(wallet.public_descriptor(KeychainKind::External).to_string(), "sh(wpkh([c55b303f/49'/1'/0']tpubDC49r947KGK52X5rBWS4BLs5m9SRY3pYHnvRrm7HcybZ3BfdEsGFyzCMzayi1u58eT82ZeyFZwH7DD6Q83E3fM9CpfMtmnTygnLfP59jL9L/0/*))#3tka9g0q"); /// # Ok::<_, Box>(()) /// ``` @@ -381,7 +381,7 @@ impl> DescriptorTemplate for Bip49Public { /// .network(Network::Testnet) /// .create_wallet_no_persist()?; /// -/// assert_eq!(wallet.next_unused_address(KeychainKind::External).to_string(), "tb1qhl85z42h7r4su5u37rvvw0gk8j2t3n9y7zsg4n"); +/// assert_eq!(wallet.last_unused_address(KeychainKind::External).to_string(), "tb1qhl85z42h7r4su5u37rvvw0gk8j2t3n9y7zsg4n"); /// assert_eq!(wallet.public_descriptor(KeychainKind::External).to_string(), "wpkh([c55b303f/84'/1'/0']tpubDDc5mum24DekpNw92t6fHGp8Gr2JjF9J7i4TZBtN6Vp8xpAULG5CFaKsfugWa5imhrQQUZKXe261asP5koDHo5bs3qNTmf3U3o4v9SaB8gg/0/*)#6kfecsmr"); /// # Ok::<_, Box>(()) /// ``` @@ -420,7 +420,7 @@ impl> DescriptorTemplate for Bip84 { /// .network(Network::Testnet) /// .create_wallet_no_persist()?; /// -/// assert_eq!(wallet.next_unused_address(KeychainKind::External).to_string(), "tb1qedg9fdlf8cnnqfd5mks6uz5w4kgpk2pr6y4qc7"); +/// assert_eq!(wallet.last_unused_address(KeychainKind::External).to_string(), "tb1qedg9fdlf8cnnqfd5mks6uz5w4kgpk2pr6y4qc7"); /// assert_eq!(wallet.public_descriptor(KeychainKind::External).to_string(), "wpkh([c55b303f/84'/1'/0']tpubDC2Qwo2TFsaNC4ju8nrUJ9mqVT3eSgdmy1yPqhgkjwmke3PRXutNGRYAUo6RCHTcVQaDR3ohNU9we59brGHuEKPvH1ags2nevW5opEE9Z5Q/0/*)#dhu402yv"); /// # Ok::<_, Box>(()) /// ``` @@ -458,7 +458,7 @@ impl> DescriptorTemplate for Bip84Public { /// .network(Network::Testnet) /// .create_wallet_no_persist()?; /// -/// assert_eq!(wallet.next_unused_address(KeychainKind::External).to_string(), "tb1p5unlj09djx8xsjwe97269kqtxqpwpu2epeskgqjfk4lnf69v4tnqpp35qu"); +/// assert_eq!(wallet.last_unused_address(KeychainKind::External).to_string(), "tb1p5unlj09djx8xsjwe97269kqtxqpwpu2epeskgqjfk4lnf69v4tnqpp35qu"); /// assert_eq!(wallet.public_descriptor(KeychainKind::External).to_string(), "tr([c55b303f/86'/1'/0']tpubDCiHofpEs47kx358bPdJmTZHmCDqQ8qw32upCSxHrSEdeeBs2T5Mq6QMB2ukeMqhNBiyhosBvJErteVhfURPGXPv3qLJPw5MVpHUewsbP2m/0/*)#dkgvr5hm"); /// # Ok::<_, Box>(()) /// ``` @@ -497,7 +497,7 @@ impl> DescriptorTemplate for Bip86 { /// .network(Network::Testnet) /// .create_wallet_no_persist()?; /// -/// assert_eq!(wallet.next_unused_address(KeychainKind::External).to_string(), "tb1pwjp9f2k5n0xq73ecuu0c5njvgqr3vkh7yaylmpqvsuuaafymh0msvcmh37"); +/// assert_eq!(wallet.last_unused_address(KeychainKind::External).to_string(), "tb1pwjp9f2k5n0xq73ecuu0c5njvgqr3vkh7yaylmpqvsuuaafymh0msvcmh37"); /// assert_eq!(wallet.public_descriptor(KeychainKind::External).to_string(), "tr([c55b303f/86'/1'/0']tpubDC2Qwo2TFsaNC4ju8nrUJ9mqVT3eSgdmy1yPqhgkjwmke3PRXutNGRYAUo6RCHTcVQaDR3ohNU9we59brGHuEKPvH1ags2nevW5opEE9Z5Q/0/*)#2p65srku"); /// # Ok::<_, Box>(()) /// ``` diff --git a/crates/wallet/src/test_utils.rs b/crates/wallet/src/test_utils.rs index 050b9fb19..4a4564857 100644 --- a/crates/wallet/src/test_utils.rs +++ b/crates/wallet/src/test_utils.rs @@ -245,7 +245,7 @@ pub fn receive_output( value: u64, pos: ChainPosition, ) -> OutPoint { - let addr = wallet.next_unused_address(KeychainKind::External).address; + let addr = wallet.last_unused_address(KeychainKind::External).address; receive_output_to_address(wallet, addr, value, pos) } diff --git a/crates/wallet/src/wallet/mod.rs b/crates/wallet/src/wallet/mod.rs index 68d5e6bec..790133a34 100644 --- a/crates/wallet/src/wallet/mod.rs +++ b/crates/wallet/src/wallet/mod.rs @@ -737,7 +737,7 @@ impl Wallet { }) } - /// Get the next unused address for the given `keychain`, i.e. the address with the lowest + /// Get the last unused address for the given `keychain`, i.e. the address with the lowest /// derivation index that hasn't been used. /// /// This will attempt to derive and reveal a new address if no newly revealed addresses @@ -745,7 +745,7 @@ impl Wallet { /// /// **WARNING**: To avoid address reuse you must persist the changes resulting from one or more /// calls to this method before closing the wallet. See [`Wallet::reveal_next_address`]. - pub fn next_unused_address(&mut self, keychain: KeychainKind) -> AddressInfo { + pub fn last_unused_address(&mut self, keychain: KeychainKind) -> AddressInfo { let keychain = self.map_keychain(keychain); let index = &mut self.indexed_graph.index; diff --git a/crates/wallet/tests/wallet.rs b/crates/wallet/tests/wallet.rs index 6bfae2ec7..fa97e0d0d 100644 --- a/crates/wallet/tests/wallet.rs +++ b/crates/wallet/tests/wallet.rs @@ -469,7 +469,7 @@ fn test_create_tx_empty_recipients() { #[should_panic(expected = "NoUtxosSelected")] fn test_create_tx_manually_selected_empty_utxos() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) @@ -480,7 +480,7 @@ fn test_create_tx_manually_selected_empty_utxos() { #[test] fn test_create_tx_version_0() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) @@ -491,7 +491,7 @@ fn test_create_tx_version_0() { #[test] fn test_create_tx_version_1_csv() { let (mut wallet, _) = get_funded_wallet_single(get_test_single_sig_csv()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) @@ -502,7 +502,7 @@ fn test_create_tx_version_1_csv() { #[test] fn test_create_tx_custom_version() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) @@ -516,7 +516,7 @@ fn test_create_tx_custom_version() { fn test_create_tx_default_locktime_is_last_sync_height() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); let psbt = builder.finish().unwrap(); @@ -529,7 +529,7 @@ fn test_create_tx_default_locktime_is_last_sync_height() { #[test] fn test_create_tx_fee_sniping_locktime_last_sync() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); @@ -545,7 +545,7 @@ fn test_create_tx_fee_sniping_locktime_last_sync() { #[test] fn test_create_tx_default_locktime_cltv() { let (mut wallet, _) = get_funded_wallet_single(get_test_single_sig_cltv()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); let psbt = builder.finish().unwrap(); @@ -556,7 +556,7 @@ fn test_create_tx_default_locktime_cltv() { #[test] fn test_create_tx_custom_locktime() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) @@ -573,7 +573,7 @@ fn test_create_tx_custom_locktime() { #[test] fn test_create_tx_custom_locktime_compatible_with_cltv() { let (mut wallet, _) = get_funded_wallet_single(get_test_single_sig_cltv()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) @@ -586,7 +586,7 @@ fn test_create_tx_custom_locktime_compatible_with_cltv() { #[test] fn test_create_tx_custom_locktime_incompatible_with_cltv() { let (mut wallet, _) = get_funded_wallet_single(get_test_single_sig_cltv()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) @@ -600,7 +600,7 @@ fn test_create_tx_custom_locktime_incompatible_with_cltv() { fn test_create_tx_custom_csv() { // desc: wsh(and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),older(6))) let (mut wallet, _) = get_funded_wallet_single(get_test_single_sig_csv()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .set_exact_sequence(Sequence(42)) @@ -613,7 +613,7 @@ fn test_create_tx_custom_csv() { #[test] fn test_create_tx_no_rbf_csv() { let (mut wallet, _) = get_funded_wallet_single(get_test_single_sig_csv()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); let psbt = builder.finish().unwrap(); @@ -624,7 +624,7 @@ fn test_create_tx_no_rbf_csv() { #[test] fn test_create_tx_incompatible_csv() { let (mut wallet, _) = get_funded_wallet_single(get_test_single_sig_csv()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) @@ -637,7 +637,7 @@ fn test_create_tx_incompatible_csv() { #[test] fn test_create_tx_with_default_rbf_csv() { let (mut wallet, _) = get_funded_wallet_single(get_test_single_sig_csv()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); let psbt = builder.finish().unwrap(); @@ -649,7 +649,7 @@ fn test_create_tx_with_default_rbf_csv() { #[test] fn test_create_tx_no_rbf_cltv() { let (mut wallet, _) = get_funded_wallet_single(get_test_single_sig_cltv()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); builder.set_exact_sequence(Sequence(0xFFFFFFFE)); @@ -661,7 +661,7 @@ fn test_create_tx_no_rbf_cltv() { #[test] fn test_create_tx_custom_rbf_sequence() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) @@ -674,7 +674,7 @@ fn test_create_tx_custom_rbf_sequence() { #[test] fn test_create_tx_change_policy() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) @@ -698,7 +698,7 @@ fn test_create_tx_change_policy() { #[test] fn test_create_tx_default_sequence() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); let psbt = builder.finish().unwrap(); @@ -718,7 +718,7 @@ macro_rules! check_fee { #[test] fn test_create_tx_drain_wallet_and_drain_to() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let psbt = builder.finish().unwrap(); @@ -737,7 +737,7 @@ fn test_create_tx_drain_wallet_and_drain_to_and_with_recipient() { let addr = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt") .unwrap() .assume_checked(); - let drain_addr = wallet.next_unused_address(KeychainKind::External); + let drain_addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .add_recipient(addr.script_pubkey(), Amount::from_sat(20_000)) @@ -766,7 +766,7 @@ fn test_create_tx_drain_wallet_and_drain_to_and_with_recipient() { #[test] fn test_create_tx_drain_to_and_utxos() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let utxos: Vec<_> = wallet.list_unspent().map(|u| u.outpoint).collect(); let mut builder = wallet.build_tx(); builder @@ -787,7 +787,7 @@ fn test_create_tx_drain_to_and_utxos() { #[should_panic(expected = "NoRecipients")] fn test_create_tx_drain_to_no_drain_wallet_no_utxos() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let drain_addr = wallet.next_unused_address(KeychainKind::External); + let drain_addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(drain_addr.script_pubkey()); builder.finish().unwrap(); @@ -796,7 +796,7 @@ fn test_create_tx_drain_to_no_drain_wallet_no_utxos() { #[test] fn test_create_tx_default_fee_rate() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); let psbt = builder.finish().unwrap(); @@ -808,7 +808,7 @@ fn test_create_tx_default_fee_rate() { #[test] fn test_create_tx_custom_fee_rate() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) @@ -822,7 +822,7 @@ fn test_create_tx_custom_fee_rate() { #[test] fn test_create_tx_absolute_fee() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .drain_to(addr.script_pubkey()) @@ -842,7 +842,7 @@ fn test_create_tx_absolute_fee() { #[test] fn test_create_tx_absolute_zero_fee() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .drain_to(addr.script_pubkey()) @@ -863,7 +863,7 @@ fn test_create_tx_absolute_zero_fee() { #[should_panic(expected = "InsufficientFunds")] fn test_create_tx_absolute_high_fee() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .drain_to(addr.script_pubkey()) @@ -878,7 +878,7 @@ fn test_create_tx_add_change() { let seed = [0; 32]; let mut rng: StdRng = SeedableRng::from_seed(seed); let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) @@ -897,7 +897,7 @@ fn test_create_tx_add_change() { #[test] fn test_create_tx_skip_change_dust() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(49_800)); let psbt = builder.finish().unwrap(); @@ -912,7 +912,7 @@ fn test_create_tx_skip_change_dust() { #[should_panic(expected = "InsufficientFunds")] fn test_create_tx_drain_to_dust_amount() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); // very high fee rate, so that the only output would be below dust let mut builder = wallet.build_tx(); builder @@ -925,7 +925,7 @@ fn test_create_tx_drain_to_dust_amount() { #[test] fn test_create_tx_ordering_respected() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let bip69_txin_cmp = |tx_a: &TxIn, tx_b: &TxIn| { let project_outpoint = |t: &TxIn| (t.previous_output.txid, t.previous_output.vout); @@ -963,7 +963,7 @@ fn test_create_tx_ordering_respected() { #[test] fn test_create_tx_default_sighash() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(30_000)); let psbt = builder.finish().unwrap(); @@ -974,7 +974,7 @@ fn test_create_tx_default_sighash() { #[test] fn test_create_tx_custom_sighash() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .add_recipient(addr.script_pubkey(), Amount::from_sat(30_000)) @@ -993,7 +993,7 @@ fn test_create_tx_input_hd_keypaths() { use core::str::FromStr; let (mut wallet, _) = get_funded_wallet_single("wpkh([d34db33f/44'/0'/0']tpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/0/*)"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let psbt = builder.finish().unwrap(); @@ -1015,7 +1015,7 @@ fn test_create_tx_output_hd_keypaths() { let (mut wallet, _) = get_funded_wallet_single("wpkh([d34db33f/44'/0'/0']tpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/0/*)"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let psbt = builder.finish().unwrap(); @@ -1037,7 +1037,7 @@ fn test_create_tx_set_redeem_script_p2sh() { let (mut wallet, _) = get_funded_wallet_single("sh(pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW))"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let psbt = builder.finish().unwrap(); @@ -1060,7 +1060,7 @@ fn test_create_tx_set_witness_script_p2wsh() { let (mut wallet, _) = get_funded_wallet_single("wsh(pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW))"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let psbt = builder.finish().unwrap(); @@ -1082,7 +1082,7 @@ fn test_create_tx_set_redeem_witness_script_p2wsh_p2sh() { let (mut wallet, _) = get_funded_wallet_single( "sh(wsh(pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW)))", ); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let psbt = builder.finish().unwrap(); @@ -1100,7 +1100,7 @@ fn test_create_tx_set_redeem_witness_script_p2wsh_p2sh() { fn test_create_tx_non_witness_utxo() { let (mut wallet, _) = get_funded_wallet_single("sh(pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW))"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let psbt = builder.finish().unwrap(); @@ -1113,7 +1113,7 @@ fn test_create_tx_non_witness_utxo() { fn test_create_tx_only_witness_utxo() { let (mut wallet, _) = get_funded_wallet_single("wsh(pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW))"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .drain_to(addr.script_pubkey()) @@ -1129,7 +1129,7 @@ fn test_create_tx_only_witness_utxo() { fn test_create_tx_shwpkh_has_witness_utxo() { let (mut wallet, _) = get_funded_wallet_single("sh(wpkh(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW))"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let psbt = builder.finish().unwrap(); @@ -1141,7 +1141,7 @@ fn test_create_tx_shwpkh_has_witness_utxo() { fn test_create_tx_both_non_witness_utxo_and_witness_utxo_default() { let (mut wallet, _) = get_funded_wallet_single("wsh(pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW))"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let psbt = builder.finish().unwrap(); @@ -1157,7 +1157,7 @@ fn test_create_tx_add_utxo() { input: vec![], output: vec![TxOut { script_pubkey: wallet - .next_unused_address(KeychainKind::External) + .last_unused_address(KeychainKind::External) .script_pubkey(), value: Amount::from_sat(25_000), }], @@ -1204,7 +1204,7 @@ fn test_create_tx_manually_selected_insufficient() { input: vec![], output: vec![TxOut { script_pubkey: wallet - .next_unused_address(KeychainKind::External) + .last_unused_address(KeychainKind::External) .script_pubkey(), value: Amount::from_sat(25_000), }], @@ -1258,7 +1258,7 @@ fn test_create_tx_policy_path_no_csv() { input: vec![], output: vec![TxOut { script_pubkey: wallet - .next_unused_address(KeychainKind::External) + .last_unused_address(KeychainKind::External) .script_pubkey(), value: Amount::from_sat(50_000), }], @@ -1328,7 +1328,7 @@ fn test_create_tx_policy_path_ignored_subtree_with_csv() { fn test_create_tx_global_xpubs_with_origin() { use bitcoin::bip32; let (mut wallet, _) = get_funded_wallet_single("wpkh([73756c7f/48'/0'/0'/2']tpubDCKxNyM3bLgbEX13Mcd8mYxbVg9ajDkWXMh29hMWBurKfVmBfWAM96QVP3zaUcN51HvkZ3ar4VwP82kC8JZhhux8vFQoJintSpVBwpFvyU3/0/*)"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) @@ -1456,7 +1456,7 @@ fn test_create_tx_increment_change_index() { test.name, ); assert_eq!( - wallet.next_unused_address(change_keychain).index, + wallet.last_unused_address(change_keychain).index, exp_next_unused, "next unused index test {}", test.name, @@ -1713,7 +1713,7 @@ fn test_get_psbt_input() { )] fn test_create_tx_global_xpubs_origin_missing() { let (mut wallet, _) = get_funded_wallet_single("wpkh(tpubDCKxNyM3bLgbEX13Mcd8mYxbVg9ajDkWXMh29hMWBurKfVmBfWAM96QVP3zaUcN51HvkZ3ar4VwP82kC8JZhhux8vFQoJintSpVBwpFvyU3/0/*)"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) @@ -1725,7 +1725,7 @@ fn test_create_tx_global_xpubs_origin_missing() { fn test_create_tx_global_xpubs_master_without_origin() { use bitcoin::bip32; let (mut wallet, _) = get_funded_wallet_single("wpkh(tpubD6NzVbkrYhZ4Y55A58Gv9RSNF5hy84b5AJqYy7sCcjFrkcLpPre8kmgfit6kY1Zs3BLgeypTDBZJM222guPpdz7Cup5yzaMu62u7mYGbwFL/0/*)"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) @@ -1746,7 +1746,7 @@ fn test_create_tx_global_xpubs_master_without_origin() { #[should_panic(expected = "IrreplaceableTransaction")] fn test_bump_fee_irreplaceable_tx() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); builder.set_exact_sequence(Sequence(0xFFFFFFFE)); @@ -1762,7 +1762,7 @@ fn test_bump_fee_irreplaceable_tx() { #[should_panic(expected = "TransactionConfirmed")] fn test_bump_fee_confirmed_tx() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); let psbt = builder.finish().unwrap(); @@ -1784,7 +1784,7 @@ fn test_bump_fee_confirmed_tx() { #[test] fn test_bump_fee_low_fee_rate() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); @@ -1814,7 +1814,7 @@ fn test_bump_fee_low_fee_rate() { #[should_panic(expected = "FeeTooLow")] fn test_bump_fee_low_abs() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); let psbt = builder.finish().unwrap(); @@ -1832,7 +1832,7 @@ fn test_bump_fee_low_abs() { #[should_panic(expected = "FeeTooLow")] fn test_bump_fee_zero_abs() { let (mut wallet, _) = get_funded_wallet_wpkh(); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); let psbt = builder.finish().unwrap(); @@ -2034,7 +2034,7 @@ fn test_bump_fee_drain_wallet() { input: vec![], output: vec![TxOut { script_pubkey: wallet - .next_unused_address(KeychainKind::External) + .last_unused_address(KeychainKind::External) .script_pubkey(), value: Amount::from_sat(25_000), }], @@ -2095,7 +2095,7 @@ fn test_bump_fee_remove_output_manually_selected_only() { input: vec![], output: vec![TxOut { script_pubkey: wallet - .next_unused_address(KeychainKind::External) + .last_unused_address(KeychainKind::External) .script_pubkey(), value: Amount::from_sat(25_000), }], @@ -2144,7 +2144,7 @@ fn test_bump_fee_add_input() { input: vec![], output: vec![TxOut { script_pubkey: wallet - .next_unused_address(KeychainKind::External) + .last_unused_address(KeychainKind::External) .script_pubkey(), value: Amount::from_sat(25_000), }], @@ -2623,7 +2623,7 @@ fn test_fee_amount_negative_drain_val() { #[test] fn test_sign_single_xprv() { let (mut wallet, _) = get_funded_wallet_single("wpkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let mut psbt = builder.finish().unwrap(); @@ -2638,7 +2638,7 @@ fn test_sign_single_xprv() { #[test] fn test_sign_single_xprv_with_master_fingerprint_and_path() { let (mut wallet, _) = get_funded_wallet_single("wpkh([d34db33f/84h/1h/0h]tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let mut psbt = builder.finish().unwrap(); @@ -2653,7 +2653,7 @@ fn test_sign_single_xprv_with_master_fingerprint_and_path() { #[test] fn test_sign_single_xprv_bip44_path() { let (mut wallet, _) = get_funded_wallet_single("wpkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/44'/0'/0'/0/*)"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let mut psbt = builder.finish().unwrap(); @@ -2668,7 +2668,7 @@ fn test_sign_single_xprv_bip44_path() { #[test] fn test_sign_single_xprv_sh_wpkh() { let (mut wallet, _) = get_funded_wallet_single("sh(wpkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*))"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let mut psbt = builder.finish().unwrap(); @@ -2684,7 +2684,7 @@ fn test_sign_single_xprv_sh_wpkh() { fn test_sign_single_wif() { let (mut wallet, _) = get_funded_wallet_single("wpkh(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW)"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let mut psbt = builder.finish().unwrap(); @@ -2699,7 +2699,7 @@ fn test_sign_single_wif() { #[test] fn test_sign_single_xprv_no_hd_keypaths() { let (mut wallet, _) = get_funded_wallet_single("wpkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let mut psbt = builder.finish().unwrap(); @@ -2786,7 +2786,7 @@ fn test_try_finalize_sign_option() { let (mut wallet, _) = get_funded_wallet_single("wpkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)"); for try_finalize in &[true, false] { - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let mut psbt = builder.finish().unwrap(); @@ -2820,7 +2820,7 @@ fn test_taproot_try_finalize_sign_option() { let (mut wallet, _) = get_funded_wallet_single(get_test_tr_with_taptree()); for try_finalize in &[true, false] { - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let mut psbt = builder.finish().unwrap(); @@ -2869,7 +2869,7 @@ fn test_sign_nonstandard_sighash() { let sighash = EcdsaSighashType::NonePlusAnyoneCanPay; let (mut wallet, _) = get_funded_wallet_single("wpkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .drain_to(addr.script_pubkey()) @@ -2927,7 +2927,7 @@ fn test_unused_address() { assert_eq!( wallet - .next_unused_address(KeychainKind::External) + .last_unused_address(KeychainKind::External) .to_string(), "tb1q6yn66vajcctph75pvylgkksgpp6nq04ppwct9a" ); @@ -2942,7 +2942,7 @@ fn test_unused_address() { } #[test] -fn test_next_unused_address() { +fn test_last_unused_address() { let descriptor = "wpkh(tpubEBr4i6yk5nf5DAaJpsi9N2pPYBeJ7fZ5Z9rmN4977iYLCGco1VyjB9tvvuvYtfZzjD5A8igzgw3HeWeeKFmanHYqksqZXYXGsw5zjnj7KM9/*)"; let change_descriptor = get_test_wpkh(); let mut wallet = Wallet::create(descriptor, change_descriptor) @@ -2953,7 +2953,7 @@ fn test_next_unused_address() { assert_eq!( wallet - .next_unused_address(KeychainKind::External) + .last_unused_address(KeychainKind::External) .to_string(), "tb1q6yn66vajcctph75pvylgkksgpp6nq04ppwct9a" ); @@ -2961,7 +2961,7 @@ fn test_next_unused_address() { // calling next_unused again gives same address assert_eq!( wallet - .next_unused_address(KeychainKind::External) + .last_unused_address(KeychainKind::External) .to_string(), "tb1q6yn66vajcctph75pvylgkksgpp6nq04ppwct9a" ); @@ -2969,11 +2969,11 @@ fn test_next_unused_address() { // test mark used / unused assert!(wallet.mark_used(KeychainKind::External, 0)); - let next_unused_addr = wallet.next_unused_address(KeychainKind::External); + let next_unused_addr = wallet.last_unused_address(KeychainKind::External); assert_eq!(next_unused_addr.index, 1); assert!(wallet.unmark_used(KeychainKind::External, 0)); - let next_unused_addr = wallet.next_unused_address(KeychainKind::External); + let next_unused_addr = wallet.last_unused_address(KeychainKind::External); assert_eq!(next_unused_addr.index, 0); // use the above address @@ -2981,7 +2981,7 @@ fn test_next_unused_address() { assert_eq!( wallet - .next_unused_address(KeychainKind::External) + .last_unused_address(KeychainKind::External) .to_string(), "tb1q4er7kxx6sssz3q7qp7zsqsdx4erceahhax77d7" ); @@ -3311,7 +3311,7 @@ fn test_taproot_psbt_input_tap_tree() { use bitcoin::taproot; let (mut wallet, _) = get_funded_wallet_single(get_test_tr_with_taptree()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); @@ -3354,7 +3354,7 @@ fn test_taproot_psbt_input_tap_tree() { #[test] fn test_taproot_sign_missing_witness_utxo() { let (mut wallet, _) = get_funded_wallet_single(get_test_tr_single_sig()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let mut psbt = builder.finish().unwrap(); @@ -3394,7 +3394,7 @@ fn test_taproot_sign_missing_witness_utxo() { #[test] fn test_taproot_sign_using_non_witness_utxo() { let (mut wallet, prev_txid) = get_funded_wallet_single(get_test_tr_single_sig()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); let mut psbt = builder.finish().unwrap(); @@ -3462,7 +3462,7 @@ fn test_taproot_foreign_utxo() { } fn test_spend_from_wallet(mut wallet: Wallet) { - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); @@ -3486,7 +3486,7 @@ fn test_spend_from_wallet(mut wallet: Wallet) { #[test] fn test_taproot_no_key_spend() { let (mut wallet, _) = get_funded_wallet_single(get_test_tr_with_taptree_both_priv()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); @@ -3521,7 +3521,7 @@ fn test_taproot_script_spend() { fn test_taproot_script_spend_sign_all_leaves() { use bdk_wallet::signer::TapLeavesOptions; let (mut wallet, _) = get_funded_wallet_single(get_test_tr_with_taptree_both_priv()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); @@ -3552,7 +3552,7 @@ fn test_taproot_script_spend_sign_include_some_leaves() { use bitcoin::taproot::TapLeafHash; let (mut wallet, _) = get_funded_wallet_single(get_test_tr_with_taptree_both_priv()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); @@ -3592,7 +3592,7 @@ fn test_taproot_script_spend_sign_exclude_some_leaves() { use bitcoin::taproot::TapLeafHash; let (mut wallet, _) = get_funded_wallet_single(get_test_tr_with_taptree_both_priv()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); @@ -3630,7 +3630,7 @@ fn test_taproot_script_spend_sign_exclude_some_leaves() { fn test_taproot_script_spend_sign_no_leaves() { use bdk_wallet::signer::TapLeavesOptions; let (mut wallet, _) = get_funded_wallet_single(get_test_tr_with_taptree_both_priv()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); @@ -3653,7 +3653,7 @@ fn test_taproot_script_spend_sign_no_leaves() { fn test_taproot_sign_derive_index_from_psbt() { let (mut wallet, _) = get_funded_wallet_single(get_test_tr_single_sig_xprv()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); @@ -3676,7 +3676,7 @@ fn test_taproot_sign_derive_index_from_psbt() { #[test] fn test_taproot_sign_explicit_sighash_all() { let (mut wallet, _) = get_funded_wallet_single(get_test_tr_single_sig()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .drain_to(addr.script_pubkey()) @@ -3696,7 +3696,7 @@ fn test_taproot_sign_non_default_sighash() { let sighash = TapSighashType::NonePlusAnyoneCanPay; let (mut wallet, _) = get_funded_wallet_single(get_test_tr_single_sig()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder .drain_to(addr.script_pubkey()) @@ -3783,7 +3783,7 @@ fn test_spend_coinbase() { }], output: vec![TxOut { script_pubkey: wallet - .next_unused_address(KeychainKind::External) + .last_unused_address(KeychainKind::External) .script_pubkey(), value: Amount::from_sat(25_000), }], @@ -3872,7 +3872,7 @@ fn test_spend_coinbase() { fn test_allow_dust_limit() { let (mut wallet, _) = get_funded_wallet_single(get_test_single_sig_cltv()); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); @@ -3898,7 +3898,7 @@ fn test_fee_rate_sign_no_grinding_high_r() { // instead of 70). We then check that our fee rate and fee calculation is // alright. let (mut wallet, _) = get_funded_wallet_single("wpkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let fee_rate = FeeRate::from_sat_per_vb_unchecked(1); let mut builder = wallet.build_tx(); let mut data = PushBytesBuf::try_from(vec![0]).unwrap(); @@ -3965,7 +3965,7 @@ fn test_fee_rate_sign_grinding_low_r() { // We then check that our fee rate and fee calculation is alright and that our // signature is 70 bytes. let (mut wallet, _) = get_funded_wallet_single("wpkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)"); - let addr = wallet.next_unused_address(KeychainKind::External); + let addr = wallet.last_unused_address(KeychainKind::External); let fee_rate = FeeRate::from_sat_per_vb_unchecked(1); let mut builder = wallet.build_tx(); builder diff --git a/example-crates/example_wallet_electrum/src/main.rs b/example-crates/example_wallet_electrum/src/main.rs index 5942714ef..0fcd07aaa 100644 --- a/example-crates/example_wallet_electrum/src/main.rs +++ b/example-crates/example_wallet_electrum/src/main.rs @@ -37,7 +37,7 @@ fn main() -> Result<(), anyhow::Error> { .create_wallet(&mut db)?, }; - let address = wallet.next_unused_address(KeychainKind::External); + let address = wallet.last_unused_address(KeychainKind::External); wallet.persist(&mut db)?; println!("Generated Address: {}", address); diff --git a/example-crates/example_wallet_esplora_async/src/main.rs b/example-crates/example_wallet_esplora_async/src/main.rs index b6ab5d6dc..20c947cbd 100644 --- a/example-crates/example_wallet_esplora_async/src/main.rs +++ b/example-crates/example_wallet_esplora_async/src/main.rs @@ -35,7 +35,7 @@ async fn main() -> Result<(), anyhow::Error> { .create_wallet(&mut conn)?, }; - let address = wallet.next_unused_address(KeychainKind::External); + let address = wallet.last_unused_address(KeychainKind::External); wallet.persist(&mut conn)?; println!("Next unused address: ({}) {}", address.index, address); diff --git a/example-crates/example_wallet_esplora_blocking/src/main.rs b/example-crates/example_wallet_esplora_blocking/src/main.rs index 7966f19f5..f34b3fcb2 100644 --- a/example-crates/example_wallet_esplora_blocking/src/main.rs +++ b/example-crates/example_wallet_esplora_blocking/src/main.rs @@ -34,7 +34,7 @@ fn main() -> Result<(), anyhow::Error> { .create_wallet(&mut db)?, }; - let address = wallet.next_unused_address(KeychainKind::External); + let address = wallet.last_unused_address(KeychainKind::External); wallet.persist(&mut db)?; println!( "Next unused address: ({}) {}",