diff --git a/wallet/src/chain_storage.rs b/wallet/src/chain_storage.rs index 1f7036de..84cbbe7d 100644 --- a/wallet/src/chain_storage.rs +++ b/wallet/src/chain_storage.rs @@ -70,7 +70,13 @@ impl WalletChainStore { public_tree.insert(data.account_id, data.chain_index, data.data); } PersistentAccountData::Private(data) => { - private_tree.insert(data.account_id, data.chain_index, data.data); + let npk = data.data.value.0.nullifier_public_key; + let chain_index = data.chain_index; + for identifier in &data.identifiers { + let account_id = nssa::AccountId::from((&npk, *identifier)); + private_tree.account_id_map.insert(account_id, chain_index.clone()); + } + private_tree.key_map.insert(chain_index, data.data); } PersistentAccountData::Preconfigured(acc_data) => match acc_data { InitialAccountData::Public(data) => { @@ -282,10 +288,7 @@ mod tests { data: public_data, }), PersistentAccountData::Private(Box::new(PersistentAccountDataPrivate { - account_id: nssa::AccountId::from(( - &private_data.value.0.nullifier_public_key, - 0_u128, - )), + identifiers: vec![], chain_index: ChainIndex::root(), data: private_data, })), diff --git a/wallet/src/config.rs b/wallet/src/config.rs index 33527009..e67d6513 100644 --- a/wallet/src/config.rs +++ b/wallet/src/config.rs @@ -28,7 +28,7 @@ pub struct PersistentAccountDataPublic { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PersistentAccountDataPrivate { - pub account_id: nssa::AccountId, + pub identifiers: Vec, pub chain_index: ChainIndex, pub data: ChildKeysPrivate, } @@ -123,16 +123,6 @@ impl PersistentStorage { } } -impl PersistentAccountData { - #[must_use] - pub fn account_id(&self) -> nssa::AccountId { - match &self { - Self::Public(acc) => acc.account_id, - Self::Private(acc) => acc.account_id, - Self::Preconfigured(acc) => acc.account_id(), - } - } -} impl From for InitialAccountData { fn from(value: PublicAccountPrivateInitialData) -> Self { diff --git a/wallet/src/helperfunctions.rs b/wallet/src/helperfunctions.rs index bdefe10a..d2e0037a 100644 --- a/wallet/src/helperfunctions.rs +++ b/wallet/src/helperfunctions.rs @@ -165,41 +165,16 @@ pub fn produce_data_for_storage( } } - let covered_private_chain_indices: std::collections::BTreeSet<_> = user_data - .private_key_tree - .account_id_map - .values() - .cloned() - .collect(); - - for (account_id, key) in &user_data.private_key_tree.account_id_map { - if let Some(data) = user_data.private_key_tree.key_map.get(key) { - vec_for_storage.push( - PersistentAccountDataPrivate { - account_id: *account_id, - chain_index: key.clone(), - data: data.clone(), - } - .into(), - ); - } - } - - // Also persist fresh nodes that have no identifiers yet and are therefore absent from - // account_id_map. Without this, a restart before the first sync would lose the node - // entirely, making it impossible to detect incoming transfers. for (chain_index, node) in &user_data.private_key_tree.key_map { - if !covered_private_chain_indices.contains(chain_index) { - let account_id = nssa::AccountId::from((&node.value.0.nullifier_public_key, 0_u128)); - vec_for_storage.push( - PersistentAccountDataPrivate { - account_id, - chain_index: chain_index.clone(), - data: node.clone(), - } - .into(), - ); - } + let identifiers = node.value.1.iter().map(|(id, _)| *id).collect(); + vec_for_storage.push( + PersistentAccountDataPrivate { + identifiers, + chain_index: chain_index.clone(), + data: node.clone(), + } + .into(), + ); } for (account_id, key) in &user_data.default_pub_account_signing_keys {