Skip to content

Commit

Permalink
fix(wallet): add default value for wait stage (#4089)
Browse files Browse the repository at this point in the history
Description
---
Setting the default value of the wallet's config option `command_send_wait_stage` as `Broadcast`.

Motivation and Context
---
The wallet in command mode is failing with the default config, due to empty default value for `command_send_wait_stage`. But the value should be `Broadcast` by default as specified in all the `config.toml` files.

How Has This Been Tested?
---
* All unit and integration test pass.
* The wallet works in command mode (before the change it didn't).
  • Loading branch information
mrnaveira authored May 16, 2022
1 parent 68b3104 commit 810d9ff
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
16 changes: 2 additions & 14 deletions applications/tari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use std::{
fs::File,
io::{LineWriter, Write},
str::FromStr,
time::{Duration, Instant},
};

Expand Down Expand Up @@ -52,6 +51,7 @@ use tari_wallet::{
key_manager_service::KeyManagerInterface,
output_manager_service::handle::OutputManagerHandle,
transaction_service::handle::{TransactionEvent, TransactionServiceHandle},
TransactionStage,
WalletConfig,
WalletSqlite,
};
Expand Down Expand Up @@ -95,17 +95,6 @@ pub enum WalletCommand {
RevalidateWalletDb,
}

#[derive(Debug, EnumString, PartialEq, Clone, Copy)]
pub enum TransactionStage {
Initiated,
DirectSendOrSaf,
Negotiated,
Broadcast,
MinedUnconfirmed,
Mined,
TimedOut,
}

#[derive(Debug)]
pub struct SentTransaction {}

Expand Down Expand Up @@ -630,8 +619,7 @@ pub async fn command_runner(
commands: Vec<ParsedCommand>,
wallet: WalletSqlite,
) -> Result<(), CommandError> {
let wait_stage =
TransactionStage::from_str(&config.command_send_wait_stage).map_err(|e| CommandError::Config(e.to_string()))?;
let wait_stage = config.command_send_wait_stage;

let mut transaction_service = wallet.transaction_service.clone();
let mut output_service = wallet.output_manager_service.clone();
Expand Down
16 changes: 14 additions & 2 deletions base_layer/wallet/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use std::{
};

use serde::{Deserialize, Serialize};
use strum::EnumString;
use tari_common::{
configuration::{serializers, Network, StringList},
SubConfigPath,
Expand Down Expand Up @@ -63,7 +64,7 @@ pub struct WalletConfig {
pub contacts_online_ping_window: usize,
#[serde(with = "serializers::seconds")]
pub command_send_wait_timeout: Duration,
pub command_send_wait_stage: String,
pub command_send_wait_stage: TransactionStage,
pub notify_file: Option<PathBuf>,
pub grpc_address: Option<Multiaddr>,
pub custom_base_node: Option<String>,
Expand Down Expand Up @@ -93,7 +94,7 @@ impl Default for WalletConfig {
password: None,
contacts_auto_ping_interval: Duration::from_secs(30),
contacts_online_ping_window: 30,
command_send_wait_stage: String::new(),
command_send_wait_stage: TransactionStage::Broadcast,
command_send_wait_timeout: Duration::from_secs(300),
notify_file: None,
grpc_address: None,
Expand Down Expand Up @@ -125,3 +126,14 @@ impl WalletConfig {
self.p2p.set_base_path(self.data_dir.as_path());
}
}

#[derive(Debug, EnumString, PartialEq, Clone, Copy, Serialize, Deserialize)]
pub enum TransactionStage {
Initiated,
DirectSendOrSaf,
Negotiated,
Broadcast,
MinedUnconfirmed,
Mined,
TimedOut,
}
2 changes: 1 addition & 1 deletion base_layer/wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub mod key_manager_service;
pub mod schema;
pub mod utxo_scanner_service;

pub use config::WalletConfig;
pub use config::{TransactionStage, WalletConfig};
pub use wallet::Wallet;

use crate::{
Expand Down

0 comments on commit 810d9ff

Please sign in to comment.