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.
This commit is contained in:
rishflab 2021-09-28 09:37:51 +10:00
parent 05a28dc37a
commit 394adb0a4f
6 changed files with 81 additions and 2 deletions

View File

@ -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

View File

@ -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<Amount>,
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(

View File

@ -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?;

View File

@ -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,

View File

@ -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)]

View File

@ -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<S>(x: &monero::Network, s: S) -> Result<S::Ok, S::Error>
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::*;