mirror of
https://github.com/damus-io/notedeck.git
synced 2024-09-19 13:16:34 +00:00
account_manager: don't add the same pubkey more than once
If we are passing keys on the command line, let's make sure we aren't adding duplicates when we integrate the keystore. Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
parent
307b8af8f1
commit
1810515ad2
@ -4,6 +4,7 @@ use enostr::Keypair;
|
||||
|
||||
use crate::key_storage::KeyStorage;
|
||||
pub use crate::user_account::UserAccount;
|
||||
use tracing::info;
|
||||
|
||||
/// The interface for managing the user's accounts.
|
||||
/// Represents all user-facing operations related to account management.
|
||||
@ -55,9 +56,24 @@ impl AccountManager {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_account(&mut self, account: Keypair) {
|
||||
pub fn has_account_pubkey(&self, pubkey: &[u8; 32]) -> bool {
|
||||
for account in &self.accounts {
|
||||
if account.pubkey.bytes() == pubkey {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
pub fn add_account(&mut self, account: Keypair) -> bool {
|
||||
if self.has_account_pubkey(account.pubkey.bytes()) {
|
||||
info!("already have account, not adding {}", account.pubkey);
|
||||
return false;
|
||||
}
|
||||
let _ = self.key_store.add_key(&account);
|
||||
self.accounts.push(account)
|
||||
self.accounts.push(account);
|
||||
true
|
||||
}
|
||||
|
||||
pub fn num_accounts(&self) -> usize {
|
||||
|
Loading…
Reference in New Issue
Block a user