fix: comments fix 2

This commit is contained in:
Oleksandr Pravdyvyi 2025-09-02 07:32:39 +03:00
parent 5c3418ca8e
commit 9993590d45
No known key found for this signature in database
GPG Key ID: 9F8955C63C443871
11 changed files with 561 additions and 261 deletions

View File

@ -11,7 +11,6 @@ pub type PublicKey = AffinePoint;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct NSSAUserData {
pub key_holder: KeyChain,
pub accounts: HashMap<nssa::Address, nssa_core::account::Account>,
}
impl NSSAUserData {
@ -20,7 +19,6 @@ impl NSSAUserData {
Self {
key_holder,
accounts: HashMap::new(),
}
}
@ -38,7 +36,6 @@ impl NSSAUserData {
pub fn new_with_accounts(
accounts_keys: HashMap<nssa::Address, nssa::PrivateKey>,
accounts: HashMap<nssa::Address, nssa_core::account::Account>,
) -> Result<Self> {
if !Self::valid_key_transaction_pairing_check(&accounts_keys) {
anyhow::bail!("Key transaction pairing check not satisfied, there is addresses, which is not derived from keys");
@ -48,44 +45,18 @@ impl NSSAUserData {
Ok(Self {
key_holder,
accounts,
})
}
pub fn generate_new_account(&mut self) -> nssa::Address {
let address = self.key_holder.generate_new_private_key();
self.accounts
.insert(address, nssa_core::account::Account::default());
address
}
pub fn get_account_balance(&self, address: &nssa::Address) -> u128 {
self.accounts
.get(address)
.map(|acc| acc.balance)
.unwrap_or(0)
}
pub fn get_account(&self, address: &nssa::Address) -> Option<&nssa_core::account::Account> {
self.accounts.get(address)
}
pub fn get_account_signing_key(&self, address: &nssa::Address) -> Option<&nssa::PrivateKey> {
self.key_holder.get_pub_account_signing_key(address)
}
pub fn update_account_balance(&mut self, address: nssa::Address, new_balance: u128) {
self.accounts
.entry(address)
.and_modify(|acc| acc.balance = new_balance)
.or_default();
}
//ToDo: Part of a private keys update
// pub fn make_tag(&self) -> Tag {
// self.address.value()[0]
// }
}
impl Default for NSSAUserData {
@ -102,29 +73,6 @@ mod tests {
fn test_new_account() {
let mut user_data = NSSAUserData::new();
let addr = user_data.generate_new_account();
assert_eq!(user_data.get_account_balance(&addr), 0);
let _addr = user_data.generate_new_account();
}
#[test]
fn test_update_balance() {
let mut user_data = NSSAUserData::new();
let address = user_data.generate_new_account();
user_data.update_account_balance(address, 500);
assert_eq!(user_data.get_account_balance(&address), 500);
}
//ToDo: Part of a private keys update
// #[test]
// fn accounts_accounts_mask_tag_consistency() {
// let account = NSSAUserData::new();
// let account_mask = account.make_account_public_mask();
// assert_eq!(account.make_tag(), account_mask.make_tag());
// }
}

View File

@ -5,7 +5,7 @@ edition = "2024"
[dependencies]
thiserror = "2.0.12"
risc0-zkvm = "2.3.1"
risc0-zkvm = "3.0.3"
nssa-core = { path = "core" }
program-methods = { path = "program_methods" }
serde = "1.0.219"

View File

@ -4,5 +4,5 @@ version = "0.1.0"
edition = "2024"
[dependencies]
risc0-zkvm = "2.3.1"
risc0-zkvm = "3.0.3"
serde = { version = "1.0", default-features = false }

View File

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"
[build-dependencies]
risc0-build = { version = "2.3.1" }
risc0-build = { version = "3.0.3" }
[package.metadata.risc0]
methods = ["guest"]

File diff suppressed because it is too large Load Diff

View File

@ -6,5 +6,5 @@ edition = "2021"
[workspace]
[dependencies]
risc0-zkvm = { version = "2.3.1", default-features = false, features = ['std'] }
risc0-zkvm = { version = "3.0.3", default-features = false, features = ['std'] }
nssa-core = { path = "../../core" }

View File

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"
[build-dependencies]
risc0-build = { version = "2.3.1" }
risc0-build = { version = "3.0.3" }
[package.metadata.risc0]
methods = ["guest"]

View File

@ -6,5 +6,5 @@ edition = "2021"
[workspace]
[dependencies]
risc0-zkvm = { version = "2.3.1", default-features = false, features = ['std'] }
risc0-zkvm = { version = "3.0.3", default-features = false, features = ['std'] }
nssa-core = { path = "../../core" }

View File

@ -18,7 +18,7 @@ reqwest.workspace = true
thiserror.workspace = true
tokio.workspace = true
tempfile.workspace = true
risc0-zkvm = "2.3.1"
risc0-zkvm = "3.0.3"
hex.workspace = true
actix-rt.workspace = true
clap.workspace = true

View File

@ -14,13 +14,6 @@ pub struct WalletChainStore {
impl WalletChainStore {
pub fn new(config: WalletConfig) -> Result<Self> {
let accounts: HashMap<nssa::Address, nssa_core::account::Account> = config
.initial_accounts
.clone()
.into_iter()
.map(|init_acc_data| (init_acc_data.address, init_acc_data.account))
.collect();
let accounts_keys: HashMap<nssa::Address, nssa::PrivateKey> = config
.initial_accounts
.clone()
@ -31,7 +24,7 @@ impl WalletChainStore {
let utxo_commitments_store = UTXOCommitmentsMerkleTree::new(vec![]);
Ok(Self {
user_data: NSSAUserData::new_with_accounts(accounts_keys, accounts)?,
user_data: NSSAUserData::new_with_accounts(accounts_keys)?,
utxo_commitments_store,
wallet_config: config,
})
@ -93,7 +86,6 @@ mod tests {
let store = WalletChainStore::new(config.clone()).unwrap();
assert_eq!(store.user_data.accounts.len(), 2);
assert_eq!(
store.utxo_commitments_store.get_root().unwrap_or([0; 32]),
[0; 32]

View File

@ -12,9 +12,10 @@ use log::info;
use nssa::Address;
use clap::{Parser, Subcommand};
use nssa_core::account::Account;
use crate::helperfunctions::{
fetch_config, fetch_persistent_accounts, produce_account_addr_from_hex,
fetch_config, produce_account_addr_from_hex,
};
pub const HOME_DIR_ENV_VAR: &str = "NSSA_WALLET_HOME_DIR";
@ -30,17 +31,10 @@ pub struct WalletCore {
}
impl WalletCore {
pub async fn start_from_config_update_chain(config: WalletConfig) -> Result<Self> {
pub fn start_from_config_update_chain(config: WalletConfig) -> Result<Self> {
let client = Arc::new(SequencerClient::new(config.sequencer_addr.clone())?);
let mut storage = WalletChainStore::new(config)?;
let persistent_accounts = fetch_persistent_accounts()?;
for acc in persistent_accounts {
storage
.user_data
.update_account_balance(acc.address, acc.account.balance);
}
let storage = WalletChainStore::new(config)?;
Ok(Self {
storage,
@ -48,10 +42,19 @@ impl WalletCore {
})
}
pub async fn create_new_account(&mut self) -> Address {
pub fn create_new_account(&mut self) -> Address {
self.storage.user_data.generate_new_account()
}
pub fn search_for_initial_account(&self, acc_addr: Address) -> Option<Account> {
for initial_acc in &self.storage.wallet_config.initial_accounts {
if initial_acc.address == acc_addr {
return Some(initial_acc.account.clone());
}
}
None
}
pub async fn send_public_native_token_transfer(
&self,
from: Address,
@ -59,7 +62,7 @@ impl WalletCore {
to: Address,
balance_to_move: u128,
) -> Result<SendTxResponse, ExecutionFailureKind> {
let account = self.storage.user_data.get_account(&from);
let account = self.search_for_initial_account(from);
if let Some(account) = account {
if account.balance >= balance_to_move {
@ -138,7 +141,7 @@ pub async fn execute_subcommand(command: Command) -> Result<()> {
let from = produce_account_addr_from_hex(from)?;
let to = produce_account_addr_from_hex(to)?;
let wallet_core = WalletCore::start_from_config_update_chain(wallet_config).await?;
let wallet_core = WalletCore::start_from_config_update_chain(wallet_config)?;
let res = wallet_core
.send_public_native_token_transfer(from, nonce, to, amount)