Skip to content

Commit

Permalink
feat: backup spend for pre-mine (#6431)
Browse files Browse the repository at this point in the history
Description
---
Adds backup pre-mine spend functionality.
  • Loading branch information
SWvheerden committed Jul 29, 2024
1 parent 3377e9c commit 1224b6a
Show file tree
Hide file tree
Showing 7 changed files with 453 additions and 0 deletions.
43 changes: 43 additions & 0 deletions applications/minotari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@ async fn encumber_aggregate_utxo(
.map_err(CommandError::TransactionServiceError)
}

async fn spend_backup_pre_mine_utxo(
mut wallet_transaction_service: TransactionServiceHandle,
fee_per_gram: MicroMinotari,
output_hash: HashOutput,
expected_commitment: PedersenCommitment,
recipient_address: TariAddress,
) -> Result<TxId, CommandError> {
wallet_transaction_service
.spend_backup_pre_mine_utxo(fee_per_gram, output_hash, expected_commitment, recipient_address)
.await
.map_err(CommandError::TransactionServiceError)
}

/// finalises an already encumbered a n-of-m transaction
async fn finalise_aggregate_utxo(
mut wallet_transaction_service: TransactionServiceHandle,
Expand Down Expand Up @@ -794,6 +807,36 @@ pub async fn command_runner(
println!("Send '{}' to parties for step 2", get_file_name(SESSION_INFO, None));
println!();
},
PreMineSpendBackupUtxo(args) => {
let commitment = if let Ok(val) = Commitment::from_hex(&args.commitment) {
val
} else {
eprintln!("\nError: Invalid 'commitment' provided!\n");
continue;
};
let hash = if let Ok(val) = FixedHash::from_hex(&args.output_hash) {
val
} else {
eprintln!("\nError: Invalid 'output_hash' provided!\n");
continue;
};
match spend_backup_pre_mine_utxo(
transaction_service.clone(),
args.fee_per_gram,
hash,
commitment.clone(),
args.recipient_address,
)
.await
{
Ok(tx_id) => {
println!();
println!("Spend utxo: {} with tx_id: {}", commitment.to_hex(), tx_id);
println!();
},
Err(e) => eprintln!("\nError:Spent pre-mine transaction error! {}\n", e),
}
},
PreMineCreatePartyDetails(args) => {
if args.alias.is_empty() || args.alias.contains(" ") {
eprintln!("\nError: Alias cannot contain spaces!\n");
Expand Down
13 changes: 13 additions & 0 deletions applications/minotari_console_wallet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ pub enum CliCommands {
PreMineEncumberAggregateUtxo(PreMineEncumberAggregateUtxoArgs),
PreMineCreateInputOutputSigs(PreMineCreateInputOutputSigArgs),
PreMineSpendAggregateUtxo(PreMineSpendAggregateUtxoArgs),
PreMineSpendBackupUtxo(PreMineSpendBackupUtxoArgs),
SendOneSidedToStealthAddress(SendMinotariArgs),
MakeItRain(MakeItRainArgs),
CoinSplit(CoinSplitArgs),
Expand Down Expand Up @@ -206,6 +207,18 @@ pub struct PreMineSpendAggregateUtxoArgs {
pub input_file_names: Vec<String>,
}

#[derive(Debug, Args, Clone)]
pub struct PreMineSpendBackupUtxoArgs {
#[clap(long)]
pub fee_per_gram: MicroMinotari,
#[clap(long)]
pub commitment: String,
#[clap(long)]
pub output_hash: String,
#[clap(long)]
pub recipient_address: TariAddress,
}

#[derive(Debug, Args, Clone)]
pub struct MakeItRainArgs {
pub destination: TariAddress,
Expand Down
1 change: 1 addition & 0 deletions applications/minotari_console_wallet/src/wallet_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ mod test {
CliCommands::RevalidateWalletDb => {},
CliCommands::RegisterValidatorNode(_) => {},
CliCommands::CreateTlsCerts => {},
CliCommands::PreMineSpendBackupUtxo(_) => {},
}
}
assert!(
Expand Down
44 changes: 44 additions & 0 deletions base_layer/wallet/src/output_manager_service/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ pub enum OutputManagerRequest {
dh_shared_secret_shares: Vec<PublicKey>,
recipient_address: TariAddress,
},
SpendBackupPreMineUtxo {
tx_id: TxId,
fee_per_gram: MicroMinotari,
output_hash: HashOutput,
expected_commitment: PedersenCommitment,
recipient_address: TariAddress,
},
PrepareToSendTransaction {
tx_id: TxId,
amount: MicroMinotari,
Expand Down Expand Up @@ -167,6 +174,18 @@ impl fmt::Display for OutputManagerRequest {
expected_commitment.to_hex(),
output_hash
),
SpendBackupPreMineUtxo {
tx_id,
output_hash,
expected_commitment,
..
} => write!(
f,
"spending backup pre-mine utxo with tx_id: {} and output: ({},{})",
tx_id,
expected_commitment.to_hex(),
output_hash
),
GetRecipientTransaction(_) => write!(f, "GetRecipientTransaction"),
ConfirmPendingTransaction(v) => write!(f, "ConfirmPendingTransaction ({})", v),
PrepareToSendTransaction { message, .. } => write!(f, "PrepareToSendTransaction ({})", message),
Expand Down Expand Up @@ -250,6 +269,7 @@ pub enum OutputManagerResponse {
PublicKey,
),
),
SpendBackupPreMineUtxo((Transaction, MicroMinotari, MicroMinotari)),
OutputConfirmed,
PendingTransactionConfirmed,
PayToSelfTransaction((MicroMinotari, Transaction)),
Expand Down Expand Up @@ -817,6 +837,30 @@ impl OutputManagerHandle {
}
}

pub async fn spend_backup_pre_mine_utxo(
&mut self,
tx_id: TxId,
fee_per_gram: MicroMinotari,
output_hash: HashOutput,
expected_commitment: PedersenCommitment,
recipient_address: TariAddress,
) -> Result<(Transaction, MicroMinotari, MicroMinotari), OutputManagerError> {
match self
.handle
.call(OutputManagerRequest::SpendBackupPreMineUtxo {
tx_id,
fee_per_gram,
output_hash,
expected_commitment,
recipient_address,
})
.await??
{
OutputManagerResponse::SpendBackupPreMineUtxo((transaction, amount, fee)) => Ok((transaction, amount, fee)),
_ => Err(OutputManagerError::UnexpectedApiResponse),
}
}

pub async fn create_pay_to_self_transaction(
&mut self,
tx_id: TxId,
Expand Down
Loading

0 comments on commit 1224b6a

Please sign in to comment.