mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-02 13:23:10 +00:00
fix: comments fix
This commit is contained in:
parent
17b6851d00
commit
c3b5d62ea6
@ -19,8 +19,6 @@ pub struct RegisterAccountRequest {
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct SendTxRequest {
|
||||
pub transaction: Transaction,
|
||||
///UTXO Commitment Root, Pub Tx Root
|
||||
pub tx_roots: [[u8; 32]; 2],
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
||||
@ -7,8 +7,6 @@ use crate::transaction::Transaction;
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct SendTxRequest {
|
||||
pub transaction: Transaction,
|
||||
///UTXO Commitment Root, Pub Tx Root
|
||||
pub tx_roots: [[u8; 32]; 2],
|
||||
}
|
||||
|
||||
//Responses
|
||||
|
||||
@ -91,12 +91,8 @@ impl SequencerClient {
|
||||
pub async fn send_tx(
|
||||
&self,
|
||||
transaction: Transaction,
|
||||
tx_roots: [[u8; 32]; 2],
|
||||
) -> Result<SendTxResponse, SequencerClientError> {
|
||||
let tx_req = SendTxRequest {
|
||||
transaction,
|
||||
tx_roots,
|
||||
};
|
||||
let tx_req = SendTxRequest { transaction };
|
||||
|
||||
let req = serde_json::to_value(tx_req)?;
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"home": "./node",
|
||||
"home": "./wallet",
|
||||
"override_rust_log": null,
|
||||
"sequencer_addr": "http://127.0.0.1:3040",
|
||||
"seq_poll_timeout_secs": 10,
|
||||
@ -66,20 +66,21 @@ pub async fn post_test(residual: (ServerHandle, JoinHandle<Result<()>>, TempDir)
|
||||
sequencer_loop_handle.abort();
|
||||
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,
|
||||
}
|
||||
|
||||
pub async fn test_success() {
|
||||
let command = Command::SendNativeTokenTransfer {
|
||||
from: ACC_SENDER.to_string(),
|
||||
nonce: 0,
|
||||
to: ACC_RECEIVER.to_string(),
|
||||
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();
|
||||
|
||||
@ -110,13 +111,14 @@ pub async fn test_success_move_to_another_account() {
|
||||
|
||||
let command = Command::SendNativeTokenTransfer {
|
||||
from: ACC_SENDER.to_string(),
|
||||
nonce: 0,
|
||||
to: hex_acc_receiver_new_acc.clone(),
|
||||
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();
|
||||
|
||||
@ -145,13 +147,14 @@ pub async fn test_success_move_to_another_account() {
|
||||
pub async fn test_failure() {
|
||||
let command = Command::SendNativeTokenTransfer {
|
||||
from: ACC_SENDER.to_string(),
|
||||
nonce: 0,
|
||||
to: ACC_RECEIVER.to_string(),
|
||||
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();
|
||||
|
||||
|
||||
@ -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))
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use accounts::account_core::{address::AccountAddress, AccountPublicMask};
|
||||
use common::merkle_tree_public::{merkle_tree::UTXOCommitmentsMerkleTree, TreeHashType};
|
||||
@ -20,9 +20,7 @@ pub struct PublicSCContext {
|
||||
pub caller_balance: u64,
|
||||
pub account_masks: BTreeMap<AccountAddress, AccountPublicMask>,
|
||||
pub comitment_store_root: TreeHashType,
|
||||
pub pub_tx_store_root: TreeHashType,
|
||||
pub commitments_tree: UTXOCommitmentsMerkleTree,
|
||||
pub nullifiers_set: HashSet<[u8; 32]>,
|
||||
}
|
||||
|
||||
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_VALUES_SORTED, &account_mask_values)?;
|
||||
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(NULLIFIERS_SET, &self.nullifiers_set)?;
|
||||
|
||||
s.end()
|
||||
}
|
||||
@ -100,12 +96,9 @@ mod tests {
|
||||
fn create_test_context() -> PublicSCContext {
|
||||
let caller_address = [1; 32];
|
||||
let comitment_store_root = [3; 32];
|
||||
let pub_tx_store_root = [4; 32];
|
||||
|
||||
let commitments_tree =
|
||||
UTXOCommitmentsMerkleTree::new(vec![UTXOCommitment { hash: [5; 32] }]);
|
||||
let mut nullifiers_set = HashSet::new();
|
||||
nullifiers_set.insert([6; 32]);
|
||||
|
||||
let mut account_masks = BTreeMap::new();
|
||||
|
||||
@ -122,9 +115,7 @@ mod tests {
|
||||
caller_balance: 100,
|
||||
account_masks,
|
||||
comitment_store_root,
|
||||
pub_tx_store_root,
|
||||
commitments_tree,
|
||||
nullifiers_set,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -80,7 +80,6 @@ impl SequencerCore {
|
||||
pub fn transaction_pre_check(
|
||||
&mut self,
|
||||
tx: Transaction,
|
||||
tx_roots: [[u8; 32]; 2],
|
||||
) -> Result<AuthenticatedTransaction, TransactionMalformationErrorKind> {
|
||||
let tx = tx
|
||||
.into_authenticated()
|
||||
@ -103,16 +102,6 @@ impl SequencerCore {
|
||||
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
|
||||
match tx_kind {
|
||||
TxKind::Public => {
|
||||
@ -197,7 +186,6 @@ impl SequencerCore {
|
||||
pub fn push_tx_into_mempool_pre_check(
|
||||
&mut self,
|
||||
transaction: Transaction,
|
||||
tx_roots: [[u8; 32]; 2],
|
||||
) -> Result<(), TransactionMalformationErrorKind> {
|
||||
let mempool_size = self.mempool.len();
|
||||
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());
|
||||
|
||||
@ -526,8 +514,8 @@ mod tests {
|
||||
vec![[71; 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());
|
||||
}
|
||||
@ -553,8 +541,8 @@ mod tests {
|
||||
let tx = common::test_utils::create_dummy_transaction_native_token_transfer(
|
||||
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());
|
||||
}
|
||||
@ -580,8 +568,8 @@ mod tests {
|
||||
let tx = common::test_utils::create_dummy_transaction_native_token_transfer(
|
||||
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!(
|
||||
result.err().unwrap(),
|
||||
@ -610,8 +598,8 @@ mod tests {
|
||||
let tx = common::test_utils::create_dummy_transaction_native_token_transfer(
|
||||
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
|
||||
assert!(result.is_ok());
|
||||
@ -673,7 +661,6 @@ mod tests {
|
||||
vec![[72; 32]],
|
||||
vec![[82; 32]],
|
||||
);
|
||||
let tx_roots = sequencer.get_tree_roots();
|
||||
|
||||
// Fill the mempool
|
||||
let dummy_tx = MempoolTransaction {
|
||||
@ -681,7 +668,7 @@ mod tests {
|
||||
};
|
||||
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!(
|
||||
result,
|
||||
@ -701,9 +688,8 @@ mod tests {
|
||||
vec![[73; 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_eq!(sequencer.mempool.len(), 1);
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ impl JsonHandler {
|
||||
{
|
||||
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 {
|
||||
@ -290,9 +290,7 @@ mod tests {
|
||||
};
|
||||
let tx = Transaction::new(tx_body, SignaturePrivateKey::from_slice(&[1; 32]).unwrap());
|
||||
|
||||
sequencer_core
|
||||
.push_tx_into_mempool_pre_check(tx, [[0; 32]; 2])
|
||||
.unwrap();
|
||||
sequencer_core.push_tx_into_mempool_pre_check(tx).unwrap();
|
||||
sequencer_core
|
||||
.produce_new_block_with_mempool_transactions()
|
||||
.unwrap();
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
use accounts::account_core::{address::AccountAddress, Account};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct NodeAccountsStore {
|
||||
pub struct WalletAccountsStore {
|
||||
pub accounts: HashMap<AccountAddress, Account>,
|
||||
}
|
||||
|
||||
impl NodeAccountsStore {
|
||||
impl WalletAccountsStore {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
accounts: HashMap::new(),
|
||||
@ -21,7 +21,7 @@ impl NodeAccountsStore {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for NodeAccountsStore {
|
||||
impl Default for WalletAccountsStore {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
@ -45,13 +45,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_create_empty_store() {
|
||||
let store = NodeAccountsStore::new();
|
||||
let store = WalletAccountsStore::new();
|
||||
assert!(store.accounts.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_register_account() {
|
||||
let mut store = NodeAccountsStore::new();
|
||||
let mut store = WalletAccountsStore::new();
|
||||
|
||||
let account = create_sample_account(100);
|
||||
let account_addr = account.address;
|
||||
@ -65,7 +65,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_unregister_account() {
|
||||
let mut store = NodeAccountsStore::new();
|
||||
let mut store = WalletAccountsStore::new();
|
||||
|
||||
let account = create_sample_account(100);
|
||||
let account_addr = account.address;
|
||||
@ -79,7 +79,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
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());
|
||||
store.unregister_account(account_addr);
|
||||
@ -89,7 +89,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_register_multiple_accounts() {
|
||||
let mut store = NodeAccountsStore::new();
|
||||
let mut store = WalletAccountsStore::new();
|
||||
|
||||
let account1 = create_sample_account(100);
|
||||
let account2 = create_sample_account(200);
|
||||
|
||||
@ -1,15 +1,12 @@
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
|
||||
use accounts::account_core::{address::AccountAddress, Account};
|
||||
use anyhow::Result;
|
||||
use common::{
|
||||
merkle_tree_public::merkle_tree::{PublicTransactionMerkleTree, UTXOCommitmentsMerkleTree},
|
||||
nullifier::UTXONullifier,
|
||||
};
|
||||
use common::merkle_tree_public::merkle_tree::UTXOCommitmentsMerkleTree;
|
||||
use sc_core::public_context::PublicSCContext;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::config::NodeConfig;
|
||||
use crate::config::WalletConfig;
|
||||
|
||||
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 nullifier_store: HashSet<UTXONullifier>,
|
||||
pub utxo_commitments_store: UTXOCommitmentsMerkleTree,
|
||||
pub pub_tx_store: PublicTransactionMerkleTree,
|
||||
pub node_config: NodeConfig,
|
||||
pub wallet_config: WalletConfig,
|
||||
}
|
||||
|
||||
impl NodeChainStore {
|
||||
pub fn new(config: NodeConfig) -> Result<Self> {
|
||||
impl WalletChainStore {
|
||||
pub fn new(config: WalletConfig) -> Result<Self> {
|
||||
let acc_map = HashMap::new();
|
||||
let nullifier_store = HashSet::new();
|
||||
let utxo_commitments_store = UTXOCommitmentsMerkleTree::new(vec![]);
|
||||
let pub_tx_store = PublicTransactionMerkleTree::new(vec![]);
|
||||
|
||||
Ok(Self {
|
||||
acc_map,
|
||||
nullifier_store,
|
||||
utxo_commitments_store,
|
||||
pub_tx_store,
|
||||
node_config: config,
|
||||
wallet_config: config,
|
||||
})
|
||||
}
|
||||
|
||||
@ -75,12 +66,6 @@ impl NodeChainStore {
|
||||
caller_balance: self.acc_map.get(&caller).unwrap().balance,
|
||||
account_masks,
|
||||
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(),
|
||||
}
|
||||
}
|
||||
@ -267,8 +252,8 @@ mod tests {
|
||||
initial_accounts
|
||||
}
|
||||
|
||||
fn create_sample_node_config(home: PathBuf) -> NodeConfig {
|
||||
NodeConfig {
|
||||
fn create_sample_wallet_config(home: PathBuf) -> WalletConfig {
|
||||
WalletConfig {
|
||||
home,
|
||||
override_rust_log: None,
|
||||
sequencer_addr: "http://127.0.0.1".to_string(),
|
||||
@ -282,12 +267,11 @@ mod tests {
|
||||
let temp_dir = tempdir().unwrap();
|
||||
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.nullifier_store.is_empty());
|
||||
assert_eq!(
|
||||
store.utxo_commitments_store.get_root().unwrap_or([0; 32]),
|
||||
[0; 32]
|
||||
|
||||
@ -37,7 +37,7 @@ impl From<GasConfig> for zkvm::gas_calculator::GasCalculator {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct NodeConfig {
|
||||
pub struct WalletConfig {
|
||||
///Home dir of sequencer storage
|
||||
pub home: PathBuf,
|
||||
///Override rust log (env var logging level)
|
||||
|
||||
@ -2,24 +2,7 @@ use std::{fs::File, io::BufReader, path::PathBuf, str::FromStr};
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
|
||||
use crate::{config::NodeConfig, 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()
|
||||
}
|
||||
use crate::{config::WalletConfig, HOME_DIR_ENV_VAR};
|
||||
|
||||
///Get home dir for wallet. Env var `NSSA_WALLET_HOME_DIR` must be set before execution to succeed.
|
||||
pub fn get_home() -> Result<PathBuf> {
|
||||
@ -27,9 +10,9 @@ pub fn get_home() -> Result<PathBuf> {
|
||||
}
|
||||
|
||||
///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 file = File::open(config_home.join("node_config.json"))?;
|
||||
let file = File::open(config_home.join("wallet_config.json"))?;
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
Ok(serde_json::from_reader(reader)?)
|
||||
|
||||
@ -9,9 +9,9 @@ use common::{
|
||||
|
||||
use accounts::account_core::{address::AccountAddress, Account};
|
||||
use anyhow::Result;
|
||||
use chain_storage::NodeChainStore;
|
||||
use chain_storage::WalletChainStore;
|
||||
use common::transaction::TransactionBody;
|
||||
use config::NodeConfig;
|
||||
use config::WalletConfig;
|
||||
use log::info;
|
||||
use sc_core::proofs_circuits::pedersen_commitment_vec;
|
||||
use tokio::sync::RwLock;
|
||||
@ -26,19 +26,18 @@ pub const BLOCK_GEN_DELAY_SECS: u64 = 20;
|
||||
pub mod chain_storage;
|
||||
pub mod config;
|
||||
pub mod helperfunctions;
|
||||
pub mod requests_structs;
|
||||
|
||||
pub struct NodeCore {
|
||||
pub storage: Arc<RwLock<NodeChainStore>>,
|
||||
pub node_config: NodeConfig,
|
||||
pub struct WalletCore {
|
||||
pub storage: Arc<RwLock<WalletChainStore>>,
|
||||
pub wallet_config: WalletConfig,
|
||||
pub sequencer_client: Arc<SequencerClient>,
|
||||
}
|
||||
|
||||
impl NodeCore {
|
||||
pub async fn start_from_config_update_chain(config: NodeConfig) -> Result<Self> {
|
||||
impl WalletCore {
|
||||
pub async fn start_from_config_update_chain(config: WalletConfig) -> Result<Self> {
|
||||
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 {
|
||||
storage.acc_map.insert(acc.address, acc);
|
||||
}
|
||||
@ -47,19 +46,11 @@ impl NodeCore {
|
||||
|
||||
Ok(Self {
|
||||
storage: wrapped_storage,
|
||||
node_config: config.clone(),
|
||||
wallet_config: config.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 {
|
||||
let account = Account::new();
|
||||
account.log();
|
||||
@ -82,8 +73,6 @@ impl NodeCore {
|
||||
to: AccountAddress,
|
||||
balance_to_move: u64,
|
||||
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
||||
let tx_roots = self.get_roots().await;
|
||||
|
||||
let public_context = {
|
||||
let read_guard = self.storage.read().await;
|
||||
|
||||
@ -123,10 +112,7 @@ impl NodeCore {
|
||||
|
||||
let signed_transaction = Transaction::new(tx, key_to_sign_transaction);
|
||||
|
||||
Ok(self
|
||||
.sequencer_client
|
||||
.send_tx(signed_transaction, tx_roots)
|
||||
.await?)
|
||||
Ok(self.sequencer_client.send_tx(signed_transaction).await?)
|
||||
} else {
|
||||
Err(ExecutionFailureKind::AmountMismatchError)
|
||||
}
|
||||
@ -142,6 +128,9 @@ pub enum Command {
|
||||
///from - valid 32 byte hex string
|
||||
#[arg(long)]
|
||||
from: String,
|
||||
///nonce - u64 integer
|
||||
#[arg(long)]
|
||||
nonce: u64,
|
||||
///to - valid 32 byte hex string
|
||||
#[arg(long)]
|
||||
to: String,
|
||||
@ -162,17 +151,21 @@ pub struct Args {
|
||||
|
||||
pub async fn execute_subcommand(command: Command) -> Result<()> {
|
||||
match command {
|
||||
Command::SendNativeTokenTransfer { from, to, amount } => {
|
||||
let node_config = fetch_config()?;
|
||||
Command::SendNativeTokenTransfer {
|
||||
from,
|
||||
nonce,
|
||||
to,
|
||||
amount,
|
||||
} => {
|
||||
let wallet_config = fetch_config()?;
|
||||
|
||||
let from = produce_account_addr_from_hex(from)?;
|
||||
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
|
||||
.send_public_native_token_transfer(from, 0, to, amount)
|
||||
.send_public_native_token_transfer(from, nonce, to, amount)
|
||||
.await?;
|
||||
|
||||
info!("Results of tx send is {res:#?}");
|
||||
|
||||
@ -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),
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user