mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-05-08 17:19:45 +00:00
refactor wallet config to use identifiers instead of the redundant account_id field
This commit is contained in:
parent
f0b89f8acb
commit
f512a3bf0f
@ -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,
|
||||
|
||||
@ -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<PublicAccountPrivateInitialData> {
|
||||
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<PrivateAccountPrivateInitialD
|
||||
|
||||
vec![
|
||||
PrivateAccountPrivateInitialData {
|
||||
account_id: AccountId::from((&key_chain_1.nullifier_public_key, 0)),
|
||||
account: Account {
|
||||
program_owner: DEFAULT_PROGRAM_OWNER,
|
||||
balance: PRIV_ACC_A_INITIAL_BALANCE,
|
||||
@ -154,7 +159,6 @@ pub fn initial_priv_accounts_private_keys() -> Vec<PrivateAccountPrivateInitialD
|
||||
identifier: 0,
|
||||
},
|
||||
PrivateAccountPrivateInitialData {
|
||||
account_id: AccountId::from((&key_chain_2.nullifier_public_key, 0)),
|
||||
account: Account {
|
||||
program_owner: DEFAULT_PROGRAM_OWNER,
|
||||
balance: PRIV_ACC_B_INITIAL_BALANCE,
|
||||
@ -358,11 +362,11 @@ mod tests {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
init_private_accs_keys[0].account_id.to_string(),
|
||||
init_private_accs_keys[0].account_id().to_string(),
|
||||
PRIV_ACC_A_TEXT_ADDR
|
||||
);
|
||||
assert_eq!(
|
||||
init_private_accs_keys[1].account_id.to_string(),
|
||||
init_private_accs_keys[1].account_id().to_string(),
|
||||
PRIV_ACC_B_TEXT_ADDR
|
||||
);
|
||||
|
||||
|
||||
@ -84,7 +84,7 @@ impl WalletChainStore {
|
||||
}
|
||||
InitialAccountData::Private(data) => {
|
||||
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)],
|
||||
|
||||
@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user