Skip to content

Commit 83f86cd

Browse files
committed
refactor(wallet)!: rename method to last_unused_address
As per both out-of-band discussions, and the latest discussion at weekly development call, the semantics of this method can be misleading, as it's not guaranteed you get a next one on every call, that'd only happen if the address has been used and the application synced with latest blockchain state. Renaming it to `last_unused_address` gives it a better semantics, as you'll always get the last derived address which still unused. As per usage where the user needs always a new derived address on every call, you should still use the `reveal_next_address`, nothing changed.
1 parent 3bc45b5 commit 83f86cd

File tree

7 files changed

+95
-95
lines changed

7 files changed

+95
-95
lines changed

crates/wallet/examples/compiler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn main() -> Result<(), Box<dyn Error>> {
6464

6565
println!(
6666
"First derived address from the descriptor: \n{}",
67-
wallet.next_unused_address(KeychainKind::External),
67+
wallet.last_unused_address(KeychainKind::External),
6868
);
6969

7070
// BDK also has it's own `Policy` structure to represent the spending condition in a more

crates/wallet/src/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ pub fn receive_output(
245245
value: u64,
246246
pos: ChainPosition<ConfirmationBlockTime>,
247247
) -> OutPoint {
248-
let addr = wallet.next_unused_address(KeychainKind::External).address;
248+
let addr = wallet.last_unused_address(KeychainKind::External).address;
249249
receive_output_to_address(wallet, addr, value, pos)
250250
}
251251

crates/wallet/src/wallet/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,15 +737,15 @@ impl Wallet {
737737
})
738738
}
739739

740-
/// Get the next unused address for the given `keychain`, i.e. the address with the lowest
740+
/// Get the last unused address for the given `keychain`, i.e. the address with the lowest
741741
/// derivation index that hasn't been used.
742742
///
743743
/// This will attempt to derive and reveal a new address if no newly revealed addresses
744744
/// are available. See also [`reveal_next_address`](Self::reveal_next_address).
745745
///
746746
/// **WARNING**: To avoid address reuse you must persist the changes resulting from one or more
747747
/// calls to this method before closing the wallet. See [`Wallet::reveal_next_address`].
748-
pub fn next_unused_address(&mut self, keychain: KeychainKind) -> AddressInfo {
748+
pub fn last_unused_address(&mut self, keychain: KeychainKind) -> AddressInfo {
749749
let keychain = self.map_keychain(keychain);
750750
let index = &mut self.indexed_graph.index;
751751

crates/wallet/tests/wallet.rs

Lines changed: 88 additions & 88 deletions
Large diffs are not rendered by default.

example-crates/example_wallet_electrum/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn main() -> Result<(), anyhow::Error> {
3737
.create_wallet(&mut db)?,
3838
};
3939

40-
let address = wallet.next_unused_address(KeychainKind::External);
40+
let address = wallet.last_unused_address(KeychainKind::External);
4141
wallet.persist(&mut db)?;
4242
println!("Generated Address: {}", address);
4343

example-crates/example_wallet_esplora_async/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async fn main() -> Result<(), anyhow::Error> {
3535
.create_wallet(&mut conn)?,
3636
};
3737

38-
let address = wallet.next_unused_address(KeychainKind::External);
38+
let address = wallet.last_unused_address(KeychainKind::External);
3939
wallet.persist(&mut conn)?;
4040
println!("Next unused address: ({}) {}", address.index, address);
4141

example-crates/example_wallet_esplora_blocking/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn main() -> Result<(), anyhow::Error> {
3434
.create_wallet(&mut db)?,
3535
};
3636

37-
let address = wallet.next_unused_address(KeychainKind::External);
37+
let address = wallet.last_unused_address(KeychainKind::External);
3838
wallet.persist(&mut db)?;
3939
println!(
4040
"Next unused address: ({}) {}",

0 commit comments

Comments
 (0)