Add --sled flag to use deprecated sled db

This commit is contained in:
rishflab 2021-09-27 11:13:08 +10:00
parent e3e354c319
commit eddb8d6f68
5 changed files with 89 additions and 2 deletions

View file

@ -21,6 +21,7 @@ where
let json = args.json;
let disable_timestamp = args.disable_timestamp;
let testnet = args.testnet;
let sled = args.sled;
let config = args.config;
let command: RawCommand = args.cmd;
@ -29,6 +30,7 @@ where
testnet,
json,
disable_timestamp,
sled,
config_path: config_path(config, testnet)?,
env_config: env_config(testnet),
cmd: Command::Start { resume_only },
@ -37,6 +39,7 @@ where
testnet,
json,
disable_timestamp,
sled,
config_path: config_path(config, testnet)?,
env_config: env_config(testnet),
cmd: Command::History,
@ -45,6 +48,7 @@ where
testnet,
json,
disable_timestamp,
sled,
config_path: config_path(config, testnet)?,
env_config: env_config(testnet),
cmd: Command::WithdrawBtc {
@ -56,6 +60,7 @@ where
testnet,
json,
disable_timestamp,
sled,
config_path: config_path(config, testnet)?,
env_config: env_config(testnet),
cmd: Command::Balance,
@ -67,6 +72,7 @@ where
testnet,
json,
disable_timestamp,
sled,
config_path: config_path(config, testnet)?,
env_config: env_config(testnet),
cmd: Command::Redeem {
@ -81,6 +87,7 @@ where
testnet,
json,
disable_timestamp,
sled,
config_path: config_path(config, testnet)?,
env_config: env_config(testnet),
cmd: Command::Cancel { swap_id },
@ -91,6 +98,7 @@ where
testnet,
json,
disable_timestamp,
sled,
config_path: config_path(config, testnet)?,
env_config: env_config(testnet),
cmd: Command::Refund { swap_id },
@ -101,6 +109,7 @@ where
testnet,
json,
disable_timestamp,
sled,
config_path: config_path(config, testnet)?,
env_config: env_config(testnet),
cmd: Command::Punish { swap_id },
@ -109,6 +118,7 @@ where
testnet,
json,
disable_timestamp,
sled,
config_path: config_path(config, testnet)?,
env_config: env_config(testnet),
cmd: Command::SafelyAbort { swap_id },
@ -168,6 +178,7 @@ pub struct BitcoinAddressNetworkMismatch {
pub struct Arguments {
pub testnet: bool,
pub json: bool,
pub sled: bool,
pub disable_timestamp: bool,
pub config_path: PathBuf,
pub env_config: env::Config,
@ -228,6 +239,13 @@ pub struct RawArguments {
)]
pub disable_timestamp: bool,
#[structopt(
short,
long = "sled",
help = "Forces the asb to use the deprecated sled db if it is available"
)]
pub sled: bool,
#[structopt(
long = "config",
help = "Provide a custom path to the configuration file. The configuration file must be a toml file.",
@ -344,6 +362,7 @@ mod tests {
let expected_args = Arguments {
testnet: false,
json: false,
sled: false,
disable_timestamp: false,
config_path: default_mainnet_conf_path,
env_config: mainnet_env_config,
@ -362,6 +381,7 @@ mod tests {
let expected_args = Arguments {
testnet: false,
json: false,
sled: false,
disable_timestamp: false,
config_path: default_mainnet_conf_path,
env_config: mainnet_env_config,
@ -380,6 +400,7 @@ mod tests {
let expected_args = Arguments {
testnet: false,
json: false,
sled: false,
disable_timestamp: false,
config_path: default_mainnet_conf_path,
env_config: mainnet_env_config,
@ -402,6 +423,7 @@ mod tests {
let expected_args = Arguments {
testnet: false,
json: false,
sled: false,
disable_timestamp: false,
config_path: default_mainnet_conf_path,
env_config: mainnet_env_config,
@ -429,6 +451,7 @@ mod tests {
let expected_args = Arguments {
testnet: false,
json: false,
sled: false,
disable_timestamp: false,
config_path: default_mainnet_conf_path,
env_config: mainnet_env_config,
@ -455,6 +478,7 @@ mod tests {
let expected_args = Arguments {
testnet: false,
json: false,
sled: false,
disable_timestamp: false,
config_path: default_mainnet_conf_path,
env_config: mainnet_env_config,
@ -481,6 +505,7 @@ mod tests {
let expected_args = Arguments {
testnet: false,
json: false,
sled: false,
disable_timestamp: false,
config_path: default_mainnet_conf_path,
env_config: mainnet_env_config,
@ -507,6 +532,7 @@ mod tests {
let expected_args = Arguments {
testnet: false,
json: false,
sled: false,
disable_timestamp: false,
config_path: default_mainnet_conf_path,
env_config: mainnet_env_config,
@ -527,6 +553,7 @@ mod tests {
let expected_args = Arguments {
testnet: true,
json: false,
sled: false,
disable_timestamp: false,
config_path: default_testnet_conf_path,
env_config: testnet_env_config,
@ -545,6 +572,7 @@ mod tests {
let expected_args = Arguments {
testnet: true,
json: false,
sled: false,
disable_timestamp: false,
config_path: default_testnet_conf_path,
env_config: testnet_env_config,
@ -563,6 +591,7 @@ mod tests {
let expected_args = Arguments {
testnet: true,
json: false,
sled: false,
disable_timestamp: false,
config_path: default_testnet_conf_path,
env_config: testnet_env_config,
@ -587,6 +616,7 @@ mod tests {
let expected_args = Arguments {
testnet: true,
json: false,
sled: false,
disable_timestamp: false,
config_path: default_testnet_conf_path,
env_config: testnet_env_config,
@ -614,6 +644,7 @@ mod tests {
let expected_args = Arguments {
testnet: true,
json: false,
sled: false,
disable_timestamp: false,
config_path: default_testnet_conf_path,
env_config: testnet_env_config,
@ -641,6 +672,7 @@ mod tests {
let expected_args = Arguments {
testnet: true,
json: false,
sled: false,
disable_timestamp: false,
config_path: default_testnet_conf_path,
env_config: testnet_env_config,
@ -668,6 +700,7 @@ mod tests {
let expected_args = Arguments {
testnet: true,
json: false,
sled: false,
disable_timestamp: false,
config_path: default_testnet_conf_path,
env_config: testnet_env_config,
@ -695,6 +728,7 @@ mod tests {
let expected_args = Arguments {
testnet: true,
json: false,
sled: false,
disable_timestamp: false,
config_path: default_testnet_conf_path,
env_config: testnet_env_config,
@ -715,6 +749,7 @@ mod tests {
let expected_args = Arguments {
testnet: false,
json: false,
sled: false,
disable_timestamp: true,
config_path: default_mainnet_conf_path,
env_config: mainnet_env_config,

View file

@ -47,6 +47,7 @@ async fn main() -> Result<()> {
testnet,
json,
disable_timestamp,
sled,
config_path,
env_config,
cmd,
@ -94,7 +95,7 @@ async fn main() -> Result<()> {
let db_path = config.data.dir.join("database");
let sled_path = config.data.dir.join(db_path);
let db = open_db(sled_path, config.data.dir.join("sqlite"), true).await?;
let db = open_db(sled_path, config.data.dir.join("sqlite"), sled).await?;
let seed =
Seed::from_file_or_generate(&config.data.dir).expect("Could not retrieve/initialize seed");

View file

@ -45,6 +45,7 @@ async fn main() -> Result<()> {
data_dir,
debug,
json,
sled,
cmd,
} = match parse_args_and_apply_defaults(env::args_os())? {
ParseResult::Arguments(args) => args,
@ -54,7 +55,7 @@ async fn main() -> Result<()> {
}
};
let db = open_db(data_dir.join("database"), data_dir.join("sqlite"), true).await?;
let db = open_db(data_dir.join("database"), data_dir.join("sqlite"), sled).await?;
match cmd {
Command::BuyXmr {

View file

@ -33,6 +33,7 @@ pub struct Arguments {
pub env_config: env::Config,
pub debug: bool,
pub json: bool,
pub sled: bool,
pub data_dir: PathBuf,
pub cmd: Command,
}
@ -66,6 +67,7 @@ where
let debug = args.debug;
let json = args.json;
let sled = args.sled;
let is_testnet = args.testnet;
let data = args.data;
@ -90,6 +92,7 @@ where
env_config: env_config_from(is_testnet),
debug,
json,
sled,
data_dir: data::data_dir_from(data, is_testnet)?,
cmd: Command::BuyXmr {
seller,
@ -106,6 +109,7 @@ where
env_config: env_config_from(is_testnet),
debug,
json,
sled,
data_dir: data::data_dir_from(data, is_testnet)?,
cmd: Command::History,
},
@ -117,6 +121,7 @@ where
env_config: env_config_from(is_testnet),
debug,
json,
sled,
data_dir: data::data_dir_from(data, is_testnet)?,
cmd: Command::Balance {
bitcoin_electrum_rpc_url,
@ -136,6 +141,7 @@ where
env_config: env_config_from(is_testnet),
debug,
json,
sled,
data_dir: data::data_dir_from(data, is_testnet)?,
cmd: Command::WithdrawBtc {
bitcoin_electrum_rpc_url,
@ -159,6 +165,7 @@ where
env_config: env_config_from(is_testnet),
debug,
json,
sled,
data_dir: data::data_dir_from(data, is_testnet)?,
cmd: Command::Resume {
swap_id,
@ -180,6 +187,7 @@ where
env_config: env_config_from(is_testnet),
debug,
json,
sled,
data_dir: data::data_dir_from(data, is_testnet)?,
cmd: Command::Cancel {
swap_id,
@ -199,6 +207,7 @@ where
env_config: env_config_from(is_testnet),
debug,
json,
sled,
data_dir: data::data_dir_from(data, is_testnet)?,
cmd: Command::Refund {
swap_id,
@ -214,6 +223,7 @@ where
env_config: env_config_from(is_testnet),
debug,
json,
sled,
data_dir: data::data_dir_from(data, is_testnet)?,
cmd: Command::ListSellers {
rendezvous_point,
@ -304,6 +314,13 @@ struct RawArguments {
)]
json: bool,
#[structopt(
short,
long = "sled",
help = "Forces the swap-cli to use the deprecated sled db if it is available"
)]
sled: bool,
#[structopt(subcommand)]
cmd: RawCommand,
}
@ -1105,6 +1122,7 @@ mod tests {
env_config: env::Testnet::get_config(),
debug: false,
json: false,
sled: false,
data_dir: data_dir_path_cli().join(TESTNET),
cmd: Command::BuyXmr {
seller: Multiaddr::from_str(MULTI_ADDRESS).unwrap(),
@ -1125,6 +1143,7 @@ mod tests {
env_config: env::Mainnet::get_config(),
debug: false,
json: false,
sled: false,
data_dir: data_dir_path_cli().join(MAINNET),
cmd: Command::BuyXmr {
seller: Multiaddr::from_str(MULTI_ADDRESS).unwrap(),
@ -1144,6 +1163,7 @@ mod tests {
env_config: env::Testnet::get_config(),
debug: false,
json: false,
sled: false,
data_dir: data_dir_path_cli().join(TESTNET),
cmd: Command::Resume {
swap_id: Uuid::from_str(SWAP_ID).unwrap(),
@ -1161,6 +1181,7 @@ mod tests {
env_config: env::Mainnet::get_config(),
debug: false,
json: false,
sled: false,
data_dir: data_dir_path_cli().join(MAINNET),
cmd: Command::Resume {
swap_id: Uuid::from_str(SWAP_ID).unwrap(),
@ -1177,6 +1198,7 @@ mod tests {
env_config: env::Testnet::get_config(),
debug: false,
json: false,
sled: false,
data_dir: data_dir_path_cli().join(TESTNET),
cmd: Command::Cancel {
swap_id: Uuid::from_str(SWAP_ID).unwrap(),
@ -1192,6 +1214,7 @@ mod tests {
env_config: env::Mainnet::get_config(),
debug: false,
json: false,
sled: false,
data_dir: data_dir_path_cli().join(MAINNET),
cmd: Command::Cancel {
swap_id: Uuid::from_str(SWAP_ID).unwrap(),
@ -1206,6 +1229,7 @@ mod tests {
env_config: env::Testnet::get_config(),
debug: false,
json: false,
sled: false,
data_dir: data_dir_path_cli().join(TESTNET),
cmd: Command::Refund {
swap_id: Uuid::from_str(SWAP_ID).unwrap(),
@ -1221,6 +1245,7 @@ mod tests {
env_config: env::Mainnet::get_config(),
debug: false,
json: false,
sled: false,
data_dir: data_dir_path_cli().join(MAINNET),
cmd: Command::Refund {
swap_id: Uuid::from_str(SWAP_ID).unwrap(),