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: remove ablity to send 1-sided tx #6367

Merged
merged 4 commits into from
Jun 20, 2024
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
55 changes: 0 additions & 55 deletions applications/minotari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,30 +224,6 @@ pub async fn register_validator_node(
.map_err(CommandError::TransactionServiceError)
}

/// Send a one-sided transaction to a recipient
pub async fn send_one_sided(
mut wallet_transaction_service: TransactionServiceHandle,
fee_per_gram: u64,
amount: MicroMinotari,
selection_criteria: UtxoSelectionCriteria,
dest_address: TariAddress,
message: String,
payment_id: PaymentId,
) -> Result<TxId, CommandError> {
wallet_transaction_service
.send_one_sided_transaction(
dest_address,
amount,
selection_criteria,
OutputFeatures::default(),
fee_per_gram * uT,
message,
payment_id,
)
.await
.map_err(CommandError::TransactionServiceError)
}

pub async fn send_one_sided_to_stealth_address(
mut wallet_transaction_service: TransactionServiceHandle,
fee_per_gram: u64,
Expand Down Expand Up @@ -448,18 +424,6 @@ pub async fn make_it_rain(
MakeItRainTransactionType::Interactive => {
send_tari(tx_service, fee, amount, address.clone(), msg.clone()).await
},
MakeItRainTransactionType::OneSided => {
send_one_sided(
tx_service,
fee,
amount,
UtxoSelectionCriteria::default(),
address.clone(),
msg.clone(),
PaymentId::Empty,
)
.await
},
MakeItRainTransactionType::StealthOneSided => {
send_one_sided_to_stealth_address(
tx_service,
Expand Down Expand Up @@ -723,25 +687,6 @@ pub async fn command_runner(
Err(e) => eprintln!("SendMinotari error! {}", e),
}
},
SendOneSided(args) => {
match send_one_sided(
transaction_service.clone(),
config.fee_per_gram,
args.amount,
UtxoSelectionCriteria::default(),
args.destination,
args.message,
PaymentId::Empty,
)
.await
{
Ok(tx_id) => {
debug!(target: LOG_TARGET, "send-one-sided concluded with tx_id {}", tx_id);
tx_ids.push(tx_id);
},
Err(e) => eprintln!("SendOneSided error! {}", e),
}
},
SendOneSidedToStealthAddress(args) => {
match send_one_sided_to_stealth_address(
transaction_service.clone(),
Expand Down
4 changes: 0 additions & 4 deletions applications/minotari_console_wallet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ pub enum CliCommands {
GetBalance,
SendMinotari(SendMinotariArgs),
BurnMinotari(BurnMinotariArgs),
SendOneSided(SendMinotariArgs),
SendOneSidedToStealthAddress(SendMinotariArgs),
MakeItRain(MakeItRainArgs),
CoinSplit(CoinSplitArgs),
Expand Down Expand Up @@ -185,8 +184,6 @@ impl MakeItRainArgs {
pub fn transaction_type(&self) -> MakeItRainTransactionType {
if self.stealth {
MakeItRainTransactionType::StealthOneSided
} else if self.one_sided {
MakeItRainTransactionType::OneSided
} else if self.burn_tari {
MakeItRainTransactionType::BurnTari
} else {
Expand All @@ -198,7 +195,6 @@ impl MakeItRainArgs {
#[derive(Debug, Clone, Copy)]
pub enum MakeItRainTransactionType {
Interactive,
OneSided,
StealthOneSided,
BurnTari,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pub struct WalletGrpcServer {
}

impl WalletGrpcServer {
#[allow(dead_code)]
pub fn new(wallet: WalletSqlite) -> Result<Self, ConsensusBuilderError> {
let rules = ConsensusManager::builder(wallet.network.as_network()).build()?;
Ok(Self { wallet, rules })
Expand Down
48 changes: 5 additions & 43 deletions applications/minotari_console_wallet/src/ui/components/send_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ impl SendTab {
Span::styled("S", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to send a normal transaction, "),
Span::styled("O", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to send a one-sided transaction, "),
Span::styled("X", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to send a one-sided transaction to a stealth address."),
Span::raw(" to send a one-sided transaction"),
]),
])
.wrap(Wrap { trim: false })
Expand Down Expand Up @@ -260,9 +258,7 @@ impl SendTab {
} else if 'y' == c {
match self.confirmation_dialog {
None => (),
Some(ConfirmationDialogType::Normal) |
Some(ConfirmationDialogType::OneSided) |
Some(ConfirmationDialogType::StealthAddress) => {
Some(ConfirmationDialogType::Normal) | Some(ConfirmationDialogType::StealthAddress) => {
if 'y' == c {
let amount = if let Ok(v) = self.amount_field.parse::<MicroMinotari>() {
v
Expand All @@ -287,25 +283,6 @@ impl SendTab {

let mut reset_fields = false;
match self.confirmation_dialog {
Some(ConfirmationDialogType::OneSided) => {
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(),
self.payment_id_field.clone(),
tx,
)) {
Err(e) => {
self.error_message = Some(format!(
"Error sending one-sided transaction:\n{}\nPress Enter to continue.",
e
))
},
Ok(_) => reset_fields = true,
}
},
Some(ConfirmationDialogType::StealthAddress) => {
match Handle::current().block_on(
app_state.send_one_sided_to_stealth_address_transaction(
Expand Down Expand Up @@ -534,24 +511,12 @@ impl<B: Backend> Component<B> for SendTab {
9,
);
},
Some(ConfirmationDialogType::OneSided) => {
draw_dialog(
f,
area,
"Confirm Sending Transaction".to_string(),
"Are you sure you want to send this one-sided transaction?\n(Y)es / (N)o".to_string(),
Color::Red,
120,
9,
);
},
Some(ConfirmationDialogType::StealthAddress) => {
draw_dialog(
f,
area,
"Confirm Sending Transaction".to_string(),
"Are you sure you want to send this one-sided transaction to a stealth address?\n(Y)es / (N)o"
.to_string(),
"Are you sure you want to send this one-sided transaction?\n(Y)es / (N)o".to_string(),
Color::Red,
120,
9,
Expand Down Expand Up @@ -608,8 +573,7 @@ impl<B: Backend> Component<B> for SendTab {
},
'f' => self.send_input_mode = SendInputMode::Fee,
'm' => self.send_input_mode = SendInputMode::Message,
'p' => self.send_input_mode = SendInputMode::PaymentId,
's' | 'o' | 'x' => {
's' | 'o' => {
if self.to_field.is_empty() {
self.error_message =
Some("Destination Tari Address/Emoji ID\nPress Enter to continue.".to_string());
Expand All @@ -626,8 +590,7 @@ impl<B: Backend> Component<B> for SendTab {
}

self.confirmation_dialog = Some(match c {
'o' => ConfirmationDialogType::OneSided,
'x' => ConfirmationDialogType::StealthAddress,
'o' => ConfirmationDialogType::StealthAddress,
_ => ConfirmationDialogType::Normal,
});
},
Expand Down Expand Up @@ -702,6 +665,5 @@ pub enum SendInputMode {
#[derive(PartialEq, Debug)]
pub enum ConfirmationDialogType {
Normal,
OneSided,
StealthAddress,
}
44 changes: 1 addition & 43 deletions applications/minotari_console_wallet/src/ui/state/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ use crate::{
ui::{
state::{
debouncer::BalanceEnquiryDebouncer,
tasks::{
send_burn_transaction_task,
send_one_sided_transaction_task,
send_register_template_transaction_task,
send_transaction_task,
},
tasks::{send_burn_transaction_task, send_register_template_transaction_task, send_transaction_task},
wallet_event_monitor::WalletEventMonitor,
},
ui_burnt_proof::UiBurntProof,
Expand Down Expand Up @@ -330,43 +325,6 @@ impl AppState {
Ok(())
}

pub async fn send_one_sided_transaction(
&mut self,
address: String,
amount: u64,
selection_criteria: UtxoSelectionCriteria,
fee_per_gram: u64,
message: String,
payment_id: String,
result_tx: watch::Sender<UiTransactionSendStatus>,
) -> Result<(), UiError> {
let inner = self.inner.write().await;
let address = match TariAddress::from_emoji_string(&address) {
Ok(address) => address,
Err(_) => TariAddress::from_bytes(&from_hex(&address).map_err(|_| UiError::PublicKeyParseError)?)
.map_err(|_| UiError::PublicKeyParseError)?,
};
let output_features = OutputFeatures { ..Default::default() };
let payment_id_bytes: Vec<u8> = payment_id.as_bytes().to_vec();
let payment_id = PaymentId::Open(payment_id_bytes);

let fee_per_gram = fee_per_gram * uT;
let tx_service_handle = inner.wallet.transaction_service.clone();
tokio::spawn(send_one_sided_transaction_task(
address,
MicroMinotari::from(amount),
selection_criteria,
output_features,
message,
fee_per_gram,
payment_id,
tx_service_handle,
result_tx,
));

Ok(())
}

pub async fn send_one_sided_to_stealth_address_transaction(
&mut self,
address: String,
Expand Down
56 changes: 0 additions & 56 deletions applications/minotari_console_wallet/src/ui/state/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,62 +131,6 @@ pub async fn send_transaction_task(
}
}

pub async fn send_one_sided_transaction_task(
address: TariAddress,
amount: MicroMinotari,
selection_criteria: UtxoSelectionCriteria,
output_features: OutputFeatures,
message: String,
fee_per_gram: MicroMinotari,
payment_id: PaymentId,
mut transaction_service_handle: TransactionServiceHandle,
result_tx: watch::Sender<UiTransactionSendStatus>,
) {
let _result = result_tx.send(UiTransactionSendStatus::Initiated);
let mut event_stream = transaction_service_handle.get_event_stream();
match transaction_service_handle
.send_one_sided_transaction(
address,
amount,
selection_criteria,
output_features,
fee_per_gram,
message,
payment_id,
)
.await
{
Err(e) => {
let _result = result_tx.send(UiTransactionSendStatus::Error(UiError::from(e).to_string()));
},
Ok(our_tx_id) => {
loop {
match event_stream.recv().await {
Ok(event) => {
if let TransactionEvent::TransactionCompletedImmediately(tx_id) = &*event {
if our_tx_id == *tx_id {
let _result = result_tx.send(UiTransactionSendStatus::TransactionComplete);
return;
}
}
},
Err(e @ broadcast::error::RecvError::Lagged(_)) => {
log::warn!(target: LOG_TARGET, "Error reading from event broadcast channel {:?}", e);
continue;
},
Err(broadcast::error::RecvError::Closed) => {
break;
},
}
}

let _result = result_tx.send(UiTransactionSendStatus::Error(
"One-sided transaction could not be sent".to_string(),
));
},
}
}

pub async fn send_one_sided_to_stealth_address_transaction(
address: TariAddress,
amount: MicroMinotari,
Expand Down
1 change: 0 additions & 1 deletion applications/minotari_console_wallet/src/wallet_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,6 @@ mod test {
CliCommands::GetBalance => get_balance = true,
CliCommands::SendMinotari(_) => send_tari = true,
CliCommands::BurnMinotari(_) => burn_tari = true,
CliCommands::SendOneSided(_) => {},
CliCommands::SendOneSidedToStealthAddress(_) => {},
CliCommands::MakeItRain(_) => make_it_rain = true,
CliCommands::CoinSplit(_) => coin_split = true,
Expand Down
1 change: 1 addition & 0 deletions base_layer/tari_mining_helper_ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub enum InterfaceError {
/// This struct is meant to hold an error for use by Miningcore. The error has an integer code and string
/// message
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct MiningHelperError {
pub code: i32,
pub message: String,
Expand Down
2 changes: 1 addition & 1 deletion base_layer/wallet_ffi/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -3149,7 +3149,7 @@ unsigned long long wallet_send_transaction(struct TariWallet *wallet,
unsigned long long fee_per_gram,
const char *message,
bool one_sided,
unsigned long long payment_id,
const char *payment_id_string,
int *error_out);

/**
Expand Down
16 changes: 0 additions & 16 deletions integration_tests/tests/features/WalletCli.feature
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,6 @@ Feature: Wallet CLI
When I mine 5 blocks on BASE
Then all nodes are at height 20
Then I get balance of wallet WALLET is at least 20000000000 uT via command line
#
@long-running
Scenario: As a user I want to send one-sided via command line
Given I have a seed node SEED
When I have a base node BASE connected to seed SEED
When I have wallet SENDER connected to base node BASE
When I have wallet RECEIVER connected to base node BASE
When I have mining node MINE connected to base node BASE and wallet SENDER
When mining node MINE mines 5 blocks
Then I wait for wallet SENDER to have at least 1100000 uT
When I wait 30 seconds
Then I stop wallet SENDER
Then I send one-sided 1000000 uT from SENDER to RECEIVER via command line
Then wallet SENDER has at least 1 transactions that are all TRANSACTION_STATUS_BROADCAST and not cancelled
When mining node MINE mines 5 blocks
Then I wait for wallet RECEIVER to have at least 1000000 uT

@long-running
Scenario: As a user I want to make-it-rain via command line
Expand Down
Loading
Loading