Skip to content

Commit d1ec3eb

Browse files
authored
chore: simplify premine spending process (#6845)
Description --- simplyfies the prespend commands and process. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced pre-mining operations with interactive prompts, including dynamic alias validation and file path input. - Introduced JSON serialization and deserialization for `TariAddress` objects. - **CLI Enhancements** - Reorganized command-line options with improved defaults and streamlined argument handling for pre-mining functions. - **Refactor & Improvements** - Upgraded session management with timestamp-based identifiers for output directories. - Improved error handling and descriptive messages for command processing. - Adopted custom formatting for address display to ensure consistency. - **Chores** - Simplified and updated dependency configurations for easier maintenance. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent ccb361e commit d1ec3eb

File tree

13 files changed

+320
-246
lines changed

13 files changed

+320
-246
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

applications/minotari_console_wallet/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ clap = { version = "3.2", features = ["derive", "env"] }
3838
config = "0.14.0"
3939
crossterm = { version = "0.28" }
4040
digest = "0.10"
41+
dialoguer = { version = "0.10" }
4142
dirs-next = "2.0"
4243
futures = { version = "^0.3.16", default-features = false, features = [
4344
"alloc",

applications/minotari_console_wallet/src/automation/commands.rs

+201-181
Large diffs are not rendered by default.

applications/minotari_console_wallet/src/automation/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct PreMineSpendStep1SessionInfo {
5151
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
5252
struct RecipientInfo {
5353
output_to_be_spend: usize,
54+
#[serde(with = "tari_common_types::tari_address::tari_address_json_bs58")]
5455
recipient_address: TariAddress,
5556
}
5657

applications/minotari_console_wallet/src/automation/utils.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,8 @@ use std::{
2727
path::{Path, PathBuf},
2828
};
2929

30-
use digest::crypto_common::rand_core::OsRng;
30+
use chrono::Utc;
3131
use serde::{de::DeserializeOwned, Serialize};
32-
use tari_common_types::types::PrivateKey;
33-
use tari_crypto::keys::SecretKey;
34-
use tari_utilities::encoding::MBase58;
3532

3633
use crate::automation::{
3734
commands::{FILE_EXTENSION, SPEND_SESSION_INFO},
@@ -133,8 +130,8 @@ fn append_to_json_file<P: AsRef<Path>, T: Serialize>(file: P, data: T) -> Result
133130

134131
/// Create a unique session-based output directory
135132
pub(crate) fn create_pre_mine_output_dir(alias: Option<&str>) -> Result<(String, PathBuf), CommandError> {
136-
let mut session_id = PrivateKey::random(&mut OsRng).to_monero_base58();
137-
session_id.truncate(if alias.is_some() { 8 } else { 16 });
133+
let date_time = Utc::now();
134+
let mut session_id = format!("{}", date_time.format("%Y%m%d%H%M%S"));
138135
if let Some(alias) = alias {
139136
session_id.push('_');
140137
session_id.push_str(alias);

applications/minotari_console_wallet/src/cli.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ pub enum CliCommands {
139139
SendMinotari(SendMinotariArgs),
140140
BurnMinotari(BurnMinotariArgs),
141141
PreMineSpendGetOutputStatus,
142-
PreMineSpendSessionInfo(PreMineSpendSessionInfoArgs),
143-
PreMineSpendPartyDetails(PreMineSpendPartyDetailsArgs),
144-
PreMineSpendEncumberAggregateUtxo(PreMineSpendEncumberAggregateUtxoArgs),
145-
PreMineSpendInputOutputSigs(PreMineSpendInputOutputSigArgs),
146-
PreMineSpendAggregateTransaction(PreMineSpendAggregateTransactionArgs),
142+
PreMineStart(PreMineStartSessionArgs),
143+
PreMineStartParty(PreMineSpendPartyDetailsArgs),
144+
PreMineEncumber(PreMineSpendEncumberAggregateUtxoArgs),
145+
PreMineSigs(PreMineSpendInputOutputSigArgs),
146+
PreMineSpendTx(PreMineSpendAggregateTransactionArgs),
147147
PreMineSpendBackupUtxo(PreMineSpendBackupUtxoArgs),
148148
SendOneSidedToStealthAddress(SendMinotariArgs),
149149
MakeItRain(MakeItRainArgs),
@@ -190,8 +190,8 @@ pub struct BurnMinotariArgs {
190190
}
191191

192192
#[derive(Debug, Args, Clone)]
193-
pub struct PreMineSpendSessionInfoArgs {
194-
#[clap(long)]
193+
pub struct PreMineStartSessionArgs {
194+
#[clap(long, default_value = "1")]
195195
pub fee_per_gram: MicroMinotari,
196196
#[clap(long)]
197197
pub recipient_info: Vec<CliRecipientInfo>,
@@ -251,21 +251,19 @@ impl FromStr for CliRecipientInfo {
251251
#[derive(Debug, Args, Clone)]
252252
pub struct PreMineSpendPartyDetailsArgs {
253253
#[clap(long)]
254-
pub input_file: PathBuf,
254+
pub input_file: Option<String>,
255255
#[clap(long)]
256256
pub pre_mine_file_path: Option<PathBuf>,
257-
#[clap(long)]
258-
pub recipient_info: Vec<CliRecipientInfo>,
259-
#[clap(long)]
257+
#[clap(long, default_value = "")]
260258
pub alias: String,
261259
}
262260

263261
#[derive(Debug, Args, Clone)]
264262
pub struct PreMineSpendEncumberAggregateUtxoArgs {
265-
#[clap(long)]
263+
#[clap(long, default_value = "")]
266264
pub session_id: String,
267265
#[clap(long)]
268-
pub input_file_names: Vec<String>,
266+
pub member: Vec<String>,
269267
#[clap(long)]
270268
pub pre_mine_file_path: Option<PathBuf>,
271269
#[clap(short, long, default_value = "Spend pre-mine encumber aggregate UTXO")]
@@ -274,23 +272,23 @@ pub struct PreMineSpendEncumberAggregateUtxoArgs {
274272

275273
#[derive(Debug, Args, Clone)]
276274
pub struct PreMineSpendInputOutputSigArgs {
277-
#[clap(long)]
275+
#[clap(long, default_value = "")]
278276
pub session_id: String,
279277
#[clap(long)]
280278
pub pre_mine_file_path: Option<PathBuf>,
281279
}
282280

283281
#[derive(Debug, Args, Clone)]
284282
pub struct PreMineSpendAggregateTransactionArgs {
285-
#[clap(long)]
283+
#[clap(long, default_value = "")]
286284
pub session_id: String,
287285
#[clap(long)]
288-
pub input_file_names: Vec<String>,
286+
pub member: Vec<String>,
289287
}
290288

291289
#[derive(Debug, Args, Clone)]
292290
pub struct PreMineSpendBackupUtxoArgs {
293-
#[clap(long)]
291+
#[clap(long, default_value = "1")]
294292
pub fee_per_gram: MicroMinotari,
295293
#[clap(long)]
296294
pub output_index: usize,

applications/minotari_console_wallet/src/wallet_modes.rs

+22-31
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,13 @@ fn force_exit_for_pre_mine_commands(command: &CliCommands) -> (bool, bool) {
169169
matches!(
170170
command,
171171
CliCommands::PreMineSpendGetOutputStatus |
172-
CliCommands::PreMineSpendSessionInfo(_) |
173-
CliCommands::PreMineSpendEncumberAggregateUtxo(_) |
174-
CliCommands::PreMineSpendPartyDetails(_) |
175-
CliCommands::PreMineSpendInputOutputSigs(_) |
172+
CliCommands::PreMineStart(_) |
173+
CliCommands::PreMineEncumber(_) |
174+
CliCommands::PreMineStartParty(_) |
175+
CliCommands::PreMineSigs(_) |
176176
CliCommands::PreMineSpendBackupUtxo(_)
177177
),
178-
matches!(command, CliCommands::PreMineSpendAggregateTransaction(_)),
178+
matches!(command, CliCommands::PreMineSpendTx(_)),
179179
)
180180
}
181181

@@ -534,8 +534,7 @@ mod test {
534534
#[test]
535535
#[allow(clippy::too_many_lines)]
536536
fn clap_parses_user_defined_commands_as_expected() {
537-
let script =
538-
"
537+
let script = "
539538
# Beginning of script file
540539
541540
get-balance
@@ -545,45 +544,37 @@ mod test {
545544
discover-peer f6b2ca781342a3ebe30ee1643655c96f1d7c14f4d49f077695395de98ae73665
546545
547546
send-minotari --payment-id Our_secret! 125T \
548-
f425UWsDp714RiN53c1G6ek57rfFnotB5NCMyrn4iDgbR8i2sXVHa4xSsedd66o9KmkRgErQnyDdCaAdNLzcKrj7eUb
547+
f425UWsDp714RiN53c1G6ek57rfFnotB5NCMyrn4iDgbR8i2sXVHa4xSsedd66o9KmkRgErQnyDdCaAdNLzcKrj7eUb
549548
550549
burn-minotari --payment-id Ups_these_funds_will_be_burned! 100T
551550
552551
pre-mine-spend-get-output-status
553552
554-
pre-mine-spend-session-info --fee-per-gram 2 \
555-
--recipient-info=[1,123,313]:\
556-
f4LR9f6WwwcPiKJjK5ciTkU1ocNhANa3FPw1wkyVUwbuKpgiihawCXy6PFszunUWQ4Te8KVFnyWVHHwsk9x5Cg7ZQiA \
557-
--verify-unspent-outputs --use-pre-mine-input-file
553+
pre-mine-start \
554+
--recipient-info=[1,123,313]:\
555+
f4LR9f6WwwcPiKJjK5ciTkU1ocNhANa3FPw1wkyVUwbuKpgiihawCXy6PFszunUWQ4Te8KVFnyWVHHwsk9x5Cg7ZQiA
558556
559-
pre-mine-spend-party-details --input-file ./step_1_session_info.txt --alias alice \
560-
--recipient-info=[1,123,313]:\
561-
f4LR9f6WwwcPiKJjK5ciTkU1ocNhANa3FPw1wkyVUwbuKpgiihawCXy6PFszunUWQ4Te8KVFnyWVHHwsk9x5Cg7ZQiA \
562-
--pre-mine-file-path ./pre_mine_file.txt
557+
pre-mine-start-party --alias alice --input-file './step_1_session_info.json'
563558
564-
pre-mine-spend-encumber-aggregate-utxo --session-id ee1643655c \
565-
--input-file-names=step_2_for_leader_from_alice.txt --input-file-names=step_2_for_leader_from_bob.txt \
566-
--input-file-names=step_2_for_leader_from_carol.txt
559+
pre-mine-encumber --session-id 20250306070544 --member=alice --member=bob
567560
568-
pre-mine-spend-input-output-sigs --session-id ee1643655c
561+
pre-mine-sigs --session-id 20250306070544
569562
570-
pre-mine-spend-aggregate-transaction --session-id ee1643655c \
571-
--input-file-names=step_4_for_leader_from_alice.txt --input-file-names=step_4_for_leader_from_bob.txt \
572-
--input-file-names=step_4_for_leader_from_carol.txt
563+
pre-mine-spend-tx --session-id 20250306070544 --member=alice --member=bob
573564
574565
coin-split --payment-id Make_many_dust_UTXOs! --fee-per-gram 2 0.001T 499
575566
576567
make-it-rain --duration 100 --transactions-per-second 10 --start-amount 0.009200T --increase-amount 0T \
577-
--start-time now --payment-id Stressing_it_a_bit...!_(from_Feeling-a-bit-Generous) \
578-
f425UWsDp714RiN53c1G6ek57rfFnotB5NCMyrn4iDgbR8i2sXVHa4xSsedd66o9KmkRgErQnyDdCaAdNLzcKrj7eUb
568+
--start-time now --payment-id Stressing_it_a_bit...!_(from_Feeling-a-bit-Generous) \
569+
f425UWsDp714RiN53c1G6ek57rfFnotB5NCMyrn4iDgbR8i2sXVHa4xSsedd66o9KmkRgErQnyDdCaAdNLzcKrj7eUb
579570
580571
export-tx 123456789 --output-file pie.txt
581572
582573
import-tx --input-file pie_this_message.txt
583574
584575
# End of script file
585576
"
586-
.to_string();
577+
.to_string();
587578

588579
let commands = parse_command_file(script).unwrap();
589580

@@ -608,11 +599,11 @@ mod test {
608599
CliCommands::SendMinotari(_) => send_tari = true,
609600
CliCommands::BurnMinotari(_) => burn_tari = true,
610601
CliCommands::PreMineSpendGetOutputStatus => pre_mine_spend_get_output_status = true,
611-
CliCommands::PreMineSpendSessionInfo(_) => pre_mine_spend_session_info = true,
612-
CliCommands::PreMineSpendPartyDetails(_) => pre_mine_spend_party_details = true,
613-
CliCommands::PreMineSpendEncumberAggregateUtxo(_) => pre_mine_spend_encumber_aggregate_utxo = true,
614-
CliCommands::PreMineSpendInputOutputSigs(_) => pre_mine_spend_input_output_sigs = true,
615-
CliCommands::PreMineSpendAggregateTransaction(_) => pre_mine_spend_aggregate_transaction = true,
602+
CliCommands::PreMineStart(_) => pre_mine_spend_session_info = true,
603+
CliCommands::PreMineStartParty(_) => pre_mine_spend_party_details = true,
604+
CliCommands::PreMineEncumber(_) => pre_mine_spend_encumber_aggregate_utxo = true,
605+
CliCommands::PreMineSigs(_) => pre_mine_spend_input_output_sigs = true,
606+
CliCommands::PreMineSpendTx(_) => pre_mine_spend_aggregate_transaction = true,
616607
CliCommands::SendOneSidedToStealthAddress(_) => {},
617608
CliCommands::MakeItRain(_) => make_it_rain = true,
618609
CliCommands::CoinSplit(_) => coin_split = true,

applications/minotari_node/src/grpc_method.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ mod tests {
212212
assert!(config.inner_config.allow_methods.contains(&GrpcMethod::GetConstants));
213213
assert!(!config.inner_config.allow_methods.contains(&GrpcMethod::GetBlocks)); // commented out in the config
214214
assert!(config.inner_config.allow_methods.contains(&GrpcMethod::Identify));
215-
assert!(!config.inner_config.allow_methods.contains(&GrpcMethod::GetShardKey)); // commented out in the config
215+
assert!(!config.inner_config.allow_methods.contains(&GrpcMethod::GetShardKey));
216+
// commented out in the config
216217
}
217218

218219
#[test]

base_layer/common_types/src/tari_address/mod.rs

+64
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,70 @@ impl Default for TariAddress {
378378
}
379379
}
380380

381+
pub mod tari_address_json_bs58 {
382+
use std::fmt;
383+
384+
use serde::{
385+
de::{Error, Visitor},
386+
Deserializer,
387+
Serializer,
388+
};
389+
390+
use crate::tari_address::TariAddress;
391+
392+
/// Serializes a [`TariAddress`] to a base58 string or a binary array.
393+
pub fn serialize<S>(address: &TariAddress, ser: S) -> Result<S::Ok, S::Error>
394+
where S: Serializer {
395+
if ser.is_human_readable() {
396+
ser.serialize_str(&address.to_base58())
397+
} else {
398+
ser.serialize_bytes(&address.to_vec())
399+
}
400+
}
401+
402+
/// Serializes a [`TariAddress`] from a base58 string or a binary array.
403+
pub fn deserialize<'de, D>(de: D) -> Result<TariAddress, D::Error>
404+
where D: Deserializer<'de> {
405+
let visitor = Base58Visitor::default();
406+
if de.is_human_readable() {
407+
de.deserialize_string(visitor)
408+
} else {
409+
de.deserialize_bytes(visitor)
410+
}
411+
}
412+
#[derive(Default)]
413+
struct Base58Visitor {}
414+
415+
impl<'de> Visitor<'de> for Base58Visitor {
416+
type Value = TariAddress;
417+
418+
fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
419+
fmt.write_str("Expecting a binary array or Base58 string")
420+
}
421+
422+
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
423+
where E: Error {
424+
let address = TariAddress::from_base58(v).map_err(|e| E::custom(e.to_string()))?;
425+
Ok(address)
426+
}
427+
428+
fn visit_string<E>(self, v: String) -> Result<Self::Value, E>
429+
where E: Error {
430+
self.visit_str(&v)
431+
}
432+
433+
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
434+
where E: Error {
435+
TariAddress::from_bytes(v).map_err(|e| E::custom(e.to_string()))
436+
}
437+
438+
fn visit_borrowed_bytes<E>(self, v: &'de [u8]) -> Result<Self::Value, E>
439+
where E: Error {
440+
self.visit_bytes(v)
441+
}
442+
}
443+
}
444+
381445
#[cfg(test)]
382446
mod test {
383447
use tari_crypto::keys::SecretKey;

base_layer/mmr/src/sparse_merkle_tree/node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ mod test {
670670
1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
671671
29, 30, 31, 32,
672672
]);
673-
let bin = "0000000100000010000000110000010000000101000001100000011100001000\
673+
let bin = "0000000100000010000000110000010000000101000001100000011100001000\
674674
0000100100001010000010110000110000001101000011100000111100010000\
675675
0001000100010010000100110001010000010101000101100001011100011000\
676676
0001100100011010000110110001110000011101000111100001111100100000";

comms/dht/src/outbound/broadcast.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,9 @@ where S: Service<DhtOutboundMessage, Response = (), Error = PipelineError>
551551
);
552552
let signature =
553553
MessageSignature::new_signed(self.node_identity.secret_key().clone(), &binding_hash).to_proto();
554-
Ok((None, Some(signature.to_encoded_bytes().into()), body.freeze())) // this includes the signer
555-
// public key
554+
Ok((None, Some(signature.to_encoded_bytes().into()), body.freeze()))
555+
// this includes the signer
556+
// public key
556557
} else {
557558
Ok((None, None, body.freeze()))
558559
}

hashing/Cargo.toml

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ license.workspace = true
1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

1313
[dependencies]
14-
tari_crypto = { workspace = true, default-features = false, features = [
15-
"borsh",
16-
] }
17-
borsh = { version = "1.5", default-features = false }
18-
digest = { version = "0.10", default-features = false }
14+
tari_crypto = { workspace = true, features = ["borsh"] }
15+
borsh = { version = "1.5" }
16+
digest = { version = "0.10" }
1917

2018
[dev-dependencies]
2119
blake2 = "0.10"

integration_tests/tests/steps/wallet_steps.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1593,8 +1593,9 @@ async fn wallet_with_tari_connected_to_base_node(
15931593
while reward < amount {
15941594
current_height += 1;
15951595
num_blocks += 1;
1596-
reward += world.consensus_manager.get_block_reward_at(current_height).as_u64() / 1_000_000; // 1 T = 1_000_000
1597-
// uT
1596+
reward += world.consensus_manager.get_block_reward_at(current_height).as_u64() / 1_000_000;
1597+
// 1 T = 1_000_000
1598+
// uT
15981599
}
15991600

16001601
println!("Creating miner...");

0 commit comments

Comments
 (0)