From 8b4457aa09ada1527d03af155ab3be31e2fe7348 Mon Sep 17 00:00:00 2001 From: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Fri, 8 Oct 2021 19:23:48 -0400 Subject: [PATCH] Tauri (#732) * patch * makefile * testnet genesis fixtures * fixtures * cleanup testnet defaults * devnet fixtures * tx_params in stubmit_tx needed an option for wallet library * get txs params from keypair * get_tx_params_from_keypair api change * patch miner tests --- ol/miner/src/block.rs | 5 +-- ol/onboard/src/commands/files_cmd.rs | 2 +- ol/onboard/src/commands/fix_cmd.rs | 6 ++-- ol/onboard/src/commands/wizard_fn_cmd.rs | 2 +- ol/onboard/src/commands/wizard_fork_cmd.rs | 2 +- ol/onboard/src/commands/wizard_user_cmd.rs | 2 +- ol/onboard/src/commands/wizard_val_cmd.rs | 2 +- ol/txs/src/submit_tx.rs | 37 ++++++++++++++++++++++ ol/types/src/config.rs | 6 ++-- 9 files changed, 51 insertions(+), 13 deletions(-) diff --git a/ol/miner/src/block.rs b/ol/miner/src/block.rs index 0866fd41cf..d2611db034 100644 --- a/ol/miner/src/block.rs +++ b/ol/miner/src/block.rs @@ -297,6 +297,7 @@ fn test_mine_genesis() { // if no file is found, the block height is 0 //let blocks_dir = Path::new("./test_blocks"); let configs_fixture = test_make_configs_fixture(); + dbg!(&configs_fixture); //clear from sideffects. test_helper_clear_block_dir(&configs_fixture.get_block_dir()); @@ -364,7 +365,7 @@ pub fn test_make_configs_fixture() -> AppCfg { cfg.workspace.block_dir = "test_blocks_temp_1".to_owned(); cfg.chain_info.chain_id = "0L testnet".to_owned(); cfg.profile.auth_key = - "3e4629ba1e63114b59a161e89ad4a083b3a31b5fd59e39757c493e96398e4df2".to_string(); + "3e4629ba1e63114b59a161e89ad4a083b3a31b5fd59e39757c493e96398e4df2".parse().unwrap(); cfg } @@ -376,7 +377,7 @@ pub fn genesis_preimage(cfg: &AppCfg) -> Vec { let mut preimage: Vec = vec![]; - let mut padded_key_bytes = match decode(cfg.profile.auth_key.clone()) { + let mut padded_key_bytes = match decode(cfg.profile.auth_key.clone().to_string()) { Err(x) => panic!("Invalid 0L Auth Key: {}", x), Ok(key_bytes) => { if key_bytes.len() != AUTH_KEY_BYTES { diff --git a/ol/onboard/src/commands/files_cmd.rs b/ol/onboard/src/commands/files_cmd.rs index 74eb9b8ad2..1eba1f729f 100644 --- a/ol/onboard/src/commands/files_cmd.rs +++ b/ol/onboard/src/commands/files_cmd.rs @@ -54,7 +54,7 @@ pub fn genesis_files( ) { let home_dir = miner_config.workspace.node_home.to_owned(); // 0L convention is for the namespace of the operator to be appended by '-oper' - let namespace = miner_config.profile.auth_key.clone() + "-oper"; + let namespace = miner_config.profile.auth_key.clone().to_string() + "-oper"; ol_node_files::write_node_config_files( home_dir.clone(), diff --git a/ol/onboard/src/commands/fix_cmd.rs b/ol/onboard/src/commands/fix_cmd.rs index b7f520c2f4..b359609209 100644 --- a/ol/onboard/src/commands/fix_cmd.rs +++ b/ol/onboard/src/commands/fix_cmd.rs @@ -32,13 +32,13 @@ impl Runnable for FixCmd { status_info!("\nOnboard fix", "migrating account.json"); let cfg = app_config(); let home_dir = &cfg.workspace.node_home; - let namespace = &cfg.profile.auth_key; + let namespace = cfg.profile.auth_key.to_string(); // set the waypoint if let Some(w) = self.waypoint { - key::set_waypoint(home_dir, namespace, w); + key::set_waypoint(home_dir, &namespace, w); } if self.operator { - key::set_operator_key(home_dir, namespace); + key::set_operator_key(home_dir, &namespace); } if self.account { diff --git a/ol/onboard/src/commands/wizard_fn_cmd.rs b/ol/onboard/src/commands/wizard_fn_cmd.rs index 69bd1ad94a..721d344e45 100644 --- a/ol/onboard/src/commands/wizard_fn_cmd.rs +++ b/ol/onboard/src/commands/wizard_fn_cmd.rs @@ -52,7 +52,7 @@ impl Runnable for FnWizardCmd { let home_dir = cfg.workspace.node_home.to_owned(); // 0L convention is for the namespace of the operator to be appended by '-oper' - let namespace = cfg.profile.auth_key.clone() + "-oper"; + let namespace = cfg.profile.auth_key.clone().to_string() + "-oper"; ol_node_files::write_node_config_files( home_dir.clone(), diff --git a/ol/onboard/src/commands/wizard_fork_cmd.rs b/ol/onboard/src/commands/wizard_fork_cmd.rs index dcba488fb0..d0f11cc556 100644 --- a/ol/onboard/src/commands/wizard_fork_cmd.rs +++ b/ol/onboard/src/commands/wizard_fork_cmd.rs @@ -149,7 +149,7 @@ impl Runnable for ForkCmd { let home_dir = app_config.workspace.node_home.to_owned(); // 0L convention is for the namespace of the operator to be appended by '-oper' - let namespace = app_config.profile.auth_key.clone() + "-oper"; + let namespace = app_config.profile.auth_key.clone().to_string() + "-oper"; // TODO: use node_config to get the seed peers and then write upstream_node vec in 0L.toml from that. ol_node_files::write_node_config_files( diff --git a/ol/onboard/src/commands/wizard_user_cmd.rs b/ol/onboard/src/commands/wizard_user_cmd.rs index 5f245e8be0..d12c72dd39 100644 --- a/ol/onboard/src/commands/wizard_user_cmd.rs +++ b/ol/onboard/src/commands/wizard_user_cmd.rs @@ -40,7 +40,7 @@ fn wizard(path: PathBuf, block_zero: &Option) { // Where to save block_0 app_cfg.workspace.node_home = path.clone(); - app_cfg.profile.auth_key = authkey.to_string(); + app_cfg.profile.auth_key = authkey; app_cfg.profile.account = account; // Create block zero, if there isn't one. diff --git a/ol/onboard/src/commands/wizard_val_cmd.rs b/ol/onboard/src/commands/wizard_val_cmd.rs index d6b5b49abf..1783d6b095 100644 --- a/ol/onboard/src/commands/wizard_val_cmd.rs +++ b/ol/onboard/src/commands/wizard_val_cmd.rs @@ -162,7 +162,7 @@ impl Runnable for ValWizardCmd { let home_dir = app_config.workspace.node_home.to_owned(); // 0L convention is for the namespace of the operator to be appended by '-oper' - let namespace = app_config.profile.auth_key.clone() + "-oper"; + let namespace = app_config.profile.auth_key.clone().to_string() + "-oper"; // TODO: use node_config to get the seed peers and then write upstream_node vec in 0L.toml from that. ol_node_files::write_node_config_files( diff --git a/ol/txs/src/submit_tx.rs b/ol/txs/src/submit_tx.rs index 1d21138f84..7be6284241 100644 --- a/ol/txs/src/submit_tx.rs +++ b/ol/txs/src/submit_tx.rs @@ -381,6 +381,43 @@ pub fn get_tx_params_from_toml( Ok(tx_params) } + +/// Gets transaction params from the 0L project root. +pub fn get_tx_params_from_keypair( + config: AppCfg, + tx_type: TxType, + keypair: KeyPair, + wp: Option, + use_upstream_url: bool, + is_swarm: bool, +) -> Result { + + let waypoint = wp.unwrap_or_else(|| { + config.get_waypoint(None).unwrap() + }); + + let chain_id = if is_swarm { + ChainId::new(4) + } else { + // main net id + ChainId::new(1) + }; + + let tx_params = TxParams { + auth_key: config.profile.auth_key, + signer_address: config.profile.account, + owner_address: config.profile.account, + url: config.what_url(use_upstream_url), + waypoint, + keypair, + tx_cost: config.tx_configs.get_cost(tx_type), + chain_id, + }; + + Ok(tx_params) +} + + /// Wait for the response from the diem RPC. pub fn wait_for_tx( signer_address: AccountAddress, diff --git a/ol/types/src/config.rs b/ol/types/src/config.rs index 7415f5347b..51cdbc5e87 100644 --- a/ol/types/src/config.rs +++ b/ol/types/src/config.rs @@ -142,7 +142,7 @@ impl AppCfg { ) -> AppCfg { // TODO: Check if configs exist and warn on overwrite. let mut default_config = AppCfg::default(); - default_config.profile.auth_key = authkey.to_string(); + default_config.profile.auth_key = authkey; default_config.profile.account = account; // Get statement which goes into genesis block @@ -385,7 +385,7 @@ pub struct Profile { pub account: AccountAddress, /// Miner Authorization Key for 0L Blockchain. Note: not the same as public key, nor account. - pub auth_key: String, + pub auth_key: AuthenticationKey, /// An opportunity for the Miner to write a message on their genesis block. pub statement: String, @@ -403,8 +403,8 @@ pub struct Profile { impl Default for Profile { fn default() -> Self { Self { - auth_key: "".to_owned(), account: AccountAddress::from_hex_literal("0x0").unwrap(), + auth_key: AuthenticationKey::from_str("0000000000000000000000000000000000000000000000000000000000000000").unwrap(), statement: "Protests rage across the nation".to_owned(), ip: "0.0.0.0".parse().unwrap(), default_node: Some("http://localhost:8080".parse().expect("parse url")),