From c396be929554782756a39dffaa114d23cf85ef2d Mon Sep 17 00:00:00 2001 From: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> Date: Wed, 20 Sep 2023 16:20:04 +0200 Subject: [PATCH] Fix potential problem with binary_search_by_key() (#1274) * Fix potential problem with binary_search_by_key() * Changelog entry --- cli/CHANGELOG.md | 6 ++++++ cli/src/command/account.rs | 11 ++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index bba6480056..593c427f13 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security --> +## 1.0.1 - 2023-MM-DD + +### Fixed + +- Potential bug in the addresses command; + ## 1.0.0 - 2023-07-27 First release of the `cli-wallet`. diff --git a/cli/src/command/account.rs b/cli/src/command/account.rs index eea411c7ae..3dac765145 100644 --- a/cli/src/command/account.rs +++ b/cli/src/command/account.rs @@ -878,11 +878,12 @@ async fn print_address(account: &Account, address: &AccountAddress) -> Result<() let addresses = account.addresses_with_unspent_outputs().await?; let current_time = iota_sdk::utils::unix_timestamp_now().as_secs() as u32; - if let Ok(index) = addresses.binary_search_by_key(&(address.key_index(), address.internal()), |a| { - (a.key_index(), a.internal()) - }) { + if let Some(address) = addresses + .iter() + .find(|a| a.key_index() == address.key_index() && a.internal() == address.internal()) + { let mut address_amount = 0; - for output_id in addresses[index].output_ids() { + for output_id in address.output_ids() { if let Some(output_data) = account.get_output(output_id).await { // Output might be associated with the address, but can't unlocked by it, so we check that here let (required_address, _) = @@ -905,7 +906,7 @@ async fn print_address(account: &Account, address: &AccountAddress) -> Result<() } log = format!( "{log}\nOutputs: {:#?}\nBase coin amount: {}\n", - addresses[index].output_ids(), + address.output_ids(), address_amount ); } else {