From 810d9ff60ccc512419f5d42030ac13d6fe9af405 Mon Sep 17 00:00:00 2001 From: mrnaveira <47919901+mrnaveira@users.noreply.github.com> Date: Mon, 16 May 2022 11:37:11 +0100 Subject: [PATCH] fix(wallet): add default value for wait stage (#4089) 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). --- .../src/automation/commands.rs | 16 ++-------------- base_layer/wallet/src/config.rs | 16 ++++++++++++++-- base_layer/wallet/src/lib.rs | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/applications/tari_console_wallet/src/automation/commands.rs b/applications/tari_console_wallet/src/automation/commands.rs index a2fc146b6c..a37a4b1a01 100644 --- a/applications/tari_console_wallet/src/automation/commands.rs +++ b/applications/tari_console_wallet/src/automation/commands.rs @@ -23,7 +23,6 @@ use std::{ fs::File, io::{LineWriter, Write}, - str::FromStr, time::{Duration, Instant}, }; @@ -52,6 +51,7 @@ use tari_wallet::{ key_manager_service::KeyManagerInterface, output_manager_service::handle::OutputManagerHandle, transaction_service::handle::{TransactionEvent, TransactionServiceHandle}, + TransactionStage, WalletConfig, WalletSqlite, }; @@ -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 {} @@ -630,8 +619,7 @@ pub async fn command_runner( commands: Vec, 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(); diff --git a/base_layer/wallet/src/config.rs b/base_layer/wallet/src/config.rs index 4ecb06be15..67a2d1e48d 100644 --- a/base_layer/wallet/src/config.rs +++ b/base_layer/wallet/src/config.rs @@ -27,6 +27,7 @@ use std::{ }; use serde::{Deserialize, Serialize}; +use strum::EnumString; use tari_common::{ configuration::{serializers, Network, StringList}, SubConfigPath, @@ -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, pub grpc_address: Option, pub custom_base_node: Option, @@ -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, @@ -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, +} diff --git a/base_layer/wallet/src/lib.rs b/base_layer/wallet/src/lib.rs index 494d6a585a..eea5aa8142 100644 --- a/base_layer/wallet/src/lib.rs +++ b/base_layer/wallet/src/lib.rs @@ -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::{