diff --git a/applications/minotari_console_wallet/src/automation/commands.rs b/applications/minotari_console_wallet/src/automation/commands.rs index 332802a62c..097f9bbbd2 100644 --- a/applications/minotari_console_wallet/src/automation/commands.rs +++ b/applications/minotari_console_wallet/src/automation/commands.rs @@ -27,8 +27,6 @@ use std::{ fs::File, io, io::{LineWriter, Write}, - iter::once, - ops::Deref, path::{Path, PathBuf}, time::{Duration, Instant}, }; @@ -72,7 +70,6 @@ use tari_comms::{ }; use tari_comms_dht::{envelope::NodeDestination, DhtDiscoveryRequester}; use tari_core::{ - blocks::pre_mine::{create_pre_mine_genesis_block_file, get_pre_mine_items, PreMineItem}, covenants::Covenant, transactions::{ key_manager::TransactionKeyManagerInterface, @@ -80,7 +77,6 @@ use tari_core::{ transaction_components::{ encrypted_data::PaymentId, OutputFeatures, - RangeProofType, Transaction, TransactionInput, TransactionInputVersion, @@ -89,7 +85,6 @@ use tari_core::{ UnblindedOutput, WalletOutput, }, - CryptoFactories, }, }; use tari_crypto::{ @@ -97,7 +92,7 @@ use tari_crypto::{ ristretto::{pedersen::PedersenCommitment, RistrettoSecretKey}, }; use tari_key_manager::key_manager_service::{KeyId, KeyManagerInterface}; -use tari_script::{script, CheckSigSchnorrSignature, Opcode}; +use tari_script::{script, CheckSigSchnorrSignature}; use tari_utilities::{encoding::Base58, hex::Hex, ByteArray}; use tokio::{ sync::{broadcast, mpsc}, @@ -109,18 +104,14 @@ use crate::{ automation::{ utils::{ get_file_name, - json_from_file_single_object, move_session_file_to_session_dir, out_dir, read_and_verify, - read_genesis_file, read_session_info, read_verify_session_info, write_json_object_to_file_as_line, write_to_json_file, - Context, }, - PreMineCreateStep1ForLeader, PreMineSpendStep1SessionInfo, PreMineSpendStep2OutputsForLeader, PreMineSpendStep2OutputsForSelf, @@ -135,8 +126,6 @@ use crate::{ pub const LOG_TARGET: &str = "wallet::automation::commands"; // Pre-mine file names pub(crate) const FILE_EXTENSION: &str = "json"; -pub(crate) const CREATE_STEP_1_LEADER: &str = "step_1_for_leader_from_"; -pub(crate) const CREATE_STEP_2_LEADER: &str = "step_2_for_parties"; pub(crate) const SPEND_SESSION_INFO: &str = "step_1_session_info"; pub(crate) const SPEND_STEP_2_LEADER: &str = "step_2_for_leader_from_"; pub(crate) const SPEND_STEP_2_SELF: &str = "step_2_for_self"; @@ -776,435 +765,6 @@ pub async fn command_runner( Err(e) => eprintln!("BurnMinotari error! {}", e), } }, - PreMineCreateScriptInputs(args) => { - match key_manager_service.get_wallet_type().await { - WalletType::Ledger(_) => {}, - _ => { - eprintln!("\nError: Wallet type must be 'Ledger' to create pre-mine info!\n"); - break; - }, - } - - if args.alias.is_empty() || args.alias.contains(" ") { - eprintln!("\nError: Alias cannot contain spaces!\n"); - break; - } - if args.alias.chars().any(|c| !c.is_alphanumeric() && c != '_') { - eprintln!("\nError: Alias contains invalid characters! Only alphanumeric and '_' are allowed.\n"); - break; - } - - // Get the pre-mine items according to the unlock schedule specification - let pre_mine_items = match get_pre_mine_items().await { - Ok(items) => items, - Err(e) => { - eprintln!("\nError: {}\n", e); - break; - }, - }; - - let (session_id, out_dir) = match create_pre_mine_output_dir() { - Ok(values) => values, - Err(e) => { - eprintln!("\nError: {}\n", e); - break; - }, - }; - let out_file = out_dir.join(get_file_name(CREATE_STEP_1_LEADER, Some(args.alias.clone()))); - - let mut outputs_for_leader = Vec::with_capacity(pre_mine_items.len()); - let mut error = false; - for index in 0..pre_mine_items.len() as u64 { - let key_id = KeyId::Managed { - branch: TransactionKeyManagerBranch::PreMine.get_branch_key(), - index, - }; - let script_public_key = match key_manager_service.get_public_key_at_key_id(&key_id).await { - Ok(key) => key, - Err(e) => { - eprintln!("\nError: Could not retrieve script key for output {}: {}\n", index, e); - error = true; - break; - }, - }; - let verification_signature = match key_manager_service - .sign_script_message(&key_id, PrivateKey::from(index).as_bytes()) - .await - { - Ok(value) => value, - Err(e) => { - eprintln!("\nError: Could not sign script message for output {}: {}\n", index, e); - error = true; - break; - }, - }; - outputs_for_leader.push(PreMineCreateStep1ForLeader { - index, - script_public_key, - verification_signature, - }); - } - if error { - break; - } - write_to_json_file(&out_file, true, outputs_for_leader)?; - - println!(); - println!("Concluded step 1 'pre-mine-create-script-inputs'"); - println!("Your session ID is: '{}'", session_id); - println!("Your session's output directory is: '{}'", out_dir.display()); - println!("Session info saved to: '{}'", out_file.display()); - println!( - "Send '{}' to leader for step 2", - get_file_name(CREATE_STEP_1_LEADER, None) - ); - println!(); - }, - PreMineCreateGenesisFile(args) => { - // Read inputs from party members - let mut threshold_inputs = Vec::with_capacity(args.party_file_names.len()); - for file in &args.party_file_names { - threshold_inputs.push(json_from_file_single_object::<_, Vec>( - &file, None, - )?); - } - let backup_inputs = json_from_file_single_object::<_, Vec>( - &args.fail_safe_file_name, - None, - )?; - - // Get the pre-mine items according to the unlock schedule specification - let pre_mine_items = match get_pre_mine_items().await { - Ok(items) => items, - Err(e) => { - eprintln!("\nError: {}\n", e); - break; - }, - }; - - // Perform party members input verification - if let Err(e) = verify_script_pre_mine_inputs( - &threshold_inputs, - &backup_inputs, - &args.party_file_names, - &args.fail_safe_file_name, - &pre_mine_items, - ) { - eprintln!("\nError: {}\n", e); - break; - } - - // Extract the threshold and backup spend keys - let (threshold_spend_keys, backup_spend_keys, _all_spend_keys) = - match extract_threshold_and_backup_spend_keys(&threshold_inputs, &backup_inputs) { - Ok(keys) => keys, - Err(e) => { - eprintln!("\nError: {}\n", e); - break; - }, - }; - - // Create the pre-mine genesis block outputs and kernel - let (outputs, kernel) = match create_pre_mine_genesis_block_file( - &pre_mine_items, - &threshold_spend_keys, - &backup_spend_keys, - ) - .await - { - Ok(values) => values, - Err(e) => { - eprintln!("\nError: {}\n", e); - break; - }, - }; - - // Create the genesis file - let (session_id, out_dir) = match create_pre_mine_output_dir() { - Ok(values) => values, - Err(e) => { - eprintln!("\nError: {}\n", e); - break; - }, - }; - let file_name = match Network::get_current_or_user_setting_or_default() { - Network::MainNet => "mainnet_pre_mine.json", - Network::StageNet => "stagenet_pre_mine.json", - Network::NextNet => "nextnet_pre_mine.json", - Network::LocalNet => "esmeralda_pre_mine.json", - Network::Igor => "igor_pre_mine.json", - Network::Esmeralda => "esmeralda_pre_mine.json", - }; - let out_file = out_dir.join(file_name); - let mut file_stream = File::create(&out_file).expect("Could not create 'utxos.json'"); - - let mut error = false; - for output in outputs { - let utxo_s = match serde_json::to_string(&output) { - Ok(val) => val, - Err(e) => { - eprintln!("\nError: Could not serialize UTXO ({})\n", e); - error = true; - break; - }, - }; - if let Err(e) = file_stream.write_all(format!("{}\n", utxo_s).as_bytes()) { - eprintln!("\nError: Could not serialize UTXO ({})\n", e); - error = true; - break; - } - } - if error { - break; - } - let kernel = match serde_json::to_string(&kernel) { - Ok(val) => val, - Err(e) => { - eprintln!("\nError: Could not serialize kernel ({})\n", e); - break; - }, - }; - if let Err(e) = file_stream.write_all(format!("{}\n", kernel).as_bytes()) { - eprintln!("\nError: Could not write the genesis file ({})\n", e); - break; - } - - println!(); - println!("Concluded step 2 'pre-mine-create-genesis-file'"); - println!("Your session ID is: '{}'", session_id); - println!("Your session's output directory is: '{}'", out_dir.display()); - println!("Outputs written to: '{}'", out_file.display()); - println!( - "Send '{}' to parties for step 3", - get_file_name(CREATE_STEP_2_LEADER, None) - ); - println!(); - }, - PreMineCreateVerifyGenesisFile(args) => { - match key_manager_service.get_wallet_type().await { - WalletType::Ledger(_) => {}, - _ => { - eprintln!("\nError: Wallet type must be 'Ledger' to create pre-mine info!\n"); - break; - }, - } - - // Read inputs from party members - let mut threshold_inputs = Vec::with_capacity(args.party_file_names.len()); - let out_dir = out_dir(&args.session_id, Context::Create)?; - let party_files: Vec = args.party_file_names.iter().map(|v| out_dir.join(v)).collect(); - let mut error = false; - for file in &party_files { - let party_info = - match json_from_file_single_object::<_, Vec>(file, None) { - Ok(info) => info, - Err(e) => { - eprintln!("\nError: {}\n", e); - error = true; - break; - }, - }; - threshold_inputs.push(party_info); - } - if error { - break; - } - let fail_safe_file = out_dir.join(args.fail_safe_file_name); - let backup_inputs = - json_from_file_single_object::<_, Vec>(&fail_safe_file, None)?; - - // Read the pe-mine genesis file - let pre_mine_file = out_dir.join(args.pre_mine_file_name); - let (outputs, kernel) = match read_genesis_file(&pre_mine_file) { - Ok(items) => items, - Err(e) => { - eprintln!("\nError: {}\n", e); - break; - }, - }; - - // Verify the kernel signature - if let Err(e) = kernel.verify_signature() { - eprintln!("\nError: Kernel signature verification failed: {}\n", e); - break; - } - - // Get the pre-mine items according to the unlock schedule specification - let pre_mine_items = match get_pre_mine_items().await { - Ok(items) => items, - Err(e) => { - eprintln!("\nError: {}\n", e); - break; - }, - }; - - // Perform party members input verification - if let Err(e) = verify_script_pre_mine_inputs( - &threshold_inputs, - &backup_inputs, - &party_files, - &fail_safe_file, - &pre_mine_items, - ) { - eprintln!("\nError: {}\n", e); - break; - } - if outputs.len() != pre_mine_items.len() { - eprintln!( - "\nError: Mismatched number of outputs ({}) and pre-mine items ({})\n", - outputs.len(), - pre_mine_items.len() - ); - break; - } - - // Verify all outputs - let (threshold_spend_keys, backup_spend_keys, _all_party_keys) = - match extract_threshold_and_backup_spend_keys(&threshold_inputs, &backup_inputs) { - Ok(keys) => keys, - Err(e) => { - eprintln!("\nError: {}\n", e); - break; - }, - }; - - let range_proof_service = CryptoFactories::default().range_proof; - let mut error = false; - for (index, (((output, threshold_keys), backup_key), pre_mine_item)) in outputs - .iter() - .zip(threshold_spend_keys) - .zip(backup_spend_keys) - .zip(pre_mine_items) - .enumerate() - { - if pre_mine_item.value != output.minimum_value_promise { - eprintln!( - "\nError: Mismatched value for output {} ({} != {})\n", - index, pre_mine_item.value, output.minimum_value_promise - ); - error = true; - break; - } - if pre_mine_item.maturity != output.features.maturity { - eprintln!( - "\nError: Mismatched maturity for output {} ({} != {})\n", - index, pre_mine_item.maturity, output.features.maturity - ); - error = true; - break; - } - if output.features.range_proof_type != RangeProofType::RevealedValue { - eprintln!("\nError: Output {} does not have a RevealedValue range proof\n", index); - error = true; - break; - } - if let Err(e) = output.verify_metadata_signature() { - eprintln!( - "\nError: Output {} metadata signature verification failed: {}\n", - index, e - ); - error = true; - break; - } - if let Err(e) = output.verify_range_proof(&range_proof_service) { - eprintln!("\nError: Output {} range proof verification failed: {}\n", index, e); - error = true; - break; - } - // Retrieve the list of threshold keys and backup key from the script - let script_threshold_keys = - if let Some(Opcode::CheckMultiSigVerifyAggregatePubKey(_n, _m, keys, _msg)) = - output.script.as_slice().get(3) - { - keys.clone() - } else { - eprintln!( - "\nError: Output {} script does not contain a CheckMultiSigVerifyAggregatePubKey\n", - index - ); - error = true; - break; - }; - let script_backup_key = if let Some(Opcode::PushPubKey(key)) = output.script.as_slice().get(5) { - key.deref().clone() - } else { - eprintln!("\nError: Output {} script does not contain a PushPubKey\n", index); - error = true; - break; - }; - // Verify that the script keys correspond to the threshold and backup keys from the party members - let mut all_script_keys = script_threshold_keys - .iter() - .chain(once(&script_backup_key)) - .cloned() - .collect::>(); - let mut all_party_keys = threshold_keys - .iter() - .chain(once(&backup_key)) - .cloned() - .collect::>(); - all_script_keys.sort(); - all_party_keys.sort(); - if all_script_keys.len() != all_party_keys.len() { - eprintln!( - "\nError: Output {} script key count mismatch ({} != {})\n", - index, - all_script_keys.len(), - all_party_keys.len() - ); - error = true; - break; - } - all_script_keys.dedup(); - if all_party_keys.len() != all_script_keys.len() { - eprintln!("\nError: Output {} script keys not unique\n", index,); - error = true; - break; - } - for (index, (script_key, party_key)) in all_script_keys.iter().zip(all_party_keys).enumerate() { - if script_key != &party_key { - eprintln!( - "\nError: Output {} script key mismatch ({} != {})\n", - index, script_key, party_key - ); - error = true; - break; - } - } - if error { - break; - } - // Verify that script key owned by this wallet can be retrieved via the key id - let key_id = KeyId::Managed { - branch: TransactionKeyManagerBranch::PreMine.get_branch_key(), - index: index as u64, - }; - let expected_script_key = match key_manager_service.get_public_key_at_key_id(&key_id).await { - Ok(key) => key, - Err(e) => { - eprintln!("\nError: Could not retrieve script key for output {}: {}\n", index, e); - error = true; - break; - }, - }; - if !all_script_keys.iter().any(|k| k == &expected_script_key) { - eprintln!( - "\nError: Output {} script key mismatch ({} not found in script)\n", - index, expected_script_key - ); - error = true; - break; - } - } - if error { - break; - } - - println!(); - println!("Concluded step 3 'pre-mine-create-verify-genesis-file'"); - println!("Pre-mine file '{}' successfully verified", pre_mine_file.display()); - println!(); - }, PreMineSpendSessionInfo(args) => { match key_manager_service.get_wallet_type().await { WalletType::Ledger(_) => {}, @@ -1253,7 +813,7 @@ pub async fn command_runner( fee_per_gram: args.fee_per_gram, output_index: args.output_index, }; - let out_dir = out_dir(&session_info.session_id, Context::Spend)?; + let out_dir = out_dir(&session_info.session_id)?; let out_file = out_dir.join(get_file_name(SPEND_SESSION_INFO, None)); write_to_json_file(&out_file, true, session_info)?; println!(); @@ -1392,7 +952,7 @@ pub async fn command_runner( .sign_script_message(&pre_mine_script_key_id, commitment.as_bytes()) .await?; - let out_dir = out_dir(&session_info.session_id, Context::Spend)?; + let out_dir = out_dir(&session_info.session_id)?; let step_2_outputs_for_leader = PreMineSpendStep2OutputsForLeader { script_input_signature, public_script_nonce_key: script_nonce_key.pub_key, @@ -1481,7 +1041,7 @@ pub async fn command_runner( total_metadata_ephemeral_public_key, total_script_nonce, )) => { - let out_dir = out_dir(&args.session_id, Context::Spend)?; + let out_dir = out_dir(&args.session_id)?; let step_3_outputs_for_self = PreMineSpendStep3OutputsForSelf { tx_id }; let out_file = out_dir.join(get_file_name(SPEND_STEP_3_SELF, None)); write_json_object_to_file_as_line(&out_file, true, session_info.clone())?; @@ -1619,7 +1179,7 @@ pub async fn command_runner( script_offset, }; - let out_dir = out_dir(&args.session_id, Context::Spend)?; + let out_dir = out_dir(&args.session_id)?; let out_file = out_dir.join(get_file_name(SPEND_STEP_4_LEADER, Some(party_info.alias.clone()))); write_json_object_to_file_as_line(&out_file, true, session_info.clone())?; write_json_object_to_file_as_line(&out_file, false, step_4_outputs_for_leader)?; @@ -2233,121 +1793,6 @@ pub async fn command_runner( Ok(()) } -fn verify_script_pre_mine_inputs( - threshold_inputs: &[Vec], - backup_inputs: &[PreMineCreateStep1ForLeader], - party_file_names: &[PathBuf], - fail_safe_file_name: &Path, - pre_mine_items: &[PreMineItem], -) -> Result<(), String> { - for (k, party_info) in threshold_inputs.iter().enumerate() { - verify_party_script_inputs(&party_file_names[k], party_info, pre_mine_items)?; - } - verify_party_script_inputs(fail_safe_file_name, backup_inputs, pre_mine_items)?; - - // Ensure no keys for the same index are duplicated - let (_threshold_spend_keys, _backup_spend_keys, mut all_spend_keys) = - extract_threshold_and_backup_spend_keys(threshold_inputs, backup_inputs)?; - for (i, keys) in all_spend_keys.iter_mut().enumerate() { - let keys_len = keys.len(); - keys.sort(); - keys.dedup(); - if keys.len() != keys_len { - return Err(format!("Duplicate script keys for index '{}'!", i)); - } - } - // Ensure no keys for any index are duplicated - let mut all_spend_keys_flattened = all_spend_keys.into_iter().flatten().collect::>(); - all_spend_keys_flattened.sort(); - let all_spend_keys_len = all_spend_keys_flattened.len(); - all_spend_keys_flattened.dedup(); - if all_spend_keys_flattened.len() != all_spend_keys_len { - return Err("Duplicate script keys across parties!".to_string()); - } - - Ok(()) -} - -fn verify_party_script_inputs( - party_file_name: &Path, - party_info: &[PreMineCreateStep1ForLeader], - pre_mine_items: &[PreMineItem], -) -> Result<(), String> { - if party_info.len() != pre_mine_items.len() { - return Err(format!( - "Number of items in '{}' does not match the pre-mine items!", - party_file_name.display() - )); - } - // Ensure each key is unique - let mut script_keys = party_info - .iter() - .map(|v| v.script_public_key.clone()) - .collect::>(); - script_keys.sort(); - script_keys.dedup(); - if script_keys.len() != pre_mine_items.len() { - return Err(format!("Duplicate script keys in '{}'!", party_file_name.display())); - } - // Verify knowledge of the script private key - for (index, item) in party_info.iter().enumerate() { - if !item - .verification_signature - .verify(&item.script_public_key, PrivateKey::from(item.index).as_bytes()) - { - return Err(format!( - "Verification signature at index {} in '{}' is not valid!", - index, - party_file_name.display() - )); - } - if item.index != index as u64 { - return Err(format!( - "Index {} in '{}' does not align!", - index, - party_file_name.display() - )); - } - } - Ok(()) -} - -type PublicKeyVec = Vec; - -fn extract_threshold_and_backup_spend_keys( - threshold_inputs: &[Vec], - backup_inputs: &[PreMineCreateStep1ForLeader], -) -> Result<(Vec, PublicKeyVec, Vec), String> { - for item in threshold_inputs { - if item.is_empty() || item.len() != backup_inputs.len() { - return Err("Threshold/backup inputs empty or have different lengths!".to_string()); - } - } - let mut threshold_spend_keys = Vec::with_capacity(threshold_inputs[0].len()); - let mut backup_spend_keys = Vec::with_capacity(threshold_inputs[0].len()); - let mut all_spend_keys = Vec::with_capacity(threshold_inputs[0].len()); - for i in 0..threshold_inputs[0].len() { - let mut keys_for_round = Vec::with_capacity(threshold_inputs.len()); - for party_info in threshold_inputs { - keys_for_round.push(party_info[i].script_public_key.clone()); - } - threshold_spend_keys.push(keys_for_round.clone()); - backup_spend_keys.push(backup_inputs[i].clone().script_public_key); - keys_for_round.push(backup_inputs[i].clone().script_public_key); - all_spend_keys.push(keys_for_round); - } - Ok((threshold_spend_keys, backup_spend_keys, all_spend_keys)) -} - -fn create_pre_mine_output_dir() -> Result<(String, PathBuf), CommandError> { - let mut session_id = PrivateKey::random(&mut OsRng).to_base58(); - session_id.truncate(16); - let out_dir = out_dir(&session_id, Context::Create)?; - fs::create_dir_all(out_dir.clone()) - .map_err(|e| CommandError::JsonFile(format!("{} ({})", e, out_dir.display())))?; - Ok((session_id, out_dir)) -} - fn get_embedded_pre_mine_outputs(output_indexes: Vec) -> Result, CommandError> { let pre_mine_contents = match Network::get_current_or_user_setting_or_default() { Network::MainNet => { diff --git a/applications/minotari_console_wallet/src/automation/mod.rs b/applications/minotari_console_wallet/src/automation/mod.rs index 59caf40619..771268fdf9 100644 --- a/applications/minotari_console_wallet/src/automation/mod.rs +++ b/applications/minotari_console_wallet/src/automation/mod.rs @@ -39,14 +39,6 @@ use tari_core::transactions::{ }; use tari_script::{CheckSigSchnorrSignature, ExecutionStack, TariScript}; -// Step 1 outputs for leader with `PreMineCreateScriptInputs` -#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)] -struct PreMineCreateStep1ForLeader { - pub index: u64, - script_public_key: PublicKey, - verification_signature: CheckSigSchnorrSignature, -} - // Step 1 outputs for all with `PreMineSpendSessionInfo` #[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)] struct PreMineSpendStep1SessionInfo { diff --git a/applications/minotari_console_wallet/src/automation/utils.rs b/applications/minotari_console_wallet/src/automation/utils.rs index 619561a91a..95161b2c6e 100644 --- a/applications/minotari_console_wallet/src/automation/utils.rs +++ b/applications/minotari_console_wallet/src/automation/utils.rs @@ -28,7 +28,6 @@ use std::{ }; use serde::{de::DeserializeOwned, Serialize}; -use tari_core::transactions::transaction_components::{TransactionKernel, TransactionOutput}; use crate::automation::{ commands::{FILE_EXTENSION, SPEND_SESSION_INFO}, @@ -128,25 +127,17 @@ fn append_to_json_file, T: Serialize>(file: P, data: T) -> Result Ok(()) } -pub(crate) enum Context { - Create, - Spend, -} - /// Return the output directory for the session -pub(crate) fn out_dir(session_id: &str, action: Context) -> Result { +pub(crate) fn out_dir(session_id: &str) -> Result { let base_dir = dirs_next::document_dir().ok_or(CommandError::InvalidArgument( "Could not find cache directory".to_string(), ))?; - match action { - Context::Create => Ok(base_dir.join("tari_pre_mine").join("create").join(session_id)), - Context::Spend => Ok(base_dir.join("tari_pre_mine").join("spend").join(session_id)), - } + Ok(base_dir.join("tari_pre_mine").join("spend").join(session_id)) } /// Move the session file to the session directory pub(crate) fn move_session_file_to_session_dir(session_id: &str, input_file: &PathBuf) -> Result<(), CommandError> { - let out_dir = out_dir(session_id, Context::Spend)?; + let out_dir = out_dir(session_id)?; let session_file = out_dir.join(get_file_name(SPEND_SESSION_INFO, None)); if input_file != &session_file { fs::copy(input_file.clone(), session_file.clone())?; @@ -162,7 +153,7 @@ pub(crate) fn move_session_file_to_session_dir(session_id: &str, input_file: &Pa /// Read the session info from the session directory and verify the supplied session ID pub(crate) fn read_verify_session_info(session_id: &str) -> Result { - let file_path = out_dir(session_id, Context::Spend)?.join(get_file_name(SPEND_SESSION_INFO, None)); + let file_path = out_dir(session_id)?.join(get_file_name(SPEND_SESSION_INFO, None)); let session_info = json_from_file_single_object::<_, T>(&file_path, None)?; if session_info.session_id() != session_id { return Err(CommandError::InvalidArgument(format!( @@ -184,7 +175,7 @@ pub(crate) fn read_and_verify( file_name: &str, session_info: &PreMineSpendStep1SessionInfo, ) -> Result { - let out_dir = out_dir(session_id, Context::Spend)?; + let out_dir = out_dir(session_id)?; let header = json_from_file_single_object::<_, PreMineSpendStep1SessionInfo>( &out_dir.join(file_name), Some(PartialRead { @@ -224,38 +215,3 @@ pub(crate) fn get_file_name(stem: &str, suffix: Option) -> String { file_name } -pub(crate) fn read_genesis_file(file_path: &Path) -> Result<(Vec, TransactionKernel), CommandError> { - let file = File::open(file_path) - .map_err(|e| CommandError::PreMine(format!("Problem opening file '{}' ({})", file_path.display(), e)))?; - let reader = BufReader::new(file); - - let mut outputs = Vec::new(); - let mut kernel: Option = None; - - for line in reader.lines() { - let line = line.map_err(|e| { - CommandError::PreMine(format!( - "Problem reading line in file '{}' ({})", - file_path.display(), - e - )) - })?; - if let Ok(output) = serde_json::from_str::(&line) { - outputs.push(output); - } else if let Ok(k) = serde_json::from_str::(&line) { - kernel = Some(k); - } else { - eprintln!("Error: Could not deserialize line: {}", line); - } - } - if outputs.is_empty() { - return Err(CommandError::PreMine(format!( - "No outputs found in '{}'", - file_path.display() - ))); - } - let kernel = - kernel.ok_or_else(|| CommandError::PreMine(format!("No kernel found in '{}'", file_path.display())))?; - - Ok((outputs, kernel)) -} diff --git a/applications/minotari_console_wallet/src/cli.rs b/applications/minotari_console_wallet/src/cli.rs index d0531e1e19..d282aeb63b 100644 --- a/applications/minotari_console_wallet/src/cli.rs +++ b/applications/minotari_console_wallet/src/cli.rs @@ -121,9 +121,6 @@ pub enum CliCommands { GetBalance, SendMinotari(SendMinotariArgs), BurnMinotari(BurnMinotariArgs), - PreMineCreateScriptInputs(PreMineCreateScriptInputsArgs), - PreMineCreateGenesisFile(PreMineCreateGenesisFileArgs), - PreMineCreateVerifyGenesisFile(PreMineCreateVerifyGenesisFileArgs), PreMineSpendSessionInfo(PreMineSpendSessionInfoArgs), PreMineSpendPartyDetails(PreMineSpendPartyDetailsArgs), PreMineSpendEncumberAggregateUtxo(PreMineSpendEncumberAggregateUtxoArgs), @@ -173,32 +170,6 @@ pub struct BurnMinotariArgs { pub message: String, } -#[derive(Debug, Args, Clone)] -pub struct PreMineCreateScriptInputsArgs { - #[clap(long)] - pub alias: String, -} - -#[derive(Debug, Args, Clone)] -pub struct PreMineCreateGenesisFileArgs { - #[clap(long)] - pub party_file_names: Vec, - #[clap(long)] - pub fail_safe_file_name: PathBuf, -} - -#[derive(Debug, Args, Clone)] -pub struct PreMineCreateVerifyGenesisFileArgs { - #[clap(long)] - pub session_id: String, - #[clap(long)] - pub party_file_names: Vec, - #[clap(long)] - pub fail_safe_file_name: String, - #[clap(long)] - pub pre_mine_file_name: String, -} - #[derive(Debug, Args, Clone)] pub struct PreMineSpendSessionInfoArgs { #[clap(long)] diff --git a/applications/minotari_console_wallet/src/wallet_modes.rs b/applications/minotari_console_wallet/src/wallet_modes.rs index adf6b6e345..3eb45e21db 100644 --- a/applications/minotari_console_wallet/src/wallet_modes.rs +++ b/applications/minotari_console_wallet/src/wallet_modes.rs @@ -170,10 +170,7 @@ pub(crate) fn command_mode( fn force_exit_for_pre_mine_commands(command: &CliCommands) -> bool { matches!( command, - CliCommands::PreMineCreateScriptInputs(_) | - CliCommands::PreMineCreateGenesisFile(_) | - CliCommands::PreMineCreateVerifyGenesisFile(_) | - CliCommands::PreMineSpendSessionInfo(_) | + CliCommands::PreMineSpendSessionInfo(_) | CliCommands::PreMineSpendEncumberAggregateUtxo(_) | CliCommands::PreMineSpendAggregateTransaction(_) | CliCommands::PreMineSpendPartyDetails(_) | @@ -533,17 +530,6 @@ mod test { burn-minotari --message Ups_these_funds_will_be_burned! 100T - pre-mine-create-script-inputs --alias alice - - pre-mine-create-genesis-file --party-file-names=step_1_for_leader_from_alice.json \ - --party-file-names=step_1_for_leader_from_bob.json --party-file-names=step_1_for_leader_from_carol.json \ - --fail-safe-file-name step_1_for_leader_from_dave.json - - pre-mine-create-verify-genesis-file --session-id ee1643655c \ - --party-file-names=step_1_for_leader_from_alice.json --party-file-names=step_1_for_leader_from_bob.json \ - --party-file-names=step_1_for_leader_from_carol.json --fail-safe-file-name \ - step_1_for_leader_from_dave.json --pre-mine-file-name ./step_2_for_parties.json - pre-mine-spend-session-info --fee-per-gram 2 --output-index 123 --recipient-address \ f4LR9f6WwwcPiKJjK5ciTkU1ocNhANa3FPw1wkyVUwbuKpgiihawCXy6PFszunUWQ4Te8KVFnyWVHHwsk9x5Cg7ZQiA \ --verify-unspent-outputs @@ -579,9 +565,6 @@ mod test { let mut get_balance = false; let mut send_tari = false; let mut burn_tari = false; - let mut pre_mine_create_script_inputs = false; - let mut pre_mine_create_genesis_file = false; - let mut pre_mine_create_verify_genesis_file = false; let mut pre_mine_spend_session_info = false; let mut pre_mine_spend_encumber_aggregate_utxo = false; let mut pre_mine_spend_aggregate_transaction = false; @@ -598,9 +581,6 @@ mod test { CliCommands::GetBalance => get_balance = true, CliCommands::SendMinotari(_) => send_tari = true, CliCommands::BurnMinotari(_) => burn_tari = true, - CliCommands::PreMineCreateScriptInputs(_) => pre_mine_create_script_inputs = true, - CliCommands::PreMineCreateGenesisFile(_) => pre_mine_create_genesis_file = true, - CliCommands::PreMineCreateVerifyGenesisFile(_) => pre_mine_create_verify_genesis_file = true, CliCommands::PreMineSpendSessionInfo(_) => pre_mine_spend_session_info = true, CliCommands::PreMineSpendPartyDetails(_) => pre_mine_spend_party_details = true, CliCommands::PreMineSpendEncumberAggregateUtxo(_) => pre_mine_spend_encumber_aggregate_utxo = true, @@ -642,9 +622,6 @@ mod test { get_balance && send_tari && burn_tari && - pre_mine_create_script_inputs && - pre_mine_create_genesis_file && - pre_mine_create_verify_genesis_file && pre_mine_spend_session_info && pre_mine_spend_encumber_aggregate_utxo && pre_mine_spend_aggregate_transaction &&