fix: comments fix

This commit is contained in:
Oleksandr Pravdyvyi 2025-08-11 08:55:08 +03:00
parent 17b6851d00
commit c3b5d62ea6
No known key found for this signature in database
GPG Key ID: 9F8955C63C443871
15 changed files with 72 additions and 187 deletions

View File

@ -19,8 +19,6 @@ pub struct RegisterAccountRequest {
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct SendTxRequest { pub struct SendTxRequest {
pub transaction: Transaction, pub transaction: Transaction,
///UTXO Commitment Root, Pub Tx Root
pub tx_roots: [[u8; 32]; 2],
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]

View File

@ -7,8 +7,6 @@ use crate::transaction::Transaction;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct SendTxRequest { pub struct SendTxRequest {
pub transaction: Transaction, pub transaction: Transaction,
///UTXO Commitment Root, Pub Tx Root
pub tx_roots: [[u8; 32]; 2],
} }
//Responses //Responses

View File

@ -91,12 +91,8 @@ impl SequencerClient {
pub async fn send_tx( pub async fn send_tx(
&self, &self,
transaction: Transaction, transaction: Transaction,
tx_roots: [[u8; 32]; 2],
) -> Result<SendTxResponse, SequencerClientError> { ) -> Result<SendTxResponse, SequencerClientError> {
let tx_req = SendTxRequest { let tx_req = SendTxRequest { transaction };
transaction,
tx_roots,
};
let req = serde_json::to_value(tx_req)?; let req = serde_json::to_value(tx_req)?;

View File

@ -1,5 +1,5 @@
{ {
"home": "./node", "home": "./wallet",
"override_rust_log": null, "override_rust_log": null,
"sequencer_addr": "http://127.0.0.1:3040", "sequencer_addr": "http://127.0.0.1:3040",
"seq_poll_timeout_secs": 10, "seq_poll_timeout_secs": 10,

View File

@ -66,20 +66,21 @@ pub async fn post_test(residual: (ServerHandle, JoinHandle<Result<()>>, TempDir)
sequencer_loop_handle.abort(); sequencer_loop_handle.abort();
seq_http_server_handle.stop(true).await; seq_http_server_handle.stop(true).await;
//At this point all of the references to node_core and sequencer_core must be lost. //At this point all of the references to sequencer_core must be lost.
//So they are dropped and tempdirs will be dropped too, //So they are dropped and tempdirs will be dropped too,
} }
pub async fn test_success() { pub async fn test_success() {
let command = Command::SendNativeTokenTransfer { let command = Command::SendNativeTokenTransfer {
from: ACC_SENDER.to_string(), from: ACC_SENDER.to_string(),
nonce: 0,
to: ACC_RECEIVER.to_string(), to: ACC_RECEIVER.to_string(),
amount: 100, amount: 100,
}; };
let node_config = fetch_config().unwrap(); let wallet_config = fetch_config().unwrap();
let seq_client = SequencerClient::new(node_config.sequencer_addr.clone()).unwrap(); let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap();
wallet::execute_subcommand(command).await.unwrap(); wallet::execute_subcommand(command).await.unwrap();
@ -110,13 +111,14 @@ pub async fn test_success_move_to_another_account() {
let command = Command::SendNativeTokenTransfer { let command = Command::SendNativeTokenTransfer {
from: ACC_SENDER.to_string(), from: ACC_SENDER.to_string(),
nonce: 0,
to: hex_acc_receiver_new_acc.clone(), to: hex_acc_receiver_new_acc.clone(),
amount: 100, amount: 100,
}; };
let node_config = fetch_config().unwrap(); let wallet_config = fetch_config().unwrap();
let seq_client = SequencerClient::new(node_config.sequencer_addr.clone()).unwrap(); let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap();
wallet::execute_subcommand(command).await.unwrap(); wallet::execute_subcommand(command).await.unwrap();
@ -145,13 +147,14 @@ pub async fn test_success_move_to_another_account() {
pub async fn test_failure() { pub async fn test_failure() {
let command = Command::SendNativeTokenTransfer { let command = Command::SendNativeTokenTransfer {
from: ACC_SENDER.to_string(), from: ACC_SENDER.to_string(),
nonce: 0,
to: ACC_RECEIVER.to_string(), to: ACC_RECEIVER.to_string(),
amount: 1000000, amount: 1000000,
}; };
let node_config = fetch_config().unwrap(); let wallet_config = fetch_config().unwrap();
let seq_client = SequencerClient::new(node_config.sequencer_addr.clone()).unwrap(); let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap();
wallet::execute_subcommand(command).await.unwrap(); wallet::execute_subcommand(command).await.unwrap();

View File

@ -98,12 +98,6 @@ pub fn private_circuit(
)); ));
} }
for nullifier in in_nullifiers.iter() {
let nullifier: [u8; 32] = nullifier.clone().try_into().unwrap();
assert!(!public_context.nullifiers_set.contains(&nullifier));
}
(in_nullifiers, generate_commitments(output_utxos)) (in_nullifiers, generate_commitments(output_utxos))
} }
@ -147,12 +141,6 @@ pub fn deshielded_circuit(
)); ));
} }
for nullifier in in_nullifiers.iter() {
let nullifier: [u8; 32] = nullifier.clone().try_into().unwrap();
assert!(!public_context.nullifiers_set.contains(&nullifier));
}
in_nullifiers in_nullifiers
} }

