Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add use transaction output as provided with encumber_aggregate_utxo #6594

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions applications/minotari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use minotari_wallet::{
connectivity_service::WalletConnectivityInterface,
output_manager_service::{
handle::{OutputManagerEvent, OutputManagerHandle},
service::UseOutput,
UtxoSelectionCriteria,
},
transaction_service::{
Expand Down Expand Up @@ -198,7 +199,6 @@ pub async fn burn_tari(
async fn encumber_aggregate_utxo(
mut wallet_transaction_service: TransactionServiceHandle,
fee_per_gram: MicroMinotari,
output_hash: HashOutput,
expected_commitment: PedersenCommitment,
script_input_shares: HashMap<PublicKey, CheckSigSchnorrSignature>,
script_signature_public_nonces: Vec<PublicKey>,
Expand All @@ -207,11 +207,11 @@ async fn encumber_aggregate_utxo(
dh_shared_secret_shares: Vec<PublicKey>,
recipient_address: TariAddress,
original_maturity: u64,
use_output: UseOutput,
) -> Result<(TxId, Transaction, PublicKey, PublicKey, PublicKey), CommandError> {
wallet_transaction_service
.encumber_aggregate_utxo(
fee_per_gram,
output_hash,
expected_commitment,
script_input_shares,
script_signature_public_nonces,
Expand All @@ -220,6 +220,7 @@ async fn encumber_aggregate_utxo(
dh_shared_secret_shares,
recipient_address,
original_maturity,
use_output,
)
.await
.map_err(CommandError::TransactionServiceError)
Expand Down Expand Up @@ -1252,7 +1253,6 @@ pub async fn command_runner(
match encumber_aggregate_utxo(
transaction_service.clone(),
session_info.fee_per_gram,
embedded_output.hash(),
embedded_output.commitment.clone(),
input_shares,
script_signature_public_nonces,
Expand All @@ -1261,6 +1261,11 @@ pub async fn command_runner(
dh_shared_secret_shares,
current_recipient_address,
original_maturity,
if pre_mine_from_file.is_some() {
UseOutput::AsProvided(embedded_output)
} else {
UseOutput::FromBlockchain(embedded_output.hash())
},
)
.await
{
Expand Down
32 changes: 19 additions & 13 deletions base_layer/wallet/src/output_manager_service/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use tower::Service;

use crate::output_manager_service::{
error::OutputManagerError,
service::{Balance, OutputInfoByTxId},
service::{Balance, OutputInfoByTxId, UseOutput},
storage::models::{DbWalletOutput, KnownOneSidedPaymentScript, SpendingPriority},
UtxoSelectionCriteria,
};
Expand All @@ -64,7 +64,6 @@ pub enum OutputManagerRequest {
EncumberAggregateUtxo {
tx_id: TxId,
fee_per_gram: MicroMinotari,
output_hash: HashOutput,
expected_commitment: PedersenCommitment,
script_input_shares: HashMap<PublicKey, CheckSigSchnorrSignature>,
script_signature_public_nonces: Vec<PublicKey>,
Expand All @@ -73,6 +72,7 @@ pub enum OutputManagerRequest {
dh_shared_secret_shares: Vec<PublicKey>,
recipient_address: TariAddress,
original_maturity: u64,
use_output: UseOutput,
},
SpendBackupPreMineUtxo {
tx_id: TxId,
Expand Down Expand Up @@ -172,18 +172,24 @@ impl fmt::Display for OutputManagerRequest {
},
EncumberAggregateUtxo {
tx_id,
output_hash,
expected_commitment,
original_maturity,
use_output,
..
} => write!(
f,
"Encumber aggregate utxo with tx_id: {} and output: ({},{}) with original maturity: {}",
tx_id,
expected_commitment.to_hex(),
output_hash,
original_maturity,
),
} => {
let output_hash = match use_output {
UseOutput::FromBlockchain(hash) => *hash,
UseOutput::AsProvided(output) => output.hash(),
};
write!(
f,
"Encumber aggregate utxo with tx_id: {} and output: ({},{}) with original maturity: {}",
tx_id,
expected_commitment.to_hex(),
output_hash,
original_maturity,
)
},
SpendBackupPreMineUtxo {
tx_id,
output_hash,
Expand Down Expand Up @@ -808,7 +814,6 @@ impl OutputManagerHandle {
&mut self,
tx_id: TxId,
fee_per_gram: MicroMinotari,
output_hash: HashOutput,
expected_commitment: PedersenCommitment,
script_input_shares: HashMap<PublicKey, CheckSigSchnorrSignature>,
script_signature_public_nonces: Vec<PublicKey>,
Expand All @@ -817,6 +822,7 @@ impl OutputManagerHandle {
dh_shared_secret_shares: Vec<PublicKey>,
recipient_address: TariAddress,
original_maturity: u64,
use_output: UseOutput,
) -> Result<
(
Transaction,
Expand All @@ -833,7 +839,6 @@ impl OutputManagerHandle {
.call(OutputManagerRequest::EncumberAggregateUtxo {
tx_id,
fee_per_gram,
output_hash,
expected_commitment,
script_input_shares,
script_signature_public_nonces,
Expand All @@ -842,6 +847,7 @@ impl OutputManagerHandle {
dh_shared_secret_shares,
recipient_address,
original_maturity,
use_output,
})
.await??
{
Expand Down
41 changes: 27 additions & 14 deletions base_layer/wallet/src/output_manager_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ where
OutputManagerRequest::EncumberAggregateUtxo {
tx_id,
fee_per_gram,
output_hash,
expected_commitment,
script_input_shares,
script_signature_public_nonces,
Expand All @@ -258,11 +257,11 @@ where
dh_shared_secret_shares,
recipient_address,
original_maturity,
use_output,
} => self
.encumber_aggregate_utxo(
tx_id,
fee_per_gram,
output_hash,
expected_commitment,
script_input_shares,
script_signature_public_nonces,
Expand All @@ -274,6 +273,7 @@ where
original_maturity,
RangeProofType::BulletProofPlus,
0.into(),
use_output,
)
.await
.map(OutputManagerResponse::EncumberAggregateUtxo),
Expand Down Expand Up @@ -1243,7 +1243,6 @@ where
&mut self,
tx_id: TxId,
fee_per_gram: MicroMinotari,
output_hash: HashOutput,
expected_commitment: PedersenCommitment,
mut script_input_shares: HashMap<PublicKey, CheckSigSchnorrSignature>,
script_signature_public_nonces: Vec<PublicKey>,
Expand All @@ -1255,6 +1254,7 @@ where
original_maturity: u64,
range_proof_type: RangeProofType,
minimum_value_promise: MicroMinotari,
use_output: UseOutput,
hansieodendaal marked this conversation as resolved.
Show resolved Hide resolved
) -> Result<
(
Transaction,
Expand All @@ -1267,17 +1267,20 @@ where
OutputManagerError,
> {
trace!(target: LOG_TARGET, "encumber_aggregate_utxo: start");
// Fetch the output from the blockchain
let output = self
.fetch_unspent_outputs_from_node(vec![output_hash])
.await?
.pop()
.ok_or_else(|| {
OutputManagerError::ServiceError(format!(
"Output with hash {} not found in blockchain (TxId: {})",
output_hash, tx_id
))
})?;
// Fetch the output from the blockchain or use provided
let output = match use_output {
UseOutput::FromBlockchain(output_hash) => self
.fetch_unspent_outputs_from_node(vec![output_hash])
.await?
.pop()
.ok_or_else(|| {
OutputManagerError::ServiceError(format!(
"Output with hash {} not found in blockchain (TxId: {})",
output_hash, tx_id
))
})?,
UseOutput::AsProvided(val) => val,
};
if output.commitment != expected_commitment {
return Err(OutputManagerError::ServiceError(format!(
"Output commitment does not match expected commitment (TxId: {})",
Expand Down Expand Up @@ -3299,6 +3302,16 @@ where
}
}

/// Use the provided output when encumbering an aggregate UTXO or not, for use with
/// `fn encumber_aggregate_utxo`
#[derive(Clone)]
pub enum UseOutput {
/// The transaction output will be fetched from the blockchain
FromBlockchain(HashOutput),
/// The transaction output must be provided
AsProvided(TransactionOutput),
}

fn get_multi_sig_script_components(
script: &TariScript,
tx_id: TxId,
Expand Down
88 changes: 47 additions & 41 deletions base_layer/wallet/src/transaction_service/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use tokio::sync::broadcast;
use tower::Service;

use crate::{
output_manager_service::UtxoSelectionCriteria,
output_manager_service::{service::UseOutput, UtxoSelectionCriteria},
transaction_service::{
error::TransactionServiceError,
storage::models::{
Expand Down Expand Up @@ -104,7 +104,6 @@ pub enum TransactionServiceRequest {
},
EncumberAggregateUtxo {
fee_per_gram: MicroMinotari,
output_hash: HashOutput,
expected_commitment: PedersenCommitment,
script_input_shares: HashMap<PublicKey, CheckSigSchnorrSignature>,
script_signature_public_nonces: Vec<PublicKey>,
Expand All @@ -113,6 +112,7 @@ pub enum TransactionServiceRequest {
dh_shared_secret_shares: Vec<PublicKey>,
recipient_address: TariAddress,
original_maturity: u64,
use_output: UseOutput,
},
SpendBackupPreMineUtxo {
fee_per_gram: MicroMinotari,
Expand Down Expand Up @@ -246,7 +246,6 @@ impl fmt::Display for TransactionServiceRequest {
)),
Self::EncumberAggregateUtxo {
fee_per_gram,
output_hash,
expected_commitment,
script_input_shares,
script_signature_public_nonces,
Expand All @@ -255,43 +254,50 @@ impl fmt::Display for TransactionServiceRequest {
dh_shared_secret_shares,
recipient_address,
original_maturity,
use_output,
..
} => f.write_str(&format!(
"Creating encumber n-of-m utxo with: fee_per_gram = {}, output_hash = {}, commitment = {}, \
script_input_shares = {:?}, script_signature_shares = {:?}, sender_offset_public_key_shares = {:?}, \
metadata_ephemeral_public_key_shares = {:?}, dh_shared_secret_shares = {:?}, recipient_address = {}, \
original_maturity: {}",
fee_per_gram,
output_hash,
expected_commitment.to_hex(),
script_input_shares
.iter()
.map(|v| format!(
"(public_key: {}, sig: {}, nonce: {})",
v.0.to_hex(),
v.1.get_signature().to_hex(),
v.1.get_public_nonce().to_hex()
))
.collect::<Vec<String>>(),
script_signature_public_nonces
.iter()
.map(|v| format!("(public nonce: {})", v.to_hex(),))
.collect::<Vec<String>>(),
sender_offset_public_key_shares
.iter()
.map(|v| v.to_hex())
.collect::<Vec<String>>(),
metadata_ephemeral_public_key_shares
.iter()
.map(|v| v.to_hex())
.collect::<Vec<String>>(),
dh_shared_secret_shares
.iter()
.map(|v| v.to_hex())
.collect::<Vec<String>>(),
recipient_address,
original_maturity,
)),
} => {
let output_hash = match use_output {
UseOutput::FromBlockchain(hash) => *hash,
UseOutput::AsProvided(output) => output.hash(),
};
f.write_str(&format!(
"Creating encumber n-of-m utxo with: fee_per_gram = {}, output_hash = {}, commitment = {}, \
script_input_shares = {:?}, script_signature_shares = {:?}, sender_offset_public_key_shares = \
{:?}, metadata_ephemeral_public_key_shares = {:?}, dh_shared_secret_shares = {:?}, \
recipient_address = {}, original_maturity: {}",
fee_per_gram,
output_hash,
expected_commitment.to_hex(),
script_input_shares
.iter()
.map(|v| format!(
"(public_key: {}, sig: {}, nonce: {})",
v.0.to_hex(),
v.1.get_signature().to_hex(),
v.1.get_public_nonce().to_hex()
))
.collect::<Vec<String>>(),
script_signature_public_nonces
.iter()
.map(|v| format!("(public nonce: {})", v.to_hex(),))
.collect::<Vec<String>>(),
sender_offset_public_key_shares
.iter()
.map(|v| v.to_hex())
.collect::<Vec<String>>(),
metadata_ephemeral_public_key_shares
.iter()
.map(|v| v.to_hex())
.collect::<Vec<String>>(),
dh_shared_secret_shares
.iter()
.map(|v| v.to_hex())
.collect::<Vec<String>>(),
recipient_address,
original_maturity,
))
},
Self::FetchUnspentOutputs { output_hashes } => {
write!(
f,
Expand Down Expand Up @@ -747,7 +753,6 @@ impl TransactionServiceHandle {
pub async fn encumber_aggregate_utxo(
&mut self,
fee_per_gram: MicroMinotari,
output_hash: HashOutput,
expected_commitment: PedersenCommitment,
script_input_shares: HashMap<PublicKey, CheckSigSchnorrSignature>,
script_signature_public_nonces: Vec<PublicKey>,
Expand All @@ -756,12 +761,12 @@ impl TransactionServiceHandle {
dh_shared_secret_shares: Vec<PublicKey>,
recipient_address: TariAddress,
original_maturity: u64,
use_output: UseOutput,
) -> Result<(TxId, Transaction, PublicKey, PublicKey, PublicKey), TransactionServiceError> {
match self
.handle
.call(TransactionServiceRequest::EncumberAggregateUtxo {
fee_per_gram,
output_hash,
expected_commitment,
script_input_shares,
script_signature_public_nonces,
Expand All @@ -770,6 +775,7 @@ impl TransactionServiceHandle {
dh_shared_secret_shares,
recipient_address,
original_maturity,
use_output,
})
.await??
{
Expand Down
Loading
Loading