Skip to content

Commit

Permalink
Fix potential problem with binary_search_by_key() (#1274)
Browse files Browse the repository at this point in the history
* Fix potential problem with binary_search_by_key()

* Changelog entry
  • Loading branch information
Thoralf-M authored Sep 20, 2023
1 parent 64413fa commit c396be9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 6 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
11 changes: 6 additions & 5 deletions cli/src/command/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, _) =
Expand All @@ -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 {
Expand Down

0 comments on commit c396be9

Please sign in to comment.