View File

@ -1,4 +1,4 @@
use std::collections::{BTreeMap, HashSet}; use std::collections::BTreeMap;
use accounts::account_core::{address::AccountAddress, AccountPublicMask}; use accounts::account_core::{address::AccountAddress, AccountPublicMask};
use common::merkle_tree_public::{merkle_tree::UTXOCommitmentsMerkleTree, TreeHashType}; use common::merkle_tree_public::{merkle_tree::UTXOCommitmentsMerkleTree, TreeHashType};
@ -20,9 +20,7 @@ pub struct PublicSCContext {
pub caller_balance: u64, pub caller_balance: u64,
pub account_masks: BTreeMap<AccountAddress, AccountPublicMask>, pub account_masks: BTreeMap<AccountAddress, AccountPublicMask>,
pub comitment_store_root: TreeHashType, pub comitment_store_root: TreeHashType,
pub pub_tx_store_root: TreeHashType,
pub commitments_tree: UTXOCommitmentsMerkleTree, pub commitments_tree: UTXOCommitmentsMerkleTree,
pub nullifiers_set: HashSet<[u8; 32]>,
} }
impl Serialize for PublicSCContext { impl Serialize for PublicSCContext {
@ -44,9 +42,7 @@ impl Serialize for PublicSCContext {
s.serialize_field(ACCOUNT_MASKS_KEYS_SORTED, &account_masks_keys)?; s.serialize_field(ACCOUNT_MASKS_KEYS_SORTED, &account_masks_keys)?;
s.serialize_field(ACCOUNT_MASKS_VALUES_SORTED, &account_mask_values)?; s.serialize_field(ACCOUNT_MASKS_VALUES_SORTED, &account_mask_values)?;
s.serialize_field(COMMITMENT_STORE_ROOT, &self.comitment_store_root)?; s.serialize_field(COMMITMENT_STORE_ROOT, &self.comitment_store_root)?;
s.serialize_field(PUT_TX_STORE_ROOT, &self.pub_tx_store_root)?;
s.serialize_field(COMMITMENT_TREE, &self.commitments_tree)?; s.serialize_field(COMMITMENT_TREE, &self.commitments_tree)?;
s.serialize_field(NULLIFIERS_SET, &self.nullifiers_set)?;
s.end() s.end()
} }
@ -100,12 +96,9 @@ mod tests {
fn create_test_context() -> PublicSCContext { fn create_test_context() -> PublicSCContext {
let caller_address = [1; 32]; let caller_address = [1; 32];
let comitment_store_root = [3; 32]; let comitment_store_root = [3; 32];
let pub_tx_store_root = [4; 32];
let commitments_tree = let commitments_tree =
UTXOCommitmentsMerkleTree::new(vec![UTXOCommitment { hash: [5; 32] }]); UTXOCommitmentsMerkleTree::new(vec![UTXOCommitment { hash: [5; 32] }]);
let mut nullifiers_set = HashSet::new();
nullifiers_set.insert([6; 32]);
let mut account_masks = BTreeMap::new(); let mut account_masks = BTreeMap::new();
@ -122,9 +115,7 @@ mod tests {
caller_balance: 100, caller_balance: 100,
account_masks, account_masks,
comitment_store_root, comitment_store_root,
pub_tx_store_root,
commitments_tree, commitments_tree,
nullifiers_set,
} }
} }

View File

@ -80,7 +80,6 @@ impl SequencerCore {
pub fn transaction_pre_check( pub fn transaction_pre_check(
&mut self, &mut self,
tx: Transaction, tx: Transaction,
tx_roots: [[u8; 32]; 2],
) -> Result<AuthenticatedTransaction, TransactionMalformationErrorKind> { ) -> Result<AuthenticatedTransaction, TransactionMalformationErrorKind> {
let tx = tx let tx = tx
.into_authenticated() .into_authenticated()
@ -103,16 +102,6 @@ impl SequencerCore {
return Err(TransactionMalformationErrorKind::MempoolFullForRound { tx: tx_hash }); return Err(TransactionMalformationErrorKind::MempoolFullForRound { tx: tx_hash });
} }
let curr_sequencer_roots = self.get_tree_roots();
if tx_roots != curr_sequencer_roots {
return Err(
TransactionMalformationErrorKind::ChainStateFurtherThanTransactionState {
tx: tx_hash,
},
);
}
//Sanity check //Sanity check
match tx_kind { match tx_kind {
TxKind::Public => { TxKind::Public => {
@ -197,7 +186,6 @@ impl SequencerCore {
pub fn push_tx_into_mempool_pre_check( pub fn push_tx_into_mempool_pre_check(
&mut self, &mut self,
transaction: Transaction, transaction: Transaction,
tx_roots: [[u8; 32]; 2],
) -> Result<(), TransactionMalformationErrorKind> { ) -> Result<(), TransactionMalformationErrorKind> {
let mempool_size = self.mempool.len(); let mempool_size = self.mempool.len();
if mempool_size >= self.sequencer_config.max_num_tx_in_block { if mempool_size >= self.sequencer_config.max_num_tx_in_block {
@ -206,7 +194,7 @@ impl SequencerCore {
}); });
} }
let authenticated_tx = self.transaction_pre_check(transaction, tx_roots)?; let authenticated_tx = self.transaction_pre_check(transaction)?;
self.mempool.push_item(authenticated_tx.into()); self.mempool.push_item(authenticated_tx.into());
@ -526,8 +514,8 @@ mod tests {
vec![[71; 32]], vec![[71; 32]],
vec![[81; 32]], vec![[81; 32]],
); );
let tx_roots = sequencer.get_tree_roots();
let result = sequencer.transaction_pre_check(tx, tx_roots); let result = sequencer.transaction_pre_check(tx);
assert!(result.is_ok()); assert!(result.is_ok());
} }
@ -553,8 +541,8 @@ mod tests {
let tx = common::test_utils::create_dummy_transaction_native_token_transfer( let tx = common::test_utils::create_dummy_transaction_native_token_transfer(
acc1, 0, acc2, 10, sign_key1, acc1, 0, acc2, 10, sign_key1,
); );
let tx_roots = sequencer.get_tree_roots();
let result = sequencer.transaction_pre_check(tx, tx_roots); let result = sequencer.transaction_pre_check(tx);
assert!(result.is_ok()); assert!(result.is_ok());
} }
@ -580,8 +568,8 @@ mod tests {
let tx = common::test_utils::create_dummy_transaction_native_token_transfer( let tx = common::test_utils::create_dummy_transaction_native_token_transfer(
acc1, 0, acc2, 10, sign_key2, acc1, 0, acc2, 10, sign_key2,
); );
let tx_roots = sequencer.get_tree_roots();
let result = sequencer.transaction_pre_check(tx, tx_roots); let result = sequencer.transaction_pre_check(tx);
assert_eq!( assert_eq!(
result.err().unwrap(), result.err().unwrap(),
@ -610,8 +598,8 @@ mod tests {
let tx = common::test_utils::create_dummy_transaction_native_token_transfer( let tx = common::test_utils::create_dummy_transaction_native_token_transfer(
acc1, 0, acc2, 10000000, sign_key1, acc1, 0, acc2, 10000000, sign_key1,
); );
let tx_roots = sequencer.get_tree_roots();
let result = sequencer.transaction_pre_check(tx, tx_roots); let result = sequencer.transaction_pre_check(tx);
//Passed pre-check //Passed pre-check
assert!(result.is_ok()); assert!(result.is_ok());
@ -673,7 +661,6 @@ mod tests {
vec![[72; 32]], vec![[72; 32]],
vec![[82; 32]], vec![[82; 32]],
); );
let tx_roots = sequencer.get_tree_roots();
// Fill the mempool // Fill the mempool
let dummy_tx = MempoolTransaction { let dummy_tx = MempoolTransaction {
@ -681,7 +668,7 @@ mod tests {
}; };
sequencer.mempool.push_item(dummy_tx); sequencer.mempool.push_item(dummy_tx);
let result = sequencer.push_tx_into_mempool_pre_check(tx, tx_roots); let result = sequencer.push_tx_into_mempool_pre_check(tx);
assert!(matches!( assert!(matches!(
result, result,
@ -701,9 +688,8 @@ mod tests {
vec![[73; 32]], vec![[73; 32]],
vec![[83; 32]], vec![[83; 32]],
); );
let tx_roots = sequencer.get_tree_roots();
let result = sequencer.push_tx_into_mempool_pre_check(tx, tx_roots); let result = sequencer.push_tx_into_mempool_pre_check(tx);
assert!(result.is_ok()); assert!(result.is_ok());
assert_eq!(sequencer.mempool.len(), 1); assert_eq!(sequencer.mempool.len(), 1);
} }

View File

@ -88,7 +88,7 @@ impl JsonHandler {
{ {
let mut state = self.sequencer_state.lock().await; let mut state = self.sequencer_state.lock().await;
state.push_tx_into_mempool_pre_check(send_tx_req.transaction, send_tx_req.tx_roots)?; state.push_tx_into_mempool_pre_check(send_tx_req.transaction)?;
} }
let helperstruct = SendTxResponse { let helperstruct = SendTxResponse {
@ -290,9 +290,7 @@ mod tests {
}; };
let tx = Transaction::new(tx_body, SignaturePrivateKey::from_slice(&[1; 32]).unwrap()); let tx = Transaction::new(tx_body, SignaturePrivateKey::from_slice(&[1; 32]).unwrap());
sequencer_core sequencer_core.push_tx_into_mempool_pre_check(tx).unwrap();
.push_tx_into_mempool_pre_check(tx, [[0; 32]; 2])
.unwrap();
sequencer_core sequencer_core
.produce_new_block_with_mempool_transactions() .produce_new_block_with_mempool_transactions()
.unwrap(); .unwrap();

View File

@ -1,11 +1,11 @@
use accounts::account_core::{address::AccountAddress, Account}; use accounts::account_core::{address::AccountAddress, Account};
use std::collections::HashMap; use std::collections::HashMap;
pub struct NodeAccountsStore { pub struct WalletAccountsStore {
pub accounts: HashMap<AccountAddress, Account>, pub accounts: HashMap<AccountAddress, Account>,
} }
impl NodeAccountsStore { impl WalletAccountsStore {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
accounts: HashMap::new(), accounts: HashMap::new(),
@ -21,7 +21,7 @@ impl NodeAccountsStore {
} }
} }
impl Default for NodeAccountsStore { impl Default for WalletAccountsStore {
fn default() -> Self { fn default() -> Self {
Self::new() Self::new()
} }
@ -45,13 +45,13 @@ mod tests {
#[test] #[test]
fn test_create_empty_store() { fn test_create_empty_store() {
let store = NodeAccountsStore::new(); let store = WalletAccountsStore::new();
assert!(store.accounts.is_empty()); assert!(store.accounts.is_empty());
} }
#[test] #[test]
fn test_register_account() { fn test_register_account() {
let mut store = NodeAccountsStore::new(); let mut store = WalletAccountsStore::new();
let account = create_sample_account(100); let account = create_sample_account(100);
let account_addr = account.address; let account_addr = account.address;
@ -65,7 +65,7 @@ mod tests {
#[test] #[test]
fn test_unregister_account() { fn test_unregister_account() {
let mut store = NodeAccountsStore::new(); let mut store = WalletAccountsStore::new();
let account = create_sample_account(100); let account = create_sample_account(100);
let account_addr = account.address; let account_addr = account.address;
@ -79,7 +79,7 @@ mod tests {
#[test] #[test]
fn test_unregister_nonexistent_account() { fn test_unregister_nonexistent_account() {
let mut store = NodeAccountsStore::new(); let mut store = WalletAccountsStore::new();
let account_addr: [u8; 32] = pad_to_32("nonexistent".to_string().as_bytes()); let account_addr: [u8; 32] = pad_to_32("nonexistent".to_string().as_bytes());
store.unregister_account(account_addr); store.unregister_account(account_addr);
@ -89,7 +89,7 @@ mod tests {
#[test] #[test]
fn test_register_multiple_accounts() { fn test_register_multiple_accounts() {
let mut store = NodeAccountsStore::new(); let mut store = WalletAccountsStore::new();
let account1 = create_sample_account(100); let account1 = create_sample_account(100);
let account2 = create_sample_account(200); let account2 = create_sample_account(200);

View File

@ -1,15 +1,12 @@
use std::collections::{BTreeMap, HashMap, HashSet}; use std::collections::{BTreeMap, HashMap};
use accounts::account_core::{address::AccountAddress, Account}; use accounts::account_core::{address::AccountAddress, Account};
use anyhow::Result; use anyhow::Result;
use common::{ use common::merkle_tree_public::merkle_tree::UTXOCommitmentsMerkleTree;
merkle_tree_public::merkle_tree::{PublicTransactionMerkleTree, UTXOCommitmentsMerkleTree},
nullifier::UTXONullifier,
};
use sc_core::public_context::PublicSCContext; use sc_core::public_context::PublicSCContext;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::config::NodeConfig; use crate::config::WalletConfig;
pub mod accounts_store; pub mod accounts_store;
@ -39,27 +36,21 @@ impl From<AccMap> for HashMap<[u8; 32], Account> {
} }
} }
pub struct NodeChainStore { pub struct WalletChainStore {
pub acc_map: HashMap<AccountAddress, Account>, pub acc_map: HashMap<AccountAddress, Account>,
pub nullifier_store: HashSet<UTXONullifier>,
pub utxo_commitments_store: UTXOCommitmentsMerkleTree, pub utxo_commitments_store: UTXOCommitmentsMerkleTree,
pub pub_tx_store: PublicTransactionMerkleTree, pub wallet_config: WalletConfig,
pub node_config: NodeConfig,
} }
impl NodeChainStore { impl WalletChainStore {
pub fn new(config: NodeConfig) -> Result<Self> { pub fn new(config: WalletConfig) -> Result<Self> {
let acc_map = HashMap::new(); let acc_map = HashMap::new();
let nullifier_store = HashSet::new();
let utxo_commitments_store = UTXOCommitmentsMerkleTree::new(vec![]); let utxo_commitments_store = UTXOCommitmentsMerkleTree::new(vec![]);
let pub_tx_store = PublicTransactionMerkleTree::new(vec![]);
Ok(Self { Ok(Self {
acc_map, acc_map,
nullifier_store,
utxo_commitments_store, utxo_commitments_store,
pub_tx_store, wallet_config: config,
node_config: config,
}) })
} }
@ -75,12 +66,6 @@ impl NodeChainStore {
caller_balance: self.acc_map.get(&caller).unwrap().balance, caller_balance: self.acc_map.get(&caller).unwrap().balance,
account_masks, account_masks,
comitment_store_root: self.utxo_commitments_store.get_root().unwrap_or([0; 32]), comitment_store_root: self.utxo_commitments_store.get_root().unwrap_or([0; 32]),
pub_tx_store_root: self.pub_tx_store.get_root().unwrap_or([0; 32]),
nullifiers_set: self
.nullifier_store
.iter()
.map(|item| item.utxo_hash)
.collect(),
commitments_tree: self.utxo_commitments_store.clone(), commitments_tree: self.utxo_commitments_store.clone(),
} }
} }
@ -267,8 +252,8 @@ mod tests {
initial_accounts initial_accounts
} }
fn create_sample_node_config(home: PathBuf) -> NodeConfig { fn create_sample_wallet_config(home: PathBuf) -> WalletConfig {
NodeConfig { WalletConfig {
home, home,
override_rust_log: None, override_rust_log: None,
sequencer_addr: "http://127.0.0.1".to_string(), sequencer_addr: "http://127.0.0.1".to_string(),
@ -282,12 +267,11 @@ mod tests {
let temp_dir = tempdir().unwrap(); let temp_dir = tempdir().unwrap();
let path = temp_dir.path(); let path = temp_dir.path();
let config = create_sample_node_config(path.to_path_buf()); let config = create_sample_wallet_config(path.to_path_buf());
let store = NodeChainStore::new(config.clone()).unwrap(); let store = WalletChainStore::new(config.clone()).unwrap();
assert!(store.acc_map.is_empty()); assert!(store.acc_map.is_empty());
assert!(store.nullifier_store.is_empty());
assert_eq!( assert_eq!(
store.utxo_commitments_store.get_root().unwrap_or([0; 32]), store.utxo_commitments_store.get_root().unwrap_or([0; 32]),
[0; 32] [0; 32]

View File

@ -37,7 +37,7 @@ impl From<GasConfig> for zkvm::gas_calculator::GasCalculator {
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NodeConfig { pub struct WalletConfig {
///Home dir of sequencer storage ///Home dir of sequencer storage
pub home: PathBuf, pub home: PathBuf,
///Override rust log (env var logging level) ///Override rust log (env var logging level)

View File

@ -2,24 +2,7 @@ use std::{fs::File, io::BufReader, path::PathBuf, str::FromStr};
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use crate::{config::NodeConfig, HOME_DIR_ENV_VAR}; use crate::{config::WalletConfig, HOME_DIR_ENV_VAR};
pub fn vec_u8_to_vec_u64(bytes: Vec<u8>) -> Vec<u64> {
// Pad with zeros to make sure it's a multiple of 8
let mut padded = bytes.clone();
while !padded.len().is_multiple_of(8) {
padded.push(0);
}
padded
.chunks(8)
.map(|chunk| {
let mut array = [0u8; 8];
array.copy_from_slice(chunk);
u64::from_le_bytes(array)
})
.collect()
}
///Get home dir for wallet. Env var `NSSA_WALLET_HOME_DIR` must be set before execution to succeed. ///Get home dir for wallet. Env var `NSSA_WALLET_HOME_DIR` must be set before execution to succeed.
pub fn get_home() -> Result<PathBuf> { pub fn get_home() -> Result<PathBuf> {
@ -27,9 +10,9 @@ pub fn get_home() -> Result<PathBuf> {
} }
///Fetch config from `NSSA_WALLET_HOME_DIR` ///Fetch config from `NSSA_WALLET_HOME_DIR`
pub fn fetch_config() -> Result<NodeConfig> { pub fn fetch_config() -> Result<WalletConfig> {
let config_home = get_home()?; let config_home = get_home()?;
let file = File::open(config_home.join("node_config.json"))?; let file = File::open(config_home.join("wallet_config.json"))?;
let reader = BufReader::new(file); let reader = BufReader::new(file);
Ok(serde_json::from_reader(reader)?) Ok(serde_json::from_reader(reader)?)

View File

@ -9,9 +9,9 @@ use common::{
use accounts::account_core::{address::AccountAddress, Account}; use accounts::account_core::{address::AccountAddress, Account};
use anyhow::Result; use anyhow::Result;
use chain_storage::NodeChainStore; use chain_storage::WalletChainStore;
use common::transaction::TransactionBody; use common::transaction::TransactionBody;
use config::NodeConfig; use config::WalletConfig;
use log::info; use log::info;
use sc_core::proofs_circuits::pedersen_commitment_vec; use sc_core::proofs_circuits::pedersen_commitment_vec;
use tokio::sync::RwLock; use tokio::sync::RwLock;
@ -26,19 +26,18 @@ pub const BLOCK_GEN_DELAY_SECS: u64 = 20;
pub mod chain_storage; pub mod chain_storage;
pub mod config; pub mod config;
pub mod helperfunctions; pub mod helperfunctions;
pub mod requests_structs;
pub struct NodeCore { pub struct WalletCore {
pub storage: Arc<RwLock<NodeChainStore>>, pub storage: Arc<RwLock<WalletChainStore>>,
pub node_config: NodeConfig, pub wallet_config: WalletConfig,
pub sequencer_client: Arc<SequencerClient>, pub sequencer_client: Arc<SequencerClient>,
} }
impl NodeCore { impl WalletCore {
pub async fn start_from_config_update_chain(config: NodeConfig) -> Result<Self> { pub async fn start_from_config_update_chain(config: WalletConfig) -> Result<Self> {
let client = Arc::new(SequencerClient::new(config.sequencer_addr.clone())?); let client = Arc::new(SequencerClient::new(config.sequencer_addr.clone())?);
let mut storage = NodeChainStore::new(config.clone())?; let mut storage = WalletChainStore::new(config.clone())?;
for acc in config.clone().initial_accounts { for acc in config.clone().initial_accounts {
storage.acc_map.insert(acc.address, acc); storage.acc_map.insert(acc.address, acc);
} }
@ -47,19 +46,11 @@ impl NodeCore {
Ok(Self { Ok(Self {
storage: wrapped_storage, storage: wrapped_storage,
node_config: config.clone(), wallet_config: config.clone(),
sequencer_client: client.clone(), sequencer_client: client.clone(),
}) })
} }
pub async fn get_roots(&self) -> [[u8; 32]; 2] {
let storage = self.storage.read().await;
[
storage.utxo_commitments_store.get_root().unwrap_or([0; 32]),
storage.pub_tx_store.get_root().unwrap_or([0; 32]),
]
}
pub async fn create_new_account(&mut self) -> AccountAddress { pub async fn create_new_account(&mut self) -> AccountAddress {
let account = Account::new(); let account = Account::new();
account.log(); account.log();
@ -82,8 +73,6 @@ impl NodeCore {
to: AccountAddress, to: AccountAddress,
balance_to_move: u64, balance_to_move: u64,
) -> Result<SendTxResponse, ExecutionFailureKind> { ) -> Result<SendTxResponse, ExecutionFailureKind> {
let tx_roots = self.get_roots().await;
let public_context = { let public_context = {
let read_guard = self.storage.read().await; let read_guard = self.storage.read().await;
@ -123,10 +112,7 @@ impl NodeCore {
let signed_transaction = Transaction::new(tx, key_to_sign_transaction); let signed_transaction = Transaction::new(tx, key_to_sign_transaction);
Ok(self Ok(self.sequencer_client.send_tx(signed_transaction).await?)
.sequencer_client
.send_tx(signed_transaction, tx_roots)
.await?)
} else { } else {
Err(ExecutionFailureKind::AmountMismatchError) Err(ExecutionFailureKind::AmountMismatchError)
} }
@ -142,6 +128,9 @@ pub enum Command {
///from - valid 32 byte hex string ///from - valid 32 byte hex string
#[arg(long)] #[arg(long)]
from: String, from: String,
///nonce - u64 integer
#[arg(long)]
nonce: u64,
///to - valid 32 byte hex string ///to - valid 32 byte hex string
#[arg(long)] #[arg(long)]
to: String, to: String,
@ -162,17 +151,21 @@ pub struct Args {
pub async fn execute_subcommand(command: Command) -> Result<()> { pub async fn execute_subcommand(command: Command) -> Result<()> {
match command { match command {
Command::SendNativeTokenTransfer { from, to, amount } => { Command::SendNativeTokenTransfer {
let node_config = fetch_config()?; from,
nonce,
to,
amount,
} => {
let wallet_config = fetch_config()?;
let from = produce_account_addr_from_hex(from)?; let from = produce_account_addr_from_hex(from)?;
let to = produce_account_addr_from_hex(to)?; let to = produce_account_addr_from_hex(to)?;
let wallet_core = NodeCore::start_from_config_update_chain(node_config).await?; let wallet_core = WalletCore::start_from_config_update_chain(wallet_config).await?;
//ToDo: Nonce management
let res = wallet_core let res = wallet_core
.send_public_native_token_transfer(from, 0, to, amount) .send_public_native_token_transfer(from, nonce, to, amount)
.await?; .await?;
info!("Results of tx send is {res:#?}"); info!("Results of tx send is {res:#?}");

View File

@ -1,33 +0,0 @@
use accounts::account_core::address::AccountAddress;
use serde::{Deserialize, Serialize};
use utxo::utxo_core::UTXO;
#[derive(Debug, Serialize, Deserialize)]
pub struct MintMoneyPublicTx {
pub acc: AccountAddress,
pub amount: u128,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SendMoneyShieldedTx {
pub acc_sender: AccountAddress,
pub amount: u128,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SendMoneyDeshieldedTx {
pub receiver_data: Vec<(u128, AccountAddress)>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct UTXOPublication {
pub utxos: Vec<UTXO>,
}
#[derive(Debug, Serialize, Deserialize)]
pub enum ActionData {
MintMoneyPublicTx(MintMoneyPublicTx),
SendMoneyShieldedTx(SendMoneyShieldedTx),
SendMoneyDeshieldedTx(SendMoneyDeshieldedTx),
UTXOPublication(UTXOPublication),
}