mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-06 23:33:10 +00:00
fix: cleanup
This commit is contained in:
parent
c5097ab879
commit
17b6851d00
63
Cargo.lock
generated
63
Cargo.lock
generated
@ -2409,7 +2409,6 @@ dependencies = [
|
||||
"env_logger",
|
||||
"hex",
|
||||
"log",
|
||||
"node_core",
|
||||
"sequencer_core",
|
||||
"sequencer_rpc",
|
||||
"sequencer_runner",
|
||||
@ -2418,6 +2417,7 @@ dependencies = [
|
||||
"tempfile",
|
||||
"tokio",
|
||||
"toml 0.7.8",
|
||||
"wallet",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2968,37 +2968,6 @@ version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a5b0c77c1b780822bc749a33e39aeb2c07584ab93332303babeabb645298a76e"
|
||||
|
||||
[[package]]
|
||||
name = "node_core"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"accounts",
|
||||
"actix-rt",
|
||||
"anyhow",
|
||||
"bincode",
|
||||
"clap",
|
||||
"common",
|
||||
"elliptic-curve",
|
||||
"env_logger",
|
||||
"hex",
|
||||
"k256",
|
||||
"log",
|
||||
"rand 0.8.5",
|
||||
"reqwest 0.11.27",
|
||||
"risc0-zkvm",
|
||||
"sc_core",
|
||||
"secp256k1-zkp",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2",
|
||||
"storage",
|
||||
"tempfile",
|
||||
"thiserror 1.0.69",
|
||||
"tokio",
|
||||
"utxo",
|
||||
"zkvm",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
@ -5240,6 +5209,36 @@ version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "wallet"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"accounts",
|
||||
"actix-rt",
|
||||
"anyhow",
|
||||
"bincode",
|
||||
"clap",
|
||||
"common",
|
||||
"elliptic-curve",
|
||||
"env_logger",
|
||||
"hex",
|
||||
"k256",
|
||||
"log",
|
||||
"rand 0.8.5",
|
||||
"reqwest 0.11.27",
|
||||
"risc0-zkvm",
|
||||
"sc_core",
|
||||
"secp256k1-zkp",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2",
|
||||
"tempfile",
|
||||
"thiserror 1.0.69",
|
||||
"tokio",
|
||||
"utxo",
|
||||
"zkvm",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "want"
|
||||
version = "0.3.1"
|
||||
|
||||
@ -8,7 +8,7 @@ members = [
|
||||
"sequencer_rpc",
|
||||
"mempool",
|
||||
"zkvm",
|
||||
"node_core",
|
||||
"wallet",
|
||||
"sequencer_core",
|
||||
"common",
|
||||
"sc_core",
|
||||
|
||||
@ -6,5 +6,5 @@ source env.sh
|
||||
|
||||
cargo test --release
|
||||
cd integration_tests
|
||||
export HOME_DIR=$(pwd)/configs/debug/node/
|
||||
export NSSA_WALLET_HOME_DIR=$(pwd)/configs/debug/node/
|
||||
cargo run $(pwd)/configs/debug all
|
||||
@ -7,6 +7,7 @@ pub mod execution_input;
|
||||
pub mod merkle_tree_public;
|
||||
pub mod nullifier;
|
||||
pub mod rpc_primitives;
|
||||
pub mod sequencer_client;
|
||||
pub mod transaction;
|
||||
pub mod utxo_commitment;
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
use common::transaction::Transaction;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::transaction::Transaction;
|
||||
|
||||
//Requests
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
@ -1,35 +1,32 @@
|
||||
use accounts::account_core::Account;
|
||||
use anyhow::Result;
|
||||
use common::rpc_primitives::requests::{
|
||||
use super::rpc_primitives::requests::{
|
||||
GetAccountBalanceRequest, GetAccountBalanceResponse, GetBlockDataRequest, GetBlockDataResponse,
|
||||
GetGenesisIdRequest, GetGenesisIdResponse, GetInitialTestnetAccountsRequest,
|
||||
RegisterAccountRequest, RegisterAccountResponse,
|
||||
};
|
||||
use common::transaction::Transaction;
|
||||
use common::{SequencerClientError, SequencerRpcError};
|
||||
use anyhow::Result;
|
||||
use json::{SendTxRequest, SendTxResponse, SequencerRpcRequest, SequencerRpcResponse};
|
||||
use reqwest::Client;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::config::NodeConfig;
|
||||
use crate::sequencer_client::json::AccountInitialData;
|
||||
use crate::transaction::Transaction;
|
||||
use crate::{SequencerClientError, SequencerRpcError};
|
||||
|
||||
pub mod json;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SequencerClient {
|
||||
pub client: reqwest::Client,
|
||||
pub config: NodeConfig,
|
||||
pub sequencer_addr: String,
|
||||
}
|
||||
|
||||
impl SequencerClient {
|
||||
pub fn new(config: NodeConfig) -> Result<Self> {
|
||||
pub fn new(sequencer_addr: String) -> Result<Self> {
|
||||
Ok(Self {
|
||||
client: Client::builder()
|
||||
//Add more fiedls if needed
|
||||
.timeout(std::time::Duration::from_secs(60))
|
||||
.build()?,
|
||||
config,
|
||||
sequencer_addr,
|
||||
})
|
||||
}
|
||||
|
||||
@ -40,7 +37,7 @@ impl SequencerClient {
|
||||
) -> Result<Value, SequencerClientError> {
|
||||
let request = SequencerRpcRequest::from_payload_version_2_0(method.to_string(), payload);
|
||||
|
||||
let call_builder = self.client.post(&self.config.sequencer_addr);
|
||||
let call_builder = self.client.post(&self.sequencer_addr);
|
||||
|
||||
let call_res = call_builder.json(&request).send().await?;
|
||||
|
||||
@ -56,6 +53,7 @@ impl SequencerClient {
|
||||
}
|
||||
}
|
||||
|
||||
///Get block data at `block_id` from sequencer
|
||||
pub async fn get_block(
|
||||
&self,
|
||||
block_id: u64,
|
||||
@ -71,6 +69,7 @@ impl SequencerClient {
|
||||
Ok(resp_deser)
|
||||
}
|
||||
|
||||
///Get account public balance for `address`. `address` must be a valid hex-string for 32 bytes.
|
||||
pub async fn get_account_balance(
|
||||
&self,
|
||||
address: String,
|
||||
@ -88,6 +87,7 @@ impl SequencerClient {
|
||||
Ok(resp_deser)
|
||||
}
|
||||
|
||||
///Send transaction to sequencer
|
||||
pub async fn send_tx(
|
||||
&self,
|
||||
transaction: Transaction,
|
||||
@ -107,25 +107,7 @@ impl SequencerClient {
|
||||
Ok(resp_deser)
|
||||
}
|
||||
|
||||
pub async fn register_account(
|
||||
&self,
|
||||
account: &Account,
|
||||
) -> Result<RegisterAccountResponse, SequencerClientError> {
|
||||
let acc_req = RegisterAccountRequest {
|
||||
address: account.address,
|
||||
};
|
||||
|
||||
let req = serde_json::to_value(acc_req)?;
|
||||
|
||||
let resp = self
|
||||
.call_method_with_payload("register_account", req)
|
||||
.await?;
|
||||
|
||||
let resp_deser = serde_json::from_value(resp)?;
|
||||
|
||||
Ok(resp_deser)
|
||||
}
|
||||
|
||||
///Get genesis id from sequencer
|
||||
pub async fn get_genesis_id(&self) -> Result<GetGenesisIdResponse, SequencerClientError> {
|
||||
let genesis_req = GetGenesisIdRequest {};
|
||||
|
||||
@ -141,6 +123,7 @@ impl SequencerClient {
|
||||
Ok(resp_deser)
|
||||
}
|
||||
|
||||
///Get initial testnet accounts from sequencer
|
||||
pub async fn get_initial_testnet_accounts(
|
||||
&self,
|
||||
) -> Result<Vec<AccountInitialData>, SequencerClientError> {
|
||||
@ -50,7 +50,6 @@ pub fn produce_dummy_empty_transaction() -> Transaction {
|
||||
tweak: Default::default(),
|
||||
secret_r: Default::default(),
|
||||
sc_addr: Default::default(),
|
||||
state_changes: Default::default(),
|
||||
};
|
||||
|
||||
Transaction::new(body, SignaturePrivateKey::from_slice(&[1; 32]).unwrap())
|
||||
@ -77,7 +76,6 @@ pub fn create_dummy_private_transaction_random_signer(
|
||||
tweak: Tweak::new(&mut rng),
|
||||
secret_r: [0; 32],
|
||||
sc_addr: "sc_addr".to_string(),
|
||||
state_changes: (serde_json::Value::Null, 0),
|
||||
};
|
||||
Transaction::new(body, SignaturePrivateKey::random(&mut rng))
|
||||
}
|
||||
@ -112,7 +110,6 @@ pub fn create_dummy_transaction_native_token_transfer(
|
||||
tweak: Tweak::new(&mut rng),
|
||||
secret_r: [0; 32],
|
||||
sc_addr: "sc_addr".to_string(),
|
||||
state_changes: (serde_json::Value::Null, 0),
|
||||
};
|
||||
Transaction::new(body, signing_key)
|
||||
}
|
||||
|
||||
@ -58,10 +58,6 @@ pub struct TransactionBody {
|
||||
pub secret_r: [u8; 32],
|
||||
///Hex-encoded address of a smart contract account called
|
||||
pub sc_addr: String,
|
||||
///Recorded changes in state of smart contract
|
||||
///
|
||||
/// First value represents vector of changes, second is new length of a state
|
||||
pub state_changes: (serde_json::Value, usize),
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
@ -325,7 +321,6 @@ mod tests {
|
||||
tweak: Tweak::from_slice(&[7; SECRET_KEY_SIZE]).unwrap(),
|
||||
secret_r: [8; 32],
|
||||
sc_addr: "someAddress".to_string(),
|
||||
state_changes: (serde_json::Value::Null, 10),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -30,8 +30,8 @@ path = "../sequencer_core"
|
||||
[dependencies.sequencer_runner]
|
||||
path = "../sequencer_runner"
|
||||
|
||||
[dependencies.node_core]
|
||||
path = "../node_core"
|
||||
[dependencies.wallet]
|
||||
path = "../wallet"
|
||||
|
||||
[dependencies.common]
|
||||
path = "../common"
|
||||
|
||||
@ -3,12 +3,13 @@ use std::{path::PathBuf, time::Duration};
|
||||
use actix_web::dev::ServerHandle;
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use common::sequencer_client::SequencerClient;
|
||||
use log::info;
|
||||
use node_core::{Command, fetch_config, sequencer_client::SequencerClient};
|
||||
use sequencer_core::config::SequencerConfig;
|
||||
use sequencer_runner::startup_sequencer;
|
||||
use tempfile::TempDir;
|
||||
use tokio::task::JoinHandle;
|
||||
use wallet::{Command, helperfunctions::fetch_config};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(version)]
|
||||
@ -78,9 +79,9 @@ pub async fn test_success() {
|
||||
|
||||
let node_config = fetch_config().unwrap();
|
||||
|
||||
let seq_client = SequencerClient::new(node_config).unwrap();
|
||||
let seq_client = SequencerClient::new(node_config.sequencer_addr.clone()).unwrap();
|
||||
|
||||
node_core::execute_subcommand(command).await.unwrap();
|
||||
wallet::execute_subcommand(command).await.unwrap();
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
@ -115,9 +116,9 @@ pub async fn test_success_move_to_another_account() {
|
||||
|
||||
let node_config = fetch_config().unwrap();
|
||||
|
||||
let seq_client = SequencerClient::new(node_config).unwrap();
|
||||
let seq_client = SequencerClient::new(node_config.sequencer_addr.clone()).unwrap();
|
||||
|
||||
node_core::execute_subcommand(command).await.unwrap();
|
||||
wallet::execute_subcommand(command).await.unwrap();
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
@ -150,9 +151,9 @@ pub async fn test_failure() {
|
||||
|
||||
let node_config = fetch_config().unwrap();
|
||||
|
||||
let seq_client = SequencerClient::new(node_config).unwrap();
|
||||
let seq_client = SequencerClient::new(node_config.sequencer_addr.clone()).unwrap();
|
||||
|
||||
node_core::execute_subcommand(command).await.unwrap();
|
||||
wallet::execute_subcommand(command).await.unwrap();
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
@ -14,7 +14,6 @@ pub fn create_public_transaction_payload(
|
||||
tweak: Tweak,
|
||||
secret_r: [u8; 32],
|
||||
sc_addr: String,
|
||||
state_changes: (serde_json::Value, usize),
|
||||
) -> TransactionBody {
|
||||
TransactionBody {
|
||||
tx_kind: TxKind::Public,
|
||||
@ -30,7 +29,6 @@ pub fn create_public_transaction_payload(
|
||||
tweak,
|
||||
secret_r,
|
||||
sc_addr,
|
||||
state_changes,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -287,7 +287,6 @@ mod tests {
|
||||
tweak: Default::default(),
|
||||
secret_r: Default::default(),
|
||||
sc_addr: Default::default(),
|
||||
state_changes: Default::default(),
|
||||
};
|
||||
let tx = Transaction::new(tx_body, SignaturePrivateKey::from_slice(&[1; 32]).unwrap());
|
||||
|
||||
@ -499,7 +498,7 @@ mod tests {
|
||||
let request = serde_json::json!({
|
||||
"jsonrpc": "2.0",
|
||||
"method": "get_transaction_by_hash",
|
||||
"params": { "hash": "a5210ef33912a448cfe6eda43878c144df81f7bdf51d19b5ddf97be11806a6ed"},
|
||||
"params": { "hash": "2c69b9639bcf8d58509204e18f1d5962029bf26840915f2bf2bb434501ad3c38"},
|
||||
"id": 1
|
||||
});
|
||||
|
||||
@ -518,14 +517,13 @@ mod tests {
|
||||
"nullifier_created_hashes": [],
|
||||
"sc_addr": "",
|
||||
"secret_r": vec![0; 32],
|
||||
"state_changes": [null, 0],
|
||||
"tweak": "0".repeat(64),
|
||||
"tx_kind": "Shielded",
|
||||
"utxo_commitments_created_hashes": [],
|
||||
"utxo_commitments_spent_hashes": [],
|
||||
},
|
||||
"public_key": "3056301006072A8648CE3D020106052B8104000A034200041B84C5567B126440995D3ED5AABA0565D71E1834604819FF9C17F5E9D5DD078F70BEAF8F588B541507FED6A642C5AB42DFDF8120A7F639DE5122D47A69A8E8D1",
|
||||
"signature": "A4E0D6A25BE829B006124F0DFD766427967AA3BEA96C29219E79BB2CC871891F384748C27E28718A4450AA78709FBF1A57DB33BCD575A2C819D2A439C2D878E6"
|
||||
"signature": "D75783642EA6E7D5E13AE8CCD3C2D3F82728C0A778A80C9F2976C739CD9F7F3F240B0532954D87761DE299A6CB9E6606295786BA5D0F5CACAB3F3626724528B1"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "node_core"
|
||||
name = "wallet"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
@ -29,9 +29,6 @@ path = "../sc_core"
|
||||
[dependencies.accounts]
|
||||
path = "../accounts"
|
||||
|
||||
[dependencies.storage]
|
||||
path = "../storage"
|
||||
|
||||
[dependencies.utxo]
|
||||
path = "../utxo"
|
||||
|
||||
43
wallet/src/helperfunctions.rs
Normal file
43
wallet/src/helperfunctions.rs
Normal file
@ -0,0 +1,43 @@
|
||||
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()
|
||||
}
|
||||
|
||||
///Get home dir for wallet. Env var `NSSA_WALLET_HOME_DIR` must be set before execution to succeed.
|
||||
pub fn get_home() -> Result<PathBuf> {
|
||||
Ok(PathBuf::from_str(&std::env::var(HOME_DIR_ENV_VAR)?)?)
|
||||
}
|
||||
|
||||
///Fetch config from `NSSA_WALLET_HOME_DIR`
|
||||
pub fn fetch_config() -> Result<NodeConfig> {
|
||||
let config_home = get_home()?;
|
||||
let file = File::open(config_home.join("node_config.json"))?;
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
Ok(serde_json::from_reader(reader)?)
|
||||
}
|
||||
|
||||
//ToDo: Replace with structures conversion in future
|
||||
pub fn produce_account_addr_from_hex(hex_str: String) -> Result<[u8; 32]> {
|
||||
hex::decode(hex_str)?
|
||||
.try_into()
|
||||
.map_err(|_| anyhow!("Failed conversion to 32 bytes"))
|
||||
}
|
||||
@ -1,77 +1,32 @@
|
||||
use std::{fs::File, io::BufReader, path::PathBuf, str::FromStr, sync::Arc};
|
||||
use std::sync::Arc;
|
||||
|
||||
use common::{
|
||||
execution_input::PublicNativeTokenSend, transaction::Transaction, ExecutionFailureKind,
|
||||
execution_input::PublicNativeTokenSend,
|
||||
sequencer_client::{json::SendTxResponse, SequencerClient},
|
||||
transaction::Transaction,
|
||||
ExecutionFailureKind,
|
||||
};
|
||||
|
||||
use accounts::account_core::{address::AccountAddress, Account};
|
||||
use anyhow::{anyhow, Result};
|
||||
use anyhow::Result;
|
||||
use chain_storage::NodeChainStore;
|
||||
use common::transaction::TransactionBody;
|
||||
use config::NodeConfig;
|
||||
use log::info;
|
||||
use sc_core::proofs_circuits::{generate_commitments, pedersen_commitment_vec};
|
||||
use sequencer_client::{json::SendTxResponse, SequencerClient};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use storage::sc_db_utils::DataBlobChangeVariant;
|
||||
use sc_core::proofs_circuits::pedersen_commitment_vec;
|
||||
use tokio::sync::RwLock;
|
||||
use utxo::utxo_core::UTXO;
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
pub const HOME_DIR_ENV_VAR: &str = "HOME_DIR";
|
||||
use crate::helperfunctions::{fetch_config, produce_account_addr_from_hex};
|
||||
|
||||
pub const HOME_DIR_ENV_VAR: &str = "NSSA_WALLET_HOME_DIR";
|
||||
pub const BLOCK_GEN_DELAY_SECS: u64 = 20;
|
||||
|
||||
pub mod chain_storage;
|
||||
pub mod config;
|
||||
pub mod sequencer_client;
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
#[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),
|
||||
}
|
||||
pub mod helperfunctions;
|
||||
pub mod requests_structs;
|
||||
|
||||
pub struct NodeCore {
|
||||
pub storage: Arc<RwLock<NodeChainStore>>,
|
||||
@ -81,7 +36,7 @@ pub struct NodeCore {
|
||||
|
||||
impl NodeCore {
|
||||
pub async fn start_from_config_update_chain(config: NodeConfig) -> Result<Self> {
|
||||
let client = Arc::new(SequencerClient::new(config.clone())?);
|
||||
let client = Arc::new(SequencerClient::new(config.sequencer_addr.clone())?);
|
||||
|
||||
let mut storage = NodeChainStore::new(config.clone())?;
|
||||
for acc in config.clone().initial_accounts {
|
||||
@ -142,11 +97,6 @@ impl NodeCore {
|
||||
|
||||
let sc_addr = hex::encode([0; 32]);
|
||||
|
||||
//Native contract does not change its state
|
||||
let state_changes: Vec<DataBlobChangeVariant> = vec![];
|
||||
let new_len = 0;
|
||||
let state_changes = (serde_json::to_value(state_changes).unwrap(), new_len);
|
||||
|
||||
let tx: TransactionBody =
|
||||
sc_core::transaction_payloads_tools::create_public_transaction_payload(
|
||||
serde_json::to_vec(&PublicNativeTokenSend {
|
||||
@ -160,7 +110,6 @@ impl NodeCore {
|
||||
tweak,
|
||||
secret_r,
|
||||
sc_addr,
|
||||
state_changes,
|
||||
);
|
||||
tx.log();
|
||||
|
||||
@ -185,56 +134,33 @@ impl NodeCore {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_commitments_helper(input_utxos: &[UTXO]) -> Vec<[u8; 32]> {
|
||||
generate_commitments(input_utxos)
|
||||
.into_iter()
|
||||
.map(|comm_raw| comm_raw.try_into().unwrap())
|
||||
.collect()
|
||||
}
|
||||
|
||||
///Represents CLI command for a wallet
|
||||
#[derive(Subcommand, Debug, Clone)]
|
||||
#[clap(about)]
|
||||
pub enum Command {
|
||||
SendNativeTokenTransfer {
|
||||
///from - valid 32 byte hex string
|
||||
#[arg(long)]
|
||||
from: String,
|
||||
///to - valid 32 byte hex string
|
||||
#[arg(long)]
|
||||
to: String,
|
||||
///amount - amount of balance to move
|
||||
#[arg(long)]
|
||||
amount: u64,
|
||||
},
|
||||
}
|
||||
|
||||
///To execute commands, env var NSSA_WALLET_HOME_DIR must be set into directory with config
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(version)]
|
||||
#[clap(version, about)]
|
||||
pub struct Args {
|
||||
/// Wallet command
|
||||
#[command(subcommand)]
|
||||
pub command: Command,
|
||||
}
|
||||
|
||||
pub fn get_home() -> Result<PathBuf> {
|
||||
Ok(PathBuf::from_str(&std::env::var(HOME_DIR_ENV_VAR)?)?)
|
||||
}
|
||||
|
||||
pub fn fetch_config() -> Result<NodeConfig> {
|
||||
let config_home = get_home()?;
|
||||
let file = File::open(config_home.join("node_config.json"))?;
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
Ok(serde_json::from_reader(reader)?)
|
||||
}
|
||||
|
||||
//ToDo: Replace with structures in future
|
||||
pub fn produce_account_addr_from_hex(hex_str: String) -> Result<[u8; 32]> {
|
||||
hex::decode(hex_str)?
|
||||
.try_into()
|
||||
.map_err(|_| anyhow!("Failed conversion to 32 bytes"))
|
||||
}
|
||||
|
||||
pub async fn execute_subcommand(command: Command) -> Result<()> {
|
||||
//env_logger::init();
|
||||
|
||||
match command {
|
||||
Command::SendNativeTokenTransfer { from, to, amount } => {
|
||||
let node_config = fetch_config()?;
|
||||
@ -1,7 +1,7 @@
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use node_core::{execute_subcommand, Args};
|
||||
use tokio::runtime::Builder;
|
||||
use wallet::{execute_subcommand, Args};
|
||||
|
||||
pub const NUM_THREADS: usize = 2;
|
||||
|
||||
@ -14,6 +14,8 @@ fn main() -> Result<()> {
|
||||
|
||||
let args = Args::parse();
|
||||
|
||||
env_logger::init();
|
||||
|
||||
runtime.block_on(async move {
|
||||
execute_subcommand(args.command).await.unwrap();
|
||||
});
|
||||
33
wallet/src/requests_structs.rs
Normal file
33
wallet/src/requests_structs.rs
Normal file
@ -0,0 +1,33 @@
|
||||
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