From f512a3bf0f7570ddabdf3c2118efe8821cf09dee Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Mon, 27 Apr 2026 23:11:58 -0300 Subject: [PATCH] refactor wallet config to use identifiers instead of the redundant account_id field --- integration_tests/src/config.rs | 2 -- testnet_initial_state/src/lib.rs | 14 +++++++++----- wallet/src/chain_storage.rs | 5 +++-- wallet/src/config.rs | 4 ++-- wallet/src/helperfunctions.rs | 3 +-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/integration_tests/src/config.rs b/integration_tests/src/config.rs index 6a3999b6..faff1e79 100644 --- a/integration_tests/src/config.rs +++ b/integration_tests/src/config.rs @@ -139,9 +139,7 @@ impl InitialData { }) }) .chain(self.private_accounts.iter().map(|(key_chain, account)| { - let account_id = AccountId::from((&key_chain.nullifier_public_key, 0)); InitialAccountData::Private(Box::new(PrivateAccountPrivateInitialData { - account_id, account: account.clone(), key_chain: key_chain.clone(), identifier: 0, diff --git a/testnet_initial_state/src/lib.rs b/testnet_initial_state/src/lib.rs index d501026f..f6f1e288 100644 --- a/testnet_initial_state/src/lib.rs +++ b/testnet_initial_state/src/lib.rs @@ -95,12 +95,18 @@ pub struct PublicAccountPrivateInitialData { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PrivateAccountPrivateInitialData { - pub account_id: nssa::AccountId, pub account: nssa_core::account::Account, pub key_chain: KeyChain, pub identifier: nssa_core::Identifier, } +impl PrivateAccountPrivateInitialData { + #[must_use] + pub fn account_id(&self) -> nssa::AccountId { + nssa::AccountId::from((&self.key_chain.nullifier_public_key, self.identifier)) + } +} + #[must_use] pub fn initial_pub_accounts_private_keys() -> Vec { let acc1_pub_sign_key = PrivateKey::try_new(PRIVATE_KEY_PUB_ACC_A).unwrap(); @@ -143,7 +149,6 @@ pub fn initial_priv_accounts_private_keys() -> Vec Vec { private_init_acc_map.insert( - data.account_id, + data.account_id(), UserPrivateAccountData { key_chain: data.key_chain, accounts: vec![(data.identifier, data.account)], @@ -122,6 +122,7 @@ impl WalletChainStore { public_init_acc_map.insert(data.account_id, data.pub_sign_key); } InitialAccountData::Private(data) => { + let account_id = data.account_id(); let mut account = data.account; // TODO: Program owner is only known after code is compiled and can't be set // in the config. Therefore we overwrite it here on @@ -129,7 +130,7 @@ impl WalletChainStore { // from the node and queried from the wallet. account.program_owner = Program::authenticated_transfer_program().id(); private_init_acc_map.insert( - data.account_id, + account_id, UserPrivateAccountData { key_chain: data.key_chain, accounts: vec![(data.identifier, account)], diff --git a/wallet/src/config.rs b/wallet/src/config.rs index e67d6513..ddb033ff 100644 --- a/wallet/src/config.rs +++ b/wallet/src/config.rs @@ -44,10 +44,10 @@ pub enum InitialAccountData { impl InitialAccountData { #[must_use] - pub const fn account_id(&self) -> nssa::AccountId { + pub fn account_id(&self) -> nssa::AccountId { match &self { Self::Public(acc) => acc.account_id, - Self::Private(acc) => acc.account_id, + Self::Private(acc) => acc.account_id(), } } diff --git a/wallet/src/helperfunctions.rs b/wallet/src/helperfunctions.rs index d2e0037a..13539f29 100644 --- a/wallet/src/helperfunctions.rs +++ b/wallet/src/helperfunctions.rs @@ -187,11 +187,10 @@ pub fn produce_data_for_storage( ); } - for (account_id, entry) in &user_data.default_user_private_accounts { + for (_, entry) in &user_data.default_user_private_accounts { for (identifier, account) in &entry.accounts { vec_for_storage.push( InitialAccountData::Private(Box::new(PrivateAccountPrivateInitialData { - account_id: *account_id, account: account.clone(), key_chain: entry.key_chain.clone(), identifier: *identifier,