Skip to content

Commit

Permalink
feat: allow user to select specific UTXOs when sending transactions #…
Browse files Browse the repository at this point in the history
…4514 (#4523)

Description
---
#4514

Motivation and Context
---
In send_transaction in base_layer/wallet/src/transaction_service/service.rs, the user cannot specify specific utxos to send.

This logic can be changed to select certain UTXOS

How Has This Been Tested?
---
existing unit tests
  • Loading branch information
agubarev authored Sep 5, 2022
1 parent 31e130a commit 4b40e61
Show file tree
Hide file tree
Showing 16 changed files with 300 additions and 73 deletions.
20 changes: 13 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 29 additions & 4 deletions applications/tari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use tari_wallet::{
connectivity_service::WalletConnectivityInterface,
error::WalletError,
key_manager_service::NextKeyResult,
output_manager_service::handle::OutputManagerHandle,
output_manager_service::{handle::OutputManagerHandle, UtxoSelectionCriteria},
transaction_service::handle::{TransactionEvent, TransactionServiceHandle},
TransactionStage,
WalletConfig,
Expand Down Expand Up @@ -118,6 +118,7 @@ pub async fn send_tari(
.send_transaction(
dest_pubkey,
amount,
UtxoSelectionCriteria::default(),
OutputFeatures::default(),
fee_per_gram * uT,
message,
Expand All @@ -131,11 +132,12 @@ pub async fn init_sha_atomic_swap(
mut wallet_transaction_service: TransactionServiceHandle,
fee_per_gram: u64,
amount: MicroTari,
selection_criteria: UtxoSelectionCriteria,
dest_pubkey: PublicKey,
message: String,
) -> Result<(TxId, PublicKey, TransactionOutput), CommandError> {
let (tx_id, pre_image, output) = wallet_transaction_service
.send_sha_atomic_swap_transaction(dest_pubkey, amount, fee_per_gram * uT, message)
.send_sha_atomic_swap_transaction(dest_pubkey, amount, selection_criteria, fee_per_gram * uT, message)
.await
.map_err(CommandError::TransactionServiceError)?;
Ok((tx_id, pre_image, output))
Expand Down Expand Up @@ -181,13 +183,15 @@ pub async fn send_one_sided(
mut wallet_transaction_service: TransactionServiceHandle,
fee_per_gram: u64,
amount: MicroTari,
selection_criteria: UtxoSelectionCriteria,
dest_pubkey: PublicKey,
message: String,
) -> Result<TxId, CommandError> {
wallet_transaction_service
.send_one_sided_transaction(
dest_pubkey,
amount,
selection_criteria,
OutputFeatures::default(),
fee_per_gram * uT,
message,
Expand All @@ -200,13 +204,15 @@ pub async fn send_one_sided_to_stealth_address(
mut wallet_transaction_service: TransactionServiceHandle,
fee_per_gram: u64,
amount: MicroTari,
selection_criteria: UtxoSelectionCriteria,
dest_pubkey: PublicKey,
message: String,
) -> Result<TxId, CommandError> {
wallet_transaction_service
.send_one_sided_to_stealth_address_transaction(
dest_pubkey,
amount,
selection_criteria,
OutputFeatures::default(),
fee_per_gram * uT,
message,
Expand Down Expand Up @@ -374,10 +380,26 @@ pub async fn make_it_rain(
send_tari(tx_service, fee, amount, pk.clone(), msg.clone()).await
},
MakeItRainTransactionType::OneSided => {
send_one_sided(tx_service, fee, amount, pk.clone(), msg.clone()).await
send_one_sided(
tx_service,
fee,
amount,
UtxoSelectionCriteria::default(),
pk.clone(),
msg.clone(),
)
.await
},
MakeItRainTransactionType::StealthOneSided => {
send_one_sided_to_stealth_address(tx_service, fee, amount, pk.clone(), msg.clone()).await
send_one_sided_to_stealth_address(
tx_service,
fee,
amount,
UtxoSelectionCriteria::default(),
pk.clone(),
msg.clone(),
)
.await
},
};
let submit_time = Instant::now();
Expand Down Expand Up @@ -594,6 +616,7 @@ pub async fn command_runner(
transaction_service.clone(),
config.fee_per_gram,
args.amount,
UtxoSelectionCriteria::default(),
args.destination.into(),
args.message,
)
Expand All @@ -606,6 +629,7 @@ pub async fn command_runner(
transaction_service.clone(),
config.fee_per_gram,
args.amount,
UtxoSelectionCriteria::default(),
args.destination.into(),
args.message,
)
Expand Down Expand Up @@ -722,6 +746,7 @@ pub async fn command_runner(
transaction_service.clone(),
config.fee_per_gram,
args.amount,
UtxoSelectionCriteria::default(),
args.destination.into(),
args.message,
)
Expand Down
13 changes: 11 additions & 2 deletions applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ use tari_core::transactions::{
use tari_utilities::{hex::Hex, ByteArray};
use tari_wallet::{
connectivity_service::{OnlineStatus, WalletConnectivityInterface},
output_manager_service::handle::OutputManagerHandle,
output_manager_service::{handle::OutputManagerHandle, UtxoSelectionCriteria},
transaction_service::{
handle::TransactionServiceHandle,
storage::models::{self, WalletTransaction},
Expand Down Expand Up @@ -301,6 +301,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
.send_sha_atomic_swap_transaction(
address.clone(),
message.amount.into(),
UtxoSelectionCriteria::default(),
message.fee_per_gram.into(),
message.message,
)
Expand Down Expand Up @@ -478,6 +479,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
.send_transaction(
pk,
amount.into(),
UtxoSelectionCriteria::default(),
OutputFeatures::default(),
fee_per_gram.into(),
message,
Expand All @@ -488,6 +490,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
.send_one_sided_transaction(
pk,
amount.into(),
UtxoSelectionCriteria::default(),
OutputFeatures::default(),
fee_per_gram.into(),
message,
Expand All @@ -498,6 +501,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
.send_one_sided_to_stealth_address_transaction(
pk,
amount.into(),
UtxoSelectionCriteria::default(),
OutputFeatures::default(),
fee_per_gram.into(),
message,
Expand Down Expand Up @@ -546,7 +550,12 @@ impl wallet_server::Wallet for WalletGrpcServer {
let mut transaction_service = self.get_transaction_service();
debug!(target: LOG_TARGET, "Trying to burn {} Tari", message.amount);
let response = match transaction_service
.burn_tari(message.amount.into(), message.fee_per_gram.into(), message.message)
.burn_tari(
message.amount.into(),
UtxoSelectionCriteria::default(),
message.fee_per_gram.into(),
message.message,
)
.await
{
Ok(tx_id) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use log::*;
use tari_core::transactions::tari_amount::MicroTari;
use tari_utilities::hex::Hex;
use tari_wallet::output_manager_service::UtxoSelectionCriteria;
use tokio::{runtime::Handle, sync::watch};
use tui::{
backend::Backend,
Expand Down Expand Up @@ -268,6 +269,7 @@ impl SendTab {
match Handle::current().block_on(app_state.send_one_sided_transaction(
self.to_field.clone(),
amount.into(),
UtxoSelectionCriteria::default(),
fee_per_gram,
self.message_field.clone(),
tx,
Expand All @@ -286,6 +288,7 @@ impl SendTab {
app_state.send_one_sided_to_stealth_address_transaction(
self.to_field.clone(),
amount.into(),
UtxoSelectionCriteria::default(),
fee_per_gram,
self.message_field.clone(),
tx,
Expand All @@ -305,6 +308,7 @@ impl SendTab {
match Handle::current().block_on(app_state.send_transaction(
self.to_field.clone(),
amount.into(),
UtxoSelectionCriteria::default(),
fee_per_gram,
self.message_field.clone(),
tx,
Expand Down
8 changes: 7 additions & 1 deletion applications/tari_console_wallet/src/ui/state/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use tari_wallet::{
base_node_service::{handle::BaseNodeEventReceiver, service::BaseNodeState},
connectivity_service::{OnlineStatus, WalletConnectivityHandle, WalletConnectivityInterface},
contacts_service::{handle::ContactsLivenessEvent, storage::database::Contact},
output_manager_service::{handle::OutputManagerEventReceiver, service::Balance},
output_manager_service::{handle::OutputManagerEventReceiver, service::Balance, UtxoSelectionCriteria},
transaction_service::{
handle::TransactionEventReceiver,
storage::models::{CompletedTransaction, TxCancellationReason},
Expand Down Expand Up @@ -265,6 +265,7 @@ impl AppState {
&mut self,
public_key: String,
amount: u64,
selection_criteria: UtxoSelectionCriteria,
fee_per_gram: u64,
message: String,
result_tx: watch::Sender<UiTransactionSendStatus>,
Expand All @@ -282,6 +283,7 @@ impl AppState {
tokio::spawn(send_transaction_task(
public_key,
MicroTari::from(amount),
selection_criteria,
output_features,
message,
fee_per_gram,
Expand All @@ -296,6 +298,7 @@ impl AppState {
&mut self,
public_key: String,
amount: u64,
selection_criteria: UtxoSelectionCriteria,
fee_per_gram: u64,
message: String,
result_tx: watch::Sender<UiTransactionSendStatus>,
Expand All @@ -313,6 +316,7 @@ impl AppState {
tokio::spawn(send_one_sided_transaction_task(
public_key,
MicroTari::from(amount),
selection_criteria,
output_features,
message,
fee_per_gram,
Expand All @@ -327,6 +331,7 @@ impl AppState {
&mut self,
dest_pubkey: String,
amount: u64,
selection_criteria: UtxoSelectionCriteria,
fee_per_gram: u64,
message: String,
result_tx: watch::Sender<UiTransactionSendStatus>,
Expand All @@ -344,6 +349,7 @@ impl AppState {
tokio::spawn(send_one_sided_to_stealth_address_transaction(
dest_pubkey,
MicroTari::from(amount),
selection_criteria,
output_features,
message,
fee_per_gram,
Expand Down
Loading

0 comments on commit 4b40e61

Please sign in to comment.