mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-05-09 17:49:42 +00:00
return impl iterator
This commit is contained in:
parent
4719b1265a
commit
e19c9ff20a
@ -134,14 +134,13 @@ impl KeyTreeNode for ChildKeysPrivate {
|
||||
self.nth_child(cci)
|
||||
}
|
||||
|
||||
fn account_ids(&self) -> Vec<nssa::AccountId> {
|
||||
fn account_ids(&self) -> impl Iterator<Item = nssa::AccountId> {
|
||||
self.value
|
||||
.1
|
||||
.iter()
|
||||
.map(|(identifier, _)| {
|
||||
nssa::AccountId::from((&self.value.0.nullifier_public_key, *identifier))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -115,8 +115,8 @@ impl KeyTreeNode for ChildKeysPublic {
|
||||
self.nth_child(cci)
|
||||
}
|
||||
|
||||
fn account_ids(&self) -> Vec<nssa::AccountId> {
|
||||
vec![self.account_id()]
|
||||
fn account_ids(&self) -> impl Iterator<Item = nssa::AccountId> {
|
||||
std::iter::once(self.account_id())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -208,7 +208,7 @@ impl KeyTree<ChildKeysPublic> {
|
||||
) -> Option<(nssa::AccountId, ChainIndex)> {
|
||||
let cci = self.generate_new_node(parent_cci)?;
|
||||
let node = self.key_map.get(&cci)?;
|
||||
let account_id = *node.account_ids().first()?;
|
||||
let account_id = node.account_ids().next()?;
|
||||
Some((account_id, cci))
|
||||
}
|
||||
|
||||
@ -217,7 +217,7 @@ impl KeyTree<ChildKeysPublic> {
|
||||
pub fn generate_new_public_node_layered(&mut self) -> Option<(nssa::AccountId, ChainIndex)> {
|
||||
let cci = self.generate_new_node_layered()?;
|
||||
let node = self.key_map.get(&cci)?;
|
||||
let account_id = *node.account_ids().first()?;
|
||||
let account_id = node.account_ids().next()?;
|
||||
Some((account_id, cci))
|
||||
}
|
||||
|
||||
@ -298,9 +298,9 @@ impl KeyTree<ChildKeysPrivate> {
|
||||
'outer: for i in (1..depth).rev() {
|
||||
println!("Cleanup of tree at depth {i}");
|
||||
for id in ChainIndex::chain_ids_at_depth(i) {
|
||||
if let Some(node) = self.key_map.get(&id) {
|
||||
if let Some(node) = self.key_map.get(&id).cloned() {
|
||||
if node.value.1.is_empty() {
|
||||
let account_ids: Vec<_> = node.account_ids();
|
||||
let account_ids = node.account_ids();
|
||||
self.key_map.remove(&id);
|
||||
for addr in account_ids {
|
||||
self.account_id_map.remove(&addr);
|
||||
|
||||
@ -4,5 +4,5 @@ pub trait KeyTreeNode: Sized {
|
||||
#[must_use]
|
||||
fn derive_child(&self, cci: u32) -> Self;
|
||||
#[must_use]
|
||||
fn account_ids(&self) -> Vec<nssa::AccountId>;
|
||||
fn account_ids(&self) -> impl Iterator<Item = nssa::AccountId>;
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ use key_protocol::{
|
||||
key_tree::{KeyTreePrivate, KeyTreePublic, chain_index::ChainIndex},
|
||||
secret_holders::SeedHolder,
|
||||
},
|
||||
key_protocol_core::NSSAUserData,
|
||||
key_protocol_core::{NSSAUserData, UserPrivateAccountData},
|
||||
};
|
||||
use log::debug;
|
||||
use nssa::program::Program;
|
||||
@ -79,8 +79,7 @@ impl WalletChainStore {
|
||||
InitialAccountData::Private(data) => {
|
||||
private_init_acc_map.insert(
|
||||
data.account_id,
|
||||
(data.key_chain, vec![(data.identifier, data.account)]),
|
||||
);
|
||||
UserPrivateAccountData{ key_chain: data.key_chain, accounts: vec![(data.identifier, data.account)]});
|
||||
}
|
||||
},
|
||||
}
|
||||
@ -121,8 +120,7 @@ impl WalletChainStore {
|
||||
account.program_owner = Program::authenticated_transfer_program().id();
|
||||
private_init_acc_map.insert(
|
||||
data.account_id,
|
||||
(data.key_chain, vec![(data.identifier, account)]),
|
||||
);
|
||||
UserPrivateAccountData{key_chain: data.key_chain, accounts:vec![(data.identifier, account)]});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -186,19 +184,19 @@ impl WalletChainStore {
|
||||
.default_user_private_accounts
|
||||
.entry(account_id)
|
||||
{
|
||||
let (key_chain, entries) = entry.get_mut();
|
||||
let identifier = entries
|
||||
let entry = entry.get_mut();
|
||||
let identifier = entry.accounts
|
||||
.iter()
|
||||
.find_map(|(id, _)| {
|
||||
(nssa::AccountId::from((&key_chain.nullifier_public_key, *id)) == account_id)
|
||||
(nssa::AccountId::from((&entry.key_chain.nullifier_public_key, *id)) == account_id)
|
||||
.then_some(*id)
|
||||
})
|
||||
.unwrap_or(0);
|
||||
// Update existing entry or insert new one
|
||||
if let Some((_, acc)) = entries.iter_mut().find(|(id, _)| *id == identifier) {
|
||||
if let Some((_, acc)) = entry.accounts.iter_mut().find(|(id, _)| *id == identifier) {
|
||||
*acc = account;
|
||||
} else {
|
||||
entries.push((identifier, account));
|
||||
entry.accounts.push((identifier, account));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -212,13 +212,13 @@ pub fn produce_data_for_storage(
|
||||
);
|
||||
}
|
||||
|
||||
for (account_id, (key_chain, entries)) in &user_data.default_user_private_accounts {
|
||||
for (identifier, account) in entries {
|
||||
for (account_id, 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: key_chain.clone(),
|
||||
key_chain: entry.key_chain.clone(),
|
||||
identifier: *identifier,
|
||||
}))
|
||||
.into(),
|
||||
|
||||
@ -508,7 +508,7 @@ impl WalletCore {
|
||||
.user_data
|
||||
.default_user_private_accounts
|
||||
.values()
|
||||
.map(|(key_chain, _)| (key_chain, None))
|
||||
.map(|entry| (&entry.key_chain, None))
|
||||
.chain(
|
||||
self.storage
|
||||
.user_data
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user