Skip to content

Commit

Permalink
Atomic version of remove_all_by_alias
Browse files Browse the repository at this point in the history
  • Loading branch information
karbyshev committed Mar 7, 2024
1 parent 7b24411 commit 7158ccd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion crates/apps/src/lib/cli/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,9 @@ fn key_address_remove(
) {
let alias = alias.to_lowercase();
let mut wallet = load_wallet(ctx);
wallet.remove_all_by_alias(alias.clone());
wallet
.remove_all_by_alias_atomic(alias.clone())
.expect("Failed to update the wallet storage.");
wallet
.save()
.unwrap_or_else(|err| edisplay_line!(io, "{}", err));
Expand Down
14 changes: 9 additions & 5 deletions crates/sdk/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,15 @@ impl<U: WalletStorage> Wallet<U> {
let other_store = wallet.utils.load_store_read_only()?;
self.utils.update_store(|store| store.extend(other_store))
}

/// Remove keys and addresses associated with the given alias
pub fn remove_all_by_alias_atomic(
&mut self,
alias: String,
) -> Result<(), LoadStoreError> {
self.utils
.update_store(|store| store.remove_alias(&alias.into()))
}
}

impl<U: WalletIo> Wallet<U> {
Expand Down Expand Up @@ -1154,11 +1163,6 @@ impl<U: WalletIo> Wallet<U> {
})
.map(Into::into)
}

/// Remove keys and addresses associated with the given alias
pub fn remove_all_by_alias(&mut self, alias: String) {
self.store.remove_alias(&alias.into())
}
}

impl<U: WalletIo + WalletStorage> Wallet<U> {
Expand Down

0 comments on commit 7158ccd

Please sign in to comment.