From 394adb0a4f4c6889e9ad4f5c0b493f7bf65f9511 Mon Sep 17 00:00:00 2001 From: rishflab Date: Tue, 28 Sep 2021 09:37:51 +1000 Subject: [PATCH] Add subcommand to print config This subcommand has been introduced to make it easy for users to find the location of the deprecated sled database in case they wish to delete it. This feature should also resolve difficulties users were facing when trying to find where xmr-btc-swap was storing their data. --- CHANGELOG.md | 3 +++ swap/src/asb/command.rs | 12 ++++++++++++ swap/src/bin/asb.rs | 4 ++++ swap/src/bin/swap.rs | 32 +++++++++++++++++++++++++++++++- swap/src/cli/command.rs | 11 +++++++++++ swap/src/env.rs | 21 ++++++++++++++++++++- 6 files changed, 81 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91c943fd..5a266e81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 This makes it easier to build applications on top of xmr-btc-swap by enabling developers to read swap information directly from the database. This resolved an issue where users where unable to run concurrent processes, for example, users could not print the swap history if another ASB or CLI process was running. The sqlite database filed is named `sqlite` and is found in the data directory. + You can print the data directory using the `config` subcommand. The schema can be found here [here](swap/migrations/20210903050345_create_swaps_table.sql). #### Database migration guide @@ -47,6 +48,8 @@ It is possible to migrate critical data from the old db to the sqlite but there ### Added - Added a `disable-timestamp` flag to the ASB that disables timestamps from logs. +- A `config` subcommand that prints the current configuration including the data directory location. + This feature should alleviate difficulties users were having when finding where xmr-btc-swap was storing data. ## [0.8.3] - 2021-09-03 diff --git a/swap/src/asb/command.rs b/swap/src/asb/command.rs index 7cad9686..403320c1 100644 --- a/swap/src/asb/command.rs +++ b/swap/src/asb/command.rs @@ -65,6 +65,15 @@ where env_config: env_config(testnet), cmd: Command::Balance, }, + RawCommand::Config => Arguments { + testnet, + json, + sled, + disable_timestamp, + config_path: config_path(config, testnet)?, + env_config: env_config(testnet), + cmd: Command::Config, + }, RawCommand::ManualRecovery(ManualRecovery::Redeem { redeem_params: RecoverCommandParams { swap_id }, do_not_await_finality, @@ -191,6 +200,7 @@ pub enum Command { resume_only: bool, }, History, + Config, WithdrawBtc { amount: Option, address: Address, @@ -270,6 +280,8 @@ pub enum RawCommand { }, #[structopt(about = "Prints swap-id and the state of each swap ever made.")] History, + #[structopt(about = "Prints the current config")] + Config, #[structopt(about = "Allows withdrawing BTC from the internal Bitcoin wallet.")] WithdrawBtc { #[structopt( diff --git a/swap/src/bin/asb.rs b/swap/src/bin/asb.rs index e9f2915c..796d0355 100644 --- a/swap/src/bin/asb.rs +++ b/swap/src/bin/asb.rs @@ -217,6 +217,10 @@ async fn main() -> Result<()> { println!("{}", table); } + Command::Config => { + let config_json = serde_json::to_string_pretty(&config)?; + println!("{}", config_json); + } Command::WithdrawBtc { amount, address } => { let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?; diff --git a/swap/src/bin/swap.rs b/swap/src/bin/swap.rs index 6a0167a6..6dc1e581 100644 --- a/swap/src/bin/swap.rs +++ b/swap/src/bin/swap.rs @@ -152,7 +152,37 @@ async fn main() -> Result<()> { println!("{}", table); } - + Command::Config => { + println!("Data directory: {}", data_dir.display()); + println!( + "Log files locations: {}", + format!("{}/wallet", data_dir.display()) + ); + println!( + "Sled folder location: {}", + format!("{}/database", data_dir.display()) + ); + println!( + "Sqlite file location: {}", + format!("{}/sqlite", data_dir.display()) + ); + println!( + "Seed file location: {}", + format!("{}/seed.pem", data_dir.display()) + ); + println!( + "Monero-wallet-rpc location: {}", + format!("{}/monero", data_dir.display()) + ); + println!( + "Internal bitcoin wallet location: {}", + format!("{}/wallet", data_dir.display()) + ); + println!( + "Internal bitcoin wallet location: {}", + format!("{}/wallet", data_dir.display()) + ); + } Command::WithdrawBtc { bitcoin_electrum_rpc_url, bitcoin_target_block, diff --git a/swap/src/cli/command.rs b/swap/src/cli/command.rs index 498ef25d..b7d68e78 100644 --- a/swap/src/cli/command.rs +++ b/swap/src/cli/command.rs @@ -113,6 +113,14 @@ where data_dir: data::data_dir_from(data, is_testnet)?, cmd: Command::History, }, + RawCommand::Config => Arguments { + env_config: env_config_from(is_testnet), + debug, + json, + sled, + data_dir: data::data_dir_from(data, is_testnet)?, + cmd: Command::Config, + }, RawCommand::Balance { bitcoin } => { let (bitcoin_electrum_rpc_url, bitcoin_target_block) = bitcoin.apply_defaults(is_testnet)?; @@ -248,6 +256,7 @@ pub enum Command { tor_socks5_port: u16, }, History, + Config, WithdrawBtc { bitcoin_electrum_rpc_url: Url, bitcoin_target_block: usize, @@ -355,6 +364,8 @@ enum RawCommand { }, /// Show a list of past, ongoing and completed swaps History, + #[structopt(about = "Prints the current config")] + Config, #[structopt(about = "Allows withdrawing BTC from the internal Bitcoin wallet.")] WithdrawBtc { #[structopt(flatten)] diff --git a/swap/src/env.rs b/swap/src/env.rs index 434e9b47..273eec49 100644 --- a/swap/src/env.rs +++ b/swap/src/env.rs @@ -1,10 +1,11 @@ use crate::asb; use crate::bitcoin::{CancelTimelock, PunishTimelock}; +use serde::Serialize; use std::cmp::max; use std::time::Duration; use time::ext::NumericalStdDuration; -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Serialize)] pub struct Config { pub bitcoin_lock_mempool_timeout: Duration, pub bitcoin_lock_confirmed_timeout: Duration, @@ -15,6 +16,7 @@ pub struct Config { pub bitcoin_network: bitcoin::Network, pub monero_avg_block_time: Duration, pub monero_finality_confirmations: u64, + #[serde(with = "monero_network")] pub monero_network: monero::Network, } @@ -123,6 +125,23 @@ pub fn new(is_testnet: bool, asb_config: &asb::config::Config) -> Config { } } +mod monero_network { + use crate::monero::Network; + use serde::Serializer; + + pub fn serialize(x: &monero::Network, s: S) -> Result + where + S: Serializer, + { + let str = match x { + Network::Mainnet => "mainnet", + Network::Stagenet => "stagenet", + Network::Testnet => "testnet", + }; + s.serialize_str(&str) + } +} + #[cfg(test)] mod tests { use super::*;