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.
sqlite2
rishflab 3 years ago
parent eddb8d6f68
commit f12879782f

@ -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
@ -43,6 +44,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

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

@ -217,6 +217,10 @@ async fn main() -> Result<()> {
println!("{}", table);
}
Command::Config => {
let config_json = serde_json::to_string_pretty(&config)?;
println!("Config: {}", config_json);
}
Command::WithdrawBtc { amount, address } => {
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;

@ -152,7 +152,11 @@ async fn main() -> Result<()> {
println!("{}", table);
}
Command::Config => {
println!("Data Directory: {}", data_dir.display());
let config_json = serde_json::to_string_pretty(&env_config)?;
println!("Config: {}", config_json);
}
Command::WithdrawBtc {
bitcoin_electrum_rpc_url,
bitcoin_target_block,

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

@ -3,8 +3,9 @@ use crate::bitcoin::{CancelTimelock, PunishTimelock};
use std::cmp::max;
use std::time::Duration;
use time::ext::NumericalStdDuration;
use serde::Serialize;
#[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 serde::Serializer;
use crate::monero::Network;
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::*;

Loading…
Cancel
Save