Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Dec 9, 2024
1 parent 8b504a8 commit c8b0f48
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 168 deletions.
67 changes: 22 additions & 45 deletions applications/minotari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ pub(crate) const SPEND_STEP_2_SELF: &str = "step_2_for_self";
pub(crate) const SPEND_STEP_3_SELF: &str = "step_3_for_self";
pub(crate) const SPEND_STEP_3_PARTIES: &str = "step_3_for_parties";
pub(crate) const SPEND_STEP_4_LEADER: &str = "step_4_for_leader_from_";
pub(crate) const NO_PAYMENT_ID: &str = "<No payment id>";

#[derive(Debug)]
pub struct SentTransaction {}
Expand Down Expand Up @@ -323,14 +322,13 @@ pub async fn claim_htlc_refund(
mut transaction_service: TransactionServiceHandle,
output_hash: FixedHash,
fee_per_gram: MicroMinotari,
message: String,
payment_id: PaymentId,
) -> Result<TxId, CommandError> {
let (tx_id, _fee, amount, tx) = output_service
.create_htlc_refund_transaction(output_hash, fee_per_gram)
.await?;
transaction_service
.submit_transaction(tx_id, tx, amount, message, payment_id)
.submit_transaction(tx_id, tx, amount, payment_id)
.await?;
Ok(tx_id)
}
Expand All @@ -342,7 +340,7 @@ pub async fn register_validator_node(
validator_node_signature: Signature,
selection_criteria: UtxoSelectionCriteria,
fee_per_gram: MicroMinotari,
message: String,
payment_id: PaymentId,
) -> Result<TxId, CommandError> {
wallet_transaction_service
.register_validator_node(
Expand All @@ -351,7 +349,7 @@ pub async fn register_validator_node(
validator_node_signature,
selection_criteria,
fee_per_gram,
message,
payment_id,
)
.await
.map_err(CommandError::TransactionServiceError)
Expand All @@ -363,7 +361,6 @@ pub async fn send_one_sided_to_stealth_address(
amount: MicroMinotari,
selection_criteria: UtxoSelectionCriteria,
dest_address: TariAddress,
message: String,
payment_id: PaymentId,
) -> Result<TxId, CommandError> {
wallet_transaction_service
Expand All @@ -373,7 +370,6 @@ pub async fn send_one_sided_to_stealth_address(
selection_criteria,
OutputFeatures::default(),
fee_per_gram * uT,
message,
payment_id,
)
.await
Expand All @@ -384,7 +380,6 @@ pub async fn coin_split(
amount_per_split: MicroMinotari,
num_splits: usize,
fee_per_gram: MicroMinotari,
message: String,
payment_id: PaymentId,
output_service: &mut OutputManagerHandle,
transaction_service: &mut TransactionServiceHandle,
Expand All @@ -393,7 +388,7 @@ pub async fn coin_split(
.create_coin_split(vec![], amount_per_split, num_splits, fee_per_gram)
.await?;
transaction_service
.submit_transaction(tx_id, tx, amount, message, payment_id)
.submit_transaction(tx_id, tx, amount, payment_id)
.await?;

Ok(tx_id)
Expand Down Expand Up @@ -472,7 +467,7 @@ pub async fn make_it_rain(
start_time: DateTime<Utc>,
destination: TariAddress,
transaction_type: MakeItRainTransactionType,
message: String,
payment_id: PaymentId,
) -> Result<(), CommandError> {
// Limit the transactions per second to a reasonable range
// Notes:
Expand All @@ -487,8 +482,8 @@ pub async fn make_it_rain(
let now = Utc::now();
let delay_ms = if start_time > now {
println!(
"`make-it-rain` scheduled to start at {}: msg \"{}\"",
start_time, message
"`make-it-rain` scheduled to start at {}: payment_id \"{}\"",
start_time, payment_id.compact_display()
);
(start_time - now).num_milliseconds() as u64
} else {
Expand All @@ -512,7 +507,7 @@ pub async fn make_it_rain(
}
println!(
"\n`make-it-rain` starting {} {} transactions \"{}\"\n",
num_txs, transaction_type, message
num_txs, transaction_type, payment_id.compact_display()
);
let (sender, mut receiver) = mpsc::channel(num_txs);
{
Expand Down Expand Up @@ -550,13 +545,12 @@ pub async fn make_it_rain(
let sender_clone = sender.clone();
let fee = fee_per_gram;
let address = destination.clone();
let msg = message.clone();
tokio::task::spawn(async move {
let spawn_start = Instant::now();
// Send transaction
let tx_id = match transaction_type {
MakeItRainTransactionType::Interactive => {
send_tari(tx_service, fee, amount, address.clone(), msg.clone(), PaymentId::Empty).await
send_tari(tx_service, fee, amount, address.clone(), payment_id.clone()).await
},
MakeItRainTransactionType::StealthOneSided => {
send_one_sided_to_stealth_address(
Expand All @@ -565,13 +559,12 @@ pub async fn make_it_rain(
amount,
UtxoSelectionCriteria::default(),
address.clone(),
msg.clone(),
PaymentId::Empty,
payment_id.clone(),
)
.await
},
MakeItRainTransactionType::BurnTari => {
burn_tari(tx_service, fee, amount, msg.clone(), PaymentId::Empty)
burn_tari(tx_service, fee, amount, payment_id.clone())
.await
.map(|(tx_id, _)| tx_id)
},
Expand Down Expand Up @@ -797,8 +790,7 @@ pub async fn command_runner(
transaction_service.clone(),
config.fee_per_gram,
args.amount,
args.message,
get_payment_id(&args.payment_id),
PaymentId::Open(args.payment_id.as_bytes().to_vec()),
)
.await
{
Expand Down Expand Up @@ -984,7 +976,7 @@ pub async fn command_runner(
output_hash,
commitment.clone(),
args.recipient_address,
get_payment_id(&args.payment_id),
PaymentId::Open(args.payment_id.as_bytes().to_vec()),
)
.await
{
Expand Down Expand Up @@ -1350,7 +1342,7 @@ pub async fn command_runner(
} else {
UseOutput::FromBlockchain(embedded_output.hash())
},
get_payment_id(&args.payment_id),
PaymentId::Open(args.payment_id.as_bytes().to_vec()),
)
.await
{
Expand Down Expand Up @@ -1993,8 +1985,7 @@ pub async fn command_runner(
config.fee_per_gram,
args.amount,
args.destination,
args.message,
get_payment_id(&args.payment_id),
PaymentId::Open(args.payment_id.as_bytes().to_vec()),
)
.await
{
Expand All @@ -2012,8 +2003,7 @@ pub async fn command_runner(
args.amount,
UtxoSelectionCriteria::default(),
args.destination,
args.message,
get_payment_id(&args.payment_id),
PaymentId::Open(args.payment_id.as_bytes().to_vec()),
)
.await
{
Expand All @@ -2039,7 +2029,7 @@ pub async fn command_runner(
args.start_time.unwrap_or_else(Utc::now),
args.destination,
transaction_type,
args.message,
PaymentId::Open(args.payment_id.as_bytes().to_vec()),
)
.await
{
Expand All @@ -2051,8 +2041,7 @@ pub async fn command_runner(
args.amount_per_split,
args.num_splits,
args.fee_per_gram,
args.message,
get_payment_id(&args.payment_id),
PaymentId::Open(args.payment_id.as_bytes().to_vec()),
&mut output_service,
&mut transaction_service.clone(),
)
Expand Down Expand Up @@ -2252,7 +2241,7 @@ pub async fn command_runner(
args.amount,
UtxoSelectionCriteria::default(),
args.destination,
args.message,
PaymentId::Open(args.payment_id.as_bytes().to_vec()),
)
.await
{
Expand All @@ -2275,8 +2264,7 @@ pub async fn command_runner(
hash,
args.pre_image.into(),
config.fee_per_gram.into(),
args.message,
get_payment_id(&args.payment_id),
PaymentId::Open(args.payment_id.as_bytes().to_vec()),
)
.await
{
Expand All @@ -2296,8 +2284,7 @@ pub async fn command_runner(
transaction_service.clone(),
hash,
config.fee_per_gram.into(),
args.message,
get_payment_id(&args.payment_id),
PaymentId::Open(args.payment_id.as_bytes().to_vec()),
)
.await
{
Expand Down Expand Up @@ -2338,7 +2325,7 @@ pub async fn command_runner(
),
UtxoSelectionCriteria::default(),
config.fee_per_gram * uT,
args.message,
PaymentId::Open(args.payment_id.as_bytes().to_vec()),
)
.await?;
debug!(target: LOG_TARGET, "Registering VN tx_id {}", tx_id);
Expand Down Expand Up @@ -2713,16 +2700,6 @@ pub async fn command_runner(
Ok(unban_peer_manager_peers)
}

fn get_payment_id(payment_id: &str) -> PaymentId {
match payment_id {
NO_PAYMENT_ID => PaymentId::Empty,
_ => {
let payment_id_arg = payment_id.as_bytes().to_vec();
PaymentId::Open(payment_id_arg)
},
}
}

async fn temp_ban_peers(wallet: &WalletSqlite, peer_list: &mut Vec<Peer>) {
for peer in peer_list {
let _unused = wallet
Expand Down
20 changes: 2 additions & 18 deletions applications/minotari_console_wallet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ use tari_utilities::{
};
use thiserror::Error;

use crate::automation::commands::NO_PAYMENT_ID;

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
#[clap(propagate_version = true)]
Expand Down Expand Up @@ -178,17 +176,13 @@ pub struct SendMinotariArgs {
pub amount: MicroMinotari,
pub destination: TariAddress,
#[clap(short, long, default_value = "<No message>")]
pub message: String,
#[clap(short, long, default_value = NO_PAYMENT_ID)]
pub payment_id: String,
}

#[derive(Debug, Args, Clone)]
pub struct BurnMinotariArgs {
pub amount: MicroMinotari,
#[clap(short, long, default_value = "Burn funds")]
pub message: String,
#[clap(short, long, default_value = NO_PAYMENT_ID)]
pub payment_id: String,
}

Expand Down Expand Up @@ -272,8 +266,6 @@ pub struct PreMineSpendEncumberAggregateUtxoArgs {
#[clap(long)]
pub pre_mine_file_path: Option<PathBuf>,
#[clap(short, long, default_value = "Spend pre-mine encumber aggregate UTXO")]
pub message: String,
#[clap(short, long, default_value = NO_PAYMENT_ID)]
pub payment_id: String,
}

Expand Down Expand Up @@ -304,8 +296,6 @@ pub struct PreMineSpendBackupUtxoArgs {
#[clap(long)]
pub pre_mine_file_path: Option<PathBuf>,
#[clap(short, long, default_value = "Spend pre-mine backup UTXO")]
pub message: String,
#[clap(short, long, default_value = NO_PAYMENT_ID)]
pub payment_id: String,
}

Expand All @@ -327,7 +317,7 @@ pub struct MakeItRainArgs {
#[clap(short, long)]
pub burn_tari: bool,
#[clap(short, long, default_value = "Make it rain")]
pub message: String,
pub payment_id: String,
}

impl MakeItRainArgs {
Expand Down Expand Up @@ -375,8 +365,6 @@ pub struct CoinSplitArgs {
#[clap(short, long, default_value = "1")]
pub fee_per_gram: MicroMinotari,
#[clap(short, long, default_value = "Coin split")]
pub message: String,
#[clap(short, long, default_value = NO_PAYMENT_ID)]
pub payment_id: String,
}

Expand Down Expand Up @@ -446,8 +434,6 @@ pub struct FinaliseShaAtomicSwapArgs {
#[clap(short, long)]
pub pre_image: UniPublicKey,
#[clap(short, long, default_value = "Claimed HTLC atomic swap")]
pub message: String,
#[clap(short, long, default_value = NO_PAYMENT_ID)]
pub payment_id: String,
}

Expand All @@ -460,8 +446,6 @@ pub struct ClaimShaAtomicSwapRefundArgs {
#[clap(short, long, parse(try_from_str = parse_hex), required = true)]
pub output_hash: Vec<Vec<u8>>,
#[clap(short, long, default_value = "Claimed HTLC atomic swap refund")]
pub message: String,
#[clap(short, long, default_value = NO_PAYMENT_ID)]
pub payment_id: String,
}

Expand All @@ -472,7 +456,7 @@ pub struct RegisterValidatorNodeArgs {
pub validator_node_public_nonce: UniPublicKey,
pub validator_node_signature: Vec<u8>,
#[clap(short, long, default_value = "Registering VN")]
pub message: String,
pub payment_id: String,
}

#[derive(Debug, Args, Clone)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2126,7 +2126,7 @@ impl TryFrom<UnconfirmedTransactionInfoSql> for UnconfirmedTransactionInfo {
PrivateKey::from_vec(&i.transaction_signature_key)?,
),
status: TransactionStatus::try_from(i.status)?,
payment_id: i.payment_id,
payment_id: PaymentId::from_bytes(&i.payment_id.unwrap_or_default()),
})
}
}
Expand All @@ -2137,7 +2137,7 @@ pub struct UnconfirmedTransactionInfoSql {
pub status: i32,
pub transaction_signature_nonce: Vec<u8>,
pub transaction_signature_key: Vec<u8>,
pub payment_id: PaymentId,
pub payment_id: Option<Vec<u8>>,
}

impl UnconfirmedTransactionInfoSql {
Expand Down
6 changes: 4 additions & 2 deletions base_layer/wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ where
encrypted_data: EncryptedData,
minimum_value_promise: MicroMinotari,
range_proof: Option<RangeProof>,
payment_id: PaymentId,
) -> Result<TxId, WalletError> {
let unblinded_output = UnblindedOutput::new_current_version(
amount,
Expand All @@ -580,7 +581,7 @@ where
minimum_value_promise,
range_proof,
);
self.import_unblinded_output_as_non_rewindable(unblinded_output, source_address)
self.import_unblinded_output_as_non_rewindable(unblinded_output, source_address, payment_id)
.await
}

Expand All @@ -591,6 +592,7 @@ where
&mut self,
unblinded_output: UnblindedOutput,
source_address: TariAddress,
payment_id: PaymentId,
) -> Result<TxId, WalletError> {
let value = unblinded_output.value;
let wallet_output = unblinded_output
Expand All @@ -606,7 +608,7 @@ where
None,
None,
wallet_output.to_transaction_output(&self.key_manager_service).await?,
PaymentId::Empty,
payment_id,
)
.await?;
// As non-rewindable
Expand Down
Loading

0 comments on commit c8b0f48

Please sign in to comment.