mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-22 21:31:10 -05:00
Add --sled flag to use deprecated sled db
This commit is contained in:
parent
0f7876c107
commit
05a28dc37a
29
CHANGELOG.md
29
CHANGELOG.md
@ -14,6 +14,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
The force flag was used to ignore blockheight and protocol state checks.
|
||||
Users can still restart a swap with these checks using the `resume` subcommand.
|
||||
- Changed log level of the "Advancing state", "Establishing Connection through Tor proxy" and "Connection through Tor established" log message from tracing to debug in the CLI.
|
||||
- ASB and CLI can migrate their data to sqlite to store swaps and related data.
|
||||
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.
|
||||
The schema can be found here [here](swap/migrations/20210903050345_create_swaps_table.sql).
|
||||
|
||||
#### Database migration guide
|
||||
|
||||
##### Delete old data
|
||||
|
||||
The simplest way to migrate is to accept the loss of data and delete the old database.
|
||||
|
||||
1. Find the location of the old database using the `config` subcommand.
|
||||
2. Delete the database
|
||||
3. Run xmr-btc-swap
|
||||
xmr-btc swap will create a new sqlite database and use that from now on.
|
||||
|
||||
##### Preserve old data
|
||||
|
||||
It is possible to migrate critical data from the old db to the sqlite but there are many pitfalls.
|
||||
|
||||
1. Run xmr-btc-swap as you would normally
|
||||
xmr-btc-swap will try and automatically migrate your existing data to the new database.
|
||||
If the existing database contains swaps for very early releases, the migration will fail due to an incompatible schema.
|
||||
2. Print out the swap history using the `history` subcommand.
|
||||
3. Print out the swap history stored in the old database by also passing the `--sled` flag.
|
||||
eg. `swap-cli --sled history`
|
||||
4. Compare the old and new history to see if you are happy with migration.
|
||||
5. If you are unhappy with the new history you can continue to use the old database by passing the `--sled flag`
|
||||
|
||||
### Added
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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");
|
||||
|
@ -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 {
|
||||
|
@ -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(),
|
||||
|
Loading…
Reference in New Issue
Block a user