fix context issue

This commit is contained in:
jonesmarvin8 2026-04-07 17:34:11 -04:00
parent 92ae120ae7
commit 38a64f6587
10 changed files with 79 additions and 51 deletions

View File

@ -164,15 +164,15 @@ async fn private_transfer_to_owned_account_using_claiming_path() -> Result<()> {
};
// Get the keys for the newly created account
let (to_keys, _) = ctx
let bundle = ctx
.wallet()
.storage()
.user_data
.get_private_account(to_account_id)
.unwrap()
.key_chain
.context("Failed to get private account")?;
let to_keys = bundle.key_chain;
// Send to this account using claiming path (using npk and vpk instead of account ID)
let command = Command::AuthTransfer(AuthTransferSubcommand::Send {
from: format_private_account_id(from),
@ -325,15 +325,15 @@ async fn private_transfer_to_owned_account_continuous_run_path() -> Result<()> {
};
// Get the newly created account's keys
let (to_keys, _) = ctx
let bundle = ctx
.wallet()
.storage()
.user_data
.get_private_account(to_account_id)
.unwrap()
.key_chain
.context("Failed to get private account")?;
let to_keys = bundle.key_chain;
// Send transfer using nullifier and viewing public keys
let command = Command::AuthTransfer(AuthTransferSubcommand::Send {
from: format_private_account_id(from),

View File

@ -58,16 +58,15 @@ async fn sync_private_account_with_non_zero_chain_index() -> Result<()> {
anyhow::bail!("Expected RegisterAccount return value");
};
// Get the keys for the newly created account
let (to_keys, _) = ctx
let bundle = ctx
.wallet()
.storage()
.user_data
.get_private_account(to_account_id)
.unwrap()
.key_chain
.context("Failed to get private account")?;
let to_keys = bundle.key_chain;
// Send to this account using claiming path (using npk and vpk instead of account ID)
let command = Command::AuthTransfer(AuthTransferSubcommand::Send {
from: format_private_account_id(from),

View File

@ -1097,14 +1097,14 @@ async fn token_claiming_path_with_private_accounts() -> Result<()> {
};
// Get keys for foreign mint (claiming path)
let (holder_keys, _) = ctx
let holder_keys = ctx
.wallet()
.storage()
.user_data
.get_private_account(recipient_account_id)
.unwrap()
.key_chain
.context("Failed to get private account keys")?;
.key_chain;
// .context("Failed to get private account keys")?;
// Mint using claiming path (foreign account)
let mint_amount = 9;

View File

@ -2,11 +2,14 @@ use k256::{Scalar, elliptic_curve::PrimeField as _};
use nssa_core::{NullifierPublicKey, encryption::ViewingPublicKey};
use serde::{Deserialize, Serialize};
use crate::{key_management::{
KeyChain,
key_tree::traits::KeyNode,
secret_holders::{PrivateKeyHolder, SecretSpendingKey},
}, key_protocol_core::PrivateBundle};
use crate::{
key_management::{
KeyChain,
key_tree::traits::KeyNode,
secret_holders::{PrivateKeyHolder, SecretSpendingKey},
},
key_protocol_core::PrivateBundle,
};
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ChildKeysPrivate {
@ -131,8 +134,10 @@ impl<'a> From<&'a ChildKeysPrivate> for &'a (KeyChain, nssa::Account) {
)]
impl<'a> From<&'a mut ChildKeysPrivate> for PrivateBundle {
fn from(value: &'a mut ChildKeysPrivate) -> Self {
PrivateBundle { key_chain: value.value.0.clone(),
account: value.value.1.clone(), }
Self {
key_chain: value.value.0.clone(),
account: value.value.1.clone(),
}
}
}

View File

@ -69,10 +69,7 @@ impl NSSAUserData {
pub fn new_with_accounts(
default_accounts_keys: BTreeMap<nssa::AccountId, PublicBundle>,
default_accounts_key_chains: BTreeMap<
nssa::AccountId,
PrivateBundle,
>,
default_accounts_key_chains: BTreeMap<nssa::AccountId, PrivateBundle>,
public_key_tree: KeyTreePublic,
private_key_tree: KeyTreePrivate,
) -> Result<Self> {
@ -147,11 +144,8 @@ impl NSSAUserData {
}
/// Returns the signing key for public transaction signatures.
#[must_use] //Marvin: double check TODO
#[must_use]
pub fn get_private_account(&self, account_id: nssa::AccountId) -> Option<PrivateBundle> {
// self.default_user_private_accounts
// .get(&account_id)
// .or_else(|| self.private_key_tree.get_node(account_id).map(Into::into))
self.default_user_private_accounts
.get(&account_id)
.cloned()
@ -166,7 +160,6 @@ impl NSSAUserData {
}
/// Returns the signing key for public transaction signatures.
/// TODO: fix this comment (Marvin)
pub fn get_private_account_mut(
&mut self,
account_id: &nssa::AccountId,
@ -231,7 +224,10 @@ mod tests {
let account_id_private_str = account_id_private.to_string();
println!("{account_id_private_str:#?}");
let key_chain = &user_data.get_private_account(account_id_private).unwrap().key_chain;
let key_chain = &user_data
.get_private_account(account_id_private)
.unwrap()
.key_chain;
println!("{key_chain:#?}");
}
}

View File

@ -116,8 +116,7 @@ pub unsafe extern "C" fn wallet_ffi_get_private_account_keys(
let account_id = AccountId::new(unsafe { (*account_id).data });
let Some(bundle) = wallet.storage().user_data.get_private_account(account_id)
else {
let Some(bundle) = wallet.storage().user_data.get_private_account(account_id) else {
print_error("Private account not found in wallet");
return WalletFfiError::AccountNotFound;
};

View File

@ -82,8 +82,13 @@ impl WalletChainStore {
);
}
InitialAccountData::Private(data) => {
private_init_acc_map
.insert(data.account_id, PrivateBundle {key_chain: data.key_chain, account: data.account});
private_init_acc_map.insert(
data.account_id,
PrivateBundle {
key_chain: data.key_chain,
account: data.account,
},
);
}
},
}
@ -127,7 +132,13 @@ impl WalletChainStore {
// startup. Fix this when program id can be fetched
// from the node and queried from the wallet.
account.program_owner = Program::authenticated_transfer_program().id();
private_init_acc_map.insert(data.account_id, PrivateBundle{ key_chain: data.key_chain, account: account});
private_init_acc_map.insert(
data.account_id,
PrivateBundle {
key_chain: data.key_chain,
account,
},
);
}
}
}

View File

@ -137,7 +137,7 @@ impl WalletSubcommand for NewSubcommand {
.insert(account_id.to_string(), Label::new(label));
}
let bundle= wallet_core
let bundle = wallet_core
.storage
.user_data
.get_private_account(account_id)
@ -146,7 +146,10 @@ impl WalletSubcommand for NewSubcommand {
println!(
"Generated new account with account_id Private/{account_id} at path {chain_index}",
);
println!("With npk {}", hex::encode(bundle.key_chain.nullifier_public_key.0));
println!(
"With npk {}",
hex::encode(bundle.key_chain.nullifier_public_key.0)
);
println!(
"With vpk {}",
hex::encode(bundle.key_chain.viewing_public_key.to_bytes())
@ -203,14 +206,20 @@ impl WalletSubcommand for AccountSubcommand {
println!("pk {}", hex::encode(public_key.value()));
}
AccountPrivacyKind::Private => {
let bundle= wallet_core
let bundle = wallet_core
.storage
.user_data
.get_private_account(account_id)
.context("Private account not found in storage")?;
println!("npk {}", hex::encode(bundle.key_chain.nullifier_public_key.0));
println!("vpk {}", hex::encode(bundle.key_chain.viewing_public_key.to_bytes()));
println!(
"npk {}",
hex::encode(bundle.key_chain.nullifier_public_key.0)
);
println!(
"vpk {}",
hex::encode(bundle.key_chain.viewing_public_key.to_bytes())
);
}
}
Ok(())

View File

@ -15,7 +15,10 @@ use bip39::Mnemonic;
use chain_storage::WalletChainStore;
use common::{HashType, transaction::NSSATransaction};
use config::WalletConfig;
use key_protocol::{key_management::key_tree::{chain_index::ChainIndex, traits::KeyNode as _}, key_protocol_core::PrivateBundle};
use key_protocol::{
key_management::key_tree::{chain_index::ChainIndex, traits::KeyNode as _},
key_protocol_core::PrivateBundle,
};
use log::info;
use nssa::{
Account, AccountId, PrivacyPreservingTransaction,
@ -295,13 +298,16 @@ impl WalletCore {
self.storage
.user_data
.get_private_account(account_id)
.map(|bundle| bundle.account.clone())
.map(|bundle| bundle.account)
}
#[must_use]
pub fn get_private_account_commitment(&self, account_id: AccountId) -> Option<Commitment> {
let bundle= self.storage.user_data.get_private_account(account_id)?;
Some(Commitment::new(&bundle.key_chain.nullifier_public_key, &bundle.account))
let bundle = self.storage.user_data.get_private_account(account_id)?;
Some(Commitment::new(
&bundle.key_chain.nullifier_public_key,
&bundle.account,
))
}
/// Poll transactions.
@ -484,7 +490,15 @@ impl WalletCore {
.user_data
.default_user_private_accounts
.iter()
.map(|(acc_account_id, PrivateBundle{key_chain,account: _ })| (*acc_account_id, key_chain, None))
.map(
|(
acc_account_id,
PrivateBundle {
key_chain,
account: _,
},
)| (*acc_account_id, key_chain, None),
)
.chain(self.storage.user_data.private_key_tree.key_map.iter().map(
|(chain_index, keys_node)| {
(

View File

@ -202,12 +202,7 @@ async fn private_acc_preparation(
wallet: &WalletCore,
account_id: AccountId,
) -> Result<AccountPreparedData, ExecutionFailureKind> {
let Some(from_bundle) = wallet
.storage
.user_data
.get_private_account(account_id)
.clone()
else {
let Some(from_bundle) = wallet.storage.user_data.get_private_account(account_id) else {
return Err(ExecutionFailureKind::KeyNotFoundError);
};