From 6cddedbfebb9f379d06efb77a6e38a40e43d8c1c Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Mon, 20 Mar 2023 02:17:15 +0500 Subject: [PATCH 01/90] feat: introduce adex cli utility, that is aimed to facilitate using mm2 and atomic swap protocol --- Cargo.toml | 1 + README.md | 3 +- mm2src/adex_cli/Cargo.toml | 21 ++ mm2src/adex_cli/src/cli.rs | 53 ++++ mm2src/adex_cli/src/log.rs | 18 ++ mm2src/adex_cli/src/main.rs | 8 + mm2src/adex_cli/src/scenarios/helpers.rs | 34 +++ mm2src/adex_cli/src/scenarios/init_coins.rs | 59 ++++ mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs | 276 ++++++++++++++++++ .../src/scenarios/inquire_extentions.rs | 64 ++++ mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 94 ++++++ mm2src/adex_cli/src/scenarios/mod.rs | 16 + mm2src/common/Cargo.toml | 4 +- mm2src/common/common.rs | 1 + mm2src/common/password_policy.rs | 116 ++++++++ mm2src/mm2_main/src/mm2.rs | 115 +------- 16 files changed, 767 insertions(+), 116 deletions(-) create mode 100644 mm2src/adex_cli/Cargo.toml create mode 100644 mm2src/adex_cli/src/cli.rs create mode 100644 mm2src/adex_cli/src/log.rs create mode 100644 mm2src/adex_cli/src/main.rs create mode 100644 mm2src/adex_cli/src/scenarios/helpers.rs create mode 100644 mm2src/adex_cli/src/scenarios/init_coins.rs create mode 100644 mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs create mode 100644 mm2src/adex_cli/src/scenarios/inquire_extentions.rs create mode 100644 mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs create mode 100644 mm2src/adex_cli/src/scenarios/mod.rs create mode 100644 mm2src/common/password_policy.rs diff --git a/Cargo.toml b/Cargo.toml index 421bdca2c6..ba90ae9f8d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,6 @@ [workspace] members = [ + "mm2src/adex_cli", "mm2src/coins", "mm2src/coins/utxo_signer", "mm2src/coins_activation", diff --git a/README.md b/README.md index da537c40f6..d29da8a8e3 100755 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ The AtomicDEX API core is open-source [atomic-swap](https://komodoplatform.com/en/academy/atomic-swaps/) software for seamless, decentralised, peer to peer trading between almost every blockchain asset in existence. This software works with propagation of orderbooks and swap states through the [libp2p](https://libp2p.io/) protocol and uses [Hash Time Lock Contracts (HTLCs)](https://en.bitcoinwiki.org/wiki/Hashed_Timelock_Contracts) for ensuring that the two parties in a swap either mutually complete a trade, or funds return to thier original owner. -There is no 3rd party intermediatary, no proxy tokens, and at all times users remain in sole possession of their private keys. +There is no 3rd party intermediary, no proxy tokens, and at all times users remain in sole possession of their private keys. A [well documented API](https://developers.komodoplatform.com/basic-docs/atomicdex/introduction-to-atomicdex.html) offers simple access to the underlying services using simple language agnostic JSON structured methods and parameters such that users can communicate with the core in a variety of methods such as [curl](https://developers.komodoplatform.com/basic-docs/atomicdex-api-legacy/buy.html) in CLI, or fully functioning [desktop and mobile applications](https://atomicdex.io/) like [AtomicDEX Desktop](https://github.com/KomodoPlatform/atomicDEX-Desktop). @@ -121,6 +121,7 @@ For example: The coins file contains information about the coins and tokens you want to trade. A regularly updated version is maintained in the [Komodo Platform coins repository](https://github.com/KomodoPlatform/coins/blob/master/coins). Pull Requests to add any coins not yet included are welcome. +To facilitate interoperability with the `mm2` service, there is the `adex` command line utility. It provides a questionnaire initialization mode to set up the configuration and obtain the proper coin set through the internet. It can also be used to start or stop the service. ## Usage diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml new file mode 100644 index 0000000000..417ed9738f --- /dev/null +++ b/mm2src/adex_cli/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "adex" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +clap = { version = "4.1", features = ["derive"] } +common = { path = "../common" } +derive_more = "0.99" +fork = "0.1" +inquire = "0.6" +log = "0.4" +log4rs = { version = "1.0", default-features = false, features = ["console_appender", "pattern_encoder"] } +serde = "1.0" +serde_json = { version = "1", features = ["preserve_order", "raw_value"] } +sysinfo = "0.28" +tokio = { version = "1.20" } +hyper = { version = "0.14", features = ["http2", "client", "runtime", "tcp"] } +hyper-tls = "0.5" diff --git a/mm2src/adex_cli/src/cli.rs b/mm2src/adex_cli/src/cli.rs new file mode 100644 index 0000000000..44f653796f --- /dev/null +++ b/mm2src/adex_cli/src/cli.rs @@ -0,0 +1,53 @@ +use clap::{Parser, Subcommand}; + +use crate::scenarios::{get_status, init, start_process, stop_process}; + +#[derive(Subcommand)] +enum Command { + #[command(about = "Initialize predefined mm2 coin set and configuration")] + Init { + #[arg(long, help = "coin set file path", default_value = "coins")] + coins_file: String, + #[arg(long, help = "mm2 configuration file path", default_value = "MM2.json")] + mm2_cfg_file: String, + }, + #[command(about = "Start mm2 service")] + Start { + #[arg(long, help = "mm2 configuration file path")] + mm2_cfg_file: Option, + #[arg(long, help = "coin set file path")] + coins_file: Option, + #[arg(long, help = "log file path")] + log_file: Option, + }, + #[command(about = "Stop mm2 service")] + Stop, + #[command(about = "Get mm2 running status")] + Status, +} + +#[derive(Parser)] +#[clap(author, version, about, long_about = None)] +pub struct Cli { + #[command(subcommand)] + command: Command, +} + +impl Cli { + pub fn execute() { + let parsed_cli = Self::parse(); + match &parsed_cli.command { + Command::Init { + coins_file, + mm2_cfg_file, + } => init(mm2_cfg_file, coins_file), + Command::Start { + mm2_cfg_file, + coins_file, + log_file, + } => start_process(mm2_cfg_file, coins_file, log_file), + Command::Stop => stop_process(), + Command::Status => get_status(), + } + } +} diff --git a/mm2src/adex_cli/src/log.rs b/mm2src/adex_cli/src/log.rs new file mode 100644 index 0000000000..3643454d61 --- /dev/null +++ b/mm2src/adex_cli/src/log.rs @@ -0,0 +1,18 @@ +use log::LevelFilter; +use log4rs::{append::console::ConsoleAppender, + config::{Appender, Root}, + encode::pattern::PatternEncoder, + Config}; + +const REDUCED_LOG_FORMAT: &str = "{l}: {m}{n}"; + +pub fn init_logging() { + let stdout = ConsoleAppender::builder() + .encoder(Box::new(PatternEncoder::new(REDUCED_LOG_FORMAT))) + .build(); + let config = Config::builder() + .appender(Appender::builder().build("stdout", Box::new(stdout))) + .build(Root::builder().appender("stdout").build(LevelFilter::Info)) + .expect("Failed to build log4rs config"); + log4rs::init_config(config).expect("Failed to init log4rs config"); +} diff --git a/mm2src/adex_cli/src/main.rs b/mm2src/adex_cli/src/main.rs new file mode 100644 index 0000000000..5d17edbf58 --- /dev/null +++ b/mm2src/adex_cli/src/main.rs @@ -0,0 +1,8 @@ +mod cli; +mod log; +mod scenarios; + +fn main() { + log::init_logging(); + cli::Cli::execute(); +} diff --git a/mm2src/adex_cli/src/scenarios/helpers.rs b/mm2src/adex_cli/src/scenarios/helpers.rs new file mode 100644 index 0000000000..da190a102a --- /dev/null +++ b/mm2src/adex_cli/src/scenarios/helpers.rs @@ -0,0 +1,34 @@ +use log::error; +use serde::Serialize; +use std::fs::OpenOptions; +use std::io::Write; +use std::ops::Deref; + +pub fn rewrite_data_file(data: T, file: &str) -> Result<(), ()> +where + T: Deref, +{ + let mut writer = OpenOptions::new() + .create(true) + .write(true) + .truncate(true) + .open(file) + .map_err(|error| { + error!("Failed to open {file}: {error}"); + })?; + + writer.write(&data).map_err(|error| { + error!("Failed to write data into {file}: {error}"); + })?; + Ok(()) +} + +pub fn rewrite_json_file(value: &T, file: &str) -> Result<(), ()> +where + T: Serialize, +{ + let data = serde_json::to_vec_pretty(value).map_err(|error| { + error!("Failed to serialize data {error}"); + })?; + rewrite_data_file(data, file) +} diff --git a/mm2src/adex_cli/src/scenarios/init_coins.rs b/mm2src/adex_cli/src/scenarios/init_coins.rs new file mode 100644 index 0000000000..8eae93020a --- /dev/null +++ b/mm2src/adex_cli/src/scenarios/init_coins.rs @@ -0,0 +1,59 @@ +use derive_more::Display; +use hyper::{body::Bytes, client::Client, Uri}; +use hyper_tls::HttpsConnector; +use log::{error, info}; + +use super::helpers::rewrite_data_file; + +const FULL_COIN_SET_ADDRESS: &str = "https://raw.githubusercontent.com/KomodoPlatform/coins/master/coins"; +const EMPTY_COIN_SET_DATA: &str = r"[]\n"; + +#[derive(Clone, Copy, Debug, Display)] +pub enum CoinSet { + Empty, + Full, +} + +#[tokio::main(flavor = "current_thread")] +pub async fn init_coins(coins_file: &str) -> Result<(), ()> { + let coin_set = inquire_coin_set(coins_file)?; + info!("Start getting mm2 coins"); + + let bytes_got; + let coins_data = match coin_set { + CoinSet::Empty => EMPTY_COIN_SET_DATA.as_bytes(), + CoinSet::Full => { + info!("Getting coin set from: {FULL_COIN_SET_ADDRESS}"); + bytes_got = get_coins_from_remote(FULL_COIN_SET_ADDRESS).await?; + bytes_got.as_ref() + }, + }; + + rewrite_data_file(coins_data, coins_file)?; + info!("Got coins data, written into: {coins_file}"); + Ok(()) +} + +fn inquire_coin_set(coins_file: &str) -> Result { + inquire::Select::new( + format!("Select one of predefined coin sets to save into: {coins_file}").as_str(), + vec![CoinSet::Empty, CoinSet::Full], + ) + .with_help_message("Information about the currencies: their ticker symbols, names, ports, addresses, etc.") + .prompt() + .map_err(|error| { + error!("Failed to select coin_set: {error}"); + }) +} + +async fn get_coins_from_remote(address: &'static str) -> Result { + let connector = HttpsConnector::new(); + let client = Client::builder().build::<_, hyper::Body>(connector); + let coins_data = client.get(Uri::from_static(address)).await.map_err(|error| { + error!("Failed to get coins from {address}: {error}"); + })?; + + hyper::body::to_bytes(coins_data).await.map_err(|error| { + error!("Failed to get bytes from response: {error}"); + }) +} diff --git a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs new file mode 100644 index 0000000000..b5f4677b33 --- /dev/null +++ b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs @@ -0,0 +1,276 @@ +use inquire::{validator::Validation, Confirm, CustomType, CustomUserError, Password, Text}; +use log::{error, info}; +use serde::Serialize; +use std::net::Ipv4Addr; +use std::ops::Not; +use std::path::Path; + +use super::helpers; +use super::inquire_extentions::{InquireOption, DEFAULT_DEFAULT_OPTION_BOOL_FORMATTER, DEFAULT_OPTION_BOOL_FORMATTER, + OPTION_BOOL_PARSER}; +use common::password_policy; + +const DEFAULT_NET_ID: u16 = 7777; +const DEFAULT_GID: &str = concat!("QA CLI ", env!("CARGO_PKG_VERSION")); +const DEFAULT_OPTION_PLACEHOLDER: &str = "Tap enter to skip"; + +pub fn init_mm2_cfg(cfg_file: &str) -> Result<(), ()> { + let mut mm2_cfg = Mm2Cfg::new(); + info!("Start collecting mm2_cfg into: {cfg_file}"); + mm2_cfg.inquire()?; + helpers::rewrite_json_file(&mm2_cfg, cfg_file)?; + info!("mm2_cfg has been writen into: {cfg_file}"); + + Ok(()) +} + +#[derive(Serialize)] +pub struct Mm2Cfg { + pub gui: Option, + pub net_id: Option, + pub rpc_password: Option, + pub passphrase: Option, + pub allow_weak_password: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub userhome: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub dbdir: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub rpcip: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub rpcport: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub rpc_local_only: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub i_am_seed: Option, + #[serde(skip_serializing_if = "Vec::::is_empty")] + pub seednodes: Vec, + #[serde(skip_serializing_if = "Option::is_none")] + pub hd_account_id: Option, +} + +impl Mm2Cfg { + pub fn new() -> Mm2Cfg { + Mm2Cfg { + gui: None, + net_id: None, + rpc_password: None, + passphrase: None, + allow_weak_password: None, + userhome: None, + dbdir: None, + rpcip: None, + rpcport: None, + rpc_local_only: None, + i_am_seed: None, + seednodes: Vec::::new(), + hd_account_id: None, + } + } + + fn inquire(&mut self) -> Result<(), ()> { + self.inquire_gui()?; + self.inquire_net_id()?; + self.inquire_passphrase()?; + self.inquire_rpc_password()?; + self.inquire_allow_weak_password()?; + self.inquire_userhome()?; + self.inquire_dbdir()?; + self.inquire_rpcip()?; + self.inquire_rpcport()?; + self.inquire_rpc_local_only()?; + self.inquire_i_am_a_seed()?; + self.inquire_seednodes()?; + self.inquire_hd_account_id()?; + Ok(()) + } + + fn inquire_dbdir(&mut self) -> Result<(), ()> { + let is_reachable_dir = |dbdir: &InquireOption| -> Result { + match dbdir { + InquireOption::None => Ok(Validation::Valid), + InquireOption::Some(dbdir) => { + let path = Path::new(dbdir); + if path.is_dir().not() { + return Ok(Validation::Invalid( + format!("\"{dbdir}\" - is not a directory or does not exist").into(), + )); + } + Ok(Validation::Valid) + }, + } + }; + + self.dbdir = CustomType::>::new("What is dbdir") + .with_placeholder(DEFAULT_OPTION_PLACEHOLDER) + .with_help_message("AtomicDEX API database path. Optional, defaults to a subfolder named DB in the path of your mm2 binary") + .with_validator(is_reachable_dir) + .prompt() + .map_err(|error| { + error!("Failed to get dbdir: {error}"); + })?.into(); + + Ok(()) + } + + fn inquire_gui(&mut self) -> Result<(), ()> { + self.gui = Text::new("What is the client identifier, gui:") + .with_default(DEFAULT_GID) + .with_placeholder(DEFAULT_GID) + .with_help_message("Information about your GUI; place essential info about your application (name, version, etc.) here. For example: AtomicDEX iOS 1.0.1") + .prompt() + .map_err(|error| { + error!("Failed to get gui: {error}"); + })?.into(); + Ok(()) + } + + fn inquire_net_id(&mut self) -> Result<(), ()> { + self.net_id = CustomType::::new("What is the network `mm2` is going to be a part, net_id:") + .with_default(DEFAULT_NET_ID) + .with_help_message(r#"Nework ID number, telling the AtomicDEX API which network to join. 7777 is the current main network, though alternative netids can be used for testing or "private" trades"#) + .with_placeholder(format!("{DEFAULT_NET_ID}").as_str()) + .prompt() + .map_err(|error| { + error!("Failed to get net_id: {error}"); + })?.into(); + Ok(()) + } + + fn inquire_passphrase(&mut self) -> Result<(), ()> { + self.passphrase = Password::new("What is the passphrase:") + .with_validator(Self::pwd_validator) + .with_help_message("Your passphrase; this is the source of each of your coins private keys. KEEP IT SAFE!") + .prompt() + .map_err(|error| { + error!("Failed to get passphrase: {error}"); + })? + .into(); + Ok(()) + } + + fn inquire_rpc_password(&mut self) -> Result<(), ()> { + self.rpc_password = Password::new("What is the rpc_password:") + .with_validator(Self::pwd_validator) + .with_help_message("Your password for protected RPC methods (userpass)") + .prompt() + .map_err(|error| { + error!("Failed to get rpc_password: {error}"); + })? + .into(); + Ok(()) + } + + fn inquire_allow_weak_password(&mut self) -> Result<(), ()> { + self.allow_weak_password = Confirm::new("Allow weak password:") + .with_default(false) + .with_placeholder("No") + .with_help_message(r#"If true, will allow low entropy rpc_password. If false rpc_password must not have 3 of the same characters in a row, must be between 8-32 characters in length, must contain at least one of each of the following: numeric, uppercase, lowercase, special character (e.g. !#$*). It also can not contain the word "password", or the chars <, >, and &. Defaults to false."#) + .prompt() + .map_err(|error| { + error!("Failed to get allow_weak_password: {error}"); + })? + .into(); + Ok(()) + } + + fn pwd_validator(pwd: &str) -> Result { + match password_policy::password_policy(pwd) { + Err(error) => Ok(Validation::Invalid(error.into())), + Ok(_) => Ok(Validation::Valid), + } + } + + fn inquire_userhome(&mut self) -> Result<(), ()> { + self.userhome = CustomType::>::new("What is userhome:") + .with_placeholder(DEFAULT_OPTION_PLACEHOLDER) + .with_help_message(r#"The path to your home, called from your environment variables and entered as a regular expression. Example: /${HOME#"/"}"#) + .prompt() + .map_err(|error| { + error!("Failed to get userhome: {error}"); + })?.into(); + Ok(()) + } + + fn inquire_rpcip(&mut self) -> Result<(), ()> { + self.rpcip = CustomType::>::new("What is rpcip:") + .with_placeholder(DEFAULT_OPTION_PLACEHOLDER) + .with_help_message("IP address to bind to for RPC server. Optional, defaults to 127.0.0.1") + .prompt() + .map_err(|error| { + error!("Failed to get rpcip: {error}"); + })? + .into(); + Ok(()) + } + + fn inquire_rpcport(&mut self) -> Result<(), ()> { + self.rpcport = CustomType::>::new("What is the rpcport:") + .with_help_message(r#"Port to use for RPC communication. Optional, defaults to 7783"#) + .with_placeholder(DEFAULT_OPTION_PLACEHOLDER) + .prompt() + .map_err(|error| { + error!("Failed to get rpcport: {error}"); + })? + .into(); + Ok(()) + } + + fn inquire_rpc_local_only(&mut self) -> Result<(), ()> { + self.rpc_local_only = CustomType::>::new("What is rpc_local_only:") + .with_parser(OPTION_BOOL_PARSER) + .with_formatter(DEFAULT_OPTION_BOOL_FORMATTER) + .with_default_value_formatter(DEFAULT_DEFAULT_OPTION_BOOL_FORMATTER) + .with_default(InquireOption::None) + .with_help_message("If false the AtomicDEX API will allow rpc methods sent from external IP addresses. Optional, defaults to true. Warning: Only use this if you know what you are doing, and have put the appropriate security measures in place.") + .prompt() + .map_err(|error| { + error!("Failed to get rpc_local_only: {error}"); + })?.into(); + Ok(()) + } + + fn inquire_i_am_a_seed(&mut self) -> Result<(), ()> { + self.i_am_seed = CustomType::>::new("What is i_am_a_seed:") + .with_parser(OPTION_BOOL_PARSER) + .with_formatter(DEFAULT_OPTION_BOOL_FORMATTER) + .with_default_value_formatter(DEFAULT_DEFAULT_OPTION_BOOL_FORMATTER) + .with_default(InquireOption::None) + .with_help_message("Runs AtomicDEX API as a seed node mode (acting as a relay for AtomicDEX API clients). Optional, defaults to false. Use of this mode is not reccomended on the main network (7777) as it could result in a pubkey ban if non-compliant. on alternative testing or private networks, at least one seed node is required to relay information to other AtomicDEX API clients using the same netID.") + .prompt() + .map_err(|error| { + error!("Failed to get i_am_a_seed: {error}"); + })?.into(); + Ok(()) + } + + fn inquire_seednodes(&mut self) -> Result<(), ()> { + info!("Reading seed nodes until tap enter is met"); + loop { + let seednode: Option = CustomType::>::new("What is next seednode:") + .with_help_message("Optional. If operating on a test or private netID, the IP address of at least one seed node is required (on the main network, these are already hardcoded)") + .with_placeholder(DEFAULT_OPTION_PLACEHOLDER) + .prompt() + .map_err(|error| { + error!("Failed to get seed node: {error}"); + })?.into(); + if seednode.is_none() { + break; + } + self.seednodes.push(seednode.unwrap()); + } + Ok(()) + } + + fn inquire_hd_account_id(&mut self) -> Result<(), ()> { + self.hd_account_id = CustomType::>::new("What is hd_account_id:") + .with_help_message(r#"Optional. If this value is set, the AtomicDEX-API will work in only the HD derivation mode, coins will need to have a coin derivation path entry in the coins file for activation. The hd_account_id value effectively takes its place in the full derivation as follows: m/44'/COIN_ID'/'/CHAIN/ADDRESS_ID"#) + .with_placeholder(DEFAULT_OPTION_PLACEHOLDER) + .prompt() + .map_err(|error| { + error!("Failed to get hd_account_id: {error}"); + })? + .into(); + Ok(()) + } +} diff --git a/mm2src/adex_cli/src/scenarios/inquire_extentions.rs b/mm2src/adex_cli/src/scenarios/inquire_extentions.rs new file mode 100644 index 0000000000..9416fe01a5 --- /dev/null +++ b/mm2src/adex_cli/src/scenarios/inquire_extentions.rs @@ -0,0 +1,64 @@ +use inquire::parser::DEFAULT_BOOL_PARSER; +use std::str::FromStr; + +#[derive(Clone)] +pub enum InquireOption { + Some(T), + None, +} + +type OptionalConfirm = InquireOption; + +impl From> for Option { + fn from(value: InquireOption) -> Self { + match value { + InquireOption::None => None, + InquireOption::Some(value) => Some(value), + } + } +} + +impl FromStr for InquireOption +where + ::Err: ToString, +{ + type Err = T::Err; + fn from_str(s: &str) -> Result { + if s.is_empty() || s.to_lowercase() == "none" { + return Ok(InquireOption::None); + } + T::from_str(s).map(InquireOption::Some) + } +} + +impl ToString for InquireOption { + fn to_string(&self) -> String { + match self { + InquireOption::Some(value) => value.to_string(), + InquireOption::None => "None".to_string(), + } + } +} + +pub type OptionBoolFormatter<'a> = &'a dyn Fn(OptionalConfirm) -> String; +pub const DEFAULT_OPTION_BOOL_FORMATTER: OptionBoolFormatter = &|ans| -> String { + match ans { + InquireOption::None => String::new(), + InquireOption::Some(true) => String::from("yes"), + InquireOption::Some(false) => String::from("no"), + } +}; + +pub type OptionBoolParser<'a> = &'a dyn Fn(&str) -> Result, ()>; +pub const OPTION_BOOL_PARSER: OptionBoolParser = &|ans: &str| -> Result, ()> { + if ans.is_empty() { + return Ok(InquireOption::None); + } + DEFAULT_BOOL_PARSER(ans).map(InquireOption::Some) +}; + +pub const DEFAULT_DEFAULT_OPTION_BOOL_FORMATTER: OptionBoolFormatter = &|ans: InquireOption| match ans { + InquireOption::None => String::from("Tap enter to skip/yes/no"), + InquireOption::Some(true) => String::from("none/Yes/no"), + InquireOption::Some(false) => String::from("none/yes/No"), +}; diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs new file mode 100644 index 0000000000..3465afac05 --- /dev/null +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -0,0 +1,94 @@ +use fork::{daemon, Fork}; +use log::{error, info}; +use std::path::PathBuf; +use std::process::{Command, Stdio}; +use std::{env, u32}; +use sysinfo::{PidExt, ProcessExt, System, SystemExt}; + +const MM2_BINARY: &str = "mm2"; +const KILL_CMD: &str = "kill"; + +fn find_proc_by_name(pname: &'_ str) -> Vec { + let s = System::new_all(); + + s.processes() + .iter() + .filter(|(_, process)| process.name() == pname) + .map(|(pid, _)| pid.as_u32()) + .collect() +} + +fn get_mm2_binary_dir() -> Result { + let mut dir = env::current_exe().map_err(|error| { + error!("Failed to get current binary dir: {error}"); + })?; + dir.pop(); + dir.push(MM2_BINARY); + Ok(dir) +} + +pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, log_file: &Option) { + let mm2_binary = match get_mm2_binary_dir() { + Err(_) => return, + Ok(path) => path, + }; + + let mut command = Command::new(mm2_binary); + if let Some(mm2_cfg_file) = mm2_cfg_file { + info!("Set env MM_CONF_PATH as: {mm2_cfg_file}"); + command.env("MM_CONF_PATH", mm2_cfg_file); + } + if let Some(coins_file) = coins_file { + info!("Set env MM_COINS_PATH as: {coins_file}"); + command.env("MM_COINS_PATH", coins_file); + } + if let Some(log_file) = log_file { + info!("Set env MM_LOG as: {log_file}"); + command.env("MM_LOG", log_file); + } + + let program = command.get_program(); + match daemon(true, true) { + Ok(Fork::Child) => { + command.output().expect("failed to execute process"); + }, + Ok(Fork::Parent(pid)) => { + info!("Successfully started: {program:?}, forked pid: {pid}"); + }, + Err(error) => error!("Failed to fork a process: {error}"), + } +} + +pub fn stop_process() { + let pids = find_proc_by_name(MM2_BINARY); + if pids.is_empty() { + info!("Process not found: {MM2_BINARY}"); + } + pids.iter().map(u32::to_string).for_each(|pid| { + match Command::new(KILL_CMD) + .arg(&pid) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status() + { + Ok(status) => { + if status.success() { + info!("Process killed: {MM2_BINARY}:{pid}") + } else { + error!("Failed to kill process: {MM2_BINARY}:{pid}") + } + }, + Err(e) => error!("Failed to kill process: {MM2_BINARY}:{pid}. Error: {e}"), + }; + }); +} + +pub fn get_status() { + let pids = find_proc_by_name(MM2_BINARY); + if pids.is_empty() { + info!("Process not found: {MM2_BINARY}"); + } + pids.iter().map(u32::to_string).for_each(|pid| { + info!("Found {MM2_BINARY} is running, pid: {pid}"); + }); +} diff --git a/mm2src/adex_cli/src/scenarios/mod.rs b/mm2src/adex_cli/src/scenarios/mod.rs new file mode 100644 index 0000000000..2a9d637f01 --- /dev/null +++ b/mm2src/adex_cli/src/scenarios/mod.rs @@ -0,0 +1,16 @@ +mod helpers; +mod init_coins; +mod init_mm2_cfg; +mod inquire_extentions; +mod mm2_proc_mng; + +use init_coins::init_coins; +use init_mm2_cfg::init_mm2_cfg; +pub use mm2_proc_mng::{get_status, start_process, stop_process}; + +pub fn init(cfg_file: &str, coins_file: &str) { + if init_mm2_cfg(cfg_file).is_err() { + return; + } + let _ = init_coins(coins_file); +} diff --git a/mm2src/common/Cargo.toml b/mm2src/common/Cargo.toml index c71ef4d73d..f4a1ff5f4d 100644 --- a/mm2src/common/Cargo.toml +++ b/mm2src/common/Cargo.toml @@ -19,6 +19,7 @@ backtrace = "0.3" bytes = "1.1" cfg-if = "1.0" crossbeam = "0.7" +derive_more = "0.99" fnv = "1.0.6" futures01 = { version = "0.1", package = "futures" } futures = { version = "0.3", package = "futures", features = ["compat", "async-await", "thread-pool"] } @@ -32,7 +33,8 @@ log = "0.4.8" parking_lot = { version = "0.12.0", features = ["nightly"] } parking_lot_core = { version = "0.6", features = ["nightly"] } primitive-types = "0.11.1" -rand = { version = "0.7", features = ["std", "small_rng"] } +rand = { version = "0.7", features = ["std", "small_rng", "wasm-bindgen"] } +regex = "1" serde = "1" serde_derive = "1" serde_json = { version = "1", features = ["preserve_order", "raw_value"] } diff --git a/mm2src/common/common.rs b/mm2src/common/common.rs index 4f8cdcfcce..6b65bc7510 100644 --- a/mm2src/common/common.rs +++ b/mm2src/common/common.rs @@ -118,6 +118,7 @@ pub mod custom_futures; pub mod custom_iter; #[path = "executor/mod.rs"] pub mod executor; pub mod number_type_casting; +pub mod password_policy; pub mod seri; #[path = "patterns/state_machine.rs"] pub mod state_machine; pub mod time_cache; diff --git a/mm2src/common/password_policy.rs b/mm2src/common/password_policy.rs new file mode 100644 index 0000000000..5ffe3720eb --- /dev/null +++ b/mm2src/common/password_policy.rs @@ -0,0 +1,116 @@ +use derive_more::Display; +use regex::Regex; + +pub const PASSWORD_MAXIMUM_CONSECUTIVE_CHARACTERS: usize = 3; + +#[derive(Debug, Display, PartialEq)] +pub enum PasswordPolicyError { + #[display(fmt = "Password can't contain the word password")] + ContainsTheWordPassword, + #[display(fmt = "Password length should be at least 8 characters long")] + PasswordLength, + #[display(fmt = "Password should contain at least 1 digit")] + PasswordMissDigit, + #[display(fmt = "Password should contain at least 1 lowercase character")] + PasswordMissLowercase, + #[display(fmt = "Password should contain at least 1 uppercase character")] + PasswordMissUppercase, + #[display(fmt = "Password should contain at least 1 special character")] + PasswordMissSpecialCharacter, + #[display(fmt = "Password can't contain the same character 3 times in a row")] + PasswordConsecutiveCharactersExceeded, +} + +pub fn password_policy(password: &str) -> Result<(), PasswordPolicyError> { + lazy_static! { + static ref REGEX_NUMBER: Regex = Regex::new(".*[0-9].*").unwrap(); + static ref REGEX_LOWERCASE: Regex = Regex::new(".*[a-z].*").unwrap(); + static ref REGEX_UPPERCASE: Regex = Regex::new(".*[A-Z].*").unwrap(); + static ref REGEX_SPECIFIC_CHARS: Regex = Regex::new(".*[^A-Za-z0-9].*").unwrap(); + } + if password.to_lowercase().contains("password") { + return Err(PasswordPolicyError::ContainsTheWordPassword); + } + let password_len = password.chars().count(); + if (0..8).contains(&password_len) { + return Err(PasswordPolicyError::PasswordLength); + } + if !REGEX_NUMBER.is_match(password) { + return Err(PasswordPolicyError::PasswordMissDigit); + } + if !REGEX_LOWERCASE.is_match(password) { + return Err(PasswordPolicyError::PasswordMissLowercase); + } + if !REGEX_UPPERCASE.is_match(password) { + return Err(PasswordPolicyError::PasswordMissUppercase); + } + if !REGEX_SPECIFIC_CHARS.is_match(password) { + return Err(PasswordPolicyError::PasswordMissSpecialCharacter); + } + if !super::is_acceptable_input_on_repeated_characters(password, PASSWORD_MAXIMUM_CONSECUTIVE_CHARACTERS) { + return Err(PasswordPolicyError::PasswordConsecutiveCharactersExceeded); + } + Ok(()) +} + +#[test] +fn check_password_policy() { + use crate::password_policy::PasswordPolicyError; + // Length + assert_eq!( + password_policy("1234567").unwrap_err(), + PasswordPolicyError::PasswordLength + ); + + // Miss special character + assert_eq!( + password_policy("pass123worD").unwrap_err(), + PasswordPolicyError::PasswordMissSpecialCharacter + ); + + // Miss digit + assert_eq!( + password_policy("SecretPassSoStrong$*").unwrap_err(), + PasswordPolicyError::PasswordMissDigit + ); + + // Miss lowercase + assert_eq!( + password_policy("SECRETPASS-SOSTRONG123*").unwrap_err(), + PasswordPolicyError::PasswordMissLowercase + ); + + // Miss uppercase + assert_eq!( + password_policy("secretpass-sostrong123*").unwrap_err(), + PasswordPolicyError::PasswordMissUppercase + ); + + // Contains the same character 3 times in a row + assert_eq!( + password_policy("SecretPassSoStrong123*aaa").unwrap_err(), + PasswordPolicyError::PasswordConsecutiveCharactersExceeded + ); + + // Contains Password uppercase + assert_eq!( + password_policy("Password123*$").unwrap_err(), + PasswordPolicyError::ContainsTheWordPassword + ); + + // Contains Password lowercase + assert_eq!( + password_policy("Foopassword123*$").unwrap_err(), + PasswordPolicyError::ContainsTheWordPassword + ); + + // Check valid long password + let long_pass = "SecretPassSoStrong*!1234567891012"; + assert!(long_pass.len() > 32); + assert!(password_policy(long_pass).is_ok()); + + // Valid passwords + password_policy("StrongPass123*").unwrap(); + password_policy(r#"StrongPass123[]\± "#).unwrap(); + password_policy("StrongPass123£StrongPass123£Pass").unwrap(); +} diff --git a/mm2src/mm2_main/src/mm2.rs b/mm2src/mm2_main/src/mm2.rs index 2281cd11a9..e22b696a50 100644 --- a/mm2src/mm2_main/src/mm2.rs +++ b/mm2src/mm2_main/src/mm2.rs @@ -28,6 +28,7 @@ use common::crash_reports::init_crash_reports; use common::double_panic_crash; use common::log::LogLevel; +use common::password_policy::password_policy; use mm2_core::mm_ctx::MmCtxBuilder; #[cfg(feature = "custom-swap-locktime")] use common::log::warn; @@ -36,10 +37,7 @@ use lp_swap::PAYMENT_LOCKTIME; #[cfg(feature = "custom-swap-locktime")] use std::sync::atomic::Ordering; -use derive_more::Display; use gstuff::slurp; -use lazy_static::lazy_static; -use regex::Regex; use serde::ser::Serialize; use serde_json::{self as json, Value as Json}; @@ -99,117 +97,6 @@ impl LpMainParams { } } -#[derive(Debug, Display, PartialEq)] -pub enum PasswordPolicyError { - #[display(fmt = "Password can't contain the word password")] - ContainsTheWordPassword, - #[display(fmt = "Password length should be at least 8 characters long")] - PasswordLength, - #[display(fmt = "Password should contain at least 1 digit")] - PasswordMissDigit, - #[display(fmt = "Password should contain at least 1 lowercase character")] - PasswordMissLowercase, - #[display(fmt = "Password should contain at least 1 uppercase character")] - PasswordMissUppercase, - #[display(fmt = "Password should contain at least 1 special character")] - PasswordMissSpecialCharacter, - #[display(fmt = "Password can't contain the same character 3 times in a row")] - PasswordConsecutiveCharactersExceeded, -} - -pub fn password_policy(password: &str) -> Result<(), MmError> { - lazy_static! { - static ref REGEX_NUMBER: Regex = Regex::new(".*[0-9].*").unwrap(); - static ref REGEX_LOWERCASE: Regex = Regex::new(".*[a-z].*").unwrap(); - static ref REGEX_UPPERCASE: Regex = Regex::new(".*[A-Z].*").unwrap(); - static ref REGEX_SPECIFIC_CHARS: Regex = Regex::new(".*[^A-Za-z0-9].*").unwrap(); - } - if password.to_lowercase().contains("password") { - return MmError::err(PasswordPolicyError::ContainsTheWordPassword); - } - let password_len = password.chars().count(); - if (0..8).contains(&password_len) { - return MmError::err(PasswordPolicyError::PasswordLength); - } - if !REGEX_NUMBER.is_match(password) { - return MmError::err(PasswordPolicyError::PasswordMissDigit); - } - if !REGEX_LOWERCASE.is_match(password) { - return MmError::err(PasswordPolicyError::PasswordMissLowercase); - } - if !REGEX_UPPERCASE.is_match(password) { - return MmError::err(PasswordPolicyError::PasswordMissUppercase); - } - if !REGEX_SPECIFIC_CHARS.is_match(password) { - return MmError::err(PasswordPolicyError::PasswordMissSpecialCharacter); - } - if !common::is_acceptable_input_on_repeated_characters(password, PASSWORD_MAXIMUM_CONSECUTIVE_CHARACTERS) { - return MmError::err(PasswordPolicyError::PasswordConsecutiveCharactersExceeded); - } - Ok(()) -} - -#[test] -fn check_password_policy() { - // Length - assert_eq!( - password_policy("1234567").unwrap_err().into_inner(), - PasswordPolicyError::PasswordLength - ); - - // Miss special character - assert_eq!( - password_policy("pass123worD").unwrap_err().into_inner(), - PasswordPolicyError::PasswordMissSpecialCharacter - ); - - // Miss digit - assert_eq!( - password_policy("SecretPassSoStrong$*").unwrap_err().into_inner(), - PasswordPolicyError::PasswordMissDigit - ); - - // Miss lowercase - assert_eq!( - password_policy("SECRETPASS-SOSTRONG123*").unwrap_err().into_inner(), - PasswordPolicyError::PasswordMissLowercase - ); - - // Miss uppercase - assert_eq!( - password_policy("secretpass-sostrong123*").unwrap_err().into_inner(), - PasswordPolicyError::PasswordMissUppercase - ); - - // Contains the same character 3 times in a row - assert_eq!( - password_policy("SecretPassSoStrong123*aaa").unwrap_err().into_inner(), - PasswordPolicyError::PasswordConsecutiveCharactersExceeded - ); - - // Contains Password uppercase - assert_eq!( - password_policy("Password123*$").unwrap_err().into_inner(), - PasswordPolicyError::ContainsTheWordPassword - ); - - // Contains Password lowercase - assert_eq!( - password_policy("Foopassword123*$").unwrap_err().into_inner(), - PasswordPolicyError::ContainsTheWordPassword - ); - - // Check valid long password - let long_pass = "SecretPassSoStrong*!1234567891012"; - assert!(long_pass.len() > 32); - assert!(password_policy(long_pass).is_ok()); - - // Valid passwords - password_policy("StrongPass123*").unwrap(); - password_policy(r#"StrongPass123[]\± "#).unwrap(); - password_policy("StrongPass123£StrongPass123£Pass").unwrap(); -} - #[cfg(feature = "custom-swap-locktime")] /// Reads `payment_locktime` from conf arg and assigns it into `PAYMENT_LOCKTIME` in lp_swap. /// Assigns 900 if `payment_locktime` is invalid or not provided. From f480d2d74c274e76c6c4289185dc88d75d16d808 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Wed, 22 Mar 2023 13:51:35 +0500 Subject: [PATCH 02/90] CHANGELOG was changed --- CHANGELOG.md | 20 +- Cargo.lock | 546 +++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 480 insertions(+), 86 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0bd0f2b76..28f66f6863 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ +## Unreleased - 2023-##-## + +### **Features:** + +- `adex` command line utility was introduced that supplies commands: `init`, `start`, `stop`, `status` [#1682](https://github.com/KomodoPlatform/atomicDEX-API/issues/1682) + ## v1.0.1-beta - 2023-03-17 -**Features:** +### **Features:** + - NFT integration `WIP` [#900](https://github.com/KomodoPlatform/atomicDEX-API/issues/900) - NFT integration PoC added. Includes ERC721 support for ETH and BSC [#1652](https://github.com/KomodoPlatform/atomicDEX-API/pull/1652) - Swap watcher nodes [#1431](https://github.com/KomodoPlatform/atomicDEX-API/issues/1431) @@ -19,7 +26,8 @@ - If an invoice payment failed, retring paying the same invoice would cause the payment to not be updated to successful in the DB even if it were successful. A method to update the payment in the DB was added to fix this. - `mm2_git` crate was added to provide an abstraction layer on Git for doing query/parse operations over the repositories [#1636](https://github.com/KomodoPlatform/atomicDEX-API/pull/1636) -**Enhancements/Fixes:** +### **Enhancements/Fixes:** + - IndexedDB Cursor can now iterate over the items step-by-step [#1678](https://github.com/KomodoPlatform/atomicDEX-API/pull/1678) - Uuid lib was update from v0.7.4 to v1.2.2 in [#1655](https://github.com/KomodoPlatform/atomicDEX-API/pull/1655) - A bug was fixed in [#1706](https://github.com/KomodoPlatform/atomicDEX-API/pull/1706) where EVM swap transactions were failing if sent before the approval transaction confirmation. @@ -34,7 +42,8 @@ ## v1.0.0-beta - 2023-03-08 -**Features:** +### **Features:** + - ARRR integration [#927](https://github.com/KomodoPlatform/atomicDEX-API/issues/927): - Zcoin native mode support was added [#1438](https://github.com/KomodoPlatform/atomicDEX-API/pull/1438) - Multi lightwalletd servers support was added [#1472](https://github.com/KomodoPlatform/atomicDEX-API/pull/1472) @@ -85,8 +94,9 @@ - Refactor ETH/ERC20 withdraw taking into account that the only way to sign a transaction is to send it using `eth_sendTransaction` [#1674](https://github.com/KomodoPlatform/atomicDEX-API/pull/1674) - Extract address's public key using `eth_singTypedDataV4` [#1674](https://github.com/KomodoPlatform/atomicDEX-API/pull/1674) - Perform swaps with coins activated with MetaMask [#1674](https://github.com/KomodoPlatform/atomicDEX-API/pull/1674) - -**Enhancements/Fixes:** + +### **Enhancements/Fixes:** + - Update `rust-web3` crate [#1674](https://github.com/KomodoPlatform/atomicDEX-API/pull/1674) - Custom enum from stringify derive macro to derive From implementations for enums [#1502](https://github.com/KomodoPlatform/atomicDEX-API/pull/1502) - Validate that `input_tx` is calling `'receiverSpend'` in `eth::extract_secret` [#1596](https://github.com/KomodoPlatform/atomicDEX-API/pull/1596) diff --git a/Cargo.lock b/Cargo.lock index 69160476d0..d25bde9173 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,6 +21,25 @@ dependencies = [ "gimli", ] +[[package]] +name = "adex" +version = "0.1.0" +dependencies = [ + "clap 4.1.11", + "common", + "derive_more", + "fork", + "hyper", + "hyper-tls", + "inquire", + "log 0.4.14", + "log4rs", + "serde", + "serde_json", + "sysinfo", + "tokio", +] + [[package]] name = "adler" version = "0.2.2" @@ -231,7 +250,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -248,7 +267,7 @@ version = "0.1.52" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "061a7acccaa286c011ddc30970520b98fa40e00c9d644633fb26b5fc63a265e3" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -309,7 +328,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.14", "libc", "winapi", ] @@ -334,7 +353,7 @@ checksum = "acee9fd5073ab6b045a275b3e709c163dd36c90685219cb21804a147b58dba43" dependencies = [ "async-trait", "axum-core", - "bitflags", + "bitflags 1.3.2", "bytes 1.1.0", "futures-util", "http 0.2.7", @@ -543,6 +562,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "487f1e0fcbe47deb8b0574e646def1c903389d95241dd1bbcc6ce4a715dfc0c1" + [[package]] name = "bitvec" version = "0.18.5" @@ -725,7 +750,7 @@ dependencies = [ "borsh-derive-internal", "borsh-schema-derive-internal", "proc-macro-crate 0.1.5", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "syn 1.0.95", ] @@ -735,7 +760,7 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5449c28a7b352f2d1e592a8a28bf139bc71afb0764a14f3c02500935d8c44065" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -746,7 +771,7 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdbd5696d8bfa21d53d9fe39a714a18538bad11492a42d066dbbc395fb1951c0" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -803,7 +828,7 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e215f8c2f9f79cb53c8335e687ffd07d5bfcb6fe5fc80723762d0be46e7cc54" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -980,20 +1005,57 @@ checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" dependencies = [ "ansi_term", "atty", - "bitflags", - "strsim", + "bitflags 1.3.2", + "strsim 0.8.0", "textwrap", "unicode-width", "vec_map", ] +[[package]] +name = "clap" +version = "4.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42dfd32784433290c51d92c438bb72ea5063797fc3cc9a21a8c4346bebbb2098" +dependencies = [ + "bitflags 2.0.2", + "clap_derive", + "clap_lex", + "is-terminal", + "once_cell", + "strsim 0.10.0", + "termcolor", +] + +[[package]] +name = "clap_derive" +version = "4.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fddf67631444a3a3e3e5ac51c36a5e01335302de677bd78759eaa90ab1f46644" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2 1.0.52", + "quote 1.0.18", + "syn 1.0.95", +] + +[[package]] +name = "clap_lex" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "033f6b7a4acb1f358c742aaca805c939ee73b4c6209ae4318ec7aca81c42e646" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "cloudabi" version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -1002,7 +1064,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4344512281c643ae7638bbabc3af17a11307803ec8f0fcad9fae512a8bf36467" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -1181,6 +1243,7 @@ dependencies = [ "cfg-if 1.0.0", "chrono", "crossbeam", + "derive_more", "findshlibs", "fnv", "futures 0.1.29", @@ -1204,6 +1267,7 @@ dependencies = [ "parking_lot_core 0.6.2", "primitive-types", "rand 0.7.3", + "regex", "ser_error", "ser_error_derive", "serde", @@ -1285,6 +1349,16 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.3" @@ -1475,6 +1549,31 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "crossterm" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" +dependencies = [ + "bitflags 1.3.2", + "crossterm_winapi", + "libc", + "mio", + "parking_lot 0.12.0", + "signal-hook", + "signal-hook-mio", + "winapi", +] + +[[package]] +name = "crossterm_winapi" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c" +dependencies = [ + "winapi", +] + [[package]] name = "crunchy" version = "0.2.2" @@ -1686,7 +1785,7 @@ dependencies = [ "cc", "codespan-reporting", "lazy_static", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "scratch", "syn 1.0.95", @@ -1704,7 +1803,7 @@ version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b846f081361125bfc8dc9d3940c84e1fd83ba54bbca7b17cd29483c828be0704" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -1778,7 +1877,7 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -1789,7 +1888,7 @@ version = "0.99.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cb0e6161ad61ed084a36ba71fbba9e3ac5aee3606fb607fe08da6acbcf3d8c" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -1931,6 +2030,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5caaa75cbd2b960ff1e5392d2cfb1f44717fffe12fc1f32b7b5d1267f99732a6" +[[package]] +name = "dyn-clone" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b0cf012f1230e43cd00ebb729c6bb58707ecfa8ad08b52ef3a4ccd2697fc30" + [[package]] name = "ecdsa" version = "0.13.4" @@ -2049,7 +2154,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21cdad81446a7f7dc43f6a77409efeb9733d2fa65553efef6018ef257c959b73" dependencies = [ "heck", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -2070,7 +2175,7 @@ name = "enum_from" version = "0.1.0" dependencies = [ "itertools", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -2232,7 +2337,7 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", "synstructure", @@ -2361,6 +2466,30 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "fork" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaf4b001d25ec51f755157ecffa208b342747ea9a4365df5438b12925c7f0056" +dependencies = [ + "libc", +] + [[package]] name = "form_urlencoded" version = "1.0.1" @@ -2479,7 +2608,7 @@ version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -2772,6 +2901,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "hex" version = "0.3.2" @@ -3027,6 +3162,19 @@ dependencies = [ "tokio-io-timeout", ] +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes 1.1.0", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "iana-time-zone" version = "0.1.53" @@ -3105,7 +3253,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5dacb10c5b3bb92d46ba347505a9041e676bb20ad220101326bffb0c93031ee" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -3144,6 +3292,22 @@ dependencies = [ "regex", ] +[[package]] +name = "inquire" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd079157ad94a32f7511b2e13037f3ae417ad80a6a9b0de29154d48b86f5d6c8" +dependencies = [ + "bitflags 1.3.2", + "crossterm", + "dyn-clone", + "lazy_static", + "newline-converter", + "thiserror", + "unicode-segmentation", + "unicode-width", +] + [[package]] name = "instant" version = "0.1.12" @@ -3156,6 +3320,17 @@ dependencies = [ "web-sys", ] +[[package]] +name = "io-lifetimes" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09270fd4fa1111bc614ed2246c7ef56239a3063d5be0d1ec3b589c505d400aeb" +dependencies = [ + "hermit-abi 0.3.1", + "libc", + "windows-sys 0.45.0", +] + [[package]] name = "iovec" version = "0.1.4" @@ -3183,6 +3358,18 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" +[[package]] +name = "is-terminal" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8687c819457e979cc940d09cb16e42a1bf70aa6b60a549de6d3a62a0ee90c69e" +dependencies = [ + "hermit-abi 0.3.1", + "io-lifetimes", + "rustix", + "windows-sys 0.45.0", +] + [[package]] name = "itertools" version = "0.10.3" @@ -3340,7 +3527,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe" dependencies = [ "arrayvec 0.5.1", - "bitflags", + "bitflags 1.3.2", "cfg-if 1.0.0", "ryu", "static_assertions", @@ -3348,9 +3535,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.126" +version = "0.2.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" [[package]] name = "libloading" @@ -3856,6 +4043,12 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a" +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + [[package]] name = "lock_api" version = "0.4.6" @@ -4043,7 +4236,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49e30813093f757be5cf21e50389a24dc7dbb22c49f23b7e8f51d69b508a5ffa" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -4523,7 +4716,7 @@ version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3048ef3680533a27f9f8e7d6a0bce44dc61e4895ea0f42709337fa1c8616fefe" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -4567,7 +4760,7 @@ checksum = "fc076939022111618a5026d3be019fd8b366e76314538ff9a1b59ffbcbf98bcd" dependencies = [ "proc-macro-crate 1.1.3", "proc-macro-error", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", "synstructure", @@ -4592,6 +4785,33 @@ dependencies = [ "unsigned-varint 0.7.1", ] +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log 0.4.14", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "newline-converter" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f71d09d5c87634207f894c6b31b6a2b2c64ea3bdcf71bd5599fdbbe1600c00f" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "nibble_vec" version = "0.1.0" @@ -4607,7 +4827,7 @@ version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cc", "cfg-if 1.0.0", "libc", @@ -4633,6 +4853,15 @@ dependencies = [ "version_check", ] +[[package]] +name = "ntapi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc51db7b362b205941f71232e56c625156eb9a929f8cf74a428fd5bc094a4afc" +dependencies = [ + "winapi", +] + [[package]] name = "num-bigint" version = "0.3.2" @@ -4662,7 +4891,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -4705,7 +4934,7 @@ version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.14", "libc", ] @@ -4726,7 +4955,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "486ea01961c4a818096de679a8b740b26d9033146ac5291b1c98557658f8cdd9" dependencies = [ "proc-macro-crate 1.1.3", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -4773,6 +5002,51 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "openssl" +version = "0.10.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b277f87dacc05a6b709965d1cbafac4649d6ce9f3ce9ceb88508b5666dfec9" +dependencies = [ + "bitflags 1.3.2", + "cfg-if 1.0.0", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +dependencies = [ + "proc-macro2 1.0.52", + "quote 1.0.18", + "syn 1.0.95", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a95792af3c4e0153c3914df2261bedd30a98476f94dc892b67dfe1d89d433a04" +dependencies = [ + "autocfg 1.1.0", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "ordered-float" version = "2.10.0" @@ -4782,6 +5056,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "os_str_bytes" +version = "6.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" + [[package]] name = "ouroboros" version = "0.13.0" @@ -4801,7 +5081,7 @@ checksum = "44a0b52c2cbaef7dffa5fec1a43274afe8bd2a644fa9fc50a9ef4ff0269b1257" dependencies = [ "Inflector", "proc-macro-error", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -4858,7 +5138,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c45ed1f39709f5a89338fab50e59816b2e8815f5bb58276e7ddf9afd495f73f8" dependencies = [ "proc-macro-crate 1.1.3", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -4893,7 +5173,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f557c32c6d268a07c921471619c0295f5efad3a0e76d4f97a05c091a51d110b2" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "syn 1.0.95", "synstructure", ] @@ -5009,7 +5289,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5aa52829b8decbef693af90202711348ab001456803ba2a98eb4ec8fb70844c" dependencies = [ "peg-runtime", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", ] @@ -5059,7 +5339,7 @@ version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "044964427019eed9d49d9d5bbce6047ef18f37100ea400912a9fa4a3523ab12a" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -5070,7 +5350,7 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "744b6f092ba29c3650faf274db506afd39944f48420f6c86b17cfe0ee1cb36bb" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -5145,7 +5425,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f28f53e8b192565862cf99343194579a022eb9c7dd3a8d03134734803c7b3125" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "syn 1.0.95", ] @@ -5199,7 +5479,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", "version_check", @@ -5211,7 +5491,7 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "version_check", ] @@ -5233,9 +5513,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.39" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" dependencies = [ "unicode-ident", ] @@ -5258,7 +5538,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8e12d01b9d66ad9eb4529c57666b6263fc1993cb30261d83ead658fdd932652" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -5303,7 +5583,7 @@ checksum = "7b670f45da57fb8542ebdbb6105a925fe571b67f9e7ed9f47a06a84e72b4e7cc" dependencies = [ "anyhow", "itertools", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -5418,7 +5698,7 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", ] [[package]] @@ -5675,7 +5955,7 @@ version = "10.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c49596760fce12ca21550ac21dc5a9617b2ea4b6e0aa7d8dab8ff2824fc2bba" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -5724,7 +6004,7 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -5763,7 +6043,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c523ccaed8ac4b0288948849a350b37d3035827413c458b6a40ddb614bb4f72" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -5968,7 +6248,7 @@ version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5f38ee71cbab2c827ec0ac24e76f82eca723cee92c509a65f67dee393c25112" dependencies = [ - "bitflags", + "bitflags 1.3.2", "fallible-iterator", "fallible-streaming-iterator", "hashlink", @@ -6032,6 +6312,20 @@ dependencies = [ "semver 1.0.6", ] +[[package]] +name = "rustix" +version = "0.36.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db4165c9963ab29e422d6c26fbc1d37f15bace6b2810221f9d925023480fcf0e" +dependencies = [ + "bitflags 1.3.2", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys 0.45.0", +] + [[package]] name = "rustls" version = "0.19.1" @@ -6125,11 +6419,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50e334bb10a245e28e5fd755cabcafd96cfcd167c99ae63a46924ca8d8703a3c" dependencies = [ "proc-macro-crate 1.1.3", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] +[[package]] +name = "schannel" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +dependencies = [ + "windows-sys 0.42.0", +] + [[package]] name = "scoped-tls" version = "1.0.0" @@ -6242,6 +6545,29 @@ dependencies = [ "zeroize", ] +[[package]] +name = "security-framework" +version = "2.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "0.9.0" @@ -6280,7 +6606,7 @@ dependencies = [ name = "ser_error_derive" version = "0.1.0" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "ser_error", "syn 1.0.95", @@ -6321,7 +6647,7 @@ version = "1.0.136" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -6344,7 +6670,7 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dc6b7951b17b051f3210b063f12cc17320e2fe30ae05b0fe2a3abb068551c76" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -6476,6 +6802,27 @@ dependencies = [ "log 0.4.14", ] +[[package]] +name = "signal-hook" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "732768f1176d21d09e076c23a93123d40bba92d50c4058da34d45c8de8e682b9" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-mio" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" +dependencies = [ + "libc", + "mio", + "signal-hook", +] + [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -6689,7 +7036,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8417a89c377728dbfbf1966b6493544f6e5e168ebc5bb444f3526481fae94e31" dependencies = [ "chrono", - "clap", + "clap 2.33.3", "rpassword", "solana-perf", "solana-remote-wallet", @@ -6723,7 +7070,7 @@ dependencies = [ "base64 0.13.0", "bincode", "bs58", - "clap", + "clap 2.33.3", "indicatif", "jsonrpc-core", "log 0.4.14", @@ -6780,7 +7127,7 @@ checksum = "7a11e1b6d5ce435bb3df95f2a970cd80500a8abf94ea87558c35fe0cce8456ab" dependencies = [ "bincode", "byteorder 1.4.3", - "clap", + "clap 2.33.3", "log 0.4.14", "serde", "serde_derive", @@ -6821,7 +7168,7 @@ version = "1.9.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "402fffb54bf5d335e6df26fc1719feecfbd7a22fafdf6649fe78380de3c47384" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "rustc_version 0.4.0", "syn 1.0.95", @@ -6869,7 +7216,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cb530af085d8aab563530ed39703096aa526249d350082823882fdd59cdf839" dependencies = [ "bincode", - "clap", + "clap 2.33.3", "log 0.4.14", "nix", "rand 0.7.3", @@ -6920,7 +7267,7 @@ checksum = "0a463f546a2f5842d35974bd4691ae5ceded6785ec24db440f773723f6ce4e11" dependencies = [ "base64 0.13.0", "bincode", - "bitflags", + "bitflags 1.3.2", "blake3", "borsh", "borsh-derive", @@ -7074,7 +7421,7 @@ dependencies = [ "assert_matches", "base64 0.13.0", "bincode", - "bitflags", + "bitflags 1.3.2", "borsh", "bs58", "bytemuck", @@ -7123,7 +7470,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c834b4e02ac911b13c13aed08b3f847e722f6be79d31b1c660c1dbd2dee83cdb" dependencies = [ "bs58", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "rustversion", "syn 1.0.95", @@ -7222,7 +7569,7 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77963e2aa8fadb589118c3aede2e78b6c4bcf1c01d588fbf33e915b390825fbd" dependencies = [ - "bitflags", + "bitflags 1.3.2", "byteorder 1.4.3", "hash-db", "hash256-std-hasher", @@ -7247,7 +7594,7 @@ version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d676664972e22a0796176e81e7bec41df461d1edf52090955cdab55f2c956ff2" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -7277,7 +7624,7 @@ checksum = "22ecb916b9664ed9f90abef0ff5a3e61454c1efea5861b2997e03f39b59b955f" dependencies = [ "Inflector", "proc-macro-crate 1.1.3", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -7425,7 +7772,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f9799e6d412271cb2414597581128b03f3285f260ea49f5363d07df6a332b3e" dependencies = [ "Inflector", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "serde", "serde_json", @@ -7473,7 +7820,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "serde", "serde_derive", @@ -7487,7 +7834,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" dependencies = [ "base-x", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "serde", "serde_derive", @@ -7508,6 +7855,12 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "subtle" version = "1.0.0" @@ -7563,7 +7916,7 @@ version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "unicode-ident", ] @@ -7589,12 +7942,27 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", "unicode-xid 0.2.0", ] +[[package]] +name = "sysinfo" +version = "0.28.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f69e0d827cce279e61c2f3399eb789271a8f136d8245edef70f06e3c9601a670" +dependencies = [ + "cfg-if 1.0.0", + "core-foundation-sys", + "libc", + "ntapi", + "once_cell", + "rayon", + "winapi", +] + [[package]] name = "tap" version = "1.0.1" @@ -7809,9 +8177,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" dependencies = [ "winapi-util", ] @@ -7874,7 +8242,7 @@ version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -7949,7 +8317,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" dependencies = [ "proc-macro-hack", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "standback", "syn 1.0.95", @@ -8053,11 +8421,21 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.23.2" @@ -8146,7 +8524,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9263bf4c9bfaae7317c1c2faf7f18491d2fe476f70c414b73bf5d445b00ffa1" dependencies = [ "prettyplease", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "prost-build", "quote 1.0.18", "syn 1.0.95", @@ -8178,7 +8556,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d342c6d58709c0a6d48d48dabbb62d4ef955cf5f0f3bbfd845838e7ae88dbae" dependencies = [ - "bitflags", + "bitflags 1.3.2", "bytes 1.1.0", "futures-core", "futures-util", @@ -8222,7 +8600,7 @@ version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e65ce065b4b5c53e73bb28912318cb8c9e9ad3921f1d669eb0e68b4c8143a2b" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", ] @@ -8420,6 +8798,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + [[package]] name = "unicode-width" version = "0.1.9" @@ -8643,7 +9027,7 @@ dependencies = [ "bumpalo", "lazy_static", "log 0.4.14", - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", "wasm-bindgen-shared", @@ -8677,7 +9061,7 @@ version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", "wasm-bindgen-backend", @@ -8710,7 +9094,7 @@ version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c2e18093f11c19ca4e188c177fecc7c372304c311189f12c2f9bea5b7324ac7" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", ] @@ -9169,7 +9553,7 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f8f187641dad4f680d25c4bfc4225b418165984179f26ca76ec4fb6441d3a17" dependencies = [ - "proc-macro2 1.0.39", + "proc-macro2 1.0.52", "quote 1.0.18", "syn 1.0.95", "synstructure", From 8ffaf33af9a5946e04af31769873897956d79d21 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Thu, 23 Mar 2023 14:09:01 +0500 Subject: [PATCH 03/90] CHANGELOG header style changed --- CHANGELOG.md | 10 ++-- mm2src/adex_cli/Cargo.toml | 7 ++- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 55 +++++++++++++++++-- 3 files changed, 60 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28f66f6863..72c90ea1a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,12 @@ ## Unreleased - 2023-##-## -### **Features:** +### Features: - `adex` command line utility was introduced that supplies commands: `init`, `start`, `stop`, `status` [#1682](https://github.com/KomodoPlatform/atomicDEX-API/issues/1682) ## v1.0.1-beta - 2023-03-17 -### **Features:** +### Features: - NFT integration `WIP` [#900](https://github.com/KomodoPlatform/atomicDEX-API/issues/900) - NFT integration PoC added. Includes ERC721 support for ETH and BSC [#1652](https://github.com/KomodoPlatform/atomicDEX-API/pull/1652) @@ -26,7 +26,7 @@ - If an invoice payment failed, retring paying the same invoice would cause the payment to not be updated to successful in the DB even if it were successful. A method to update the payment in the DB was added to fix this. - `mm2_git` crate was added to provide an abstraction layer on Git for doing query/parse operations over the repositories [#1636](https://github.com/KomodoPlatform/atomicDEX-API/pull/1636) -### **Enhancements/Fixes:** +### Enhancements/Fixes: - IndexedDB Cursor can now iterate over the items step-by-step [#1678](https://github.com/KomodoPlatform/atomicDEX-API/pull/1678) - Uuid lib was update from v0.7.4 to v1.2.2 in [#1655](https://github.com/KomodoPlatform/atomicDEX-API/pull/1655) @@ -42,7 +42,7 @@ ## v1.0.0-beta - 2023-03-08 -### **Features:** +### Features: - ARRR integration [#927](https://github.com/KomodoPlatform/atomicDEX-API/issues/927): - Zcoin native mode support was added [#1438](https://github.com/KomodoPlatform/atomicDEX-API/pull/1438) @@ -95,7 +95,7 @@ - Extract address's public key using `eth_singTypedDataV4` [#1674](https://github.com/KomodoPlatform/atomicDEX-API/pull/1674) - Perform swaps with coins activated with MetaMask [#1674](https://github.com/KomodoPlatform/atomicDEX-API/pull/1674) -### **Enhancements/Fixes:** +### Enhancements/Fixes: - Update `rust-web3` crate [#1674](https://github.com/KomodoPlatform/atomicDEX-API/pull/1674) - Custom enum from stringify derive macro to derive From implementations for enums [#1502](https://github.com/KomodoPlatform/atomicDEX-API/pull/1502) diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index 417ed9738f..8f17f01e82 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -9,7 +9,6 @@ edition = "2021" clap = { version = "4.1", features = ["derive"] } common = { path = "../common" } derive_more = "0.99" -fork = "0.1" inquire = "0.6" log = "0.4" log4rs = { version = "1.0", default-features = false, features = ["console_appender", "pattern_encoder"] } @@ -19,3 +18,9 @@ sysinfo = "0.28" tokio = { version = "1.20" } hyper = { version = "0.14", features = ["http2", "client", "runtime", "tcp"] } hyper-tls = "0.5" + +[target.'cfg(not(windows))'.dependencies] +fork = "0.1" + +[target.'cfg(windows)'.dependencies] +create_process_w = { version = "0.1.0", package = "CreateProcessW" } diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 3465afac05..5015a41de3 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -1,7 +1,9 @@ -use fork::{daemon, Fork}; +#[cfg(windows)] use create_process_w::Command; +#[cfg(unix)] use fork::{daemon, Fork}; use log::{error, info}; +use std::ffi::OsStr; use std::path::PathBuf; -use std::process::{Command, Stdio}; +#[cfg(unix)] use std::process::{Command, Stdio}; use std::{env, u32}; use sysinfo::{PidExt, ProcessExt, System, SystemExt}; @@ -18,7 +20,7 @@ fn find_proc_by_name(pname: &'_ str) -> Vec { .collect() } -fn get_mm2_binary_dir() -> Result { +fn get_mm2_binary_path() -> Result { let mut dir = env::current_exe().map_err(|error| { error!("Failed to get current binary dir: {error}"); })?; @@ -27,13 +29,14 @@ fn get_mm2_binary_dir() -> Result { Ok(dir) } +#[cfg(unix)] pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, log_file: &Option) { - let mm2_binary = match get_mm2_binary_dir() { + let mm2_binary = match get_mm2_binary_path() { Err(_) => return, Ok(path) => path, }; - let mut command = Command::new(mm2_binary); + let mut command = Command::new(&mm2_binary); if let Some(mm2_cfg_file) = mm2_cfg_file { info!("Set env MM_CONF_PATH as: {mm2_cfg_file}"); command.env("MM_CONF_PATH", mm2_cfg_file); @@ -47,7 +50,9 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, command.env("MM_LOG", log_file); } - let program = command.get_program(); + let program = mm2_binary + .file_name() + .map_or("Undefined", |name: &OsStr| name.to_str().unwrap_or("Undefined")); match daemon(true, true) { Ok(Fork::Child) => { command.output().expect("failed to execute process"); @@ -59,6 +64,41 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, } } +#[cfg(windows)] +pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, log_file: &Option) { + // let mm2_binary = match get_mm2_binary_path() { + // Err(_) => return, + // Ok(path) => path, + // }; + + //let mut command = Command::new(&mm2_binary); + // + // if let Some(mm2_cfg_file) = mm2_cfg_file { + // info!("Set env MM_CONF_PATH as: {mm2_cfg_file}"); + // std::env::set_var("MM_CONF_PATH", mm2_cfg_file); + // } + // if let Some(coins_file) = coins_file { + // info!("Set env MM_COINS_PATH as: {coins_file}"); + // std::env::set_var("MM_COINS_PATH", coins_file); + // } + // if let Some(log_file) = log_file { + // info!("Set env MM_LOG as: {log_file}"); + // std::env::set_var("MM_LOG", log_file); + // } + // let program = mm2_binary + // .file_name() + // .map_or("Undefined", |name: &OsStr| name.to_str().unwrap_or("Undefined")); + // + // match command.spawn() { + // Err(error) => error!("Failed to start: {program}, error: {error}"), + // Ok(child) => { + // let pid = child.id(); + // info!("Successfully started: {program}, forked pid: {pid}"); + // }, + // } +} + +#[cfg(unix)] pub fn stop_process() { let pids = find_proc_by_name(MM2_BINARY); if pids.is_empty() { @@ -83,6 +123,9 @@ pub fn stop_process() { }); } +#[cfg(windows)] +pub fn stop_process() { unimplemented!() } + pub fn get_status() { let pids = find_proc_by_name(MM2_BINARY); if pids.is_empty() { From 78961394f9375cefec367bb4ceb5601d965caf8c Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Thu, 23 Mar 2023 22:42:45 +0500 Subject: [PATCH 04/90] Use winapi crate to manage mm2 process --- Cargo.lock | 1 + mm2src/adex_cli/Cargo.toml | 2 +- mm2src/adex_cli/src/cli.rs | 20 +-- mm2src/adex_cli/src/log.rs | 2 +- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 139 +++++++++++------- mm2src/common/build.rs | 3 +- 6 files changed, 103 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d25bde9173..0479d25094 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,6 +38,7 @@ dependencies = [ "serde_json", "sysinfo", "tokio", + "winapi", ] [[package]] diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index 8f17f01e82..a067dc2662 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -23,4 +23,4 @@ hyper-tls = "0.5" fork = "0.1" [target.'cfg(windows)'.dependencies] -create_process_w = { version = "0.1.0", package = "CreateProcessW" } +winapi = { version = "0.3.3", features = ["processthreadsapi", "winnt"] } diff --git a/mm2src/adex_cli/src/cli.rs b/mm2src/adex_cli/src/cli.rs index 44f653796f..54fa0bd864 100644 --- a/mm2src/adex_cli/src/cli.rs +++ b/mm2src/adex_cli/src/cli.rs @@ -7,18 +7,18 @@ enum Command { #[command(about = "Initialize predefined mm2 coin set and configuration")] Init { #[arg(long, help = "coin set file path", default_value = "coins")] - coins_file: String, + mm_coins_path: String, #[arg(long, help = "mm2 configuration file path", default_value = "MM2.json")] - mm2_cfg_file: String, + mm_conf_path: String, }, #[command(about = "Start mm2 service")] Start { #[arg(long, help = "mm2 configuration file path")] - mm2_cfg_file: Option, + mm_conf_path: Option, #[arg(long, help = "coin set file path")] - coins_file: Option, + mm_coins_path: Option, #[arg(long, help = "log file path")] - log_file: Option, + mm_log: Option, }, #[command(about = "Stop mm2 service")] Stop, @@ -38,13 +38,13 @@ impl Cli { let parsed_cli = Self::parse(); match &parsed_cli.command { Command::Init { - coins_file, - mm2_cfg_file, + mm_coins_path: coins_file, + mm_conf_path: mm2_cfg_file, } => init(mm2_cfg_file, coins_file), Command::Start { - mm2_cfg_file, - coins_file, - log_file, + mm_conf_path: mm2_cfg_file, + mm_coins_path: coins_file, + mm_log: log_file, } => start_process(mm2_cfg_file, coins_file, log_file), Command::Stop => stop_process(), Command::Status => get_status(), diff --git a/mm2src/adex_cli/src/log.rs b/mm2src/adex_cli/src/log.rs index 3643454d61..5598a06ae4 100644 --- a/mm2src/adex_cli/src/log.rs +++ b/mm2src/adex_cli/src/log.rs @@ -4,7 +4,7 @@ use log4rs::{append::console::ConsoleAppender, encode::pattern::PatternEncoder, Config}; -const REDUCED_LOG_FORMAT: &str = "{l}: {m}{n}"; +const REDUCED_LOG_FORMAT: &str = "{m}{n}"; pub fn init_logging() { let stdout = ConsoleAppender::builder() diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 5015a41de3..d70aa4ea78 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -1,14 +1,42 @@ -#[cfg(windows)] use create_process_w::Command; -#[cfg(unix)] use fork::{daemon, Fork}; use log::{error, info}; -use std::ffi::OsStr; use std::path::PathBuf; -#[cfg(unix)] use std::process::{Command, Stdio}; use std::{env, u32}; use sysinfo::{PidExt, ProcessExt, System, SystemExt}; -const MM2_BINARY: &str = "mm2"; -const KILL_CMD: &str = "kill"; +#[cfg(windows)] +mod reexport { + pub use std::ffi::CString; + pub use std::mem; + pub use std::mem::size_of; + pub use std::ptr::null; + pub use winapi::um::processthreadsapi::{CreateProcessA, OpenProcess, TerminateProcess, PROCESS_INFORMATION, + STARTUPINFOA}; + pub use winapi::um::winnt::{PROCESS_TERMINATE, SYNCHRONIZE}; + + pub const MM2_BINARY: &str = "mm2.exe"; +} + +#[cfg(unix)] +mod reexport { + pub use fork::{daemon, Fork}; + pub use std::ffi::OsStr; + pub use std::process::{Command, Stdio}; + + pub const MM2_BINARY: &str = "mm2"; + pub const KILL_CMD: &str = "kill"; +} + +use reexport::*; + +pub fn get_status() { + let pids = find_proc_by_name(MM2_BINARY); + if pids.is_empty() { + info!("Process not found: {MM2_BINARY}"); + } + pids.iter().map(u32::to_string).for_each(|pid| { + info!("Found {MM2_BINARY} is running, pid: {pid}"); + }); +} fn find_proc_by_name(pname: &'_ str) -> Vec { let s = System::new_all(); @@ -29,30 +57,34 @@ fn get_mm2_binary_path() -> Result { Ok(dir) } -#[cfg(unix)] pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, log_file: &Option) { let mm2_binary = match get_mm2_binary_path() { Err(_) => return, Ok(path) => path, }; - let mut command = Command::new(&mm2_binary); if let Some(mm2_cfg_file) = mm2_cfg_file { info!("Set env MM_CONF_PATH as: {mm2_cfg_file}"); - command.env("MM_CONF_PATH", mm2_cfg_file); + env::set_var("MM_CONF_PATH", mm2_cfg_file); } if let Some(coins_file) = coins_file { info!("Set env MM_COINS_PATH as: {coins_file}"); - command.env("MM_COINS_PATH", coins_file); + env::set_var("MM_COINS_PATH", coins_file); } if let Some(log_file) = log_file { info!("Set env MM_LOG as: {log_file}"); - command.env("MM_LOG", log_file); + env::set_var("MM_LOG", log_file); } + start_process_impl(mm2_binary); +} +#[cfg(unix)] +pub fn start_process_impl(mm2_binary: PathBuf) { + let mut command = Command::new(&mm2_binary); let program = mm2_binary .file_name() .map_or("Undefined", |name: &OsStr| name.to_str().unwrap_or("Undefined")); + match daemon(true, true) { Ok(Fork::Child) => { command.output().expect("failed to execute process"); @@ -65,37 +97,43 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, } #[cfg(windows)] -pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, log_file: &Option) { - // let mm2_binary = match get_mm2_binary_path() { - // Err(_) => return, - // Ok(path) => path, - // }; - - //let mut command = Command::new(&mm2_binary); - // - // if let Some(mm2_cfg_file) = mm2_cfg_file { - // info!("Set env MM_CONF_PATH as: {mm2_cfg_file}"); - // std::env::set_var("MM_CONF_PATH", mm2_cfg_file); - // } - // if let Some(coins_file) = coins_file { - // info!("Set env MM_COINS_PATH as: {coins_file}"); - // std::env::set_var("MM_COINS_PATH", coins_file); - // } - // if let Some(log_file) = log_file { - // info!("Set env MM_LOG as: {log_file}"); - // std::env::set_var("MM_LOG", log_file); - // } - // let program = mm2_binary - // .file_name() - // .map_or("Undefined", |name: &OsStr| name.to_str().unwrap_or("Undefined")); - // - // match command.spawn() { - // Err(error) => error!("Failed to start: {program}, error: {error}"), - // Ok(child) => { - // let pid = child.id(); - // info!("Successfully started: {program}, forked pid: {pid}"); - // }, - // } +pub fn start_process_impl(mm2_binary: PathBuf) { + let program = mm2_binary.to_str(); + if program.is_none() { + error!("Failed to cast mm2_binary to &str"); + return; + } + let program = CString::new(program.unwrap()); + if let Err(error) = program { + error!("Failed to construct CString program path: {error}"); + return; + } + + let mut startup_info: STARTUPINFOA = unsafe { mem::zeroed() }; + startup_info.cb = size_of::() as u32; + let mut process_info: PROCESS_INFORMATION = unsafe { mem::zeroed() }; + + let result = unsafe { + CreateProcessA( + null(), + program.unwrap().into_raw() as *mut i8, + std::ptr::null_mut(), + std::ptr::null_mut(), + 0, + 0, + std::ptr::null_mut(), + std::ptr::null(), + &mut startup_info as &mut STARTUPINFOA, + &mut process_info as *mut PROCESS_INFORMATION, + ) + }; + + match result { + 0 => error!("Failed to start: {MM2_BINARY}"), + _ => { + info!("Successfully started: {MM2_BINARY}"); + }, + } } #[cfg(unix)] @@ -124,14 +162,13 @@ pub fn stop_process() { } #[cfg(windows)] -pub fn stop_process() { unimplemented!() } - -pub fn get_status() { - let pids = find_proc_by_name(MM2_BINARY); - if pids.is_empty() { - info!("Process not found: {MM2_BINARY}"); +pub fn stop_process() { + let processes = find_proc_by_name(MM2_BINARY); + for pid in processes { + info!("Terminate process: {}", pid); + unsafe { + let handy = OpenProcess(SYNCHRONIZE | PROCESS_TERMINATE, true as i32, pid); + TerminateProcess(handy, 1); + } } - pids.iter().map(u32::to_string).for_each(|pid| { - info!("Found {MM2_BINARY} is running, pid: {pid}"); - }); } diff --git a/mm2src/common/build.rs b/mm2src/common/build.rs index 2850c0141a..0230591b5b 100644 --- a/mm2src/common/build.rs +++ b/mm2src/common/build.rs @@ -83,7 +83,8 @@ fn build_c_code() { return; } - if cfg!(windows) { + let target_os = var("CARGO_CFG_TARGET_FAMILY").expect("!CARGO_CFG_TARGET_FAMILY"); + if target_os == "windows" { // Link in the Windows-specific crash handling code. let lm_seh = last_modified_sec(&"seh.c").expect("Can't stat seh.c"); let out_dir = var("OUT_DIR").expect("!OUT_DIR"); From 59f0621ad78567b3f933d146d0a990366b6d9bc6 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Thu, 23 Mar 2023 23:46:26 +0500 Subject: [PATCH 05/90] rollback changes --- mm2src/common/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/common/Cargo.toml b/mm2src/common/Cargo.toml index f4a1ff5f4d..0fd1c6cd13 100644 --- a/mm2src/common/Cargo.toml +++ b/mm2src/common/Cargo.toml @@ -33,7 +33,7 @@ log = "0.4.8" parking_lot = { version = "0.12.0", features = ["nightly"] } parking_lot_core = { version = "0.6", features = ["nightly"] } primitive-types = "0.11.1" -rand = { version = "0.7", features = ["std", "small_rng", "wasm-bindgen"] } +rand = { version = "0.7", features = ["std", "small_rng"] } regex = "1" serde = "1" serde_derive = "1" From 4355e729494650e85fb6ed5fa5d9b3e4471a9c14 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 24 Mar 2023 09:31:49 +0500 Subject: [PATCH 06/90] use common::log proxy instead of log --- mm2src/adex_cli/src/log.rs | 2 +- mm2src/adex_cli/src/scenarios/helpers.rs | 2 +- mm2src/adex_cli/src/scenarios/init_coins.rs | 2 +- mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs | 2 +- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mm2src/adex_cli/src/log.rs b/mm2src/adex_cli/src/log.rs index 5598a06ae4..78c91ed023 100644 --- a/mm2src/adex_cli/src/log.rs +++ b/mm2src/adex_cli/src/log.rs @@ -1,4 +1,4 @@ -use log::LevelFilter; +use common::log::LevelFilter; use log4rs::{append::console::ConsoleAppender, config::{Appender, Root}, encode::pattern::PatternEncoder, diff --git a/mm2src/adex_cli/src/scenarios/helpers.rs b/mm2src/adex_cli/src/scenarios/helpers.rs index da190a102a..2282bf4b36 100644 --- a/mm2src/adex_cli/src/scenarios/helpers.rs +++ b/mm2src/adex_cli/src/scenarios/helpers.rs @@ -1,4 +1,4 @@ -use log::error; +use common::log::error; use serde::Serialize; use std::fs::OpenOptions; use std::io::Write; diff --git a/mm2src/adex_cli/src/scenarios/init_coins.rs b/mm2src/adex_cli/src/scenarios/init_coins.rs index 8eae93020a..ca9144beb8 100644 --- a/mm2src/adex_cli/src/scenarios/init_coins.rs +++ b/mm2src/adex_cli/src/scenarios/init_coins.rs @@ -1,7 +1,7 @@ +use common::log::{error, info}; use derive_more::Display; use hyper::{body::Bytes, client::Client, Uri}; use hyper_tls::HttpsConnector; -use log::{error, info}; use super::helpers::rewrite_data_file; diff --git a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs index b5f4677b33..6206a79a8d 100644 --- a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs +++ b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs @@ -1,5 +1,5 @@ +use common::log::{error, info}; use inquire::{validator::Validation, Confirm, CustomType, CustomUserError, Password, Text}; -use log::{error, info}; use serde::Serialize; use std::net::Ipv4Addr; use std::ops::Not; diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index d70aa4ea78..58febc9bd6 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -1,4 +1,4 @@ -use log::{error, info}; +use common::log::{error, info}; use std::path::PathBuf; use std::{env, u32}; use sysinfo::{PidExt, ProcessExt, System, SystemExt}; From 117a3f24f06b5ff3dda3187c438de96a6de10f96 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 24 Mar 2023 11:36:04 +0500 Subject: [PATCH 07/90] Get rid of log4rs --- Cargo.lock | 2 +- mm2src/adex_cli/Cargo.toml | 2 +- mm2src/adex_cli/src/log.rs | 22 +++++++--------------- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0479d25094..bbdbf0ed1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,12 +28,12 @@ dependencies = [ "clap 4.1.11", "common", "derive_more", + "env_logger 0.7.1", "fork", "hyper", "hyper-tls", "inquire", "log 0.4.14", - "log4rs", "serde", "serde_json", "sysinfo", diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index a067dc2662..cc3e980c93 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -9,9 +9,9 @@ edition = "2021" clap = { version = "4.1", features = ["derive"] } common = { path = "../common" } derive_more = "0.99" +env_logger = "0.7.1" inquire = "0.6" log = "0.4" -log4rs = { version = "1.0", default-features = false, features = ["console_appender", "pattern_encoder"] } serde = "1.0" serde_json = { version = "1", features = ["preserve_order", "raw_value"] } sysinfo = "0.28" diff --git a/mm2src/adex_cli/src/log.rs b/mm2src/adex_cli/src/log.rs index 78c91ed023..15b76a7918 100644 --- a/mm2src/adex_cli/src/log.rs +++ b/mm2src/adex_cli/src/log.rs @@ -1,18 +1,10 @@ -use common::log::LevelFilter; -use log4rs::{append::console::ConsoleAppender, - config::{Appender, Root}, - encode::pattern::PatternEncoder, - Config}; - -const REDUCED_LOG_FORMAT: &str = "{m}{n}"; +use env_logger; +use log::LevelFilter; +use std::io::Write; pub fn init_logging() { - let stdout = ConsoleAppender::builder() - .encoder(Box::new(PatternEncoder::new(REDUCED_LOG_FORMAT))) - .build(); - let config = Config::builder() - .appender(Appender::builder().build("stdout", Box::new(stdout))) - .build(Root::builder().appender("stdout").build(LevelFilter::Info)) - .expect("Failed to build log4rs config"); - log4rs::init_config(config).expect("Failed to init log4rs config"); + env_logger::builder() + .format(|buf, record| writeln!(buf, "{}", record.args())) + .filter_level(LevelFilter::Info) + .init(); } From e890d94a0fd7bfd17d33988ae4248650740f3ef2 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 24 Mar 2023 12:24:35 +0500 Subject: [PATCH 08/90] Spit on init_coins and polish --- mm2src/adex_cli/src/scenarios/init_coins.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/init_coins.rs b/mm2src/adex_cli/src/scenarios/init_coins.rs index ca9144beb8..86497d7c35 100644 --- a/mm2src/adex_cli/src/scenarios/init_coins.rs +++ b/mm2src/adex_cli/src/scenarios/init_coins.rs @@ -5,9 +5,6 @@ use hyper_tls::HttpsConnector; use super::helpers::rewrite_data_file; -const FULL_COIN_SET_ADDRESS: &str = "https://raw.githubusercontent.com/KomodoPlatform/coins/master/coins"; -const EMPTY_COIN_SET_DATA: &str = r"[]\n"; - #[derive(Clone, Copy, Debug, Display)] pub enum CoinSet { Empty, @@ -16,16 +13,15 @@ pub enum CoinSet { #[tokio::main(flavor = "current_thread")] pub async fn init_coins(coins_file: &str) -> Result<(), ()> { + const FULL_COIN_SET_ADDRESS: &str = "https://raw.githubusercontent.com/KomodoPlatform/coins/master/coins"; + const EMPTY_COIN_SET_DATA: Vec = Vec::new(); let coin_set = inquire_coin_set(coins_file)?; info!("Start getting mm2 coins"); - - let bytes_got; let coins_data = match coin_set { - CoinSet::Empty => EMPTY_COIN_SET_DATA.as_bytes(), + CoinSet::Empty => EMPTY_COIN_SET_DATA, CoinSet::Full => { info!("Getting coin set from: {FULL_COIN_SET_ADDRESS}"); - bytes_got = get_coins_from_remote(FULL_COIN_SET_ADDRESS).await?; - bytes_got.as_ref() + get_coins_from_remote(FULL_COIN_SET_ADDRESS).await?.to_vec() }, }; From abafc9bcccfc6e41c3cece9f478384faaad64d44 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 24 Mar 2023 12:45:00 +0500 Subject: [PATCH 09/90] Get rid of hyper --- Cargo.lock | 146 +------------------- mm2src/adex_cli/Cargo.toml | 3 +- mm2src/adex_cli/src/scenarios/init_coins.rs | 21 +-- 3 files changed, 8 insertions(+), 162 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bbdbf0ed1d..bdb8625ff4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,10 +30,9 @@ dependencies = [ "derive_more", "env_logger 0.7.1", "fork", - "hyper", - "hyper-tls", "inquire", "log 0.4.14", + "mm2_net", "serde", "serde_json", "sysinfo", @@ -1350,16 +1349,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" -[[package]] -name = "core-foundation" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "core-foundation-sys" version = "0.8.3" @@ -2467,21 +2456,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "fork" version = "0.1.21" @@ -3163,19 +3137,6 @@ dependencies = [ "tokio-io-timeout", ] -[[package]] -name = "hyper-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" -dependencies = [ - "bytes 1.1.0", - "hyper", - "native-tls", - "tokio", - "tokio-native-tls", -] - [[package]] name = "iana-time-zone" version = "0.1.53" @@ -4786,24 +4747,6 @@ dependencies = [ "unsigned-varint 0.7.1", ] -[[package]] -name = "native-tls" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" -dependencies = [ - "lazy_static", - "libc", - "log 0.4.14", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "newline-converter" version = "0.2.2" @@ -5003,51 +4946,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" -[[package]] -name = "openssl" -version = "0.10.47" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b277f87dacc05a6b709965d1cbafac4649d6ce9f3ce9ceb88508b5666dfec9" -dependencies = [ - "bitflags 1.3.2", - "cfg-if 1.0.0", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" -dependencies = [ - "proc-macro2 1.0.52", - "quote 1.0.18", - "syn 1.0.95", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a95792af3c4e0153c3914df2261bedd30a98476f94dc892b67dfe1d89d433a04" -dependencies = [ - "autocfg 1.1.0", - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "ordered-float" version = "2.10.0" @@ -6425,15 +6323,6 @@ dependencies = [ "syn 1.0.95", ] -[[package]] -name = "schannel" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" -dependencies = [ - "windows-sys 0.42.0", -] - [[package]] name = "scoped-tls" version = "1.0.0" @@ -6546,29 +6435,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "security-framework" -version = "2.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "semver" version = "0.9.0" @@ -8427,16 +8293,6 @@ dependencies = [ "syn 1.0.95", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.23.2" diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index cc3e980c93..fd643a035f 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -16,8 +16,7 @@ serde = "1.0" serde_json = { version = "1", features = ["preserve_order", "raw_value"] } sysinfo = "0.28" tokio = { version = "1.20" } -hyper = { version = "0.14", features = ["http2", "client", "runtime", "tcp"] } -hyper-tls = "0.5" +mm2_net = { path = "../mm2_net" } [target.'cfg(not(windows))'.dependencies] fork = "0.1" diff --git a/mm2src/adex_cli/src/scenarios/init_coins.rs b/mm2src/adex_cli/src/scenarios/init_coins.rs index 86497d7c35..0ed8f5b6c4 100644 --- a/mm2src/adex_cli/src/scenarios/init_coins.rs +++ b/mm2src/adex_cli/src/scenarios/init_coins.rs @@ -1,7 +1,6 @@ use common::log::{error, info}; use derive_more::Display; -use hyper::{body::Bytes, client::Client, Uri}; -use hyper_tls::HttpsConnector; +use mm2_net::transport::slurp_url; use super::helpers::rewrite_data_file; @@ -21,7 +20,11 @@ pub async fn init_coins(coins_file: &str) -> Result<(), ()> { CoinSet::Empty => EMPTY_COIN_SET_DATA, CoinSet::Full => { info!("Getting coin set from: {FULL_COIN_SET_ADDRESS}"); - get_coins_from_remote(FULL_COIN_SET_ADDRESS).await?.to_vec() + let (_status_code, _headers, data) = slurp_url(FULL_COIN_SET_ADDRESS).await.map_err(|error| { + error!("Failed to get coin set from: {FULL_COIN_SET_ADDRESS}, error: {error}"); + () + })?; + data }, }; @@ -41,15 +44,3 @@ fn inquire_coin_set(coins_file: &str) -> Result { error!("Failed to select coin_set: {error}"); }) } - -async fn get_coins_from_remote(address: &'static str) -> Result { - let connector = HttpsConnector::new(); - let client = Client::builder().build::<_, hyper::Body>(connector); - let coins_data = client.get(Uri::from_static(address)).await.map_err(|error| { - error!("Failed to get coins from {address}: {error}"); - })?; - - hyper::body::to_bytes(coins_data).await.map_err(|error| { - error!("Failed to get bytes from response: {error}"); - }) -} From ae4808c9216a9fe55b75a3cd60fc3f78cd7d4570 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 24 Mar 2023 12:53:00 +0500 Subject: [PATCH 10/90] Spit and polish --- mm2src/adex_cli/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index fd643a035f..4d17aab7f8 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -12,11 +12,11 @@ derive_more = "0.99" env_logger = "0.7.1" inquire = "0.6" log = "0.4" +mm2_net = { path = "../mm2_net" } serde = "1.0" serde_json = { version = "1", features = ["preserve_order", "raw_value"] } sysinfo = "0.28" tokio = { version = "1.20" } -mm2_net = { path = "../mm2_net" } [target.'cfg(not(windows))'.dependencies] fork = "0.1" From 4ef0f6fb6b828e52e9b6b181f9673018971840aa Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 24 Mar 2023 13:12:48 +0500 Subject: [PATCH 11/90] Spit on init_log and polish --- mm2src/adex_cli/src/log.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mm2src/adex_cli/src/log.rs b/mm2src/adex_cli/src/log.rs index 15b76a7918..5ae8388ae8 100644 --- a/mm2src/adex_cli/src/log.rs +++ b/mm2src/adex_cli/src/log.rs @@ -3,8 +3,12 @@ use log::LevelFilter; use std::io::Write; pub fn init_logging() { - env_logger::builder() - .format(|buf, record| writeln!(buf, "{}", record.args())) - .filter_level(LevelFilter::Info) - .init(); + let mut builder = env_logger::builder(); + let level = std::env::var("RUST_LOG") + .map(|s| s.parse().unwrap_or(LevelFilter::Info)) + .unwrap_or(LevelFilter::Info); + builder + .filter_level(level) + .format(|buf, record| writeln!(buf, "{}", record.args())); + builder.init(); } From 7de4766946602099ec0a13f1e6b14f0278a54348 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 24 Mar 2023 15:19:05 +0500 Subject: [PATCH 12/90] spit and polish --- Cargo.lock | 41 +++++++++++++++ mm2src/adex_cli/Cargo.toml | 1 + mm2src/adex_cli/src/log.rs | 1 - mm2src/adex_cli/src/scenarios/init_coins.rs | 1 - mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs | 52 ++++++++++++++----- mm2src/mm2_main/src/mm2.rs | 2 +- 6 files changed, 82 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 36c6cf48ad..4f7065f472 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,6 +33,7 @@ dependencies = [ "inquire", "log 0.4.14", "mm2_net", + "passwords", "serde", "serde_json", "sysinfo", @@ -5163,6 +5164,15 @@ dependencies = [ "windows-sys 0.32.0", ] +[[package]] +name = "passwords" +version = "3.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d5e617847054b49f5b1ce93cea78a88fc269ef9210afdbca660c1e5c973212f" +dependencies = [ + "random-pick", +] + [[package]] name = "paste" version = "1.0.7" @@ -5864,6 +5874,37 @@ dependencies = [ "rand_core 0.3.1", ] +[[package]] +name = "random-number" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a3da5cbb4c27c5150c03a54a7e4745437cd90f9e329ae657c0b889a144bb7be" +dependencies = [ + "proc-macro-hack", + "rand 0.8.4", + "random-number-macro-impl", +] + +[[package]] +name = "random-number-macro-impl" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99f50024fe705be34d953ca47f4617ce3a665caa1011f14a48e6a8a6ec911f0f" +dependencies = [ + "proc-macro-hack", + "quote 1.0.26", + "syn 1.0.95", +] + +[[package]] +name = "random-pick" +version = "1.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c179499072da789afe44127d5f4aa6012de2c2f96ef759990196b37387a2a0f8" +dependencies = [ + "random-number", +] + [[package]] name = "raw-cpuid" version = "10.4.0" diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index 4d17aab7f8..65ded3e208 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -13,6 +13,7 @@ env_logger = "0.7.1" inquire = "0.6" log = "0.4" mm2_net = { path = "../mm2_net" } +passwords = "3.1" serde = "1.0" serde_json = { version = "1", features = ["preserve_order", "raw_value"] } sysinfo = "0.28" diff --git a/mm2src/adex_cli/src/log.rs b/mm2src/adex_cli/src/log.rs index 5ae8388ae8..f853dc8a86 100644 --- a/mm2src/adex_cli/src/log.rs +++ b/mm2src/adex_cli/src/log.rs @@ -1,4 +1,3 @@ -use env_logger; use log::LevelFilter; use std::io::Write; diff --git a/mm2src/adex_cli/src/scenarios/init_coins.rs b/mm2src/adex_cli/src/scenarios/init_coins.rs index 0ed8f5b6c4..cf891fb2a4 100644 --- a/mm2src/adex_cli/src/scenarios/init_coins.rs +++ b/mm2src/adex_cli/src/scenarios/init_coins.rs @@ -22,7 +22,6 @@ pub async fn init_coins(coins_file: &str) -> Result<(), ()> { info!("Getting coin set from: {FULL_COIN_SET_ADDRESS}"); let (_status_code, _headers, data) = slurp_url(FULL_COIN_SET_ADDRESS).await.map_err(|error| { error!("Failed to get coin set from: {FULL_COIN_SET_ADDRESS}, error: {error}"); - () })?; data }, diff --git a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs index 6206a79a8d..62882c6ced 100644 --- a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs +++ b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs @@ -1,5 +1,6 @@ use common::log::{error, info}; -use inquire::{validator::Validation, Confirm, CustomType, CustomUserError, Password, Text}; +use inquire::{validator::Validation, Confirm, CustomType, CustomUserError, Text}; +use passwords::PasswordGenerator; use serde::Serialize; use std::net::Ipv4Addr; use std::ops::Not; @@ -72,8 +73,8 @@ impl Mm2Cfg { self.inquire_gui()?; self.inquire_net_id()?; self.inquire_passphrase()?; - self.inquire_rpc_password()?; self.inquire_allow_weak_password()?; + self.inquire_rpc_password()?; self.inquire_userhome()?; self.inquire_dbdir()?; self.inquire_rpcip()?; @@ -138,8 +139,10 @@ impl Mm2Cfg { } fn inquire_passphrase(&mut self) -> Result<(), ()> { - self.passphrase = Password::new("What is the passphrase:") - .with_validator(Self::pwd_validator) + let default_password = Self::generate_password()?; + self.passphrase = Text::new("What is the passphrase:") + .with_default(default_password.as_str()) + .with_placeholder(default_password.as_str()) .with_help_message("Your passphrase; this is the source of each of your coins private keys. KEEP IT SAFE!") .prompt() .map_err(|error| { @@ -150,9 +153,24 @@ impl Mm2Cfg { } fn inquire_rpc_password(&mut self) -> Result<(), ()> { - self.rpc_password = Password::new("What is the rpc_password:") - .with_validator(Self::pwd_validator) + let allow_weak_password = self.allow_weak_password; + let validator = move |password: &str| { + if let Some(false) = allow_weak_password { + match password_policy::password_policy(password) { + Err(error) => Ok(Validation::Invalid(error.into())), + Ok(_) => Ok(Validation::Valid), + } + } else { + Ok(Validation::Valid) + } + }; + let default_password = Self::generate_password()?; + + self.rpc_password = Text::new("What is the rpc_password:") .with_help_message("Your password for protected RPC methods (userpass)") + .with_validator(validator) + .with_default(default_password.as_str()) + .with_placeholder(default_password.as_str()) .prompt() .map_err(|error| { error!("Failed to get rpc_password: {error}"); @@ -161,6 +179,21 @@ impl Mm2Cfg { Ok(()) } + fn generate_password() -> Result { + let pg = PasswordGenerator { + length: 8, + numbers: true, + lowercase_letters: true, + uppercase_letters: true, + symbols: true, + spaces: false, + exclude_similar_characters: false, + strict: true, + }; + pg.generate_one() + .map_err(|error| error!("Failed to generate password: {error}")) + } + fn inquire_allow_weak_password(&mut self) -> Result<(), ()> { self.allow_weak_password = Confirm::new("Allow weak password:") .with_default(false) @@ -174,13 +207,6 @@ impl Mm2Cfg { Ok(()) } - fn pwd_validator(pwd: &str) -> Result { - match password_policy::password_policy(pwd) { - Err(error) => Ok(Validation::Invalid(error.into())), - Ok(_) => Ok(Validation::Valid), - } - } - fn inquire_userhome(&mut self) -> Result<(), ()> { self.userhome = CustomType::>::new("What is userhome:") .with_placeholder(DEFAULT_OPTION_PLACEHOLDER) diff --git a/mm2src/mm2_main/src/mm2.rs b/mm2src/mm2_main/src/mm2.rs index e22b696a50..7f0f079892 100644 --- a/mm2src/mm2_main/src/mm2.rs +++ b/mm2src/mm2_main/src/mm2.rs @@ -140,7 +140,7 @@ pub async fn lp_main( if !is_weak_password_accepted && cfg!(not(test)) { match password_policy(conf["rpc_password"].as_str().unwrap()) { Ok(_) => {}, - Err(err) => return Err(format!("{}", err)), + Err(err) => return Err(format!("rpc_password error: {}", err)), } } } From fa0747b5c1f45c6c40cebe5c22b142d5f8204c20 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 24 Mar 2023 16:13:19 +0500 Subject: [PATCH 13/90] spit and polish --- mm2src/adex_cli/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index 65ded3e208..8729df8ab1 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = { version = "4.1", features = ["derive"] } +clap = { version = "2.33.3", features = ["derive"] } common = { path = "../common" } derive_more = "0.99" env_logger = "0.7.1" From 7ffff62cc59202e32dc1c24daa703aab7ab04540 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 24 Mar 2023 17:10:48 +0500 Subject: [PATCH 14/90] spit and polish --- mm2src/adex_cli/src/log.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/adex_cli/src/log.rs b/mm2src/adex_cli/src/log.rs index f853dc8a86..60ffb13180 100644 --- a/mm2src/adex_cli/src/log.rs +++ b/mm2src/adex_cli/src/log.rs @@ -4,7 +4,7 @@ use std::io::Write; pub fn init_logging() { let mut builder = env_logger::builder(); let level = std::env::var("RUST_LOG") - .map(|s| s.parse().unwrap_or(LevelFilter::Info)) + .map(|s| s.parse().expect("Failed to parse RUST_LOG")) .unwrap_or(LevelFilter::Info); builder .filter_level(level) From d536767e51f59cd20a56b322c95f19749394179a Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 24 Mar 2023 17:32:23 +0500 Subject: [PATCH 15/90] roll back cli --- mm2src/adex_cli/Cargo.toml | 2 +- mm2src/adex_cli/src/cli.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index 8729df8ab1..65ded3e208 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = { version = "2.33.3", features = ["derive"] } +clap = { version = "4.1", features = ["derive"] } common = { path = "../common" } derive_more = "0.99" env_logger = "0.7.1" diff --git a/mm2src/adex_cli/src/cli.rs b/mm2src/adex_cli/src/cli.rs index 54fa0bd864..0a93b8f133 100644 --- a/mm2src/adex_cli/src/cli.rs +++ b/mm2src/adex_cli/src/cli.rs @@ -1,4 +1,4 @@ -use clap::{Parser, Subcommand}; +use clap::{App, AppSettings, Arg, SubCommand}; use crate::scenarios::{get_status, init, start_process, stop_process}; From 6ea0ce988cbc24d119c41cd1ea6310a6edbd7c5a Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 24 Mar 2023 17:35:26 +0500 Subject: [PATCH 16/90] roll back cli --- mm2src/adex_cli/src/cli.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/adex_cli/src/cli.rs b/mm2src/adex_cli/src/cli.rs index 0a93b8f133..54fa0bd864 100644 --- a/mm2src/adex_cli/src/cli.rs +++ b/mm2src/adex_cli/src/cli.rs @@ -1,4 +1,4 @@ -use clap::{App, AppSettings, Arg, SubCommand}; +use clap::{Parser, Subcommand}; use crate::scenarios::{get_status, init, start_process, stop_process}; From e0bab197a5dd677f54eb467f6603feeb04d8286f Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 24 Mar 2023 22:59:27 +0500 Subject: [PATCH 17/90] squash changes --- Cargo.lock | 107 ++---------- mm2src/adex_cli/Cargo.toml | 7 +- mm2src/adex_cli/src/cli.rs | 122 +++++++++---- mm2src/adex_cli/src/main.rs | 2 +- mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs | 160 +++++++++--------- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 29 ++-- 6 files changed, 206 insertions(+), 221 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6c5fb76546..9056adf055 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,10 +22,10 @@ dependencies = [ ] [[package]] -name = "adex" +name = "adex-cli" version = "0.1.0" dependencies = [ - "clap 4.1.13", + "clap", "common", "derive_more", "env_logger 0.7.1", @@ -162,9 +162,9 @@ dependencies = [ [[package]] name = "ansi_term" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" dependencies = [ "winapi", ] @@ -329,7 +329,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi 0.1.14", + "hermit-abi", "libc", "winapi", ] @@ -994,55 +994,19 @@ dependencies = [ [[package]] name = "clap" -version = "2.33.3" +version = "2.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "ansi_term", "atty", "bitflags", - "strsim 0.8.0", + "strsim", "textwrap", "unicode-width", "vec_map", ] -[[package]] -name = "clap" -version = "4.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c911b090850d79fc64fe9ea01e28e465f65e821e08813ced95bced72f7a8a9b" -dependencies = [ - "bitflags", - "clap_derive", - "clap_lex", - "is-terminal", - "once_cell", - "strsim 0.10.0", - "termcolor", -] - -[[package]] -name = "clap_derive" -version = "4.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a932373bab67b984c790ddf2c9ca295d8e3af3b7ef92de5a5bacdccdee4b09b" -dependencies = [ - "heck", - "proc-macro2 1.0.53", - "quote 1.0.26", - "syn 2.0.8", -] - -[[package]] -name = "clap_lex" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "033f6b7a4acb1f358c742aaca805c939ee73b4c6209ae4318ec7aca81c42e646" -dependencies = [ - "os_str_bytes", -] - [[package]] name = "cloudabi" version = "0.0.3" @@ -2894,12 +2858,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hermit-abi" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" - [[package]] name = "hex" version = "0.3.2" @@ -3337,18 +3295,6 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" -[[package]] -name = "is-terminal" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8687c819457e979cc940d09cb16e42a1bf70aa6b60a549de6d3a62a0ee90c69e" -dependencies = [ - "hermit-abi 0.3.1", - "io-lifetimes", - "rustix", - "windows-sys 0.45.0", -] - [[package]] name = "itertools" version = "0.10.3" @@ -4896,7 +4842,7 @@ version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" dependencies = [ - "hermit-abi 0.1.14", + "hermit-abi", "libc", ] @@ -4973,12 +4919,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "os_str_bytes" -version = "6.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" - [[package]] name = "ouroboros" version = "0.13.0" @@ -6952,7 +6892,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8417a89c377728dbfbf1966b6493544f6e5e168ebc5bb444f3526481fae94e31" dependencies = [ "chrono", - "clap 2.33.3", + "clap", "rpassword", "solana-perf", "solana-remote-wallet", @@ -6986,7 +6926,7 @@ dependencies = [ "base64 0.13.0", "bincode", "bs58", - "clap 2.33.3", + "clap", "indicatif", "jsonrpc-core", "log 0.4.14", @@ -7043,7 +6983,7 @@ checksum = "7a11e1b6d5ce435bb3df95f2a970cd80500a8abf94ea87558c35fe0cce8456ab" dependencies = [ "bincode", "byteorder 1.4.3", - "clap 2.33.3", + "clap", "log 0.4.14", "serde", "serde_derive", @@ -7132,7 +7072,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cb530af085d8aab563530ed39703096aa526249d350082823882fdd59cdf839" dependencies = [ "bincode", - "clap 2.33.3", + "clap", "log 0.4.14", "nix", "rand 0.7.3", @@ -7771,12 +7711,6 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - [[package]] name = "subtle" version = "1.0.0" @@ -7837,17 +7771,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "syn" -version = "2.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc02725fd69ab9f26eab07fad303e2497fad6fb9eba4f96c4d1687bdf704ad9" -dependencies = [ - "proc-macro2 1.0.53", - "quote 1.0.26", - "unicode-ident", -] - [[package]] name = "sync_wrapper" version = "0.1.1" @@ -7877,9 +7800,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.28.3" +version = "0.28.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f69e0d827cce279e61c2f3399eb789271a8f136d8245edef70f06e3c9601a670" +checksum = "b4c2f3ca6693feb29a89724516f016488e9aafc7f37264f898593ee4b942f31b" dependencies = [ "cfg-if 1.0.0", "core-foundation-sys", diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index 65ded3e208..aaa768f081 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -1,12 +1,13 @@ [package] -name = "adex" +name = "adex-cli" version = "0.1.0" edition = "2021" - +authors = ["Rozhkov Dmitrii "] +description = "Provides a CLI interface and facilitates interoperating to komodo atomic dex throught the mm2 service" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = { version = "4.1", features = ["derive"] } +clap = "2.33.3" common = { path = "../common" } derive_more = "0.99" env_logger = "0.7.1" diff --git a/mm2src/adex_cli/src/cli.rs b/mm2src/adex_cli/src/cli.rs index 54fa0bd864..2135674cf6 100644 --- a/mm2src/adex_cli/src/cli.rs +++ b/mm2src/adex_cli/src/cli.rs @@ -1,53 +1,113 @@ -use clap::{Parser, Subcommand}; +use clap::{App, Arg, SubCommand}; +use log::error; +use std::env; use crate::scenarios::{get_status, init, start_process, stop_process}; -#[derive(Subcommand)] enum Command { - #[command(about = "Initialize predefined mm2 coin set and configuration")] Init { - #[arg(long, help = "coin set file path", default_value = "coins")] mm_coins_path: String, - #[arg(long, help = "mm2 configuration file path", default_value = "MM2.json")] mm_conf_path: String, }, - #[command(about = "Start mm2 service")] Start { - #[arg(long, help = "mm2 configuration file path")] mm_conf_path: Option, - #[arg(long, help = "coin set file path")] mm_coins_path: Option, - #[arg(long, help = "log file path")] mm_log: Option, }, - #[command(about = "Stop mm2 service")] Stop, - #[command(about = "Get mm2 running status")] Status, } -#[derive(Parser)] -#[clap(author, version, about, long_about = None)] -pub struct Cli { - #[command(subcommand)] - command: Command, -} +pub fn process_cli() { + let mut app = App::new(env!("CARGO_PKG_NAME")) + .version(env!("CARGO_PKG_VERSION")) + .author(env!("CARGO_PKG_AUTHORS")) + .about(env!("CARGO_PKG_DESCRIPTION")) + .subcommand( + SubCommand::with_name("init") + .about("Initialize predefined mm2 coin set and configuration") + .arg( + Arg::with_name("mm-coins-path") + .long("mm-coins-path") + .value_name("FILE") + .help("coin set file path") + .default_value("coins"), + ) + .arg( + Arg::with_name("mm-conf-path") + .long("mm-conf-path") + .value_name("FILE") + .help("mm2 configuration file path") + .default_value("MM2.json"), + ), + ) + .subcommand( + SubCommand::with_name("start") + .about("Start mm2 service") + .arg( + Arg::with_name("mm-conf-path") + .long("mm-conf-path") + .value_name("FILE") + .help("mm2 configuration file path"), + ) + .arg( + Arg::with_name("mm-coins-path") + .long("mm-coins-path") + .value_name("FILE") + .help("coin set file path"), + ) + .arg( + Arg::with_name("mm-log") + .long("mm-log") + .value_name("FILE") + .help("log file path"), + ), + ) + .subcommand(SubCommand::with_name("stop").about("Stop mm2 service")) + .subcommand(SubCommand::with_name("status").about("Get mm2 running status")); + + let matches = app.clone().get_matches(); -impl Cli { - pub fn execute() { - let parsed_cli = Self::parse(); - match &parsed_cli.command { + let command = match matches.subcommand() { + ("init", Some(init_matches)) => { + let mm_coins_path = init_matches.value_of("mm-coins-path").unwrap_or("coins").to_owned(); + let mm_conf_path = init_matches.value_of("mm-conf-path").unwrap_or("MM2.json").to_owned(); Command::Init { - mm_coins_path: coins_file, - mm_conf_path: mm2_cfg_file, - } => init(mm2_cfg_file, coins_file), + mm_coins_path, + mm_conf_path, + } + }, + ("start", Some(start_matches)) => { + let mm_conf_path = start_matches.value_of("mm-conf-path").map(|s| s.to_owned()); + let mm_coins_path = start_matches.value_of("mm-coins-path").map(|s| s.to_owned()); + let mm_log = start_matches.value_of("mm-log").map(|s| s.to_owned()); Command::Start { - mm_conf_path: mm2_cfg_file, - mm_coins_path: coins_file, - mm_log: log_file, - } => start_process(mm2_cfg_file, coins_file, log_file), - Command::Stop => stop_process(), - Command::Status => get_status(), - } + mm_conf_path, + mm_coins_path, + mm_log, + } + }, + ("stop", _) => Command::Stop, + ("status", _) => Command::Status, + _ => { + let _ = app + .print_long_help() + .map_err(|error| error!("Failed to print_long_help: {error}")); + return; + }, + }; + + match command { + Command::Init { + mm_coins_path: coins_file, + mm_conf_path: mm2_cfg_file, + } => init(&mm2_cfg_file, &coins_file), + Command::Start { + mm_conf_path: mm2_cfg_file, + mm_coins_path: coins_file, + mm_log: log_file, + } => start_process(&mm2_cfg_file, &coins_file, &log_file), + Command::Stop => stop_process(), + Command::Status => get_status(), } } diff --git a/mm2src/adex_cli/src/main.rs b/mm2src/adex_cli/src/main.rs index 5d17edbf58..7feae23a61 100644 --- a/mm2src/adex_cli/src/main.rs +++ b/mm2src/adex_cli/src/main.rs @@ -4,5 +4,5 @@ mod scenarios; fn main() { log::init_logging(); - cli::Cli::execute(); + cli::process_cli(); } diff --git a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs index 62882c6ced..bb4bf10e4b 100644 --- a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs +++ b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs @@ -14,6 +14,8 @@ use common::password_policy; const DEFAULT_NET_ID: u16 = 7777; const DEFAULT_GID: &str = concat!("QA CLI ", env!("CARGO_PKG_VERSION")); const DEFAULT_OPTION_PLACEHOLDER: &str = "Tap enter to skip"; +const RPC_PORT_MIN: u16 = 1024; +const RPC_PORT_MAX: u16 = 49151; pub fn init_mm2_cfg(cfg_file: &str) -> Result<(), ()> { let mut mm2_cfg = Mm2Cfg::new(); @@ -33,8 +35,6 @@ pub struct Mm2Cfg { pub passphrase: Option, pub allow_weak_password: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub userhome: Option, - #[serde(skip_serializing_if = "Option::is_none")] pub dbdir: Option, #[serde(skip_serializing_if = "Option::is_none")] pub rpcip: Option, @@ -58,7 +58,6 @@ impl Mm2Cfg { rpc_password: None, passphrase: None, allow_weak_password: None, - userhome: None, dbdir: None, rpcip: None, rpcport: None, @@ -75,7 +74,6 @@ impl Mm2Cfg { self.inquire_passphrase()?; self.inquire_allow_weak_password()?; self.inquire_rpc_password()?; - self.inquire_userhome()?; self.inquire_dbdir()?; self.inquire_rpcip()?; self.inquire_rpcport()?; @@ -103,38 +101,38 @@ impl Mm2Cfg { }; self.dbdir = CustomType::>::new("What is dbdir") - .with_placeholder(DEFAULT_OPTION_PLACEHOLDER) - .with_help_message("AtomicDEX API database path. Optional, defaults to a subfolder named DB in the path of your mm2 binary") - .with_validator(is_reachable_dir) - .prompt() - .map_err(|error| { - error!("Failed to get dbdir: {error}"); - })?.into(); + .with_placeholder(DEFAULT_OPTION_PLACEHOLDER) + .with_help_message("AtomicDEX API database path. Optional, defaults to a subfolder named DB in the path of your mm2 binary") + .with_validator(is_reachable_dir) + .prompt() + .map_err(|error| { + error!("Failed to get dbdir: {error}"); + })?.into(); Ok(()) } fn inquire_gui(&mut self) -> Result<(), ()> { self.gui = Text::new("What is the client identifier, gui:") - .with_default(DEFAULT_GID) - .with_placeholder(DEFAULT_GID) - .with_help_message("Information about your GUI; place essential info about your application (name, version, etc.) here. For example: AtomicDEX iOS 1.0.1") - .prompt() - .map_err(|error| { - error!("Failed to get gui: {error}"); - })?.into(); + .with_default(DEFAULT_GID) + .with_placeholder(DEFAULT_GID) + .with_help_message("Information about your GUI; place essential info about your application (name, version, etc.) here. For example: AtomicDEX iOS 1.0.1") + .prompt() + .map_err(|error| { + error!("Failed to get gui: {error}"); + })?.into(); Ok(()) } fn inquire_net_id(&mut self) -> Result<(), ()> { self.net_id = CustomType::::new("What is the network `mm2` is going to be a part, net_id:") - .with_default(DEFAULT_NET_ID) - .with_help_message(r#"Nework ID number, telling the AtomicDEX API which network to join. 7777 is the current main network, though alternative netids can be used for testing or "private" trades"#) - .with_placeholder(format!("{DEFAULT_NET_ID}").as_str()) - .prompt() - .map_err(|error| { - error!("Failed to get net_id: {error}"); - })?.into(); + .with_default(DEFAULT_NET_ID) + .with_help_message(r#"Network ID number, telling the AtomicDEX API which network to join. 7777 is the current main network, though alternative netids can be used for testing or "private" trades"#) + .with_placeholder(format!("{DEFAULT_NET_ID}").as_str()) + .prompt() + .map_err(|error| { + error!("Failed to get net_id: {error}"); + })?.into(); Ok(()) } @@ -196,25 +194,14 @@ impl Mm2Cfg { fn inquire_allow_weak_password(&mut self) -> Result<(), ()> { self.allow_weak_password = Confirm::new("Allow weak password:") - .with_default(false) - .with_placeholder("No") - .with_help_message(r#"If true, will allow low entropy rpc_password. If false rpc_password must not have 3 of the same characters in a row, must be between 8-32 characters in length, must contain at least one of each of the following: numeric, uppercase, lowercase, special character (e.g. !#$*). It also can not contain the word "password", or the chars <, >, and &. Defaults to false."#) - .prompt() - .map_err(|error| { - error!("Failed to get allow_weak_password: {error}"); - })? - .into(); - Ok(()) - } - - fn inquire_userhome(&mut self) -> Result<(), ()> { - self.userhome = CustomType::>::new("What is userhome:") - .with_placeholder(DEFAULT_OPTION_PLACEHOLDER) - .with_help_message(r#"The path to your home, called from your environment variables and entered as a regular expression. Example: /${HOME#"/"}"#) - .prompt() - .map_err(|error| { - error!("Failed to get userhome: {error}"); - })?.into(); + .with_default(false) + .with_placeholder("No") + .with_help_message(r#"If true, will allow low entropy rpc_password. If false rpc_password must not have 3 of the same characters in a row, must be between 8-32 characters in length, must contain at least one of each of the following: numeric, uppercase, lowercase, special character (e.g. !#$*). It also can not contain the word "password", or the chars <, >, and &. Defaults to false."#) + .prompt() + .map_err(|error| { + error!("Failed to get allow_weak_password: {error}"); + })? + .into(); Ok(()) } @@ -231,8 +218,23 @@ impl Mm2Cfg { } fn inquire_rpcport(&mut self) -> Result<(), ()> { + let validator = |value: &InquireOption| -> Result { + match value { + InquireOption::None => Ok(Validation::Valid), + InquireOption::Some(value) => { + if (RPC_PORT_MIN..RPC_PORT_MAX + 1).contains(value) { + Ok(Validation::Valid) + } else { + Ok(Validation::Invalid( + format!("rpc_port is out of range: [{RPC_PORT_MIN}, {RPC_PORT_MAX}]").into(), + )) + } + }, + } + }; self.rpcport = CustomType::>::new("What is the rpcport:") .with_help_message(r#"Port to use for RPC communication. Optional, defaults to 7783"#) + .with_validator(validator) .with_placeholder(DEFAULT_OPTION_PLACEHOLDER) .prompt() .map_err(|error| { @@ -244,59 +246,59 @@ impl Mm2Cfg { fn inquire_rpc_local_only(&mut self) -> Result<(), ()> { self.rpc_local_only = CustomType::>::new("What is rpc_local_only:") - .with_parser(OPTION_BOOL_PARSER) - .with_formatter(DEFAULT_OPTION_BOOL_FORMATTER) - .with_default_value_formatter(DEFAULT_DEFAULT_OPTION_BOOL_FORMATTER) - .with_default(InquireOption::None) - .with_help_message("If false the AtomicDEX API will allow rpc methods sent from external IP addresses. Optional, defaults to true. Warning: Only use this if you know what you are doing, and have put the appropriate security measures in place.") - .prompt() - .map_err(|error| { - error!("Failed to get rpc_local_only: {error}"); - })?.into(); + .with_parser(OPTION_BOOL_PARSER) + .with_formatter(DEFAULT_OPTION_BOOL_FORMATTER) + .with_default_value_formatter(DEFAULT_DEFAULT_OPTION_BOOL_FORMATTER) + .with_default(InquireOption::None) + .with_help_message("If false the AtomicDEX API will allow rpc methods sent from external IP addresses. Optional, defaults to true. Warning: Only use this if you know what you are doing, and have put the appropriate security measures in place.") + .prompt() + .map_err(|error| { + error!("Failed to get rpc_local_only: {error}"); + })?.into(); Ok(()) } fn inquire_i_am_a_seed(&mut self) -> Result<(), ()> { self.i_am_seed = CustomType::>::new("What is i_am_a_seed:") - .with_parser(OPTION_BOOL_PARSER) - .with_formatter(DEFAULT_OPTION_BOOL_FORMATTER) - .with_default_value_formatter(DEFAULT_DEFAULT_OPTION_BOOL_FORMATTER) - .with_default(InquireOption::None) - .with_help_message("Runs AtomicDEX API as a seed node mode (acting as a relay for AtomicDEX API clients). Optional, defaults to false. Use of this mode is not reccomended on the main network (7777) as it could result in a pubkey ban if non-compliant. on alternative testing or private networks, at least one seed node is required to relay information to other AtomicDEX API clients using the same netID.") - .prompt() - .map_err(|error| { - error!("Failed to get i_am_a_seed: {error}"); - })?.into(); + .with_parser(OPTION_BOOL_PARSER) + .with_formatter(DEFAULT_OPTION_BOOL_FORMATTER) + .with_default_value_formatter(DEFAULT_DEFAULT_OPTION_BOOL_FORMATTER) + .with_default(InquireOption::None) + .with_help_message("Runs AtomicDEX API as a seed node mode (acting as a relay for AtomicDEX API clients). Optional, defaults to false. Use of this mode is not reccomended on the main network (7777) as it could result in a pubkey ban if non-compliant. on alternative testing or private networks, at least one seed node is required to relay information to other AtomicDEX API clients using the same netID.") + .prompt() + .map_err(|error| { + error!("Failed to get i_am_a_seed: {error}"); + })?.into(); Ok(()) } fn inquire_seednodes(&mut self) -> Result<(), ()> { info!("Reading seed nodes until tap enter is met"); loop { - let seednode: Option = CustomType::>::new("What is next seednode:") - .with_help_message("Optional. If operating on a test or private netID, the IP address of at least one seed node is required (on the main network, these are already hardcoded)") - .with_placeholder(DEFAULT_OPTION_PLACEHOLDER) - .prompt() - .map_err(|error| { - error!("Failed to get seed node: {error}"); - })?.into(); - if seednode.is_none() { + let seednode: Option = CustomType::>::new("What is the next seednode:") + .with_help_message("Optional. If operating on a test or private netID, the IP address of at least one seed node is required (on the main network, these are already hardcoded)") + .with_placeholder(DEFAULT_OPTION_PLACEHOLDER) + .prompt() + .map_err(|error| { + error!("Failed to get seed node: {error}"); + })?.into(); + let Some(seednode) = seednode else { break; - } - self.seednodes.push(seednode.unwrap()); + }; + self.seednodes.push(seednode); } Ok(()) } fn inquire_hd_account_id(&mut self) -> Result<(), ()> { self.hd_account_id = CustomType::>::new("What is hd_account_id:") - .with_help_message(r#"Optional. If this value is set, the AtomicDEX-API will work in only the HD derivation mode, coins will need to have a coin derivation path entry in the coins file for activation. The hd_account_id value effectively takes its place in the full derivation as follows: m/44'/COIN_ID'/'/CHAIN/ADDRESS_ID"#) - .with_placeholder(DEFAULT_OPTION_PLACEHOLDER) - .prompt() - .map_err(|error| { - error!("Failed to get hd_account_id: {error}"); - })? - .into(); + .with_help_message(r#"Optional. If this value is set, the AtomicDEX-API will work in only the HD derivation mode, coins will need to have a coin derivation path entry in the coins file for activation. The hd_account_id value effectively takes its place in the full derivation as follows: m/44'/COIN_ID'/'/CHAIN/ADDRESS_ID"#) + .with_placeholder(DEFAULT_OPTION_PLACEHOLDER) + .prompt() + .map_err(|error| { + error!("Failed to get hd_account_id: {error}"); + })? + .into(); Ok(()) } } diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 58febc9bd6..46603d71c1 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -87,7 +87,7 @@ pub fn start_process_impl(mm2_binary: PathBuf) { match daemon(true, true) { Ok(Fork::Child) => { - command.output().expect("failed to execute process"); + command.output().expect("Failed to execute process"); }, Ok(Fork::Parent(pid)) => { info!("Successfully started: {program:?}, forked pid: {pid}"); @@ -98,16 +98,17 @@ pub fn start_process_impl(mm2_binary: PathBuf) { #[cfg(windows)] pub fn start_process_impl(mm2_binary: PathBuf) { - let program = mm2_binary.to_str(); - if program.is_none() { + let Some(program) = mm2_binary.to_str() else { error!("Failed to cast mm2_binary to &str"); return; - } - let program = CString::new(program.unwrap()); - if let Err(error) = program { - error!("Failed to construct CString program path: {error}"); - return; - } + }; + let program = match CString::new(program) { + Ok(program) => program, + Err(error) => { + error!("Failed to construct CString program path: {error}"); + return; + }, + }; let mut startup_info: STARTUPINFOA = unsafe { mem::zeroed() }; startup_info.cb = size_of::() as u32; @@ -116,23 +117,21 @@ pub fn start_process_impl(mm2_binary: PathBuf) { let result = unsafe { CreateProcessA( null(), - program.unwrap().into_raw() as *mut i8, + program.into_raw() as *mut i8, std::ptr::null_mut(), std::ptr::null_mut(), 0, 0, std::ptr::null_mut(), std::ptr::null(), - &mut startup_info as &mut STARTUPINFOA, - &mut process_info as *mut PROCESS_INFORMATION, + &mut startup_info, + &mut process_info, ) }; match result { 0 => error!("Failed to start: {MM2_BINARY}"), - _ => { - info!("Successfully started: {MM2_BINARY}"); - }, + _ => info!("Successfully started: {MM2_BINARY}"), } } From 34d08fc2af3eac67c6981c7b13fd247860b1624e Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Mon, 27 Mar 2023 19:11:13 +0500 Subject: [PATCH 18/90] Got rid of userhome from mm2 help --- Cargo.lock | 122 ++++++++++++++++++------------------- mm2src/mm2_main/src/mm2.rs | 1 - 2 files changed, 61 insertions(+), 62 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9056adf055..c0338ba3fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -162,9 +162,9 @@ dependencies = [ [[package]] name = "ansi_term" -version = "0.12.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ "winapi", ] @@ -251,7 +251,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -268,7 +268,7 @@ version = "0.1.52" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "061a7acccaa286c011ddc30970520b98fa40e00c9d644633fb26b5fc63a265e3" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -745,7 +745,7 @@ dependencies = [ "borsh-derive-internal", "borsh-schema-derive-internal", "proc-macro-crate 0.1.5", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "syn 1.0.95", ] @@ -755,7 +755,7 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5449c28a7b352f2d1e592a8a28bf139bc71afb0764a14f3c02500935d8c44065" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -766,7 +766,7 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdbd5696d8bfa21d53d9fe39a714a18538bad11492a42d066dbbc395fb1951c0" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -823,7 +823,7 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e215f8c2f9f79cb53c8335e687ffd07d5bfcb6fe5fc80723762d0be46e7cc54" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -994,9 +994,9 @@ dependencies = [ [[package]] name = "clap" -version = "2.34.0" +version = "2.33.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" dependencies = [ "ansi_term", "atty", @@ -1757,7 +1757,7 @@ dependencies = [ "cc", "codespan-reporting", "lazy_static", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "scratch", "syn 1.0.95", @@ -1775,7 +1775,7 @@ version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b846f081361125bfc8dc9d3940c84e1fd83ba54bbca7b17cd29483c828be0704" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -1849,7 +1849,7 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -1860,7 +1860,7 @@ version = "0.99.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cb0e6161ad61ed084a36ba71fbba9e3ac5aee3606fb607fe08da6acbcf3d8c" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -2126,7 +2126,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21cdad81446a7f7dc43f6a77409efeb9733d2fa65553efef6018ef257c959b73" dependencies = [ "heck", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -2147,7 +2147,7 @@ name = "enum_from" version = "0.1.0" dependencies = [ "itertools", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -2309,7 +2309,7 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", "synstructure", @@ -2565,7 +2565,7 @@ version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -3191,7 +3191,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5dacb10c5b3bb92d46ba347505a9041e676bb20ad220101326bffb0c93031ee" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -4161,7 +4161,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49e30813093f757be5cf21e50389a24dc7dbb22c49f23b7e8f51d69b508a5ffa" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -4642,7 +4642,7 @@ version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3048ef3680533a27f9f8e7d6a0bce44dc61e4895ea0f42709337fa1c8616fefe" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -4686,7 +4686,7 @@ checksum = "fc076939022111618a5026d3be019fd8b366e76314538ff9a1b59ffbcbf98bcd" dependencies = [ "proc-macro-crate 1.1.3", "proc-macro-error", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", "synstructure", @@ -4799,7 +4799,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -4863,7 +4863,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "486ea01961c4a818096de679a8b740b26d9033146ac5291b1c98557658f8cdd9" dependencies = [ "proc-macro-crate 1.1.3", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -4938,7 +4938,7 @@ checksum = "44a0b52c2cbaef7dffa5fec1a43274afe8bd2a644fa9fc50a9ef4ff0269b1257" dependencies = [ "Inflector", "proc-macro-error", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -4995,7 +4995,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c45ed1f39709f5a89338fab50e59816b2e8815f5bb58276e7ddf9afd495f73f8" dependencies = [ "proc-macro-crate 1.1.3", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -5030,7 +5030,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f557c32c6d268a07c921471619c0295f5efad3a0e76d4f97a05c091a51d110b2" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "syn 1.0.95", "synstructure", ] @@ -5155,7 +5155,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5aa52829b8decbef693af90202711348ab001456803ba2a98eb4ec8fb70844c" dependencies = [ "peg-runtime", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", ] @@ -5205,7 +5205,7 @@ version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "044964427019eed9d49d9d5bbce6047ef18f37100ea400912a9fa4a3523ab12a" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -5216,7 +5216,7 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "744b6f092ba29c3650faf274db506afd39944f48420f6c86b17cfe0ee1cb36bb" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -5291,7 +5291,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f28f53e8b192565862cf99343194579a022eb9c7dd3a8d03134734803c7b3125" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "syn 1.0.95", ] @@ -5345,7 +5345,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", "version_check", @@ -5357,7 +5357,7 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "version_check", ] @@ -5379,9 +5379,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.53" +version = "1.0.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba466839c78239c09faf015484e5cc04860f88242cff4d03eb038f04b4699b73" +checksum = "e472a104799c74b514a57226160104aa483546de37e839ec50e3c2e41dd87534" dependencies = [ "unicode-ident", ] @@ -5404,7 +5404,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8e12d01b9d66ad9eb4529c57666b6263fc1993cb30261d83ead658fdd932652" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -5449,7 +5449,7 @@ checksum = "7b670f45da57fb8542ebdbb6105a925fe571b67f9e7ed9f47a06a84e72b4e7cc" dependencies = [ "anyhow", "itertools", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -5564,7 +5564,7 @@ version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", ] [[package]] @@ -5940,7 +5940,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c523ccaed8ac4b0288948849a350b37d3035827413c458b6a40ddb614bb4f72" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -6307,7 +6307,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50e334bb10a245e28e5fd755cabcafd96cfcd167c99ae63a46924ca8d8703a3c" dependencies = [ "proc-macro-crate 1.1.3", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -6462,7 +6462,7 @@ dependencies = [ name = "ser_error_derive" version = "0.1.0" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "ser_error", "syn 1.0.95", @@ -6503,7 +6503,7 @@ version = "1.0.136" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -6526,7 +6526,7 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dc6b7951b17b051f3210b063f12cc17320e2fe30ae05b0fe2a3abb068551c76" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -7024,7 +7024,7 @@ version = "1.9.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "402fffb54bf5d335e6df26fc1719feecfbd7a22fafdf6649fe78380de3c47384" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "rustc_version 0.4.0", "syn 1.0.95", @@ -7326,7 +7326,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c834b4e02ac911b13c13aed08b3f847e722f6be79d31b1c660c1dbd2dee83cdb" dependencies = [ "bs58", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "rustversion", "syn 1.0.95", @@ -7450,7 +7450,7 @@ version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d676664972e22a0796176e81e7bec41df461d1edf52090955cdab55f2c956ff2" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -7480,7 +7480,7 @@ checksum = "22ecb916b9664ed9f90abef0ff5a3e61454c1efea5861b2997e03f39b59b955f" dependencies = [ "Inflector", "proc-macro-crate 1.1.3", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -7628,7 +7628,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f9799e6d412271cb2414597581128b03f3285f260ea49f5363d07df6a332b3e" dependencies = [ "Inflector", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "serde", "serde_json", @@ -7676,7 +7676,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "serde", "serde_derive", @@ -7690,7 +7690,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" dependencies = [ "base-x", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "serde", "serde_derive", @@ -7766,7 +7766,7 @@ version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "unicode-ident", ] @@ -7792,7 +7792,7 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", "unicode-xid 0.2.0", @@ -8091,7 +8091,7 @@ version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -8166,7 +8166,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" dependencies = [ "proc-macro-hack", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "standback", "syn 1.0.95", @@ -8270,7 +8270,7 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -8363,7 +8363,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9263bf4c9bfaae7317c1c2faf7f18491d2fe476f70c414b73bf5d445b00ffa1" dependencies = [ "prettyplease", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "prost-build", "quote 1.0.26", "syn 1.0.95", @@ -8439,7 +8439,7 @@ version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e65ce065b4b5c53e73bb28912318cb8c9e9ad3921f1d669eb0e68b4c8143a2b" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", ] @@ -8866,7 +8866,7 @@ dependencies = [ "bumpalo", "lazy_static", "log 0.4.14", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", "wasm-bindgen-shared", @@ -8900,7 +8900,7 @@ version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", "wasm-bindgen-backend", @@ -8933,7 +8933,7 @@ version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c2e18093f11c19ca4e188c177fecc7c372304c311189f12c2f9bea5b7324ac7" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", ] @@ -9392,7 +9392,7 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f8f187641dad4f680d25c4bfc4225b418165984179f26ca76ec4fb6441d3a17" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.95", "synstructure", diff --git a/mm2src/mm2_main/src/mm2.rs b/mm2src/mm2_main/src/mm2.rs index 76cf5cbeed..5293b228c7 100644 --- a/mm2src/mm2_main/src/mm2.rs +++ b/mm2src/mm2_main/src/mm2.rs @@ -199,7 +199,6 @@ Some (but not all) of the JSON configuration parameters (* - required): seednodes .. Seednode IPs that node will use. At least one seed IP must be present if the node is not a seed itself. stderr .. Print a message to stderr and exit. - userhome .. System home directory of a user ('/root' by default). wif .. `1` to add WIFs to the information we provide about a coin. Environment variables: From 6addf5fea8361d9e86b1434ff21063ef95bc6598 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Mon, 27 Mar 2023 19:31:27 +0500 Subject: [PATCH 19/90] Use default gui configuration value --- mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs index bb4bf10e4b..ad1453bcf3 100644 --- a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs +++ b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs @@ -12,7 +12,7 @@ use super::inquire_extentions::{InquireOption, DEFAULT_DEFAULT_OPTION_BOOL_FORMA use common::password_policy; const DEFAULT_NET_ID: u16 = 7777; -const DEFAULT_GID: &str = concat!("QA CLI ", env!("CARGO_PKG_VERSION")); +const DEFAULT_GID: &str = "adex-cli"; const DEFAULT_OPTION_PLACEHOLDER: &str = "Tap enter to skip"; const RPC_PORT_MIN: u16 = 1024; const RPC_PORT_MAX: u16 = 49151; @@ -113,14 +113,8 @@ impl Mm2Cfg { } fn inquire_gui(&mut self) -> Result<(), ()> { - self.gui = Text::new("What is the client identifier, gui:") - .with_default(DEFAULT_GID) - .with_placeholder(DEFAULT_GID) - .with_help_message("Information about your GUI; place essential info about your application (name, version, etc.) here. For example: AtomicDEX iOS 1.0.1") - .prompt() - .map_err(|error| { - error!("Failed to get gui: {error}"); - })?.into(); + self.gui = Some(DEFAULT_GID.into()); + info!("> gui is set by default: {DEFAULT_GID}"); Ok(()) } From 3f93b332caeba5d5510288436178df98830cdccb Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Mon, 27 Mar 2023 20:19:46 +0500 Subject: [PATCH 20/90] Spti and polish --- mm2src/adex_cli/src/scenarios/init_coins.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/init_coins.rs b/mm2src/adex_cli/src/scenarios/init_coins.rs index cf891fb2a4..fefcdd7c66 100644 --- a/mm2src/adex_cli/src/scenarios/init_coins.rs +++ b/mm2src/adex_cli/src/scenarios/init_coins.rs @@ -13,11 +13,11 @@ pub enum CoinSet { #[tokio::main(flavor = "current_thread")] pub async fn init_coins(coins_file: &str) -> Result<(), ()> { const FULL_COIN_SET_ADDRESS: &str = "https://raw.githubusercontent.com/KomodoPlatform/coins/master/coins"; - const EMPTY_COIN_SET_DATA: Vec = Vec::new(); + const EMPTY_COIN_SET_DATA: &[u8] = b"[]\n"; let coin_set = inquire_coin_set(coins_file)?; info!("Start getting mm2 coins"); let coins_data = match coin_set { - CoinSet::Empty => EMPTY_COIN_SET_DATA, + CoinSet::Empty => Vec::::from(EMPTY_COIN_SET_DATA), CoinSet::Full => { info!("Getting coin set from: {FULL_COIN_SET_ADDRESS}"); let (_status_code, _headers, data) = slurp_url(FULL_COIN_SET_ADDRESS).await.map_err(|error| { From 4aac321e6dec4d4fd48ed354661036360c2e6b50 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Mon, 27 Mar 2023 21:49:13 +0500 Subject: [PATCH 21/90] Provide macos configuration --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 46603d71c1..f7715e51af 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -57,6 +57,7 @@ fn get_mm2_binary_path() -> Result { Ok(dir) } +#[cfg(all(any(unix, windows), not(macos)))] pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, log_file: &Option) { let mm2_binary = match get_mm2_binary_path() { Err(_) => return, @@ -78,7 +79,7 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, start_process_impl(mm2_binary); } -#[cfg(unix)] +#[cfg(all(unix, not(macos)))] pub fn start_process_impl(mm2_binary: PathBuf) { let mut command = Command::new(&mm2_binary); let program = mm2_binary @@ -135,7 +136,7 @@ pub fn start_process_impl(mm2_binary: PathBuf) { } } -#[cfg(unix)] +#[cfg(all(unix, not(macos)))] pub fn stop_process() { let pids = find_proc_by_name(MM2_BINARY); if pids.is_empty() { @@ -171,3 +172,13 @@ pub fn stop_process() { } } } + +#[cfg(macos)] +pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, log_file: &Option) { + unimplemented!(); +} + +#[cfg(macos)] +pub fn stop_process() { + unimplemented!(); +} From 514884c1361a0c2de23bd29aee2c0694d32d6d05 Mon Sep 17 00:00:00 2001 From: Onur Date: Mon, 27 Mar 2023 21:04:23 +0300 Subject: [PATCH 22/90] ci: improve CI/CD workflows (#1736) * improve CI/CD logic Signed-off-by: ozkanonur * add changelog entry Signed-off-by: ozkanonur --------- Signed-off-by: ozkanonur Reviewed-by: shamardy --- .github/workflows/dev-build.yml | 61 ++++++++++++++++++++++++++---- .github/workflows/fmt-and-lint.yml | 10 +---- .github/workflows/test.yml | 10 +---- CHANGELOG.md | 7 ++++ 4 files changed, 62 insertions(+), 26 deletions(-) diff --git a/.github/workflows/dev-build.yml b/.github/workflows/dev-build.yml index 900048e6ae..f41fdfd057 100644 --- a/.github/workflows/dev-build.yml +++ b/.github/workflows/dev-build.yml @@ -1,11 +1,8 @@ name: Development builds on: push: - branches: - - dev - pull_request: - branches: - - dev + branches-ignore: + - main concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} @@ -42,6 +39,9 @@ jobs: cargo build --bin mm2 --profile ci - name: Compress build output + env: + AVAILABLE: ${{ secrets.FILE_SERVER_KEY }} + if: ${{ env.AVAILABLE != '' }} run: | NAME="mm2_$COMMIT_HASH-linux-x86-64.zip" zip $NAME target/ci/mm2 -j @@ -49,6 +49,9 @@ jobs: mv $NAME ./$BRANCH_NAME/ - name: Upload output + env: + AVAILABLE: ${{ secrets.FILE_SERVER_KEY }} + if: ${{ env.AVAILABLE != '' }} uses: garygrossgarten/github-action-scp@release with: host: ${{ secrets.FILE_SERVER_HOST }} @@ -59,11 +62,11 @@ jobs: remote: "/uploads/${{ env.BRANCH_NAME }}" - name: Login to dockerhub - if: github.event_name != 'pull_request' + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/dev' run: docker login --username ${{ secrets.DOCKER_HUB_USERNAME }} --password ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} docker.io - name: Build and push container image - if: github.event_name != 'pull_request' + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/dev' run: | CONTAINER_TAG="dev-$COMMIT_HASH" docker build -t komodoofficial/atomicdexapi:"$CONTAINER_TAG" -t komodoofficial/atomicdexapi:dev-latest -f Dockerfile.dev-release . @@ -95,6 +98,9 @@ jobs: cargo build --bin mm2 --profile ci --target x86_64-apple-darwin - name: Compress build output + env: + AVAILABLE: ${{ secrets.FILE_SERVER_KEY }} + if: ${{ env.AVAILABLE != '' }} run: | NAME="mm2_$COMMIT_HASH-mac-x86-64.zip" zip $NAME target/x86_64-apple-darwin/ci/mm2 -j @@ -102,6 +108,9 @@ jobs: mv $NAME ./$BRANCH_NAME/ - name: Upload output + env: + AVAILABLE: ${{ secrets.FILE_SERVER_KEY }} + if: ${{ env.AVAILABLE != '' }} uses: garygrossgarten/github-action-scp@release with: host: ${{ secrets.FILE_SERVER_HOST }} @@ -138,6 +147,9 @@ jobs: cargo build --bin mm2 --profile ci - name: Compress build output + env: + AVAILABLE: ${{ secrets.FILE_SERVER_KEY }} + if: ${{ env.AVAILABLE != '' }} run: | $NAME="mm2_$Env:COMMIT_HASH-win-x86-64.zip" 7z a $NAME .\target\ci\mm2.exe .\target\ci\*.dll @@ -145,6 +157,9 @@ jobs: mv $NAME ./$Env:BRANCH_NAME/ - name: Upload output + env: + AVAILABLE: ${{ secrets.FILE_SERVER_KEY }} + if: ${{ env.AVAILABLE != '' }} uses: garygrossgarten/github-action-scp@release with: host: ${{ secrets.FILE_SERVER_HOST }} @@ -179,6 +194,9 @@ jobs: cargo rustc --target x86_64-apple-darwin --lib --profile ci --package mm2_bin_lib --crate-type=staticlib - name: Compress build output + env: + AVAILABLE: ${{ secrets.FILE_SERVER_KEY }} + if: ${{ env.AVAILABLE != '' }} run: | NAME="mm2_$COMMIT_HASH-mac-dylib-x86-64.zip" mv target/x86_64-apple-darwin/ci/libmm2lib.a target/x86_64-apple-darwin/ci/libmm2.a @@ -187,6 +205,9 @@ jobs: mv $NAME ./$BRANCH_NAME/ - name: Upload output + env: + AVAILABLE: ${{ secrets.FILE_SERVER_KEY }} + if: ${{ env.AVAILABLE != '' }} uses: garygrossgarten/github-action-scp@release with: host: ${{ secrets.FILE_SERVER_HOST }} @@ -225,6 +246,9 @@ jobs: wasm-pack build mm2src/mm2_bin_lib --target web --out-dir ../../target/target-wasm-release - name: Compress build output + env: + AVAILABLE: ${{ secrets.FILE_SERVER_KEY }} + if: ${{ env.AVAILABLE != '' }} run: | NAME="mm2_$COMMIT_HASH-wasm.zip" zip $NAME ./target/target-wasm-release/mm2lib_bg.wasm ./target/target-wasm-release/mm2lib.js ./target/target-wasm-release/snippets -j @@ -232,6 +256,9 @@ jobs: mv $NAME ./$BRANCH_NAME/ - name: Upload output + env: + AVAILABLE: ${{ secrets.FILE_SERVER_KEY }} + if: ${{ env.AVAILABLE != '' }} uses: garygrossgarten/github-action-scp@release with: host: ${{ secrets.FILE_SERVER_HOST }} @@ -267,6 +294,9 @@ jobs: cargo rustc --target aarch64-apple-ios --lib --profile ci --package mm2_bin_lib --crate-type=staticlib - name: Compress build output + env: + AVAILABLE: ${{ secrets.FILE_SERVER_KEY }} + if: ${{ env.AVAILABLE != '' }} run: | NAME="mm2_$COMMIT_HASH-ios-aarch64.zip" mv target/aarch64-apple-ios/ci/libmm2lib.a target/aarch64-apple-ios/ci/libmm2.a @@ -275,6 +305,9 @@ jobs: mv $NAME ./$BRANCH_NAME/ - name: Upload output + env: + AVAILABLE: ${{ secrets.FILE_SERVER_KEY }} + if: ${{ env.AVAILABLE != '' }} uses: garygrossgarten/github-action-scp@release with: host: ${{ secrets.FILE_SERVER_HOST }} @@ -315,6 +348,9 @@ jobs: CC_aarch64_linux_android=aarch64-linux-android21-clang CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android21-clang cargo rustc --target=aarch64-linux-android --lib --profile ci --crate-type=staticlib --package mm2_bin_lib - name: Compress build output + env: + AVAILABLE: ${{ secrets.FILE_SERVER_KEY }} + if: ${{ env.AVAILABLE != '' }} run: | NAME="mm2_$COMMIT_HASH-android-aarch64.zip" mv target/aarch64-linux-android/ci/libmm2lib.a target/aarch64-linux-android/ci/libmm2.a @@ -323,6 +359,9 @@ jobs: mv $NAME ./$BRANCH_NAME/ - name: Upload output + env: + AVAILABLE: ${{ secrets.FILE_SERVER_KEY }} + if: ${{ env.AVAILABLE != '' }} uses: garygrossgarten/github-action-scp@release with: host: ${{ secrets.FILE_SERVER_HOST }} @@ -363,6 +402,9 @@ jobs: CC_armv7_linux_androideabi=armv7a-linux-androideabi21-clang CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=armv7a-linux-androideabi21-clang cargo rustc --target=armv7-linux-androideabi --lib --profile ci --crate-type=staticlib --package mm2_bin_lib - name: Compress build output + env: + AVAILABLE: ${{ secrets.FILE_SERVER_KEY }} + if: ${{ env.AVAILABLE != '' }} run: | NAME="mm2_$COMMIT_HASH-android-armv7.zip" mv target/armv7-linux-androideabi/ci/libmm2lib.a target/armv7-linux-androideabi/ci/libmm2.a @@ -371,6 +413,9 @@ jobs: mv $NAME ./$BRANCH_NAME/ - name: Upload output + env: + AVAILABLE: ${{ secrets.FILE_SERVER_KEY }} + if: ${{ env.AVAILABLE != '' }} uses: garygrossgarten/github-action-scp@release with: host: ${{ secrets.FILE_SERVER_HOST }} @@ -382,7 +427,7 @@ jobs: deployment-commitment: - if: github.event_name != 'pull_request' + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/dev' needs: linux-x86-64 timeout-minutes: 15 runs-on: ubuntu-18.04 diff --git a/.github/workflows/fmt-and-lint.yml b/.github/workflows/fmt-and-lint.yml index b9c5c92701..09ab32ba8b 100644 --- a/.github/workflows/fmt-and-lint.yml +++ b/.github/workflows/fmt-and-lint.yml @@ -1,13 +1,5 @@ name: Format and Lint -on: - push: - branches: - - main - - dev - pull_request: - branches: - - main - - dev +on: [push] concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5cd82b5311..5ff6f0e491 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,13 +1,5 @@ name: Test -on: - push: - branches: - - main - - dev - pull_request: - branches: - - main - - dev +on: [push] concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ae1785eb0..4340ab5f7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## {inc-release} + +**Features:** + +**Enhancements/Fixes:** +- CI/CD workflow logics are improved [#1736](https://github.com/KomodoPlatform/atomicDEX-API/pull/1736) + ## v1.0.1-beta - 2023-03-17 **Features:** From 04f4f1497a4bba2a490d7997f723201ee6709d38 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Tue, 28 Mar 2023 00:42:23 +0500 Subject: [PATCH 23/90] Inline each inquire method on initializing mm configuration --- mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs index ad1453bcf3..1f2f9a65e3 100644 --- a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs +++ b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs @@ -84,6 +84,7 @@ impl Mm2Cfg { Ok(()) } + #[inline] fn inquire_dbdir(&mut self) -> Result<(), ()> { let is_reachable_dir = |dbdir: &InquireOption| -> Result { match dbdir { @@ -112,12 +113,14 @@ impl Mm2Cfg { Ok(()) } + #[inline] fn inquire_gui(&mut self) -> Result<(), ()> { self.gui = Some(DEFAULT_GID.into()); info!("> gui is set by default: {DEFAULT_GID}"); Ok(()) } + #[inline] fn inquire_net_id(&mut self) -> Result<(), ()> { self.net_id = CustomType::::new("What is the network `mm2` is going to be a part, net_id:") .with_default(DEFAULT_NET_ID) @@ -130,6 +133,7 @@ impl Mm2Cfg { Ok(()) } + #[inline] fn inquire_passphrase(&mut self) -> Result<(), ()> { let default_password = Self::generate_password()?; self.passphrase = Text::new("What is the passphrase:") @@ -144,6 +148,7 @@ impl Mm2Cfg { Ok(()) } + #[inline] fn inquire_rpc_password(&mut self) -> Result<(), ()> { let allow_weak_password = self.allow_weak_password; let validator = move |password: &str| { @@ -186,6 +191,7 @@ impl Mm2Cfg { .map_err(|error| error!("Failed to generate password: {error}")) } + #[inline] fn inquire_allow_weak_password(&mut self) -> Result<(), ()> { self.allow_weak_password = Confirm::new("Allow weak password:") .with_default(false) @@ -199,6 +205,7 @@ impl Mm2Cfg { Ok(()) } + #[inline] fn inquire_rpcip(&mut self) -> Result<(), ()> { self.rpcip = CustomType::>::new("What is rpcip:") .with_placeholder(DEFAULT_OPTION_PLACEHOLDER) @@ -211,6 +218,7 @@ impl Mm2Cfg { Ok(()) } + #[inline] fn inquire_rpcport(&mut self) -> Result<(), ()> { let validator = |value: &InquireOption| -> Result { match value { @@ -238,6 +246,7 @@ impl Mm2Cfg { Ok(()) } + #[inline] fn inquire_rpc_local_only(&mut self) -> Result<(), ()> { self.rpc_local_only = CustomType::>::new("What is rpc_local_only:") .with_parser(OPTION_BOOL_PARSER) @@ -252,6 +261,7 @@ impl Mm2Cfg { Ok(()) } + #[inline] fn inquire_i_am_a_seed(&mut self) -> Result<(), ()> { self.i_am_seed = CustomType::>::new("What is i_am_a_seed:") .with_parser(OPTION_BOOL_PARSER) @@ -266,6 +276,7 @@ impl Mm2Cfg { Ok(()) } + #[inline] fn inquire_seednodes(&mut self) -> Result<(), ()> { info!("Reading seed nodes until tap enter is met"); loop { @@ -284,6 +295,7 @@ impl Mm2Cfg { Ok(()) } + #[inline] fn inquire_hd_account_id(&mut self) -> Result<(), ()> { self.hd_account_id = CustomType::>::new("What is hd_account_id:") .with_help_message(r#"Optional. If this value is set, the AtomicDEX-API will work in only the HD derivation mode, coins will need to have a coin derivation path entry in the coins file for activation. The hd_account_id value effectively takes its place in the full derivation as follows: m/44'/COIN_ID'/'/CHAIN/ADDRESS_ID"#) From addf3b023b2c3d57ae50ccd2560179fafe3aae01 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Tue, 28 Mar 2023 01:35:57 +0500 Subject: [PATCH 24/90] Fix errors related to macos configuration --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index f7715e51af..276648c885 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -57,7 +57,7 @@ fn get_mm2_binary_path() -> Result { Ok(dir) } -#[cfg(all(any(unix, windows), not(macos)))] +#[cfg(all(any(unix, windows), not(target_os == "macos")))] pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, log_file: &Option) { let mm2_binary = match get_mm2_binary_path() { Err(_) => return, @@ -79,7 +79,7 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, start_process_impl(mm2_binary); } -#[cfg(all(unix, not(macos)))] +#[cfg(all(unix, not(target_os == "macos")))] pub fn start_process_impl(mm2_binary: PathBuf) { let mut command = Command::new(&mm2_binary); let program = mm2_binary @@ -136,7 +136,7 @@ pub fn start_process_impl(mm2_binary: PathBuf) { } } -#[cfg(all(unix, not(macos)))] +#[cfg(all(unix, not(target_os == "macos")))] pub fn stop_process() { let pids = find_proc_by_name(MM2_BINARY); if pids.is_empty() { @@ -173,12 +173,12 @@ pub fn stop_process() { } } -#[cfg(macos)] +#[cfg(target_os == "macos")] pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, log_file: &Option) { unimplemented!(); } -#[cfg(macos)] +#[cfg(target_os == "macos")] pub fn stop_process() { unimplemented!(); } From 11518caed3b13f45af104eb6c1566da7d7713d72 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Tue, 28 Mar 2023 01:47:31 +0500 Subject: [PATCH 25/90] Fix errors related to macos configuration --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 276648c885..b85d4dddf5 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -57,7 +57,7 @@ fn get_mm2_binary_path() -> Result { Ok(dir) } -#[cfg(all(any(unix, windows), not(target_os == "macos")))] +#[cfg(all(any(unix, windows), not(target_os = "macos")))] pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, log_file: &Option) { let mm2_binary = match get_mm2_binary_path() { Err(_) => return, @@ -79,7 +79,7 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, start_process_impl(mm2_binary); } -#[cfg(all(unix, not(target_os == "macos")))] +#[cfg(all(unix, not(target_os = "macos")))] pub fn start_process_impl(mm2_binary: PathBuf) { let mut command = Command::new(&mm2_binary); let program = mm2_binary @@ -136,7 +136,7 @@ pub fn start_process_impl(mm2_binary: PathBuf) { } } -#[cfg(all(unix, not(target_os == "macos")))] +#[cfg(all(unix, not(target_os = "macos")))] pub fn stop_process() { let pids = find_proc_by_name(MM2_BINARY); if pids.is_empty() { @@ -173,12 +173,12 @@ pub fn stop_process() { } } -#[cfg(target_os == "macos")] +#[cfg(target_os = "macos")] pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, log_file: &Option) { unimplemented!(); } -#[cfg(target_os == "macos")] +#[cfg(target_os = "macos")] pub fn stop_process() { unimplemented!(); } From 52767e2dc2c56d92deb5a6b31034a01100bba3cd Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Tue, 28 Mar 2023 01:55:35 +0500 Subject: [PATCH 26/90] Try to ignore adex-cli for wasm32 --- mm2src/adex_cli/src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm2src/adex_cli/src/main.rs b/mm2src/adex_cli/src/main.rs index 7feae23a61..99a56d7254 100644 --- a/mm2src/adex_cli/src/main.rs +++ b/mm2src/adex_cli/src/main.rs @@ -1,7 +1,8 @@ -mod cli; -mod log; -mod scenarios; +#[cfg(not(target_arch = "wasm32"))] mod cli; +#[cfg(not(target_arch = "wasm32"))] mod log; +#[cfg(not(target_arch = "wasm32"))] mod scenarios; +#[cfg(not(target_arch = "wasm32"))] fn main() { log::init_logging(); cli::process_cli(); From 4395e979b8e2f57ce1e4425e44e45c79b47680dd Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Tue, 28 Mar 2023 02:12:48 +0500 Subject: [PATCH 27/90] Avoid macos related warnings --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index b85d4dddf5..ea83a351d0 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -174,7 +174,7 @@ pub fn stop_process() { } #[cfg(target_os = "macos")] -pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, log_file: &Option) { +pub fn start_process(_mm2_cfg_file: &Option, _coins_file: &Option, _log_file: &Option) { unimplemented!(); } From 65459bb2e105a7bd25434e5f820ebbb28ca5e7ce Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Tue, 28 Mar 2023 02:21:20 +0500 Subject: [PATCH 28/90] disable wasm32 )) --- mm2src/adex_cli/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index aaa768f081..ce187ccab8 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -6,7 +6,7 @@ authors = ["Rozhkov Dmitrii "] description = "Provides a CLI interface and facilitates interoperating to komodo atomic dex throught the mm2 service" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[dependencies] +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] clap = "2.33.3" common = { path = "../common" } derive_more = "0.99" @@ -20,7 +20,7 @@ serde_json = { version = "1", features = ["preserve_order", "raw_value"] } sysinfo = "0.28" tokio = { version = "1.20" } -[target.'cfg(not(windows))'.dependencies] +[target.'cfg(all(not(target_arch = "wasm32"), not(windows)))'.dependencies] fork = "0.1" [target.'cfg(windows)'.dependencies] From 1cdb6938273a935779cbce3d532d6b095b5eda3a Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Tue, 28 Mar 2023 02:42:16 +0500 Subject: [PATCH 29/90] disable all for macos --- mm2src/adex_cli/src/main.rs | 3 +++ mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/mm2src/adex_cli/src/main.rs b/mm2src/adex_cli/src/main.rs index 99a56d7254..eb80a3b868 100644 --- a/mm2src/adex_cli/src/main.rs +++ b/mm2src/adex_cli/src/main.rs @@ -2,6 +2,9 @@ #[cfg(not(target_arch = "wasm32"))] mod log; #[cfg(not(target_arch = "wasm32"))] mod scenarios; +#[cfg(target_arch = "wasm32")] +fn main() {} + #[cfg(not(target_arch = "wasm32"))] fn main() { log::init_logging(); diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index ea83a351d0..6901b1e35d 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -1,6 +1,10 @@ +#[cfg(all(any(unix, windows), not(target_os = "macos")))] use common::log::{error, info}; +#[cfg(all(any(unix, windows), not(target_os = "macos")))] use std::path::PathBuf; +#[cfg(all(any(unix, windows), not(target_os = "macos")))] use std::{env, u32}; +#[cfg(all(any(unix, windows), not(target_os = "macos")))] use sysinfo::{PidExt, ProcessExt, System, SystemExt}; #[cfg(windows)] @@ -16,7 +20,7 @@ mod reexport { pub const MM2_BINARY: &str = "mm2.exe"; } -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "macos")))] mod reexport { pub use fork::{daemon, Fork}; pub use std::ffi::OsStr; @@ -28,6 +32,7 @@ mod reexport { use reexport::*; +#[cfg(all(any(unix, windows), not(target_os = "macos")))] pub fn get_status() { let pids = find_proc_by_name(MM2_BINARY); if pids.is_empty() { @@ -38,6 +43,7 @@ pub fn get_status() { }); } +#[cfg(all(any(unix, windows), not(target_os = "macos")))] fn find_proc_by_name(pname: &'_ str) -> Vec { let s = System::new_all(); @@ -48,6 +54,7 @@ fn find_proc_by_name(pname: &'_ str) -> Vec { .collect() } +#[cfg(all(any(unix, windows), not(target_os = "macos")))] fn get_mm2_binary_path() -> Result { let mut dir = env::current_exe().map_err(|error| { error!("Failed to get current binary dir: {error}"); From a6dc0025f2ab9a5181d390b97dbaaed2b599e544 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Tue, 28 Mar 2023 02:57:33 +0500 Subject: [PATCH 30/90] try again --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 6901b1e35d..662eed3c4b 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -30,7 +30,7 @@ mod reexport { pub const KILL_CMD: &str = "kill"; } -use reexport::*; +#[cfg(all(unix, not(target_os = "macos")))] use reexport::*; #[cfg(all(any(unix, windows), not(target_os = "macos")))] pub fn get_status() { @@ -189,3 +189,8 @@ pub fn start_process(_mm2_cfg_file: &Option, _coins_file: &Option Date: Tue, 28 Mar 2023 03:23:28 +0500 Subject: [PATCH 31/90] Fix windows clippy after all --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 662eed3c4b..fca5dd0d76 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -30,7 +30,8 @@ mod reexport { pub const KILL_CMD: &str = "kill"; } -#[cfg(all(unix, not(target_os = "macos")))] use reexport::*; +#[cfg(all(any(unix, windows), not(target_os = "macos")))] +use reexport::*; #[cfg(all(any(unix, windows), not(target_os = "macos")))] pub fn get_status() { From 32e7c6508fe7254a08df6379e29171c4cc04db3d Mon Sep 17 00:00:00 2001 From: Onur Date: Wed, 29 Mar 2023 00:22:42 +0300 Subject: [PATCH 32/90] refactor: simplified project root (#1738) * refactor projcet root Signed-off-by: ozkanonur * add changelog entry Signed-off-by: ozkanonur --------- Signed-off-by: ozkanonur Reviewed-by: shamardy , ca333 --- Dockerfile => .docker/Dockerfile | 2 +- .../Dockerfile.aarch64-linux-android | 4 +- .../Dockerfile.armv7-linux-androideabi | 4 +- .../Dockerfile.armv7-unknown-linux-gnueabihf | 2 +- .../Dockerfile.dev-release | 2 +- .../Dockerfile.i686-linux-android | 4 +- .../Dockerfile.parity.dev | 6 +- .../Dockerfile.release | 2 +- .../Dockerfile.ubuntu.ci | 2 +- .../Dockerfile.x86_64-linux-android | 4 +- .../parity.dev.chain.json | 0 .github/workflows/dev-build.yml | 6 +- .github/workflows/release-build.yml | 6 +- .gitignore | 14 +- .gitlab-ci.yml | 110 ------ CHANGELOG.md | 1 + README.md | 2 +- docs/ANDROID.md | 8 +- docs/ANDROID_CROSS_ON_M1_MAC.md | 2 +- CONTRIBUTING.md => docs/CONTRIBUTING.md | 0 docs/RASPBERRY_PI4_CROSS.md | 2 +- examples/README.md | 3 + {wasm_build => examples/wasm}/README.md | 0 {wasm_build => examples/wasm}/index.html | 0 {wasm_build => examples/wasm}/script.js | 0 iguana/tools/getos.pyc | Bin 8275 -> 0 bytes js/Dockerfile | 75 ----- js/package-lock.json | 98 ------ js/package.json | 15 - js/wasm-build.sh | 9 - js/wasm-run.js | 316 ------------------ js/worker.js | 3 - android-ndk.rb => scripts/ci/android-ndk.rb | 0 android-ndk.sh => scripts/ci/android-ndk.sh | 0 {etomic_build => scripts/mm2}/autoprice | 0 {etomic_build => scripts/mm2}/buy | 0 .../mm2}/client/all_swaps_uuids_by_filter | 0 .../mm2}/client/ban_pubkey | 0 .../mm2}/client/best_orders | 0 .../mm2}/client/buy_ONE_ANOTHER | 0 {etomic_build => scripts/mm2}/client/client | 0 .../mm2}/client/client_debug | 0 .../mm2}/client/disable_coin | 0 {etomic_build => scripts/mm2}/client/enable | 0 .../mm2}/client/enable_ADEX | 0 .../mm2}/client/enable_BCH | 0 .../mm2}/client/enable_BNB | 0 .../mm2}/client/enable_BNBT | 0 .../mm2}/client/enable_GRS | 0 .../mm2}/client/enable_MORTY | 0 .../mm2}/client/enable_RICK | 0 .../mm2}/client/enable_USDF | 0 .../mm2}/client/enable_tBCH | 0 .../mm2}/client/enable_tBCH_USDF | 0 .../mm2}/client/get_trade_fee | 0 .../mm2}/client/list_banned_pubkeys | 0 .../mm2}/client/min_trading_vol | 0 .../mm2}/client/my_balance | 0 .../mm2}/client/my_recent_swaps | 0 .../mm2}/client/my_tx_history_from_id | 0 .../mm2}/client/my_tx_history_page_number | 0 .../mm2}/client/passphrase | 0 .../mm2}/client/setpassphrase | 0 .../mm2}/client/setprice_ONE_ANOTHER | 0 {etomic_build => scripts/mm2}/client/userpass | 0 .../mm2}/client/validate_address | 0 {etomic_build => scripts/mm2}/client/withdraw | 0 {etomic_build => scripts/mm2}/enable | 0 {etomic_build => scripts/mm2}/orderbook | 0 {etomic_build => scripts/mm2}/seed/enable | 0 {etomic_build => scripts/mm2}/seed/myipaddr | 0 {etomic_build => scripts/mm2}/seed/passphrase | 0 {etomic_build => scripts/mm2}/seed/run | 0 {etomic_build => scripts/mm2}/seed/run_debug | 0 .../mm2}/seed/sell_ONE_ANOTHER | 0 .../mm2}/seed/setpassphrase | 0 {etomic_build => scripts/mm2}/seed/userpass | 0 {etomic_build => scripts/mm2}/setpassphrase | 0 {etomic_build => scripts/mm2}/stop | 0 {etomic_build => scripts/mm2}/userpass | 0 start_ONE_ANOTHER_trade.sh | 9 - travis_cmake_linux.sh | 5 - travis_cmake_mac.sh | 7 - 83 files changed, 39 insertions(+), 684 deletions(-) rename Dockerfile => .docker/Dockerfile (98%) rename Dockerfile.aarch64-linux-android => .docker/Dockerfile.aarch64-linux-android (95%) rename Dockerfile.armv7-linux-androideabi => .docker/Dockerfile.armv7-linux-androideabi (95%) rename Dockerfile.armv7-unknown-linux-gnueabihf => .docker/Dockerfile.armv7-unknown-linux-gnueabihf (81%) rename Dockerfile.dev-release => .docker/Dockerfile.dev-release (68%) rename Dockerfile.i686-linux-android => .docker/Dockerfile.i686-linux-android (95%) rename Dockerfile.parity.dev => .docker/Dockerfile.parity.dev (72%) rename Dockerfile.release => .docker/Dockerfile.release (69%) rename Dockerfile.ubuntu.ci => .docker/Dockerfile.ubuntu.ci (95%) rename Dockerfile.x86_64-linux-android => .docker/Dockerfile.x86_64-linux-android (95%) rename parity.dev.chain.json => .docker/parity.dev.chain.json (100%) delete mode 100644 .gitlab-ci.yml rename CONTRIBUTING.md => docs/CONTRIBUTING.md (100%) create mode 100644 examples/README.md rename {wasm_build => examples/wasm}/README.md (100%) rename {wasm_build => examples/wasm}/index.html (100%) rename {wasm_build => examples/wasm}/script.js (100%) delete mode 100755 iguana/tools/getos.pyc delete mode 100644 js/Dockerfile delete mode 100644 js/package-lock.json delete mode 100644 js/package.json delete mode 100644 js/wasm-build.sh delete mode 100644 js/wasm-run.js delete mode 100644 js/worker.js rename android-ndk.rb => scripts/ci/android-ndk.rb (100%) rename android-ndk.sh => scripts/ci/android-ndk.sh (100%) rename {etomic_build => scripts/mm2}/autoprice (100%) rename {etomic_build => scripts/mm2}/buy (100%) rename {etomic_build => scripts/mm2}/client/all_swaps_uuids_by_filter (100%) rename {etomic_build => scripts/mm2}/client/ban_pubkey (100%) rename {etomic_build => scripts/mm2}/client/best_orders (100%) rename {etomic_build => scripts/mm2}/client/buy_ONE_ANOTHER (100%) rename {etomic_build => scripts/mm2}/client/client (100%) rename {etomic_build => scripts/mm2}/client/client_debug (100%) rename {etomic_build => scripts/mm2}/client/disable_coin (100%) rename {etomic_build => scripts/mm2}/client/enable (100%) rename {etomic_build => scripts/mm2}/client/enable_ADEX (100%) rename {etomic_build => scripts/mm2}/client/enable_BCH (100%) rename {etomic_build => scripts/mm2}/client/enable_BNB (100%) rename {etomic_build => scripts/mm2}/client/enable_BNBT (100%) rename {etomic_build => scripts/mm2}/client/enable_GRS (100%) rename {etomic_build => scripts/mm2}/client/enable_MORTY (100%) rename {etomic_build => scripts/mm2}/client/enable_RICK (100%) rename {etomic_build => scripts/mm2}/client/enable_USDF (100%) rename {etomic_build => scripts/mm2}/client/enable_tBCH (100%) rename {etomic_build => scripts/mm2}/client/enable_tBCH_USDF (100%) rename {etomic_build => scripts/mm2}/client/get_trade_fee (100%) rename {etomic_build => scripts/mm2}/client/list_banned_pubkeys (100%) rename {etomic_build => scripts/mm2}/client/min_trading_vol (100%) rename {etomic_build => scripts/mm2}/client/my_balance (100%) rename {etomic_build => scripts/mm2}/client/my_recent_swaps (100%) rename {etomic_build => scripts/mm2}/client/my_tx_history_from_id (100%) rename {etomic_build => scripts/mm2}/client/my_tx_history_page_number (100%) rename {etomic_build => scripts/mm2}/client/passphrase (100%) rename {etomic_build => scripts/mm2}/client/setpassphrase (100%) rename {etomic_build => scripts/mm2}/client/setprice_ONE_ANOTHER (100%) rename {etomic_build => scripts/mm2}/client/userpass (100%) rename {etomic_build => scripts/mm2}/client/validate_address (100%) rename {etomic_build => scripts/mm2}/client/withdraw (100%) rename {etomic_build => scripts/mm2}/enable (100%) rename {etomic_build => scripts/mm2}/orderbook (100%) rename {etomic_build => scripts/mm2}/seed/enable (100%) rename {etomic_build => scripts/mm2}/seed/myipaddr (100%) rename {etomic_build => scripts/mm2}/seed/passphrase (100%) rename {etomic_build => scripts/mm2}/seed/run (100%) rename {etomic_build => scripts/mm2}/seed/run_debug (100%) rename {etomic_build => scripts/mm2}/seed/sell_ONE_ANOTHER (100%) rename {etomic_build => scripts/mm2}/seed/setpassphrase (100%) rename {etomic_build => scripts/mm2}/seed/userpass (100%) rename {etomic_build => scripts/mm2}/setpassphrase (100%) rename {etomic_build => scripts/mm2}/stop (100%) rename {etomic_build => scripts/mm2}/userpass (100%) delete mode 100755 start_ONE_ANOTHER_trade.sh delete mode 100755 travis_cmake_linux.sh delete mode 100644 travis_cmake_mac.sh diff --git a/Dockerfile b/.docker/Dockerfile similarity index 98% rename from Dockerfile rename to .docker/Dockerfile index 6a1ba87559..eb53aa84ec 100644 --- a/Dockerfile +++ b/.docker/Dockerfile @@ -6,7 +6,7 @@ # docker build --tag mm2 . # NB: The version here was picked to match the one tested in our CI. The latest Travis has (as of 2018-11) is Xenial. -FROM ubuntu:xenial +FROM docker.io/ubuntu:xenial RUN \ apt-get update &&\ diff --git a/Dockerfile.aarch64-linux-android b/.docker/Dockerfile.aarch64-linux-android similarity index 95% rename from Dockerfile.aarch64-linux-android rename to .docker/Dockerfile.aarch64-linux-android index 6d3c32598f..9f2c17fde6 100644 --- a/Dockerfile.aarch64-linux-android +++ b/.docker/Dockerfile.aarch64-linux-android @@ -1,4 +1,4 @@ -FROM ubuntu:16.04 +FROM docker.io/ubuntu:16.04 RUN apt-get update && \ apt-get install -y --no-install-recommends \ @@ -23,7 +23,7 @@ RUN apt-get update && \ libc6-dev-i386 && \ apt-get clean -COPY android-ndk.sh / +COPY ./scripts/ci/android-ndk.sh / RUN bash /android-ndk.sh arm64 21 ENV PATH=$PATH:/android-ndk/bin ENV RUSTFMT=rustfmt diff --git a/Dockerfile.armv7-linux-androideabi b/.docker/Dockerfile.armv7-linux-androideabi similarity index 95% rename from Dockerfile.armv7-linux-androideabi rename to .docker/Dockerfile.armv7-linux-androideabi index f132042cd6..b6115d4fa8 100644 --- a/Dockerfile.armv7-linux-androideabi +++ b/.docker/Dockerfile.armv7-linux-androideabi @@ -1,4 +1,4 @@ -FROM ubuntu:16.04 +FROM docker.io/ubuntu:16.04 RUN apt-get update && \ apt-get install -y --no-install-recommends \ @@ -23,7 +23,7 @@ RUN apt-get update && \ libc6-dev-i386 && \ apt-get clean -COPY android-ndk.sh / +COPY ./scripts/ci/android-ndk.sh / RUN bash /android-ndk.sh arm 21 ENV PATH=$PATH:/android-ndk/bin ENV RUSTFMT=rustfmt diff --git a/Dockerfile.armv7-unknown-linux-gnueabihf b/.docker/Dockerfile.armv7-unknown-linux-gnueabihf similarity index 81% rename from Dockerfile.armv7-unknown-linux-gnueabihf rename to .docker/Dockerfile.armv7-unknown-linux-gnueabihf index 613a1098b3..30c95315f6 100644 --- a/Dockerfile.armv7-unknown-linux-gnueabihf +++ b/.docker/Dockerfile.armv7-unknown-linux-gnueabihf @@ -1,4 +1,4 @@ -FROM rustembedded/cross:armv7-unknown-linux-gnueabihf-0.2.1 +FROM docker.io/rustembedded/cross:armv7-unknown-linux-gnueabihf-0.2.1 RUN dpkg --add-architecture armhf RUN apt-get update && apt-get install -y llvm-3.9-dev libclang-3.9-dev clang-3.9 libc6-dev-i386 libssl-dev:armhf && apt-get install -y g++-arm-linux-gnueabihf && apt-get clean ENV CMAKE_FORCE_C_COMPILER=arm-linux-gnueabihf-gcc \ diff --git a/Dockerfile.dev-release b/.docker/Dockerfile.dev-release similarity index 68% rename from Dockerfile.dev-release rename to .docker/Dockerfile.dev-release index 48e3f47e72..33aa9c5d27 100644 --- a/Dockerfile.dev-release +++ b/.docker/Dockerfile.dev-release @@ -1,4 +1,4 @@ -FROM debian:stable-slim +FROM docker.io/debian:stable-slim WORKDIR /mm2 COPY target/ci/mm2 /usr/local/bin/mm2 EXPOSE 7783 diff --git a/Dockerfile.i686-linux-android b/.docker/Dockerfile.i686-linux-android similarity index 95% rename from Dockerfile.i686-linux-android rename to .docker/Dockerfile.i686-linux-android index 01ec36f3ec..76717f40b9 100644 --- a/Dockerfile.i686-linux-android +++ b/.docker/Dockerfile.i686-linux-android @@ -1,4 +1,4 @@ -FROM ubuntu:16.04 +FROM docker.io/ubuntu:16.04 RUN apt-get update && \ apt-get install -y --no-install-recommends \ @@ -23,7 +23,7 @@ RUN apt-get update && \ libc6-dev-i386 && \ apt-get clean -COPY android-ndk.sh / +COPY ./scripts/ci/android-ndk.sh / RUN bash /android-ndk.sh x86 21 ENV PATH=$PATH:/android-ndk/bin ENV RUSTFMT=rustfmt diff --git a/Dockerfile.parity.dev b/.docker/Dockerfile.parity.dev similarity index 72% rename from Dockerfile.parity.dev rename to .docker/Dockerfile.parity.dev index 8dddf5c208..92abb4da3c 100644 --- a/Dockerfile.parity.dev +++ b/.docker/Dockerfile.parity.dev @@ -1,10 +1,10 @@ # Setup Ethereum dev blockchain with pre-deployed swap contract and ERC20 token. # For more info check Parity docs: https://wiki.parity.io/Private-development-chain and chain config file: parity.dev.chain.json # Usage example: -# docker build . -f Dockerfile.parity.dev -t artempikulin/parity_dev_node +# docker build . -f .docker/Dockerfile.parity.dev -t artempikulin/parity_dev_node # docker run -p 8545:8545 artempikulin/parity_dev_node -FROM parity/parity:beta -COPY parity.dev.chain.json /home/parity/.local/share/io.parity.ethereum/chain.json +FROM docker.io/parity/parity:beta +COPY .docker/parity.dev.chain.json /home/parity/.local/share/io.parity.ethereum/chain.json USER root RUN chmod -R 777 /home/parity/.local/share/io.parity.ethereum USER parity diff --git a/Dockerfile.release b/.docker/Dockerfile.release similarity index 69% rename from Dockerfile.release rename to .docker/Dockerfile.release index 0b07d7f3a0..8de75301d6 100644 --- a/Dockerfile.release +++ b/.docker/Dockerfile.release @@ -1,4 +1,4 @@ -FROM debian:stable-slim +FROM docker.io/debian:stable-slim WORKDIR /mm2 COPY target/release/mm2 /usr/local/bin/mm2 EXPOSE 7783 diff --git a/Dockerfile.ubuntu.ci b/.docker/Dockerfile.ubuntu.ci similarity index 95% rename from Dockerfile.ubuntu.ci rename to .docker/Dockerfile.ubuntu.ci index 028117edd7..fc759dbcca 100644 --- a/Dockerfile.ubuntu.ci +++ b/.docker/Dockerfile.ubuntu.ci @@ -1,4 +1,4 @@ -FROM ubuntu:xenial-20151218.1 +FROM docker.io/ubuntu:xenial-20151218.1 RUN \ apt-get update &&\ diff --git a/Dockerfile.x86_64-linux-android b/.docker/Dockerfile.x86_64-linux-android similarity index 95% rename from Dockerfile.x86_64-linux-android rename to .docker/Dockerfile.x86_64-linux-android index 54b61089f4..d404629908 100644 --- a/Dockerfile.x86_64-linux-android +++ b/.docker/Dockerfile.x86_64-linux-android @@ -1,4 +1,4 @@ -FROM ubuntu:16.04 +FROM docker.io/ubuntu:16.04 RUN apt-get update && \ apt-get install -y --no-install-recommends \ @@ -24,7 +24,7 @@ RUN apt-get update && \ libc6-dev-i386 && \ apt-get clean -COPY android-ndk.sh / +COPY ./scripts/ci/android-ndk.sh / RUN bash /android-ndk.sh x86_64 21 ENV PATH=$PATH:/android-ndk/bin ENV RUSTFMT=rustfmt diff --git a/parity.dev.chain.json b/.docker/parity.dev.chain.json similarity index 100% rename from parity.dev.chain.json rename to .docker/parity.dev.chain.json diff --git a/.github/workflows/dev-build.yml b/.github/workflows/dev-build.yml index f41fdfd057..8ef8886fa6 100644 --- a/.github/workflows/dev-build.yml +++ b/.github/workflows/dev-build.yml @@ -69,7 +69,7 @@ jobs: if: github.event_name != 'pull_request' && github.ref == 'refs/heads/dev' run: | CONTAINER_TAG="dev-$COMMIT_HASH" - docker build -t komodoofficial/atomicdexapi:"$CONTAINER_TAG" -t komodoofficial/atomicdexapi:dev-latest -f Dockerfile.dev-release . + docker build -t komodoofficial/atomicdexapi:"$CONTAINER_TAG" -t komodoofficial/atomicdexapi:dev-latest -f .docker/Dockerfile.dev-release . docker push komodoofficial/atomicdexapi:"$CONTAINER_TAG" docker push komodoofficial/atomicdexapi:dev-latest @@ -329,7 +329,7 @@ jobs: rustup target add aarch64-linux-android - name: Setup NDK - run: ./android-ndk.sh x86 21 + run: ./scripts/ci/android-ndk.sh x86 21 - name: Calculate commit hash for PR commit if: github.event_name == 'pull_request' @@ -383,7 +383,7 @@ jobs: rustup target add armv7-linux-androideabi - name: Setup NDK - run: ./android-ndk.sh x86 21 + run: ./scripts/ci/android-ndk.sh x86 21 - name: Calculate commit hash for PR commit if: github.event_name == 'pull_request' diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index 9cf009f810..2c12e3c5ab 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -61,7 +61,7 @@ jobs: - name: Build and push container image run: | export CONTAINER_TAG=$(./target/release/mm2 --version | awk '{print $3}') - docker build -t komodoofficial/atomicdexapi:"$CONTAINER_TAG" -t komodoofficial/atomicdexapi:main-latest -f Dockerfile.release . + docker build -t komodoofficial/atomicdexapi:"$CONTAINER_TAG" -t komodoofficial/atomicdexapi:main-latest -f .docker/Dockerfile.release . docker push komodoofficial/atomicdexapi:"$CONTAINER_TAG" docker push komodoofficial/atomicdexapi:main-latest @@ -291,7 +291,7 @@ jobs: rustup target add aarch64-linux-android - name: Setup NDK - run: ./android-ndk.sh x86 21 + run: ./scripts/ci/android-ndk.sh x86 21 - name: Calculate commit hash for PR commit if: github.event_name == 'pull_request' @@ -339,7 +339,7 @@ jobs: rustup target add armv7-linux-androideabi - name: Setup NDK - run: ./android-ndk.sh x86 21 + run: ./scripts/ci/android-ndk.sh x86 21 - name: Calculate commit hash for PR commit if: github.event_name == 'pull_request' diff --git a/.gitignore b/.gitignore index a29a345ca0..6c5d310af4 100755 --- a/.gitignore +++ b/.gitignore @@ -15,13 +15,12 @@ DB/* .env.client .env.seed -etomic_build/client/DB -etomic_build/client/stats.log -etomic_build/client/unparsed.txt -etomic_build/seed/DB -etomic_build/seed/stats.log -etomic_build/seed/unparsed.txt -iguana/exchanges/manychains +scripts/mm2/client/DB +scripts/mm2/client/stats.log +scripts/mm2/client/unparsed.txt +scripts/mm2/seed/DB +scripts/mm2/seed/stats.log +scripts/mm2/seed/unparsed.txt /marketmaker_depends /x64 @@ -40,7 +39,6 @@ iguana/exchanges/manychains /MM_VERSION /MM_VERSION.tmp /target -/iguana/exchanges/etomicswap/target # Subcrate artefacts /mm2src/*/target diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 2be033cc91..0000000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,110 +0,0 @@ -stages: - - initial-build - - post-build - -variables: - GIT_CLEAN_FLAGS: none - -android-armv7: - tags: - - android - - armv7 - stage: initial-build - script: - - . $HOME/.cargo/env - - export PATH=$PATH:/home/azureagent/android-ndk/arch-ndk/armv7/android-ndk/bin - - CC_armv7_linux_androideabi=armv7a-linux-androideabi21-clang CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=armv7a-linux-androideabi21-clang cargo build --features native --target=armv7-linux-androideabi --release --lib - artifacts: - paths: - - target/armv7-linux-androideabi/release/libmm2.a - -android-aarch64: - tags: - - android - - aarch64 - stage: initial-build - script: - - . $HOME/.cargo/env - - export PATH=$PATH:/home/azureagent/android-ndk/arch-ndk/aarch64/android-ndk/bin/ - - CC_aarch64_linux_android=aarch64-linux-android21-clang CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android21-clang cargo build --features native --target=aarch64-linux-android --release --lib - artifacts: - paths: - - target/aarch64-linux-android/release/libmm2.a - -android-x86_64: - tags: - - android - - x86_64 - stage: initial-build - script: - - . $HOME/.cargo/env - - export PATH=$PATH:/home/azureagent/android-ndk/arch-ndk/x86_64/android-ndk/bin - - CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER=x86_64-linux-android21-clang CC_x86_64_linux_android=x86_64-linux-android21-clang cargo build --features native --target=x86_64-linux-android --release --lib - artifacts: - paths: - - target/x86_64-linux-android/release/libmm2.a - -android-i686: - tags: - - android - - i686 - stage: initial-build - script: - - . $HOME/.cargo/env - - export PATH=$PATH:/home/azureagent/android-ndk/arch-ndk/i686/android-ndk/bin - - CARGO_TARGET_I686_LINUX_ANDROID_LINKER=i686-linux-android21-clang CC_i686_linux_android=i686-linux-android21-clang cargo build --features native --target=i686-linux-android --release --lib - artifacts: - paths: - - target/i686-linux-android/release/libmm2.a - -macos-aarch64: - tags: - - mac - - aarch64 - stage: post-build - needs: - - job: macos-build - script: - - cp /Users/hetzner/GitLab/archive/aarch64/libmm2.a . - artifacts: - paths: - - libmm2.a - -#macos-x86_64: -# tags: -# - mac -# - x86_64 -# stage: post-build -# needs: -# - job: macos-build -# script: -# - cp /Users/administrator/GitLab/archive/x86_64/libmm2.a . -# artifacts: -# paths: -# - libmm2.a - -#macos-universal: -# tags: -# - mac -# - universal -# stage: post-build -# needs: -# - job: macos-build -# script: -# - cp /Users/administrator/GitLab/archive/universal/libmm2.a . -# artifacts: -# paths: -# - libmm2.a - -macos-build: - tags: - - mac - - universal - stage: initial-build - script: -# - cargo lipo --features native --targets x86_64-apple-ios,aarch64-apple-ios --release -# TMP disable universal builds until x86_64 build is fixed on server - - IPHONEOS_DEPLOYMENT_TARGET=9.0 cargo build --target aarch64-apple-ios --release --lib - - cp target/aarch64-apple-ios/release/libmm2.a /Users/hetzner/GitLab/archive/aarch64/libmm2.a -# - cp target/universal/release/libmm2.a /Users/hetzner/GitLab/archive/universal/libmm2.a -# - cp target/x86_64-apple-ios/release/libmm2.a /Users/hetzner/GitLab/archive/x86_64/libmm2.a diff --git a/CHANGELOG.md b/CHANGELOG.md index 4340ab5f7d..f63d6e2632 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ **Enhancements/Fixes:** - CI/CD workflow logics are improved [#1736](https://github.com/KomodoPlatform/atomicDEX-API/pull/1736) +- Project root is simplified/refactored [#1738](https://github.com/KomodoPlatform/atomicDEX-API/pull/1738) ## v1.0.1-beta - 2023-03-17 diff --git a/README.md b/README.md index b5e9acaa39..010ba3094c 100755 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ Refer to the [Komodo Developer Docs](https://developers.komodoplatform.com/basic ## Additional docs for developers -- [Contribution guide](./CONTRIBUTING.md) +- [Contribution guide](./docs/CONTRIBUTING.md) - [Setting up the environment to run the full tests suite](./docs/DEV_ENVIRONMENT.md) - [Git flow and general workflow](./docs/GIT_FLOW_AND_WORKING_PROCESS.md) - [Komodo Developer Docs](https://developers.komodoplatform.com/basic-docs/atomicdex/introduction-to-atomicdex.html) diff --git a/docs/ANDROID.md b/docs/ANDROID.md index 3a665493cf..75e4016650 100644 --- a/docs/ANDROID.md +++ b/docs/ANDROID.md @@ -27,19 +27,19 @@ The [Android NDK installer](https://github.com/rust-embedded/cross/tree/master/d #### armeabi-v7a ABI Docker image - (cd supernet && docker build --tag armv7-linux-androideabi-aga -f Dockerfile.armv7-linux-androideabi .) + (cd supernet && docker build --tag armv7-linux-androideabi-aga -f .docker/Dockerfile.armv7-linux-androideabi .) #### arm64-v8a ABI Docker image - (cd supernet && docker build --tag aarch64-linux-android-aga -f Dockerfile.aarch64-linux-android .) + (cd supernet && docker build --tag aarch64-linux-android-aga -f .docker/Dockerfile.aarch64-linux-android .) ### x86 ABI Docker image - (cd supernet && docker build --tag i686-linux-android-aga -f Dockerfile.i686-linux-android .) + (cd supernet && docker build --tag i686-linux-android-aga -f .docker/Dockerfile.i686-linux-android .) ### x86_64 ABI Docker image - (cd supernet && docker build --tag x86_64-linux-android-aga -f Dockerfile.x86_64-linux-android .) + (cd supernet && docker build --tag x86_64-linux-android-aga -f .docker/Dockerfile.x86_64-linux-android .) ### Setup the NDK_HOME variable diff --git a/docs/ANDROID_CROSS_ON_M1_MAC.md b/docs/ANDROID_CROSS_ON_M1_MAC.md index 3d9321a49e..666e7be92c 100644 --- a/docs/ANDROID_CROSS_ON_M1_MAC.md +++ b/docs/ANDROID_CROSS_ON_M1_MAC.md @@ -2,7 +2,7 @@ 1. Ensure that your terminal is added to `Developer tools` in MacOS Security & Privacy settings. 2. The cross-compilation requires Android NDK version 21. Custom brew cask file is located at the root of this repo. -3. Install android-ndk by `brew install --cask android-ndk.rb` or other preferred way. +3. Install android-ndk by `brew install --cask ./scripts/ci/android-ndk.rb` or other preferred way. 4. Add Android targets via rustup ```shell rustup target add armv7-linux-androideabi diff --git a/CONTRIBUTING.md b/docs/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTING.md rename to docs/CONTRIBUTING.md diff --git a/docs/RASPBERRY_PI4_CROSS.md b/docs/RASPBERRY_PI4_CROSS.md index b4cf3ca072..91bb6a27dd 100644 --- a/docs/RASPBERRY_PI4_CROSS.md +++ b/docs/RASPBERRY_PI4_CROSS.md @@ -4,6 +4,6 @@ rustup install nightly rustup default nightly ``` 2. Install cross: `cargo install cross`. -3. Build the Docker image for cross compilation: `docker build -f Dockerfile.armv7-unknown-linux-gnueabihf -t mm2-armv7-unknown-linux-gnueabihf .` +3. Build the Docker image for cross compilation: `docker build -f .docker/Dockerfile.armv7-unknown-linux-gnueabihf -t mm2-armv7-unknown-linux-gnueabihf .` 4. Build mm2: `cross build --target armv7-unknown-linux-gnueabihf` or `cross build --target armv7-unknown-linux-gnueabihf --release` for release build. 5. The binary path will be `target/armv7-unknown-linux-gnueabihf/debug/mm2` or `target/armv7-unknown-linux-gnueabihf/release/mm2` for release build. \ No newline at end of file diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000000..e33942a767 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,3 @@ +# AtomicDEX-API Examples + +This directory contains example implementation/use cases of AtomicDEX-API \ No newline at end of file diff --git a/wasm_build/README.md b/examples/wasm/README.md similarity index 100% rename from wasm_build/README.md rename to examples/wasm/README.md diff --git a/wasm_build/index.html b/examples/wasm/index.html similarity index 100% rename from wasm_build/index.html rename to examples/wasm/index.html diff --git a/wasm_build/script.js b/examples/wasm/script.js similarity index 100% rename from wasm_build/script.js rename to examples/wasm/script.js diff --git a/iguana/tools/getos.pyc b/iguana/tools/getos.pyc deleted file mode 100755 index 72f8ff3ebef6ff8c0a73ce1a732da2175b43c4ec..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8275 zcmbtZ&u<&am98c!$)qJqwrtrR|LRHX8G6U0oEfj2cs<@xBzf#)ED257o+z3SEp|(4 ziR`AUnzpo%_mByY9C8S-K@LFQepaS3h2T?|ZMRi+`D@%>3IgAGK8WGlKsg;4wdRlnRtuN9w4cpxTaFN5i)y`?=Syn6l;=m(`beH1RqLZFEU4WvwRyDaB)IcTxr8ly%rVrGg15#F+0f6&_bxnCYbYj#8g0 z^^NrtDwtwneOd*_C38{*CnR%91=Et5QNc;coL0dp$(&KajAYKL;Iw4kP{A3=oKwMB z$(&c=1r@xZ_6kb>z&W@m)0M^g2oYy70NayjBA2_A(gxaep{e8z-zhvhwYYANy zUg8RZbL#YGRt3S2xw3+4R4;IM{)}WXOhes?;?P}bxPBbCPkkLFJ>w?nPN-dTVA8PT zc6HJXbsB}HUa1U3@QNGzozP9TT;{uNKix`n$L*Ogkly}AFRtmec3j_7DAi6{ei|h) zds*1gNhhqk?%GadT>P=8Yc4u;(K>9Um9->kw|4v}<||SB zG}#O5mFR!*vuyqeYi-@ySk=k4_B-y~s2v)&y8q?5s~aCC$#y&3utRUmcf0M#PH3ZL zXA|y+X%X_zqS)NV|Jk8;%&Zm9XYO~qvkOU_hH+|UANZ}6#)~gVM;*UqX4p~B=-JIE zp52xy)a-aE&8Hp3z5S?wTr|c6k22ShbPv)U=<412O&3am!m&%xlMbKsA`PwU9+pq# znU;>aX(fUQD(P}b>qPf$l+|Blr$>;40JWpMMiqHg<)|sEn@#R+vzb<;&`E+`8%6sT zs+8o+Rpe$LnoyhB-S*9!H)o^mo*(=9zZBbIX1BvMG4<|&M@@bakKr(*PJcor6c<>3 z9!aXyt`G$?F!`cNO9b|(1TO`b(+Q^Y3m-Kbi(hYgD=TYN>MdnsV$xCk!;oS86oSy2 zpYEhoWDsetNmkTY@b0g!H5c!DueBoS>%%a`JXSHx+ZaXGraotFAfIe)SQU5>OEQ;- zY6`5;RWVYl1HM<3+B+n+#-MgYYS$E~t^rtq?rhr(y7)Gfr=Th>d0CXvI@kt&J(QJ{ z17EXD7+9ycZ|W;=Uo@a<7;w^(U|;84wn^najdW>g&`zi_#t0+1JzLQS=T? zu4X*)4vOX&66IWWO3n%U6a+Gya}kd~W)YczVnnUahigQw&mDCL02Ilxu;W9hNb>pv zF0TQcG-R#IDQ$DrTUl6YG*-Okyti=g{@T*Q+Cy*Y^P3*e-FWX^v9b9Fi*q*wh#plh zkOKxI4NBl_0ZGB*n(l=naMy2}&{`ZJ>+9AIy2`WY3ze^8X0lPR$;VMVcViBH7}~Ic z4o?)$K#!tBZYHNGI@|#iputKsL%961 zOs$|W2Af8u={G}7#k^@un*KD@R8mj=q@HZ@@A09`Ywrk{&pDKtW_bi1N+GY$Ib7Ef zPI<7dgYyb_hX7WN1u|chd{I4)-&CdasJP^H2S1+?chtv_gur1*Z2@c5GPG{((p#Ee ze6VC(RM@N=Cn+3W555?l45Z@fBuQzB(7#f*ETMDT9)WS;H_asS)_b{L_%xC_LO82i zNIIP;bypJ;(aj3KhV%t)*GC8OwhUqi7lR*%tS1Ra@iIkNkEo6lYW=07Z~Xl&*E?2cTyT{M0T_kgT(HrCe)E z7S!x!3z81tFYOeB-RTLQa+p^(A9@$d>6w=Q85QDyl~Z<3!H%X2qYi(kopI+3p2_T) zDO^Td5v3_-!Z}%Jao4zhPD(88XUJH)BDybRR;Ljk!n?r`8f*ldU>-kJ2kV*L0r7}t zw}IFrQbY7P=<$=E0=2Le1d=~dKrOAc zpis*w5xq33#K7{vWguE=&fSo0V)ngv2i`-rx<}oM>#KF-Et3XGFO}Fu5a8>MP@SPV z7z9xz66uIRc;`{HPNlbrkh2vUBOR{_u1aWKy}!ByOS2g0#SGL!?=s5Xamo^^OZ%;` zOQ3sSK&i^1yeT$PzME|BN`^%H+Tf7jcpg1{3tfv{DQtTg^ja#6J4NRrATR}BOvrB^ z2%N|QC4P_OWw#|8svk&wkvp4_?fW^|4wDjv@zQAak^~1Rk1>1$h|XqQRaU!w>azWR zFYkXKY9&bXw$prM{foS2@UCTWV9ilmg`6Y<1{_@5vh2{pJ#Xc~Qgd~F?VdS}+WRpq zG78+Gda{i~=0kN7^v6NC1%pQ9&m+kd^CBm*%WJ68XsK6;2646?InU!zLRsFM%yIiO z2Jzbx1(I_%eG>{%OrwwuzPNOE{^3V!GGPHyVs^qdjy*;~&AU+?EbWK)W5#$xs1h*B zIibn!y${gi>jKLXHwWsXHw&!732+Tq$C)b508*p)UqN{aEF{1p^cgk?u>J#_Ghmn* zZXk+4gHTIB{Nr2nxefRf+ro{PK)Vk)un1i;;?XC06GBY;PVUd)q2aS33(Clv#BV~% z{D}4l)_TE>@+Dx=4tA8n=GXF`^f=^hH&r?=Cw9aJWeRM=Z&#%97}=4n$1uA>MtPH@ zyba8y$e4p9IHmL@2UDhOqA`Hvjr8@M>g%0G8-cOZ0M zB?>LiT1I`ByG{@E;<=F9YmbOxP&~uZHi864Sq2T_mh0v$Ud!8X4zw*{tC#wlZR=S< zfD;*K1#C zZqz<`=c*v~b9-=;n4QSM*84|}%Q$}ShW91*DhB*Ma^4b?e)J(mB@FMmY+xumWZn`j zx5QhJem-uleBGPlD>s>ZnaNj>h-cAZ+S73>2}17*>o~?rL*^<|K|8xMAsvJ`pKYD= zy4F9@jd+Vpc%2|G!oPKUsdtZMI(n;MFagfxHWY%2T07otw7oJdkYf;xEc**>dYkW} zC>Ig%HiZhFQfYkboO2lzFc%zW#@u3SvU!jAbm_17^IZsX>qoE`eDf~ z3W)VV2aG%}GJ`66NX3yLhH0Q!AmgKWaE1#8g?vZ2Wf5@4U&F@2U>HOdA)^X7ey|86 zhm8s+)~cwvjWJgdg#y98n+1Gs-0N)ORwKJqk_)A`Z+HCNMBl03&ZE9NZ{sS;bq8fS z4&DYW=$egqYk9<*by&yivPX4EuZsrqW2C`E%sC{O=_kj@Xyi;;(3f&hG$P00%dKz>dX@y)Fa$03ZMd;|{0b05@#F@uuG}HrxRJ+i$@A!9b!i z)PN{t&@evKz>fj_F%We0yP|XNH{h$maefBitfr*_lm`fd4e=>pucY)J34DZA_#l8v zho>u)N3xd?zrd4lp%6pZGN$x|!}uMc211CEivLsU%SvBy2GwdnSNgvk#7dkV!YIsY zgdq_kC9WrsTb@{gBZgjB@&7nTKfH&PV(3Qo3^sPzaC>Vt@vF@GEgsVBaW74D*i3mR zMhDKY+uT8BRpZXUr9_nCg1-l=gHy<@90$l9ez@Q*J`SVTTzfv{wKxu%SL*_@T6U>! z=%HQe!yVkaTpm7>@DKti)bi+op6QTlwb*a9Wj%(0 z#^+2{K7*ilI&MThFK|>g`?|z=wVDa`Y8eUOLOAbD2&hjEnM0J`VElC zzOp!iyO$51zxcO_TDZ}?gE_9m?E~x@FelduZVQaO8M>w$wxX?wAGk0tH;wSU%Cag6 zv`VeYfz#L9yk84pf=a>7^g3`&66?MOSjI}>*=b|Lb7$#^Hwi3E`z z<6}9W5`JhzaQTppcbPD5meV)3wNKxqco~wFIV@nm;9*p}e4EB|hwNux{+p=rK4J0& zBoeq~cPQKTLyOE)%f4G(8GGYW#OnxPq- zMb_AC21%>g^fpmp4=Kyc$&rKh;C+<|LpnLBh>X8!$T`_qJU*cV(ug;YM0O_wcQcB& z5__OvX#Pxt`$P#i-lg6xicqiif>vO0o<;HF#D+aP2_yy^_k<1P)_mihdc4;Y+?f;~ zobWS9{>~ku{%+fkgLk+j;qFn~fMvgh@#00?hK=F3QkvwQSaGIQE|rg#%jHYu6Xnz8 R_sUcFy /tmp/rustup-init.sh &&\ - sh /tmp/rustup-init.sh -y --default-toolchain none &&\ - . /root/.cargo/env &&\ - rustup set profile minimal &&\ - rustup install nightly-2020-02-01 &&\ - rustup default nightly-2020-02-01 &&\ - # It seems that bindgen won't prettify without it: - rustup component add rustfmt-preview &&\ - rm -f /tmp/rustup-init.sh - -ENV PATH="/root/.cargo/bin:${PATH}" - -# First 7 characters of the commit ID. -ENV MM_VERSION="737ae6e" - -RUN cd /tmp &&\ - wget https://api.github.com/repos/KomodoPlatform/atomicDEX-API/tarball/$MM_VERSION &&\ - tar -xzf $MM_VERSION &&\ - ls &&\ - mv KomodoPlatform-atomicDEX-API-$MM_VERSION /mm2 &&\ - rm $MM_VERSION &&\ - echo $MM_VERSION > /mm2/MM_VERSION - -RUN cd /mm2 && cargo fetch - -# -- End of the shared parts -- - -RUN cd /tmp &&\ - wget https://nodejs.org/dist/v12.13.0/node-v12.13.0-linux-x64.tar.xz &&\ - tar -xJf node-v12.13.0-linux-x64.tar.xz &&\ - cd /tmp/node-v12.13.0-linux-x64 &&\ - cp -r * /usr/local/ &&\ - cd /tmp &&\ - rm -rf node* &&\ - node --version - -RUN rustup target add wasm32-unknown-unknown - -RUN cargo install rustfilt - -# This will overwrite the Git version with the local one. -# Only needed when we're developing or changing something locally. -#COPY . /mm2 - -RUN cd /mm2 &&\ - cargo build --target=wasm32-unknown-unknown --release &&\ - mv target/wasm32-unknown-unknown/release/mm2.wasm js/ &&\ - cargo build --bin mm2 &&\ - cp target/debug/mm2 js/ &&\ - rm -rf target - -RUN cd /mm2/js &&\ - npm install > npm-install.log 2>&1 - -CMD cd /mm2/js && node wasm-run.js 2>&1 | rustfilt diff --git a/js/package-lock.json b/js/package-lock.json deleted file mode 100644 index eb2ca9c56a..0000000000 --- a/js/package-lock.json +++ /dev/null @@ -1,98 +0,0 @@ -{ - "name": "wasm-run", - "version": "1.0.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "bencode": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/bencode/-/bencode-2.0.1.tgz", - "integrity": "sha512-2uhEl8FdjSBUyb69qDTgOEeeqDTa+n3yMQzLW0cOzNf1Ow5bwcg3idf+qsWisIKRH8Bk8oC7UXL8irRcPA8ZEQ==", - "requires": { - "safe-buffer": "^5.1.1" - } - }, - "crc-32": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.0.tgz", - "integrity": "sha512-1uBwHxF+Y/4yF5G48fwnKq6QsIXheor3ZLPT80yGBV1oEUwpPojlEhQbWKVw1VwcTQyMGHK1/XMmTjmlsmTTGA==", - "requires": { - "exit-on-epipe": "~1.0.1", - "printj": "~1.1.0" - } - }, - "cross-spawn": { - "version": "6.0.5", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", - "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", - "requires": { - "nice-try": "^1.0.4", - "path-key": "^2.0.1", - "semver": "^5.5.0", - "shebang-command": "^1.2.0", - "which": "^1.2.9" - } - }, - "electrum-client": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/electrum-client/-/electrum-client-0.0.6.tgz", - "integrity": "sha512-u6B63JbWuufkPr7/DVPfCtMbefeqU+R6oYlwUyiZ7cGMUgbjbJYBk8+wQnJm3K+uXOupoDeyOgVHoFjz5vMwrQ==" - }, - "exit-on-epipe": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/exit-on-epipe/-/exit-on-epipe-1.0.1.tgz", - "integrity": "sha512-h2z5mrROTxce56S+pnvAV890uu7ls7f1kEvVGJbw1OlFH3/mlJ5bkXu0KRyW94v37zzHPiUd55iLn3DA7TjWpw==" - }, - "isexe": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" - }, - "nice-try": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", - "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==" - }, - "path-key": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", - "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=" - }, - "printj": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/printj/-/printj-1.1.2.tgz", - "integrity": "sha512-zA2SmoLaxZyArQTOPj5LXecR+RagfPSU5Kw1qP+jkWeNlrq+eJZyY2oS68SU1Z/7/myXM4lo9716laOFAVStCQ==" - }, - "safe-buffer": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz", - "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==" - }, - "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" - }, - "shebang-command": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", - "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", - "requires": { - "shebang-regex": "^1.0.0" - } - }, - "shebang-regex": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", - "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=" - }, - "which": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", - "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", - "requires": { - "isexe": "^2.0.0" - } - } - } -} diff --git a/js/package.json b/js/package.json deleted file mode 100644 index 31781bb7cb..0000000000 --- a/js/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "wasm-run", - "version": "1.0.0", - "description": "", - "main": "wasm-run.js", - "scripts": {}, - "author": "", - "license": "GPL-2.0-only", - "dependencies": { - "bencode": "^2.0.1", - "crc-32": "^1.2.0", - "cross-spawn": "^6.0.5", - "electrum-client": "0.0.6" - } -} diff --git a/js/wasm-build.sh b/js/wasm-build.sh deleted file mode 100644 index 255be3bdf7..0000000000 --- a/js/wasm-build.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/dash -# Run with `dash js/wasm-build.sh`. -set -ex - -cargo build --bin mm2 -ln -f target/debug/mm2 js/mm2 - -cargo build --target=wasm32-unknown-unknown --release -ln -f target/wasm32-unknown-unknown/release/mm2.wasm js/mm2.wasm diff --git a/js/wasm-run.js b/js/wasm-run.js deleted file mode 100644 index 4c0262912c..0000000000 --- a/js/wasm-run.js +++ /dev/null @@ -1,316 +0,0 @@ -// Run with: -// -// dash js/wasm-build.sh && (cd js && node wasm-run.js 2>&1 | rustfilt) - -const bencode = require('bencode') -const { Buffer } = require('buffer'); -const crc32 = require('crc-32'); // TODO: Calculate the checksum in Rust instead. -const ElectrumCli = require('electrum-client'); // https://www.npmjs.com/package/electrum-client -const fs = require('fs'); -const http = require('http'); // https://nodejs.org/dist/latest-v12.x/docs/api/http.html -const os = require('os'); -// https://nodejs.org/api/child_process.html -// https://www.npmjs.com/package/cross-spawn -const spawn = require('cross-spawn'); -// https://nodejs.org/api/worker_threads.html -// https://medium.com/@Trott/using-worker-threads-in-node-js-80494136dbb6 -// https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md -const worker_threads = require('worker_threads'); - -const snooze = ms => new Promise (resolve => setTimeout (resolve, ms)); - -const keepAliveAgent = new http.Agent ({keepAlive: true}); - -function from_utf8 (memory, ptr, len) { - const view = new Uint8Array (memory.buffer, ptr, len); - const utf8dec = new TextDecoder ('utf-8'); - return utf8dec.decode (view)} - -function to_utf8 (memory, rbuf, rcap, str) { - const encoder = new TextEncoder(); - const view = encoder.encode (str); - if (view.length > rcap) return -1; - const rbuf_slice = new Uint8Array (wasmShared.memory.buffer, rbuf, rcap); - for (let i = 0; i < view.length; ++i) rbuf_slice[i] = view[i]; - return view.length} - -function http_helper (helper, timeout_ms, payload, cb) { - const cs = crc32.buf (payload); - return http.request ({ - method: 'POST', - headers: { - 'Content-Type': 'application/octet-stream', - 'Content-Length': payload.length, - 'X-Helper-Checksum': cs - }, - hostname: '127.0.0.1', - port: 7783, - path: '/helper/' + helper, - agent: keepAliveAgent, - timeout: timeout_ms - }, cb) -} - -const wasmShared = {}; - -function registerCallback (f) { - for (;;) { - const ri = Math.ceil (Math.random() * 2147483647); - const ris = '' + ri; // TODO: Use a sparse array. - if (wasmShared.callbacks[ris] != null) continue; - wasmShared.callbacks[ris] = f; - return ri}} - -async function runWasm() { - // Wait for the helpers RPC server to start. - await snooze (500); - - const wasmBytes = fs.readFileSync ('mm2.wasm'); - const httpRequests = {}; - wasmShared.callbacks = {}; - wasmShared.electrums = {}; - const memory = new WebAssembly.Memory ({initial: 1, shared: true}); - const wasmEnv = { - //memory: memory, - call_back: function (cb_id, ptr, len) { - //console.log ('call_back', cb_id, 'invoked, ptr', ptr, 'len', len); - const cb_id_s = '' + cb_id; - const f = wasmShared.callbacks[cb_id_s]; - if (f != null) f (Buffer.from (wasmShared.memory.buffer.slice (ptr, ptr + len))); - delete wasmShared.callbacks[cb_id_s]}, - console_log: function (ptr, len) { - const decoded = from_utf8 (wasmShared.memory, ptr, len); - console.log (decoded)}, - date_now: function() {return Date.now()}, - host_env: function (ptr, len, rbuf, rcap) { - const name = from_utf8 (wasmShared.memory, ptr, len); - const v = process.env[name]; - if (v == null) return -1; - return to_utf8 (wasmShared.memory, rbuf, rcap, v)}, - host_electrum_connect: function (ptr, len) { - const args_s = from_utf8 (wasmShared.memory, ptr, len); - const args = JSON.parse (args_s); - const url = args.url; - const protocol = args.protocol.toLowerCase(); - const disable_cert_verification = args.disable_cert_verification; - const caps = /^(.*?):(\d+)$/.exec (url); - if (caps == null) return -1; - const host = caps[1]; - const port = Number (caps[2]); - if (protocol != 'tls' && protocol != 'tcp') return -2; - const ecl = new ElectrumCli (port, host, protocol); - var ri = 0, ris = ''; - for (;;) { - ri = Math.ceil (Math.random() * 2147483647); - ris = '' + ri; // TODO: Use a sparse array. - if (wasmShared.electrums[ris] == null) { - wasmShared.electrums[ris] = { - host: host, - port: port, - ecl: ecl, - connected: false, - replies: []}; - break}} - ecl.connect().then (_ => {wasmShared.electrums[ris].connected = true}); - // cf. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-headers-subscribe - ecl.subscribe.on ('blockchain.headers.subscribe', (header) => { - console.log ('host_electrum_connect] TBD, Electrum header', header); - // TODO: Pass the `header` to Rust? - // The `header` looks like `[{hex: '040000', height: 175560}]` except the `hex` is large (seen ~3k). - }); - return ri}, - host_electrum_is_connected: function (ri) { - const ris = '' + ri; // TODO: Use a sparse array. - const en = wasmShared.electrums[ris]; - if (en == null) return -1; - return en.connected ? 1 : 0}, - host_electrum_request: function (ri, ptr, len) { - const ris = '' + ri; // TODO: Use a sparse array. - const en = wasmShared.electrums[ris]; - if (en == null) return -1; - const req_s = from_utf8 (wasmShared.memory, ptr, len); - const req = JSON.parse (req_s); // JsonRpcRequest - const id = Number (req.id); - if (id > 2147483647) throw new Error ('Electrum JsonRpcRequest id is too large'); - //console.log ('host_electrum_request] ri', ri, 'req:', req); - - en.ecl.request (req.method, req.params) - .then (res => { - //console.log ('host_electrum_request] ri', ri, 'req', req, '⇒', res); - const res_s = JSON.stringify (res); - //console.log ('res_s', res_s); - en.replies[id] = res_s; - wasmShared.exports.electrum_replied (ri, id)}) - .catch (err => { - wasmShared.exports.electrum_replied (ri, id)}); - return 0}, - host_electrum_reply: function (ri, id, rbuf, rcap) { - const ris = '' + ri; // TODO: Use a sparse array. - const en = wasmShared.electrums[ris]; - if (en == null) return -2; - const res_s = en.replies[id]; - if (res_s == null) return -3; - return to_utf8 (wasmShared.memory, rbuf, rcap, res_s)}, - host_ensure_dir_is_writable: function (ptr, len) { - const path = from_utf8 (wasmShared.memory, ptr, len); - // https://nodejs.org/docs/latest/api/fs.html#fs_fs_existssync_path - const exists = fs.existsSync (path); - if (exists) { - // https://nodejs.org/docs/latest/api/fs.html#fs_fs_statsync_path_options - const stats = fs.statSync (path); - if (!stats.isDirectory()) throw new Error ('path ' + path + ' is not a directory') - } else { - // https://nodejs.org/docs/latest/api/fs.html#fs_fs_mkdirsync_path_options - fs.mkdirSync (path, {recursive: true})} - return 0}, - host_read_dir: function (path_p, path_l, rbuf, rcap) { - const path = from_utf8 (wasmShared.memory, path_p, path_l); - const dir = fs.opendirSync (path); // NB: Needs NodeJS >= 12.12.0 - let entries = []; - for (;;) { - const en = dir.readSync(); - if (en == null) break; - if (!en.isFile()) continue; - const name = en.name; - const stats = fs.statSync (path + '/' + name); - const lm = Math.floor (stats.mtimeMs); - entries.push ([lm, name])} - const jens = JSON.stringify (entries); - console.log ('host_read_dir:', jens); - return to_utf8 (wasmShared.memory, rbuf, rcap, jens)}, - host_rm: function (ptr, len) { - const path = from_utf8 (wasmShared.memory, ptr, len); - fs.unlinkSync (path); - return 0}, - host_slurp: function (path_p, path_l, rbuf, rcap) { - const path = from_utf8 (wasmShared.memory, path_p, path_l); - if (!fs.existsSync (path)) return 0; - const content = fs.readFileSync (path, {encoding: 'utf8'}); - return to_utf8 (wasmShared.memory, rbuf, rcap, content)}, - host_write: function (path_p, path_l, ptr, len) { - const path = from_utf8 (wasmShared.memory, path_p, path_l); - const content = new Uint8Array (wasmShared.memory.buffer, ptr, len); - // https://nodejs.org/docs/latest/api/fs.html#fs_fs_writefilesync_file_data_options - fs.writeFileSync (path, content); - return 0}, - http_helper_check: function (http_request_id, rbuf, rcap) { - let ris = '' + http_request_id; // TODO: Use a sparse array. - if (httpRequests[ris] == null) return -1; - if (httpRequests[ris].buf == null) return -1; - const ben = { - status: httpRequests[ris].status, - ct: httpRequests[ris].ct, - cs: httpRequests[ris].cs, - body: httpRequests[ris].buf}; - const buf = bencode.encode (ben); - if (buf.length > rcap) return -buf.length; - const rbuf_slice = new Uint8Array (wasmShared.memory.buffer, rbuf, rcap); - for (let i = 0; i < buf.length; ++i) rbuf_slice[i] = buf[i]; - return buf.length}, - http_helper_if: function (helper_ptr, helper_len, payload_ptr, payload_len, timeout_ms) { - const helper = from_utf8 (wasmShared.memory, helper_ptr, helper_len); - //const payload = new Uint8Array (wasmShared.memory, payload_ptr, payload_len); - const payload = Buffer.from (wasmShared.memory.buffer.slice (payload_ptr, payload_ptr + payload_len)); - - // Find a random ID. - let ri, ris; - for (;;) { - ri = Math.ceil (Math.random() * 2147483647); - ris = '' + ri; // TODO: Use a sparse array. - if (httpRequests[ris] == null) { - httpRequests[ris] = {}; - break}} - - let chunks = []; - const req = http_helper (helper, timeout_ms, payload, (res) => { - res.on ('data', (chunk) => chunks.push (chunk)); - res.on ('end', () => { - let len = 0; - for (const chunk of chunks) {len += chunk.length} - if (res.headers['content-length'] != null && len != res.headers['content-length']) { - throw new Error ('Content-Length mismatch')} - const buf = new Uint8Array (len); - let pos = 0; - for (const chunk of chunks) { - for (let i = 0; i < chunk.length; ++i) { - buf[pos] = chunk[i]; - ++pos}} - if (pos != len) throw new Error ('length mismatch'); - httpRequests[ris].status = res.statusCode; - httpRequests[ris].ct = res.headers['content-type']; - httpRequests[ris].cs = res.headers['x-helper-checksum']; - httpRequests[ris].buf = buf; - wasmShared.exports.http_ready (ri)});}); - req.on ('error', function (err) { - httpRequests[ris].status = 0; - httpRequests[ris].ct = 'nodejs error'; - httpRequests[ris].buf = '' + err; - wasmShared.exports.http_ready (ri)}); - req.write (payload); - req.end(); - return ri}, //< request id - peers_drop_send_handler: function (shp1, shp2) { - const payload = bencode.encode ([shp1, shp2]); - const req = http_helper ('peers_drop_send_handler', 100, payload, (res) => {res.on ('end', () => {})}); - req.on ('error', function (_) {}); - req.write (payload); - req.end()}, - temp_dir: function (rbuf, rcap) {return to_utf8 (wasmShared.memory, rbuf, rcap, os.tmpdir())}}; - - const worker = new worker_threads.Worker ('./worker.js', { - // Fails with `DOMException [DataCloneError]: # could not be cloned.` - //workerData: memory - }); - worker.on ('error', (err) => {throw err}); - // Fails with `DOMException [DataCloneError]: # could not be cloned.` - //worker.on ('online', (_) => {worker.postMessage (memory)}); - - const wasmInstantiated = await WebAssembly.instantiate (wasmBytes, {env: wasmEnv}); - const exports = wasmInstantiated.instance.exports; - /** @type {WebAssembly.Memory} */ - wasmShared.memory = exports.memory; - wasmShared.exports = exports; - - const executor_i = setInterval (function() {exports.run_executor()}, 200); - - exports.set_panic_hook(); - - //await test_peers_dht(); - await trade_test_electrum_and_eth_coins(); - - clearInterval (executor_i)} - -async function test_peers_dht() { - const peers_check = exports.peers_check(); - console.log ('wasm-run] test_peers_dht…'); - const test_finished = {}; - const cb_id = registerCallback (r => test_finished.yep = true); - wasmShared.exports.test_peers_dht (cb_id); - while (!test_finished.yep) {await snooze (100)} - console.log ('wasm-run] test_peers_dht ✅')} - -async function trade_test_electrum_and_eth_coins() { - console.log ('wasm-run] trade_test_electrum_and_eth_coins…'); - const test_finished = {}; - const cb_id = registerCallback (r => test_finished.yep = true); - wasmShared.exports.trade_test_electrum_and_eth_coins (cb_id); - while (!test_finished.yep) {await snooze (100)} - console.log ('wasm-run] trade_test_electrum_and_eth_coins ✅')} - -function stop() { - const req = http.request ({ - method: 'POST', - hostname: '127.0.0.1', - port: 7783, - agent: keepAliveAgent, - }, (res) => {}); - req.on ('error', function (_) {}); - req.write ('{"method": "stop", "userpass": "pass"}'); - req.end()} - -// Start the native helpers. -const mm2 = spawn ('js/mm2', ['{"passphrase": "-", "rpc_password": "pass", "coins": []}'], {cwd: '..'}); -mm2.stdout.on ('data', (data) => console.log ('native] ' + String (data) .trim())); -mm2.stderr.on ('data', (data) => console.log ('native] ' + String (data) .trim())); - -runWasm().then (_ => stop()) .catch (ex => {console.log (ex); stop()}); diff --git a/js/worker.js b/js/worker.js deleted file mode 100644 index 7a6ec78f84..0000000000 --- a/js/worker.js +++ /dev/null @@ -1,3 +0,0 @@ -const worker_threads = require('worker_threads'); - -//console.log ('worker.js]', worker_threads.workerData); diff --git a/android-ndk.rb b/scripts/ci/android-ndk.rb similarity index 100% rename from android-ndk.rb rename to scripts/ci/android-ndk.rb diff --git a/android-ndk.sh b/scripts/ci/android-ndk.sh similarity index 100% rename from android-ndk.sh rename to scripts/ci/android-ndk.sh diff --git a/etomic_build/autoprice b/scripts/mm2/autoprice similarity index 100% rename from etomic_build/autoprice rename to scripts/mm2/autoprice diff --git a/etomic_build/buy b/scripts/mm2/buy similarity index 100% rename from etomic_build/buy rename to scripts/mm2/buy diff --git a/etomic_build/client/all_swaps_uuids_by_filter b/scripts/mm2/client/all_swaps_uuids_by_filter similarity index 100% rename from etomic_build/client/all_swaps_uuids_by_filter rename to scripts/mm2/client/all_swaps_uuids_by_filter diff --git a/etomic_build/client/ban_pubkey b/scripts/mm2/client/ban_pubkey similarity index 100% rename from etomic_build/client/ban_pubkey rename to scripts/mm2/client/ban_pubkey diff --git a/etomic_build/client/best_orders b/scripts/mm2/client/best_orders similarity index 100% rename from etomic_build/client/best_orders rename to scripts/mm2/client/best_orders diff --git a/etomic_build/client/buy_ONE_ANOTHER b/scripts/mm2/client/buy_ONE_ANOTHER similarity index 100% rename from etomic_build/client/buy_ONE_ANOTHER rename to scripts/mm2/client/buy_ONE_ANOTHER diff --git a/etomic_build/client/client b/scripts/mm2/client/client similarity index 100% rename from etomic_build/client/client rename to scripts/mm2/client/client diff --git a/etomic_build/client/client_debug b/scripts/mm2/client/client_debug similarity index 100% rename from etomic_build/client/client_debug rename to scripts/mm2/client/client_debug diff --git a/etomic_build/client/disable_coin b/scripts/mm2/client/disable_coin similarity index 100% rename from etomic_build/client/disable_coin rename to scripts/mm2/client/disable_coin diff --git a/etomic_build/client/enable b/scripts/mm2/client/enable similarity index 100% rename from etomic_build/client/enable rename to scripts/mm2/client/enable diff --git a/etomic_build/client/enable_ADEX b/scripts/mm2/client/enable_ADEX similarity index 100% rename from etomic_build/client/enable_ADEX rename to scripts/mm2/client/enable_ADEX diff --git a/etomic_build/client/enable_BCH b/scripts/mm2/client/enable_BCH similarity index 100% rename from etomic_build/client/enable_BCH rename to scripts/mm2/client/enable_BCH diff --git a/etomic_build/client/enable_BNB b/scripts/mm2/client/enable_BNB similarity index 100% rename from etomic_build/client/enable_BNB rename to scripts/mm2/client/enable_BNB diff --git a/etomic_build/client/enable_BNBT b/scripts/mm2/client/enable_BNBT similarity index 100% rename from etomic_build/client/enable_BNBT rename to scripts/mm2/client/enable_BNBT diff --git a/etomic_build/client/enable_GRS b/scripts/mm2/client/enable_GRS similarity index 100% rename from etomic_build/client/enable_GRS rename to scripts/mm2/client/enable_GRS diff --git a/etomic_build/client/enable_MORTY b/scripts/mm2/client/enable_MORTY similarity index 100% rename from etomic_build/client/enable_MORTY rename to scripts/mm2/client/enable_MORTY diff --git a/etomic_build/client/enable_RICK b/scripts/mm2/client/enable_RICK similarity index 100% rename from etomic_build/client/enable_RICK rename to scripts/mm2/client/enable_RICK diff --git a/etomic_build/client/enable_USDF b/scripts/mm2/client/enable_USDF similarity index 100% rename from etomic_build/client/enable_USDF rename to scripts/mm2/client/enable_USDF diff --git a/etomic_build/client/enable_tBCH b/scripts/mm2/client/enable_tBCH similarity index 100% rename from etomic_build/client/enable_tBCH rename to scripts/mm2/client/enable_tBCH diff --git a/etomic_build/client/enable_tBCH_USDF b/scripts/mm2/client/enable_tBCH_USDF similarity index 100% rename from etomic_build/client/enable_tBCH_USDF rename to scripts/mm2/client/enable_tBCH_USDF diff --git a/etomic_build/client/get_trade_fee b/scripts/mm2/client/get_trade_fee similarity index 100% rename from etomic_build/client/get_trade_fee rename to scripts/mm2/client/get_trade_fee diff --git a/etomic_build/client/list_banned_pubkeys b/scripts/mm2/client/list_banned_pubkeys similarity index 100% rename from etomic_build/client/list_banned_pubkeys rename to scripts/mm2/client/list_banned_pubkeys diff --git a/etomic_build/client/min_trading_vol b/scripts/mm2/client/min_trading_vol similarity index 100% rename from etomic_build/client/min_trading_vol rename to scripts/mm2/client/min_trading_vol diff --git a/etomic_build/client/my_balance b/scripts/mm2/client/my_balance similarity index 100% rename from etomic_build/client/my_balance rename to scripts/mm2/client/my_balance diff --git a/etomic_build/client/my_recent_swaps b/scripts/mm2/client/my_recent_swaps similarity index 100% rename from etomic_build/client/my_recent_swaps rename to scripts/mm2/client/my_recent_swaps diff --git a/etomic_build/client/my_tx_history_from_id b/scripts/mm2/client/my_tx_history_from_id similarity index 100% rename from etomic_build/client/my_tx_history_from_id rename to scripts/mm2/client/my_tx_history_from_id diff --git a/etomic_build/client/my_tx_history_page_number b/scripts/mm2/client/my_tx_history_page_number similarity index 100% rename from etomic_build/client/my_tx_history_page_number rename to scripts/mm2/client/my_tx_history_page_number diff --git a/etomic_build/client/passphrase b/scripts/mm2/client/passphrase similarity index 100% rename from etomic_build/client/passphrase rename to scripts/mm2/client/passphrase diff --git a/etomic_build/client/setpassphrase b/scripts/mm2/client/setpassphrase similarity index 100% rename from etomic_build/client/setpassphrase rename to scripts/mm2/client/setpassphrase diff --git a/etomic_build/client/setprice_ONE_ANOTHER b/scripts/mm2/client/setprice_ONE_ANOTHER similarity index 100% rename from etomic_build/client/setprice_ONE_ANOTHER rename to scripts/mm2/client/setprice_ONE_ANOTHER diff --git a/etomic_build/client/userpass b/scripts/mm2/client/userpass similarity index 100% rename from etomic_build/client/userpass rename to scripts/mm2/client/userpass diff --git a/etomic_build/client/validate_address b/scripts/mm2/client/validate_address similarity index 100% rename from etomic_build/client/validate_address rename to scripts/mm2/client/validate_address diff --git a/etomic_build/client/withdraw b/scripts/mm2/client/withdraw similarity index 100% rename from etomic_build/client/withdraw rename to scripts/mm2/client/withdraw diff --git a/etomic_build/enable b/scripts/mm2/enable similarity index 100% rename from etomic_build/enable rename to scripts/mm2/enable diff --git a/etomic_build/orderbook b/scripts/mm2/orderbook similarity index 100% rename from etomic_build/orderbook rename to scripts/mm2/orderbook diff --git a/etomic_build/seed/enable b/scripts/mm2/seed/enable similarity index 100% rename from etomic_build/seed/enable rename to scripts/mm2/seed/enable diff --git a/etomic_build/seed/myipaddr b/scripts/mm2/seed/myipaddr similarity index 100% rename from etomic_build/seed/myipaddr rename to scripts/mm2/seed/myipaddr diff --git a/etomic_build/seed/passphrase b/scripts/mm2/seed/passphrase similarity index 100% rename from etomic_build/seed/passphrase rename to scripts/mm2/seed/passphrase diff --git a/etomic_build/seed/run b/scripts/mm2/seed/run similarity index 100% rename from etomic_build/seed/run rename to scripts/mm2/seed/run diff --git a/etomic_build/seed/run_debug b/scripts/mm2/seed/run_debug similarity index 100% rename from etomic_build/seed/run_debug rename to scripts/mm2/seed/run_debug diff --git a/etomic_build/seed/sell_ONE_ANOTHER b/scripts/mm2/seed/sell_ONE_ANOTHER similarity index 100% rename from etomic_build/seed/sell_ONE_ANOTHER rename to scripts/mm2/seed/sell_ONE_ANOTHER diff --git a/etomic_build/seed/setpassphrase b/scripts/mm2/seed/setpassphrase similarity index 100% rename from etomic_build/seed/setpassphrase rename to scripts/mm2/seed/setpassphrase diff --git a/etomic_build/seed/userpass b/scripts/mm2/seed/userpass similarity index 100% rename from etomic_build/seed/userpass rename to scripts/mm2/seed/userpass diff --git a/etomic_build/setpassphrase b/scripts/mm2/setpassphrase similarity index 100% rename from etomic_build/setpassphrase rename to scripts/mm2/setpassphrase diff --git a/etomic_build/stop b/scripts/mm2/stop similarity index 100% rename from etomic_build/stop rename to scripts/mm2/stop diff --git a/etomic_build/userpass b/scripts/mm2/userpass similarity index 100% rename from etomic_build/userpass rename to scripts/mm2/userpass diff --git a/start_ONE_ANOTHER_trade.sh b/start_ONE_ANOTHER_trade.sh deleted file mode 100755 index 57f7ecfb42..0000000000 --- a/start_ONE_ANOTHER_trade.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -sleep 5 -docker-compose exec -T clientnode ./enable -sleep 3 -docker-compose exec -T seednode ./enable -sleep 3 -docker-compose exec -T seednode ./sell_ONE_ANOTHER $1 $2 -sleep 3 -docker-compose exec -T clientnode ./buy_ONE_ANOTHER $1 $2 diff --git a/travis_cmake_linux.sh b/travis_cmake_linux.sh deleted file mode 100755 index f11b08e4db..0000000000 --- a/travis_cmake_linux.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -sudo rm -rf /usr/local/cmake-3.9.2 && sudo rm -rf /usr/local/cmake -wget https://cmake.org/files/v3.12/cmake-3.12.0-rc2-Linux-x86_64.sh -chmod +x cmake-3.12.0-rc2-Linux-x86_64.sh -sudo ./cmake-3.12.0-rc2-Linux-x86_64.sh --skip-license --exclude-subdir --prefix=/usr/local \ No newline at end of file diff --git a/travis_cmake_mac.sh b/travis_cmake_mac.sh deleted file mode 100644 index 0e7c8eda11..0000000000 --- a/travis_cmake_mac.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -brew info libidn2 -brew uninstall cmake --force -wget https://cmake.org/files/v3.12/cmake-3.12.0-rc2-Darwin-x86_64.tar.gz -tar -xzf cmake-3.12.0-rc2-Darwin-x86_64.tar.gz -cp -r cmake-3.12.0-rc2-Darwin-x86_64/CMake.app/Contents/bin/* /usr/local/bin/ -cp -r cmake-3.12.0-rc2-Darwin-x86_64/CMake.app/Contents/share/* /usr/local/share/ \ No newline at end of file From 51435b33fe9d3197090daa86a54800da225cde6d Mon Sep 17 00:00:00 2001 From: Onur Date: Thu, 30 Mar 2023 13:12:34 +0300 Subject: [PATCH 33/90] create base image for building mm2 and use it for CI (#1741) * create base image for building mm2 and use it for CI Signed-off-by: ozkanonur * add changelog entry Signed-off-by: ozkanonur --- .docker/Dockerfile.ci-container | 55 ++++++++++++++++++++++++++++ .github/workflows/dev-build.yml | 56 +++++++++++++++++++++++++---- .github/workflows/release-build.yml | 46 +++++++++++++++++++++--- CHANGELOG.md | 1 + scripts/ci/android-ndk.sh | 3 ++ 5 files changed, 150 insertions(+), 11 deletions(-) create mode 100644 .docker/Dockerfile.ci-container diff --git a/.docker/Dockerfile.ci-container b/.docker/Dockerfile.ci-container new file mode 100644 index 0000000000..2553521750 --- /dev/null +++ b/.docker/Dockerfile.ci-container @@ -0,0 +1,55 @@ +FROM docker.io/debian:buster-slim + +MAINTAINER Onur Özkan + +RUN apt-get update -y + +RUN apt-get install -y \ + build-essential \ + cmake \ + gcc-multilib \ + ca-certificates \ + curl \ + wget \ + gnupg \ + git \ + zip \ + sudo + +RUN ln -s /usr/bin/python3 /bin/python + +RUN apt install -y \ + software-properties-common \ + lsb-release \ + gnupg + +RUN wget https://apt.llvm.org/llvm.sh + +RUN chmod +x llvm.sh + +RUN ./llvm.sh 16 + +RUN rm ./llvm.sh + +RUN ln -s /usr/bin/clang-16 /usr/bin/clang + +ENV AR=/usr/bin/llvm-ar-16 +ENV CC=/usr/bin/clang-16 + +RUN mkdir -m 0755 -p /etc/apt/keyrings + +RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg + +RUN echo \ + "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ + "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null + +RUN apt-get update -y + +RUN apt-get install -y \ + docker-ce \ + docker-ce-cli \ + containerd.io \ + docker-buildx-plugin + +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ No newline at end of file diff --git a/.github/workflows/dev-build.yml b/.github/workflows/dev-build.yml index 8ef8886fa6..e43b91bfe6 100644 --- a/.github/workflows/dev-build.yml +++ b/.github/workflows/dev-build.yml @@ -16,9 +16,18 @@ env: jobs: linux-x86-64: timeout-minutes: 30 - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest + container: komodoofficial/ci-container:latest steps: - uses: actions/checkout@v3 + + - name: pre scripts for ci container + run: | + git config --global --add safe.directory /__w/atomicDEX-API/atomicDEX-API + echo "/bin" >> $GITHUB_PATH + echo "/usr/bin" >> $GITHUB_PATH + echo "/root/.cargo/bin" >> $GITHUB_PATH + - name: Install toolchain run: | rustup toolchain install nightly-2022-10-29 --no-self-update --profile=minimal @@ -219,9 +228,18 @@ jobs: wasm: timeout-minutes: 30 - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest + container: komodoofficial/ci-container:latest steps: - uses: actions/checkout@v3 + + - name: pre scripts for ci container + run: | + git config --global --add safe.directory /__w/atomicDEX-API/atomicDEX-API + echo "/bin" >> $GITHUB_PATH + echo "/usr/bin" >> $GITHUB_PATH + echo "/root/.cargo/bin" >> $GITHUB_PATH + - name: Install toolchain run: | rustup toolchain install nightly-2022-10-29 --no-self-update --profile=minimal @@ -229,7 +247,7 @@ jobs: rustup target add wasm32-unknown-unknown - name: Install wasm-pack - run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | bash -s -- -y - name: Calculate commit hash for PR commit if: github.event_name == 'pull_request' @@ -319,9 +337,18 @@ jobs: android-aarch64: timeout-minutes: 30 - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest + container: komodoofficial/ci-container:latest steps: - uses: actions/checkout@v3 + + - name: pre scripts for ci container + run: | + git config --global --add safe.directory /__w/atomicDEX-API/atomicDEX-API + echo "/bin" >> $GITHUB_PATH + echo "/usr/bin" >> $GITHUB_PATH + echo "/root/.cargo/bin" >> $GITHUB_PATH + - name: Install toolchain run: | rustup toolchain install nightly-2022-10-29 --no-self-update --profile=minimal @@ -373,9 +400,18 @@ jobs: android-armv7: timeout-minutes: 30 - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest + container: komodoofficial/ci-container:latest steps: - uses: actions/checkout@v3 + + - name: pre scripts for ci container + run: | + git config --global --add safe.directory /__w/atomicDEX-API/atomicDEX-API + echo "/bin" >> $GITHUB_PATH + echo "/usr/bin" >> $GITHUB_PATH + echo "/root/.cargo/bin" >> $GITHUB_PATH + - name: Install toolchain run: | rustup toolchain install nightly-2022-10-29 --no-self-update --profile=minimal @@ -430,10 +466,18 @@ jobs: if: github.event_name != 'pull_request' && github.ref == 'refs/heads/dev' needs: linux-x86-64 timeout-minutes: 15 - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest + container: komodoofficial/ci-container:latest steps: - uses: actions/checkout@v2 + - name: pre scripts for ci container + run: | + git config --global --add safe.directory /__w/atomicDEX-API/atomicDEX-API + echo "/bin" >> $GITHUB_PATH + echo "/usr/bin" >> $GITHUB_PATH + echo "/root/.cargo/bin" >> $GITHUB_PATH + - name: Calculate commit hash for PR commit if: github.event_name == 'pull_request' run: echo "COMMIT_HASH=$(git rev-parse --short=7 ${{ github.event.pull_request.head.sha }})" >> $GITHUB_ENV diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index 2c12e3c5ab..25b0700948 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -16,9 +16,18 @@ env: jobs: linux-x86-64: timeout-minutes: 60 - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest + container: komodoofficial/ci-container:latest steps: - uses: actions/checkout@v3 + + - name: pre scripts for ci container + run: | + git config --global --add safe.directory /__w/atomicDEX-API/atomicDEX-API + echo "/bin" >> $GITHUB_PATH + echo "/usr/bin" >> $GITHUB_PATH + echo "/root/.cargo/bin" >> $GITHUB_PATH + - name: Install toolchain run: | rustup toolchain install nightly-2022-10-29 --no-self-update --profile=minimal @@ -193,9 +202,18 @@ jobs: wasm: timeout-minutes: 60 - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest + container: komodoofficial/ci-container:latest steps: - uses: actions/checkout@v3 + + - name: pre scripts for ci container + run: | + git config --global --add safe.directory /__w/atomicDEX-API/atomicDEX-API + echo "/bin" >> $GITHUB_PATH + echo "/usr/bin" >> $GITHUB_PATH + echo "/root/.cargo/bin" >> $GITHUB_PATH + - name: Install toolchain run: | rustup toolchain install nightly-2022-10-29 --no-self-update --profile=minimal @@ -203,7 +221,7 @@ jobs: rustup target add wasm32-unknown-unknown - name: Install wasm-pack - run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | bash -s -- -y - name: Calculate commit hash for PR commit if: github.event_name == 'pull_request' @@ -281,9 +299,18 @@ jobs: android-aarch64: timeout-minutes: 60 - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest + container: komodoofficial/ci-container:latest steps: - uses: actions/checkout@v3 + + - name: pre scripts for ci container + run: | + git config --global --add safe.directory /__w/atomicDEX-API/atomicDEX-API + echo "/bin" >> $GITHUB_PATH + echo "/usr/bin" >> $GITHUB_PATH + echo "/root/.cargo/bin" >> $GITHUB_PATH + - name: Install toolchain run: | rustup toolchain install nightly-2022-10-29 --no-self-update --profile=minimal @@ -329,9 +356,18 @@ jobs: android-armv7: timeout-minutes: 60 - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest + container: komodoofficial/ci-container:latest steps: - uses: actions/checkout@v3 + + - name: pre scripts for ci container + run: | + git config --global --add safe.directory /__w/atomicDEX-API/atomicDEX-API + echo "/bin" >> $GITHUB_PATH + echo "/usr/bin" >> $GITHUB_PATH + echo "/root/.cargo/bin" >> $GITHUB_PATH + - name: Install toolchain run: | rustup toolchain install nightly-2022-10-29 --no-self-update --profile=minimal diff --git a/CHANGELOG.md b/CHANGELOG.md index f63d6e2632..c32730074b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ **Enhancements/Fixes:** - CI/CD workflow logics are improved [#1736](https://github.com/KomodoPlatform/atomicDEX-API/pull/1736) - Project root is simplified/refactored [#1738](https://github.com/KomodoPlatform/atomicDEX-API/pull/1738) +- Created base image to provide more glibc compatible pre-built binaries for linux [#1741](https://github.com/KomodoPlatform/atomicDEX-API/pull/1741) ## v1.0.1-beta - 2023-03-17 diff --git a/scripts/ci/android-ndk.sh b/scripts/ci/android-ndk.sh index 07ef7eb782..5a6f038ebe 100755 --- a/scripts/ci/android-ndk.sh +++ b/scripts/ci/android-ndk.sh @@ -1,3 +1,5 @@ +#!/bin/bash + set -ex NDK_URL=https://dl.google.com/android/repository/android-ndk-r21b-linux-x86_64.zip @@ -9,6 +11,7 @@ main() { local dependencies=( unzip python3 + python3-distutils curl ) From cb4593e066a70547405eefa8f7031d47c6b60bbf Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 31 Mar 2023 16:00:21 +0500 Subject: [PATCH 34/90] Roll back CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e5b8ac127..26cd6d7d9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## {inc-release} **Features:** -- `adex` command line utility was introduced that supplies +- `adex-cli` command line utility was introduced that supplies commands: `init`, `start`, `stop`, `status` [#1682](https://github.com/KomodoPlatform/atomicDEX-API/issues/1682) **Enhancements/Fixes:** - CI/CD workflow logics are improved [#1736](https://github.com/KomodoPlatform/atomicDEX-API/pull/1736) From 75d31cad2fd1214bdf3bfb7fd69fdf5fe31b920d Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 31 Mar 2023 16:11:35 +0500 Subject: [PATCH 35/90] Made password generating rule stronger --- mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs index 1f2f9a65e3..56b6569870 100644 --- a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs +++ b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs @@ -184,7 +184,7 @@ impl Mm2Cfg { uppercase_letters: true, symbols: true, spaces: false, - exclude_similar_characters: false, + exclude_similar_characters: true, strict: true, }; pg.generate_one() From 7a3aa73909979516b92234f7e8e89511aa235c55 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 31 Mar 2023 17:02:20 +0500 Subject: [PATCH 36/90] Provide different rules for seedphrase --- Cargo.lock | 1 + mm2src/adex_cli/Cargo.toml | 1 + mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs | 26 ++++++++++++------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c0338ba3fb..519f183cf2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,6 +37,7 @@ dependencies = [ "serde", "serde_json", "sysinfo", + "tiny-bip39", "tokio", "winapi", ] diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index ce187ccab8..39dad6fb9a 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -18,6 +18,7 @@ passwords = "3.1" serde = "1.0" serde_json = { version = "1", features = ["preserve_order", "raw_value"] } sysinfo = "0.28" +tiny-bip39 = "0.8.0" tokio = { version = "1.20" } [target.'cfg(all(not(target_arch = "wasm32"), not(windows)))'.dependencies] diff --git a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs index 56b6569870..e05c580925 100644 --- a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs +++ b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs @@ -1,4 +1,4 @@ -use common::log::{error, info}; +use bip39::{Language, Mnemonic, MnemonicType}; use inquire::{validator::Validation, Confirm, CustomType, CustomUserError, Text}; use passwords::PasswordGenerator; use serde::Serialize; @@ -9,6 +9,7 @@ use std::path::Path; use super::helpers; use super::inquire_extentions::{InquireOption, DEFAULT_DEFAULT_OPTION_BOOL_FORMATTER, DEFAULT_OPTION_BOOL_FORMATTER, OPTION_BOOL_PARSER}; +use common::log::{error, info}; use common::password_policy; const DEFAULT_NET_ID: u16 = 7777; @@ -32,7 +33,7 @@ pub struct Mm2Cfg { pub gui: Option, pub net_id: Option, pub rpc_password: Option, - pub passphrase: Option, + pub seed_phrase: Option, pub allow_weak_password: Option, #[serde(skip_serializing_if = "Option::is_none")] pub dbdir: Option, @@ -56,7 +57,7 @@ impl Mm2Cfg { gui: None, net_id: None, rpc_password: None, - passphrase: None, + seed_phrase: None, allow_weak_password: None, dbdir: None, rpcip: None, @@ -71,7 +72,7 @@ impl Mm2Cfg { fn inquire(&mut self) -> Result<(), ()> { self.inquire_gui()?; self.inquire_net_id()?; - self.inquire_passphrase()?; + self.inquire_seed_phrase()?; self.inquire_allow_weak_password()?; self.inquire_rpc_password()?; self.inquire_dbdir()?; @@ -134,12 +135,17 @@ impl Mm2Cfg { } #[inline] - fn inquire_passphrase(&mut self) -> Result<(), ()> { - let default_password = Self::generate_password()?; - self.passphrase = Text::new("What is the passphrase:") - .with_default(default_password.as_str()) - .with_placeholder(default_password.as_str()) - .with_help_message("Your passphrase; this is the source of each of your coins private keys. KEEP IT SAFE!") + fn inquire_seed_phrase(&mut self) -> Result<(), ()> { + let mnemonic = Mnemonic::new(MnemonicType::Words12, Language::English); + let default_password: &str = mnemonic.phrase(); + self.seed_phrase = Text::new("What is the seed phrase:") + .with_default(default_password) + .with_validator(|phrase: &str| match Mnemonic::validate(phrase, Language::English) { + Ok(_) => Ok(Validation::Valid), + Err(error) => Ok(Validation::Invalid(error.into())), + }) + .with_placeholder(default_password) + .with_help_message("Your passphrase; this is the source of each of your coins' private keys. KEEP IT SAFE!") .prompt() .map_err(|error| { error!("Failed to get passphrase: {error}"); From f289c4752ed1684833b67e97efae4dcd7163c4a7 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 31 Mar 2023 17:48:21 +0500 Subject: [PATCH 37/90] Provide an empty value for passphrase --- mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs index e05c580925..78364adad7 100644 --- a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs +++ b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs @@ -33,6 +33,7 @@ pub struct Mm2Cfg { pub gui: Option, pub net_id: Option, pub rpc_password: Option, + #[serde(rename = "passphrase")] pub seed_phrase: Option, pub allow_weak_password: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -140,17 +141,27 @@ impl Mm2Cfg { let default_password: &str = mnemonic.phrase(); self.seed_phrase = Text::new("What is the seed phrase:") .with_default(default_password) - .with_validator(|phrase: &str| match Mnemonic::validate(phrase, Language::English) { - Ok(_) => Ok(Validation::Valid), - Err(error) => Ok(Validation::Invalid(error.into())), + .with_validator(|phrase: &str| { + if phrase == "empty" { + return Ok(Validation::Valid); + } + match Mnemonic::validate(phrase, Language::English) { + Ok(_) => Ok(Validation::Valid), + Err(error) => Ok(Validation::Invalid(error.into())), + } }) .with_placeholder(default_password) - .with_help_message("Your passphrase; this is the source of each of your coins' private keys. KEEP IT SAFE!") + .with_help_message( + "Type \"empty\" to leave it empty and to use limited service\n\ + Your passphrase; this is the source of each of your coins' private keys. KEEP IT SAFE!", + ) .prompt() .map_err(|error| { error!("Failed to get passphrase: {error}"); - })? + }) + .map(|value| if "empty" == value { "".to_string() } else { value })? .into(); + Ok(()) } From f6b64469a3efbbc6097db57ebfafb911096b3343 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 31 Mar 2023 19:44:29 +0500 Subject: [PATCH 38/90] Made default password to be generated until it conforms to password policy --- mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs index 78364adad7..7aba33864f 100644 --- a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs +++ b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs @@ -204,8 +204,16 @@ impl Mm2Cfg { exclude_similar_characters: true, strict: true, }; - pg.generate_one() - .map_err(|error| error!("Failed to generate password: {error}")) + let mut password: String; + loop { + password = pg + .generate_one() + .map_err(|error| error!("Failed to generate password: {error}"))?; + if let Ok(_) = password_policy::password_policy(&password) { + break; + } + } + Ok(password) } #[inline] From 1cc68df1e7f61d3edbda1a984ff1b755c71ea4cf Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 31 Mar 2023 20:01:18 +0500 Subject: [PATCH 39/90] Spit and polish --- mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs index 7aba33864f..ac6e120135 100644 --- a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs +++ b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs @@ -204,14 +204,11 @@ impl Mm2Cfg { exclude_similar_characters: true, strict: true, }; - let mut password: String; - loop { + let mut password = String::new(); + while password_policy::password_policy(&password).is_err() { password = pg .generate_one() .map_err(|error| error!("Failed to generate password: {error}"))?; - if let Ok(_) = password_policy::password_policy(&password) { - break; - } } Ok(password) } From 776243567332cac60bd6c269c7a59147de798b8f Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 31 Mar 2023 23:04:40 +0500 Subject: [PATCH 40/90] Spit and polish --- mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs index ac6e120135..fdce368bb1 100644 --- a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs +++ b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs @@ -33,7 +33,7 @@ pub struct Mm2Cfg { pub gui: Option, pub net_id: Option, pub rpc_password: Option, - #[serde(rename = "passphrase")] + #[serde(rename = "passphrase", skip_serializing_if = "Option::is_none")] pub seed_phrase: Option, pub allow_weak_password: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -159,7 +159,7 @@ impl Mm2Cfg { .map_err(|error| { error!("Failed to get passphrase: {error}"); }) - .map(|value| if "empty" == value { "".to_string() } else { value })? + .map(|value| if "empty" == value { None } else { Some(value) })? .into(); Ok(()) From fd1aecd172ca5da88b7b54704d6bbc8ced979489 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Sat, 1 Apr 2023 14:24:54 +0500 Subject: [PATCH 41/90] Spit and polish --- mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs index fdce368bb1..dc5e6f74b2 100644 --- a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs +++ b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs @@ -142,7 +142,7 @@ impl Mm2Cfg { self.seed_phrase = Text::new("What is the seed phrase:") .with_default(default_password) .with_validator(|phrase: &str| { - if phrase == "empty" { + if phrase == "none" { return Ok(Validation::Valid); } match Mnemonic::validate(phrase, Language::English) { @@ -152,14 +152,14 @@ impl Mm2Cfg { }) .with_placeholder(default_password) .with_help_message( - "Type \"empty\" to leave it empty and to use limited service\n\ - Your passphrase; this is the source of each of your coins' private keys. KEEP IT SAFE!", + "Type \"none\" to leave it blank and use limited service\n\ + Your passphrase; this is the source of each of your coins' private keys. KEEP IT SAFE!", ) .prompt() .map_err(|error| { error!("Failed to get passphrase: {error}"); }) - .map(|value| if "empty" == value { None } else { Some(value) })? + .map(|value| if "none" == value { None } else { Some(value) })? .into(); Ok(()) From 6bbdfcaf2e285b13eacfb18d2fb749fb7547acbf Mon Sep 17 00:00:00 2001 From: ec2-user Date: Sat, 1 Apr 2023 22:14:54 +0000 Subject: [PATCH 42/90] introduce macos mm2 process managing --- mm2src/adex_cli/Cargo.toml | 2 +- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 155 +++++++++++++++--- 2 files changed, 136 insertions(+), 21 deletions(-) diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index 39dad6fb9a..eec01d8891 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -19,7 +19,7 @@ serde = "1.0" serde_json = { version = "1", features = ["preserve_order", "raw_value"] } sysinfo = "0.28" tiny-bip39 = "0.8.0" -tokio = { version = "1.20" } +tokio = { version = "1.20", features = [ "macros" ] } [target.'cfg(all(not(target_arch = "wasm32"), not(windows)))'.dependencies] fork = "0.1" diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index fca5dd0d76..cb8f3bf58e 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -1,14 +1,10 @@ -#[cfg(all(any(unix, windows), not(target_os = "macos")))] use common::log::{error, info}; -#[cfg(all(any(unix, windows), not(target_os = "macos")))] -use std::path::PathBuf; -#[cfg(all(any(unix, windows), not(target_os = "macos")))] -use std::{env, u32}; -#[cfg(all(any(unix, windows), not(target_os = "macos")))] -use sysinfo::{PidExt, ProcessExt, System, SystemExt}; +use std::path::{PathBuf}; +use std::env; #[cfg(windows)] mod reexport { + pub use std::u32; pub use std::ffi::CString; pub use std::mem; pub use std::mem::size_of; @@ -20,20 +16,47 @@ mod reexport { pub const MM2_BINARY: &str = "mm2.exe"; } -#[cfg(all(unix, not(target_os = "macos")))] -mod reexport { +pub use std::process::{Command, Stdio}; + +#[cfg(all(unix, not(target_os= "macos")))] +mod unix_not_macos_reexport { + pub use std::u32; pub use fork::{daemon, Fork}; pub use std::ffi::OsStr; pub use std::process::{Command, Stdio}; + pub use sysinfo::{PidExt, ProcessExt, System, SystemExt}; - pub const MM2_BINARY: &str = "mm2"; pub const KILL_CMD: &str = "kill"; } -#[cfg(all(any(unix, windows), not(target_os = "macos")))] -use reexport::*; +#[cfg(all(unix, not(target_os= "macos")))] +use unix_not_macos_reexport::*; + + +#[cfg(unix)] +mod unix_reexport { + pub const MM2_BINARY: &str = "mm2"; +} + +#[cfg(unix)] +use unix_reexport::*; + + +#[cfg(target_os = "macos")] +mod macos_reexport { + pub use std::fs; + pub const LAUNCH_CTL_COOL_DOWN_TIMEOUT_MS: u64 = 500; + pub use std::thread::sleep; + pub use std::time::Duration; + + pub const LAUNCHCTL_MM2_ID: &str = "com.mm2.daemon"; +} + +#[cfg(target_os = "macos")] +use macos_reexport::*; + -#[cfg(all(any(unix, windows), not(target_os = "macos")))] +#[cfg(all(unix, not(target_os= "macos")))] pub fn get_status() { let pids = find_proc_by_name(MM2_BINARY); if pids.is_empty() { @@ -44,7 +67,7 @@ pub fn get_status() { }); } -#[cfg(all(any(unix, windows), not(target_os = "macos")))] +#[cfg(all(unix, not(target_os= "macos")))] fn find_proc_by_name(pname: &'_ str) -> Vec { let s = System::new_all(); @@ -55,7 +78,6 @@ fn find_proc_by_name(pname: &'_ str) -> Vec { .collect() } -#[cfg(all(any(unix, windows), not(target_os = "macos")))] fn get_mm2_binary_path() -> Result { let mut dir = env::current_exe().map_err(|error| { error!("Failed to get current binary dir: {error}"); @@ -65,7 +87,7 @@ fn get_mm2_binary_path() -> Result { Ok(dir) } -#[cfg(all(any(unix, windows), not(target_os = "macos")))] +#[cfg(all(any(unix, windows), not(target_os="macos")))] pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, log_file: &Option) { let mm2_binary = match get_mm2_binary_path() { Err(_) => return, @@ -182,16 +204,109 @@ pub fn stop_process() { } #[cfg(target_os = "macos")] -pub fn start_process(_mm2_cfg_file: &Option, _coins_file: &Option, _log_file: &Option) { - unimplemented!(); +pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, log_file: &Option) { + let mm2_binary = match get_mm2_binary_path() { + Err(_) => return, + Ok(path) => path, + }; + + let Ok(current_dir) = env::current_dir() else { + error!("Failet to get current_dir"); + return + }; + + let Ok(plist_path) = get_plist_path() else {return;}; + + let plist = format!( + r#" + + + + Label + {} + ProgramArguments + + {} + + WorkingDirectory + {} + EnvironmentVariables + {}{}{} + RunAtLoad + + KeepAlive + + + "#, + LAUNCHCTL_MM2_ID, + mm2_binary.display(), + current_dir.display(), + log_file.as_deref().map(|log_file| format!("MM_LOG{log_file}")).unwrap_or_default(), + mm2_cfg_file.as_deref().map(|cfg_file| format!("MM_CONF_PATH{cfg_file}")).unwrap_or_default(), + coins_file.as_deref().map(|coins_file| format!("MM_COINS_PATH{coins_file}")).unwrap_or_default(), + ); + + if let Err(error) = fs::write(&plist_path, plist) { + error!("Failed to write plist file: {error}"); + return; + } + + match Command::new("launchctl") + .arg("load") + .arg(&plist_path).spawn() { + Ok(_) => info!("Successfully loaded using launchctl, label: {LAUNCHCTL_MM2_ID}"), + Err(error) => error!("Failed to load process: {error}"), + } + + match Command::new("launchctl") + .args(["start", LAUNCHCTL_MM2_ID]) + .spawn() { + Ok(_) => info!("Successfully started using launchctl, label: {LAUNCHCTL_MM2_ID}"), + Err(error) => error!("Failed to start process: {error}"), + } + +} + +#[cfg(target_os = "macos")] +fn get_plist_path() -> Result { + match env::current_dir() { + Err(error) => { + error!("Failed to get plist_pathcurrent_dir: {error}"); + Err(()) + }, + Ok(mut current_dir) => { + current_dir.push(concat!(stringify!(LAUNCHCTL_MM2_ID), ".plist")); + Ok(current_dir) + } + } } #[cfg(target_os = "macos")] pub fn stop_process() { - unimplemented!(); + let Ok(plist_path) = get_plist_path() else { return; }; + + if let Err(error) = Command::new("launchctl").arg("unload").arg(&plist_path).spawn() { + error!("Failed to unload process using launchctl: {}", error); + } else { + info!("mm2 successfully stopped by launchctl"); + } + sleep(Duration::from_millis(LAUNCH_CTL_COOL_DOWN_TIMEOUT_MS)); + if let Err(err) = fs::remove_file(&plist_path) { + error!("Failed to remove plist file: {}", err); + } } + #[cfg(target_os = "macos")] pub fn get_status() { - unimplemented!(); + let output = Command::new("launchctl") + .args(["list", LAUNCHCTL_MM2_ID]) + .output() + .unwrap(); + + if output.status.success() && String::from_utf8_lossy(&output.stdout).contains("PID") { + info!("Service '{LAUNCHCTL_MM2_ID}' is running"); + } else { + info!("Service '{LAUNCHCTL_MM2_ID}' is not running"); + } } From ca170ed13d63bcefcb1a43fe78c89215bbdf9698 Mon Sep 17 00:00:00 2001 From: ec2-user Date: Sat, 1 Apr 2023 22:29:19 +0000 Subject: [PATCH 43/90] spit and polish --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index cb8f3bf58e..19e973216e 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -275,7 +275,7 @@ fn get_plist_path() -> Result { Err(()) }, Ok(mut current_dir) => { - current_dir.push(concat!(stringify!(LAUNCHCTL_MM2_ID), ".plist")); + current_dir.push(&format!("{LAUNCHCTL_MM2_ID}.plist")); Ok(current_dir) } } From caa9d67fb22b8cca3732c6b992fc4c96d8157ed0 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Sun, 2 Apr 2023 04:10:43 +0500 Subject: [PATCH 44/90] Spit and polish --- mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs | 3 +- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 98 +++++++++---------- 2 files changed, 50 insertions(+), 51 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs index dc5e6f74b2..5dfd4574b5 100644 --- a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs +++ b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs @@ -159,8 +159,7 @@ impl Mm2Cfg { .map_err(|error| { error!("Failed to get passphrase: {error}"); }) - .map(|value| if "none" == value { None } else { Some(value) })? - .into(); + .map(|value| if "none" == value { None } else { Some(value) })?; Ok(()) } diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 19e973216e..d58458d4b2 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -1,14 +1,16 @@ use common::log::{error, info}; -use std::path::{PathBuf}; use std::env; +use std::path::PathBuf; +#[cfg(not(target_os = "macos"))] +pub use sysinfo::{PidExt, ProcessExt, System, SystemExt}; #[cfg(windows)] mod reexport { - pub use std::u32; pub use std::ffi::CString; pub use std::mem; pub use std::mem::size_of; pub use std::ptr::null; + pub use std::u32; pub use winapi::um::processthreadsapi::{CreateProcessA, OpenProcess, TerminateProcess, PROCESS_INFORMATION, STARTUPINFOA}; pub use winapi::um::winnt::{PROCESS_TERMINATE, SYNCHRONIZE}; @@ -16,47 +18,42 @@ mod reexport { pub const MM2_BINARY: &str = "mm2.exe"; } -pub use std::process::{Command, Stdio}; +#[cfg(windows)] use reexport::*; -#[cfg(all(unix, not(target_os= "macos")))] +#[cfg(all(unix, not(target_os = "macos")))] mod unix_not_macos_reexport { - pub use std::u32; pub use fork::{daemon, Fork}; pub use std::ffi::OsStr; pub use std::process::{Command, Stdio}; - pub use sysinfo::{PidExt, ProcessExt, System, SystemExt}; + pub use std::u32; pub const KILL_CMD: &str = "kill"; } -#[cfg(all(unix, not(target_os= "macos")))] +#[cfg(all(unix, not(target_os = "macos")))] use unix_not_macos_reexport::*; - #[cfg(unix)] mod unix_reexport { pub const MM2_BINARY: &str = "mm2"; } -#[cfg(unix)] -use unix_reexport::*; - +#[cfg(unix)] use unix_reexport::*; #[cfg(target_os = "macos")] mod macos_reexport { pub use std::fs; pub const LAUNCH_CTL_COOL_DOWN_TIMEOUT_MS: u64 = 500; + pub use std::process::{Command, Stdio}; pub use std::thread::sleep; pub use std::time::Duration; pub const LAUNCHCTL_MM2_ID: &str = "com.mm2.daemon"; } -#[cfg(target_os = "macos")] -use macos_reexport::*; +#[cfg(target_os = "macos")] use macos_reexport::*; - -#[cfg(all(unix, not(target_os= "macos")))] +#[cfg(not(target_os = "macos"))] pub fn get_status() { let pids = find_proc_by_name(MM2_BINARY); if pids.is_empty() { @@ -67,7 +64,7 @@ pub fn get_status() { }); } -#[cfg(all(unix, not(target_os= "macos")))] +#[cfg(not(target_os = "macos"))] fn find_proc_by_name(pname: &'_ str) -> Vec { let s = System::new_all(); @@ -87,7 +84,7 @@ fn get_mm2_binary_path() -> Result { Ok(dir) } -#[cfg(all(any(unix, windows), not(target_os="macos")))] +#[cfg(not(target_os = "macos"))] pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, log_file: &Option) { let mm2_binary = match get_mm2_binary_path() { Err(_) => return, @@ -216,7 +213,7 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, }; let Ok(plist_path) = get_plist_path() else {return;}; - + let plist = format!( r#" @@ -238,46 +235,50 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, "#, - LAUNCHCTL_MM2_ID, + LAUNCHCTL_MM2_ID, mm2_binary.display(), - current_dir.display(), - log_file.as_deref().map(|log_file| format!("MM_LOG{log_file}")).unwrap_or_default(), - mm2_cfg_file.as_deref().map(|cfg_file| format!("MM_CONF_PATH{cfg_file}")).unwrap_or_default(), - coins_file.as_deref().map(|coins_file| format!("MM_COINS_PATH{coins_file}")).unwrap_or_default(), + current_dir.display(), + log_file + .as_deref() + .map(|log_file| format!("MM_LOG{log_file}")) + .unwrap_or_default(), + mm2_cfg_file + .as_deref() + .map(|cfg_file| format!("MM_CONF_PATH{cfg_file}")) + .unwrap_or_default(), + coins_file + .as_deref() + .map(|coins_file| format!("MM_COINS_PATH{coins_file}")) + .unwrap_or_default(), ); if let Err(error) = fs::write(&plist_path, plist) { - error!("Failed to write plist file: {error}"); - return; + error!("Failed to write plist file: {error}"); + return; + } + + match Command::new("launchctl").arg("load").arg(&plist_path).spawn() { + Ok(_) => info!("Successfully loaded using launchctl, label: {LAUNCHCTL_MM2_ID}"), + Err(error) => error!("Failed to load process: {error}"), } - - match Command::new("launchctl") - .arg("load") - .arg(&plist_path).spawn() { - Ok(_) => info!("Successfully loaded using launchctl, label: {LAUNCHCTL_MM2_ID}"), - Err(error) => error!("Failed to load process: {error}"), - } - - match Command::new("launchctl") - .args(["start", LAUNCHCTL_MM2_ID]) - .spawn() { - Ok(_) => info!("Successfully started using launchctl, label: {LAUNCHCTL_MM2_ID}"), - Err(error) => error!("Failed to start process: {error}"), - } + match Command::new("launchctl").args(["start", LAUNCHCTL_MM2_ID]).spawn() { + Ok(_) => info!("Successfully started using launchctl, label: {LAUNCHCTL_MM2_ID}"), + Err(error) => error!("Failed to start process: {error}"), + } } #[cfg(target_os = "macos")] fn get_plist_path() -> Result { - match env::current_dir() { - Err(error) => { - error!("Failed to get plist_pathcurrent_dir: {error}"); - Err(()) - }, - Ok(mut current_dir) => { - current_dir.push(&format!("{LAUNCHCTL_MM2_ID}.plist")); - Ok(current_dir) - } + match env::current_dir() { + Err(error) => { + error!("Failed to get plist_pathcurrent_dir: {error}"); + Err(()) + }, + Ok(mut current_dir) => { + current_dir.push(&format!("{LAUNCHCTL_MM2_ID}.plist")); + Ok(current_dir) + }, } } @@ -296,7 +297,6 @@ pub fn stop_process() { } } - #[cfg(target_os = "macos")] pub fn get_status() { let output = Command::new("launchctl") From ddcc68307792614077360e5dbac353bfa62c09d0 Mon Sep 17 00:00:00 2001 From: ec2-user Date: Sun, 2 Apr 2023 13:56:46 +0000 Subject: [PATCH 45/90] provid process pid on macos --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index d58458d4b2..23c0c71573 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -304,9 +304,15 @@ pub fn get_status() { .output() .unwrap(); - if output.status.success() && String::from_utf8_lossy(&output.stdout).contains("PID") { - info!("Service '{LAUNCHCTL_MM2_ID}' is running"); - } else { + if !output.status.success() { info!("Service '{LAUNCHCTL_MM2_ID}' is not running"); + return; } + + if let Some(found) = String::from_utf8_lossy(&output.stdout).lines().filter(|line| line.contains("PID")).last() { + let pid = found.trim().matches(char::is_numeric).fold(String::default(), |mut pid, ch| { pid.push_str(ch); pid }); + info!("Service '{LAUNCHCTL_MM2_ID}' is running under launchctl, pid: {}", pid); + } else { + info!("Service '{LAUNCHCTL_MM2_ID}' is not running"); + }; } From 439921122e937f30284804b892c4d3a7f892fc86 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Sun, 2 Apr 2023 18:58:13 +0500 Subject: [PATCH 46/90] Spit and polish --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 23c0c71573..a25e149c66 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -306,11 +306,21 @@ pub fn get_status() { if !output.status.success() { info!("Service '{LAUNCHCTL_MM2_ID}' is not running"); - return; + return; } - - if let Some(found) = String::from_utf8_lossy(&output.stdout).lines().filter(|line| line.contains("PID")).last() { - let pid = found.trim().matches(char::is_numeric).fold(String::default(), |mut pid, ch| { pid.push_str(ch); pid }); + + if let Some(found) = String::from_utf8_lossy(&output.stdout) + .lines() + .filter(|line| line.contains("PID")) + .last() + { + let pid = found + .trim() + .matches(char::is_numeric) + .fold(String::default(), |mut pid, ch| { + pid.push_str(ch); + pid + }); info!("Service '{LAUNCHCTL_MM2_ID}' is running under launchctl, pid: {}", pid); } else { info!("Service '{LAUNCHCTL_MM2_ID}' is not running"); From d0604809ea319b504d54fea29ddc04dcb323dbf5 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Sun, 2 Apr 2023 21:46:38 +0500 Subject: [PATCH 47/90] Rollback some changes --- mm2src/mm2_main/src/mm2.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/mm2_main/src/mm2.rs b/mm2src/mm2_main/src/mm2.rs index 5293b228c7..6103362ad4 100644 --- a/mm2src/mm2_main/src/mm2.rs +++ b/mm2src/mm2_main/src/mm2.rs @@ -140,7 +140,7 @@ pub async fn lp_main( if !is_weak_password_accepted && cfg!(not(test)) { match password_policy(conf["rpc_password"].as_str().unwrap()) { Ok(_) => {}, - Err(err) => return Err(format!("rpc_password error: {}", err)), + Err(err) => return Err(format!("{}", err)), } } } From 43e6b690d5831628fc75ab0c67f3db8f6f65de71 Mon Sep 17 00:00:00 2001 From: ozkanonur Date: Sun, 2 Apr 2023 22:08:49 +0300 Subject: [PATCH 48/90] bump mm2 to `v1.0.2-beta` Signed-off-by: ozkanonur --- CHANGELOG.md | 2 +- Cargo.lock | 2 +- mm2src/mm2_bin_lib/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c32730074b..c90a734b62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## {inc-release} +## v1.0.2-beta - {inc-release-date} **Features:** diff --git a/Cargo.lock b/Cargo.lock index de68861053..9a2808998b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4179,7 +4179,7 @@ dependencies = [ [[package]] name = "mm2_bin_lib" -version = "1.0.1-beta" +version = "1.0.2-beta" dependencies = [ "chrono", "common", diff --git a/mm2src/mm2_bin_lib/Cargo.toml b/mm2src/mm2_bin_lib/Cargo.toml index 6ab41e38a4..c216278742 100644 --- a/mm2src/mm2_bin_lib/Cargo.toml +++ b/mm2src/mm2_bin_lib/Cargo.toml @@ -5,7 +5,7 @@ [package] name = "mm2_bin_lib" -version = "1.0.1-beta" +version = "1.0.2-beta" authors = ["James Lee", "Artem Pikulin", "Artem Grinblat", "Omar S.", "Onur Ozkan", "Alina Sharon", "Caglar Kaya", "Cipi", "Sergey Boiko", "Samuel Onoja", "Roman Sztergbaum", "Kadan Stadelmann "] edition = "2018" default-run = "mm2" From da0e693a69a4c080d3ebb0845cd9f06d936f9094 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Mon, 3 Apr 2023 16:30:36 +0500 Subject: [PATCH 49/90] exclude adex-cli from the mm2 workspace --- Cargo.lock | 177 ----------------------------------------------------- Cargo.toml | 5 +- README.md | 2 +- 3 files changed, 5 insertions(+), 179 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 519f183cf2..5aa839ed07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,27 +21,6 @@ dependencies = [ "gimli", ] -[[package]] -name = "adex-cli" -version = "0.1.0" -dependencies = [ - "clap", - "common", - "derive_more", - "env_logger 0.7.1", - "fork", - "inquire", - "log 0.4.14", - "mm2_net", - "passwords", - "serde", - "serde_json", - "sysinfo", - "tiny-bip39", - "tokio", - "winapi", -] - [[package]] name = "adler" version = "0.2.2" @@ -1522,31 +1501,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "crossterm" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" -dependencies = [ - "bitflags", - "crossterm_winapi", - "libc", - "mio", - "parking_lot 0.12.0", - "signal-hook", - "signal-hook-mio", - "winapi", -] - -[[package]] -name = "crossterm_winapi" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c" -dependencies = [ - "winapi", -] - [[package]] name = "crunchy" version = "0.2.2" @@ -2003,12 +1957,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5caaa75cbd2b960ff1e5392d2cfb1f44717fffe12fc1f32b7b5d1267f99732a6" -[[package]] -name = "dyn-clone" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b0cf012f1230e43cd00ebb729c6bb58707ecfa8ad08b52ef3a4ccd2697fc30" - [[package]] name = "ecdsa" version = "0.13.4" @@ -2439,15 +2387,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "fork" -version = "0.1.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9788ce090af4bf8d6e8f43d3f7d12305c787456387bd2d88856fcda3aa1f0dca" -dependencies = [ - "libc", -] - [[package]] name = "form_urlencoded" version = "1.0.1" @@ -3231,22 +3170,6 @@ dependencies = [ "regex", ] -[[package]] -name = "inquire" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd079157ad94a32f7511b2e13037f3ae417ad80a6a9b0de29154d48b86f5d6c8" -dependencies = [ - "bitflags", - "crossterm", - "dyn-clone", - "lazy_static", - "newline-converter", - "thiserror", - "unicode-segmentation", - "unicode-width", -] - [[package]] name = "instant" version = "0.1.12" @@ -4712,15 +4635,6 @@ dependencies = [ "unsigned-varint 0.7.1", ] -[[package]] -name = "newline-converter" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f71d09d5c87634207f894c6b31b6a2b2c64ea3bdcf71bd5599fdbbe1600c00f" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "nibble_vec" version = "0.1.0" @@ -4762,15 +4676,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "ntapi" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc51db7b362b205941f71232e56c625156eb9a929f8cf74a428fd5bc094a4afc" -dependencies = [ - "winapi", -] - [[package]] name = "num-bigint" version = "0.3.2" @@ -5106,15 +5011,6 @@ dependencies = [ "windows-sys 0.32.0", ] -[[package]] -name = "passwords" -version = "3.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d5e617847054b49f5b1ce93cea78a88fc269ef9210afdbca660c1e5c973212f" -dependencies = [ - "random-pick", -] - [[package]] name = "paste" version = "1.0.7" @@ -5816,37 +5712,6 @@ dependencies = [ "rand_core 0.3.1", ] -[[package]] -name = "random-number" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a3da5cbb4c27c5150c03a54a7e4745437cd90f9e329ae657c0b889a144bb7be" -dependencies = [ - "proc-macro-hack", - "rand 0.8.4", - "random-number-macro-impl", -] - -[[package]] -name = "random-number-macro-impl" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99f50024fe705be34d953ca47f4617ce3a665caa1011f14a48e6a8a6ec911f0f" -dependencies = [ - "proc-macro-hack", - "quote 1.0.26", - "syn 1.0.95", -] - -[[package]] -name = "random-pick" -version = "1.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c179499072da789afe44127d5f4aa6012de2c2f96ef759990196b37387a2a0f8" -dependencies = [ - "random-number", -] - [[package]] name = "raw-cpuid" version = "10.4.0" @@ -6659,27 +6524,6 @@ dependencies = [ "log 0.4.14", ] -[[package]] -name = "signal-hook" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "732768f1176d21d09e076c23a93123d40bba92d50c4058da34d45c8de8e682b9" -dependencies = [ - "libc", - "signal-hook-registry", -] - -[[package]] -name = "signal-hook-mio" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" -dependencies = [ - "libc", - "mio", - "signal-hook", -] - [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -7799,21 +7643,6 @@ dependencies = [ "unicode-xid 0.2.0", ] -[[package]] -name = "sysinfo" -version = "0.28.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4c2f3ca6693feb29a89724516f016488e9aafc7f37264f898593ee4b942f31b" -dependencies = [ - "cfg-if 1.0.0", - "core-foundation-sys", - "libc", - "ntapi", - "once_cell", - "rayon", - "winapi", -] - [[package]] name = "tap" version = "1.0.1" @@ -8638,12 +8467,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - [[package]] name = "unicode-width" version = "0.1.9" diff --git a/Cargo.toml b/Cargo.toml index ba90ae9f8d..388116abd7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,5 @@ [workspace] members = [ - "mm2src/adex_cli", "mm2src/coins", "mm2src/coins/utxo_signer", "mm2src/coins_activation", @@ -42,6 +41,10 @@ members = [ "mm2src/trezor", ] +exclude = [ + "mm2src/adex_cli" +] + # https://doc.rust-lang.org/beta/cargo/reference/features.html#feature-resolver-version-2 resolver = "2" diff --git a/README.md b/README.md index cdf2273239..40f82f6e81 100755 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ For example: The coins file contains information about the coins and tokens you want to trade. A regularly updated version is maintained in the [Komodo Platform coins repository](https://github.com/KomodoPlatform/coins/blob/master/coins). Pull Requests to add any coins not yet included are welcome. -To facilitate interoperability with the `mm2` service, there is the `adex` command line utility. It provides a questionnaire initialization mode to set up the configuration and obtain the proper coin set through the internet. It can also be used to start or stop the service. +To facilitate interoperability with the `mm2` service, there is the `adex-cli` command line utility. It provides a questionnaire initialization mode to set up the configuration and obtain the proper coin set through the internet. It can also be used to start or stop the service. ## Usage From 62288e488f1f0f81cd2d732df090ed57be708041 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Mon, 3 Apr 2023 16:41:09 +0500 Subject: [PATCH 50/90] Referred to an PR rather than an issue --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25644efe99..57d578c6e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## {inc-release} **Features:** -- `adex-cli` command line utility was introduced that supplies commands: `init`, `start`, `stop`, `status` [#1682](https://github.com/KomodoPlatform/atomicDEX-API/issues/1682) +- `adex-cli` command line utility was introduced that supplies commands: `init`, `start`, `stop`, `status` [#1729](https://github.com/KomodoPlatform/atomicDEX-API/pull/1729) **Enhancements/Fixes:** - CI/CD workflow logics are improved [#1736](https://github.com/KomodoPlatform/atomicDEX-API/pull/1736) From c09e9240be38848ce569775cf5b8b909dff0d55e Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Mon, 3 Apr 2023 20:24:31 +0500 Subject: [PATCH 51/90] Use the certain version of gstuff to avoid worning related to deprecated gstuff::Constructible --- mm2src/adex_cli/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index eec01d8891..d57e4a1483 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -20,6 +20,7 @@ serde_json = { version = "1", features = ["preserve_order", "raw_value"] } sysinfo = "0.28" tiny-bip39 = "0.8.0" tokio = { version = "1.20", features = [ "macros" ] } +gstuff = { version = "=0.7.4" , features = [ "nightly" ]} [target.'cfg(all(not(target_arch = "wasm32"), not(windows)))'.dependencies] fork = "0.1" From c13f0e2ac902a15ac071fb26baba3f5780f86336 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Mon, 3 Apr 2023 21:17:54 +0500 Subject: [PATCH 52/90] Use the certain version of gstuff to avoid worning related to deprecated gstuff::Constructible --- mm2src/adex_cli/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index d57e4a1483..37e834c9f8 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -20,7 +20,7 @@ serde_json = { version = "1", features = ["preserve_order", "raw_value"] } sysinfo = "0.28" tiny-bip39 = "0.8.0" tokio = { version = "1.20", features = [ "macros" ] } -gstuff = { version = "=0.7.4" , features = [ "nightly" ]} +gstuff = { version = "0.7" , features = [ "nightly" ]} [target.'cfg(all(not(target_arch = "wasm32"), not(windows)))'.dependencies] fork = "0.1" From 691ae4c1a03d52e566077fc341d51369538cd94a Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Mon, 3 Apr 2023 21:34:02 +0500 Subject: [PATCH 53/90] Revert "Use the certain version of gstuff to avoid worning related to deprecated gstuff::Constructible" This reverts commit c13f0e2ac902a15ac071fb26baba3f5780f86336. --- mm2src/adex_cli/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index 37e834c9f8..d57e4a1483 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -20,7 +20,7 @@ serde_json = { version = "1", features = ["preserve_order", "raw_value"] } sysinfo = "0.28" tiny-bip39 = "0.8.0" tokio = { version = "1.20", features = [ "macros" ] } -gstuff = { version = "0.7" , features = [ "nightly" ]} +gstuff = { version = "=0.7.4" , features = [ "nightly" ]} [target.'cfg(all(not(target_arch = "wasm32"), not(windows)))'.dependencies] fork = "0.1" From 817e9cfbfd2d4ef2c207913621135032ab4bf22f Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Mon, 3 Apr 2023 21:37:56 +0500 Subject: [PATCH 54/90] spit and polish --- mm2src/adex_cli/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index d57e4a1483..8c247d9fe7 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -11,6 +11,7 @@ clap = "2.33.3" common = { path = "../common" } derive_more = "0.99" env_logger = "0.7.1" +gstuff = { version = "=0.7.4" , features = [ "nightly" ]} inquire = "0.6" log = "0.4" mm2_net = { path = "../mm2_net" } @@ -20,7 +21,6 @@ serde_json = { version = "1", features = ["preserve_order", "raw_value"] } sysinfo = "0.28" tiny-bip39 = "0.8.0" tokio = { version = "1.20", features = [ "macros" ] } -gstuff = { version = "=0.7.4" , features = [ "nightly" ]} [target.'cfg(all(not(target_arch = "wasm32"), not(windows)))'.dependencies] fork = "0.1" From 469a4f3cab30acd5883ae76c29a9f13d81c502bd Mon Sep 17 00:00:00 2001 From: ec2-user Date: Mon, 3 Apr 2023 20:56:27 +0000 Subject: [PATCH 55/90] enable com.mm2.daemon first --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index a25e149c66..1699012462 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -230,9 +230,9 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, EnvironmentVariables {}{}{} RunAtLoad - + KeepAlive - + "#, LAUNCHCTL_MM2_ID, @@ -257,6 +257,12 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, return; } + match Command::new("launchctl").arg("enable").arg(format!("system/{LAUNCHCTL_MM2_ID}").as_str()).spawn() { + Ok(_) => info!("Successfully enabled using launchctl, label: {LAUNCHCTL_MM2_ID}"), + Err(error) => error!("Failed to enable process: {error}"), + } + + match Command::new("launchctl").arg("load").arg(&plist_path).spawn() { Ok(_) => info!("Successfully loaded using launchctl, label: {LAUNCHCTL_MM2_ID}"), Err(error) => error!("Failed to load process: {error}"), From 1c4721a674432af84b5127b26c7b40fedf46cd1d Mon Sep 17 00:00:00 2001 From: ec2-user Date: Mon, 3 Apr 2023 20:59:40 +0000 Subject: [PATCH 56/90] spit and polish --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 1699012462..c3f9843d91 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -1,4 +1,4 @@ -use common::log::{error, info}; +use common::log::{debug, error, info}; use std::env; use std::path::PathBuf; #[cfg(not(target_os = "macos"))] @@ -258,13 +258,13 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, } match Command::new("launchctl").arg("enable").arg(format!("system/{LAUNCHCTL_MM2_ID}").as_str()).spawn() { - Ok(_) => info!("Successfully enabled using launchctl, label: {LAUNCHCTL_MM2_ID}"), + Ok(_) => debug!("Successfully enabled using launchctl, label: {LAUNCHCTL_MM2_ID}"), Err(error) => error!("Failed to enable process: {error}"), } match Command::new("launchctl").arg("load").arg(&plist_path).spawn() { - Ok(_) => info!("Successfully loaded using launchctl, label: {LAUNCHCTL_MM2_ID}"), + Ok(_) => debug!("Successfully loaded using launchctl, label: {LAUNCHCTL_MM2_ID}"), Err(error) => error!("Failed to load process: {error}"), } From 500db1bb272659439d859a1983eeba9417b60fbf Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Tue, 4 Apr 2023 02:13:25 +0500 Subject: [PATCH 57/90] Rollback RunAtLoad, KeepAlive --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index c3f9843d91..fff5066365 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -230,9 +230,9 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, EnvironmentVariables {}{}{} RunAtLoad - + KeepAlive - + "#, LAUNCHCTL_MM2_ID, @@ -257,12 +257,15 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, return; } - match Command::new("launchctl").arg("enable").arg(format!("system/{LAUNCHCTL_MM2_ID}").as_str()).spawn() { + match Command::new("launchctl") + .arg("enable") + .arg(format!("system/{LAUNCHCTL_MM2_ID}").as_str()) + .spawn() + { Ok(_) => debug!("Successfully enabled using launchctl, label: {LAUNCHCTL_MM2_ID}"), Err(error) => error!("Failed to enable process: {error}"), } - match Command::new("launchctl").arg("load").arg(&plist_path).spawn() { Ok(_) => debug!("Successfully loaded using launchctl, label: {LAUNCHCTL_MM2_ID}"), Err(error) => error!("Failed to load process: {error}"), From 2df6f48cc0b4e5bb766b5e073b85900d19873b0b Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Tue, 4 Apr 2023 18:46:18 +0500 Subject: [PATCH 58/90] spit and polish --- mm2src/adex_cli/Cargo.toml | 2 +- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index 8c247d9fe7..116ddcaf8f 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -3,7 +3,7 @@ name = "adex-cli" version = "0.1.0" edition = "2021" authors = ["Rozhkov Dmitrii "] -description = "Provides a CLI interface and facilitates interoperating to komodo atomic dex throught the mm2 service" +description = "Provides a CLI interface and facilitates interoperating to komodo atomic dex through the mm2 service" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index fff5066365..ec35f888a7 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -208,7 +208,7 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, }; let Ok(current_dir) = env::current_dir() else { - error!("Failet to get current_dir"); + error!("Failed to get current_dir"); return }; @@ -281,7 +281,7 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, fn get_plist_path() -> Result { match env::current_dir() { Err(error) => { - error!("Failed to get plist_pathcurrent_dir: {error}"); + error!("Failed to get current_dir to construct plist_path: {error}"); Err(()) }, Ok(mut current_dir) => { From cc757a9fc77871f0b493813f129f235357d956f1 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Tue, 4 Apr 2023 19:56:35 +0500 Subject: [PATCH 59/90] Spit and polish --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index ec35f888a7..d2436fcefe 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -86,11 +86,6 @@ fn get_mm2_binary_path() -> Result { #[cfg(not(target_os = "macos"))] pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, log_file: &Option) { - let mm2_binary = match get_mm2_binary_path() { - Err(_) => return, - Ok(path) => path, - }; - if let Some(mm2_cfg_file) = mm2_cfg_file { info!("Set env MM_CONF_PATH as: {mm2_cfg_file}"); env::set_var("MM_CONF_PATH", mm2_cfg_file); @@ -103,6 +98,8 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, info!("Set env MM_LOG as: {log_file}"); env::set_var("MM_LOG", log_file); } + + let Ok(mm2_binary) = get_mm2_binary_path() else { return; }; start_process_impl(mm2_binary); } @@ -202,10 +199,7 @@ pub fn stop_process() { #[cfg(target_os = "macos")] pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, log_file: &Option) { - let mm2_binary = match get_mm2_binary_path() { - Err(_) => return, - Ok(path) => path, - }; + let Ok(mm2_binary) = get_mm2_binary_path() else { return; }; let Ok(current_dir) = env::current_dir() else { error!("Failed to get current_dir"); From e64dcf17a415da99cbef7183067330ebb5375b50 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Tue, 4 Apr 2023 20:45:32 +0500 Subject: [PATCH 60/90] Spit and polish --- mm2src/adex_cli/src/cli.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/adex_cli/src/cli.rs b/mm2src/adex_cli/src/cli.rs index 2135674cf6..fdbf65161d 100644 --- a/mm2src/adex_cli/src/cli.rs +++ b/mm2src/adex_cli/src/cli.rs @@ -63,7 +63,7 @@ pub fn process_cli() { .help("log file path"), ), ) - .subcommand(SubCommand::with_name("stop").about("Stop mm2 service")) + .subcommand(SubCommand::with_name("stop").about("Stop mm2 instance")) .subcommand(SubCommand::with_name("status").about("Get mm2 running status")); let matches = app.clone().get_matches(); From 3c95565998e6b6c7e73d36f508e321514b89bdda Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Wed, 5 Apr 2023 13:28:42 +0500 Subject: [PATCH 61/90] Spit and polish --- mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs index 5dfd4574b5..a0f90c3877 100644 --- a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs +++ b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs @@ -217,7 +217,7 @@ impl Mm2Cfg { self.allow_weak_password = Confirm::new("Allow weak password:") .with_default(false) .with_placeholder("No") - .with_help_message(r#"If true, will allow low entropy rpc_password. If false rpc_password must not have 3 of the same characters in a row, must be between 8-32 characters in length, must contain at least one of each of the following: numeric, uppercase, lowercase, special character (e.g. !#$*). It also can not contain the word "password", or the chars <, >, and &. Defaults to false."#) + .with_help_message(r#"If true, will allow low entropy rpc_password. If false rpc_password must not have 3 of the same characters in a row, must be at least 8 characters long, must contain at least one of each of the following: numeric, uppercase, lowercase, special character (e.g. !#$*). It also can not contain the word "password", or the chars <, >, and &. Defaults to false."#) .prompt() .map_err(|error| { error!("Failed to get allow_weak_password: {error}"); From 9cc5a03594dca3d0b893ec9ffb4f6447818b9a60 Mon Sep 17 00:00:00 2001 From: Onur Date: Wed, 5 Apr 2023 16:09:08 +0300 Subject: [PATCH 62/90] fix: set default log level (#1747) * set default log level Signed-off-by: ozkanonur * add changelog entry Signed-off-by: ozkanonur --------- Signed-off-by: ozkanonur Reviewed-by: cipig, shamardy --- CHANGELOG.md | 1 + mm2src/mm2_main/src/mm2.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c32730074b..c5a65c8db4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - CI/CD workflow logics are improved [#1736](https://github.com/KomodoPlatform/atomicDEX-API/pull/1736) - Project root is simplified/refactored [#1738](https://github.com/KomodoPlatform/atomicDEX-API/pull/1738) - Created base image to provide more glibc compatible pre-built binaries for linux [#1741](https://github.com/KomodoPlatform/atomicDEX-API/pull/1741) +- Set default log level as "info" [#1747](https://github.com/KomodoPlatform/atomicDEX-API/pull/1747) ## v1.0.1-beta - 2023-03-17 diff --git a/mm2src/mm2_main/src/mm2.rs b/mm2src/mm2_main/src/mm2.rs index c31aff6439..dcde7d5db0 100644 --- a/mm2src/mm2_main/src/mm2.rs +++ b/mm2src/mm2_main/src/mm2.rs @@ -456,7 +456,7 @@ pub fn run_lp_main( version: String, datetime: String, ) -> Result<(), String> { - env_logger::init(); + env_logger::from_env(env_logger::Env::default().default_filter_or("info")); let conf = get_mm2config(first_arg)?; From 3d524676538c8fb74bc99e71c7d0cf878ec5b263 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Thu, 6 Apr 2023 12:43:08 +0500 Subject: [PATCH 63/90] Fix bug --- mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs | 8 ++++---- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs index a0f90c3877..551cf21598 100644 --- a/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs +++ b/mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs @@ -31,7 +31,7 @@ pub fn init_mm2_cfg(cfg_file: &str) -> Result<(), ()> { #[derive(Serialize)] pub struct Mm2Cfg { pub gui: Option, - pub net_id: Option, + pub netid: Option, pub rpc_password: Option, #[serde(rename = "passphrase", skip_serializing_if = "Option::is_none")] pub seed_phrase: Option, @@ -56,7 +56,7 @@ impl Mm2Cfg { pub fn new() -> Mm2Cfg { Mm2Cfg { gui: None, - net_id: None, + netid: None, rpc_password: None, seed_phrase: None, allow_weak_password: None, @@ -124,13 +124,13 @@ impl Mm2Cfg { #[inline] fn inquire_net_id(&mut self) -> Result<(), ()> { - self.net_id = CustomType::::new("What is the network `mm2` is going to be a part, net_id:") + self.netid = CustomType::::new("What is the network `mm2` is going to be a part, netid:") .with_default(DEFAULT_NET_ID) .with_help_message(r#"Network ID number, telling the AtomicDEX API which network to join. 7777 is the current main network, though alternative netids can be used for testing or "private" trades"#) .with_placeholder(format!("{DEFAULT_NET_ID}").as_str()) .prompt() .map_err(|error| { - error!("Failed to get net_id: {error}"); + error!("Failed to get netid: {error}"); })?.into(); Ok(()) } diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index d2436fcefe..79510628f8 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -1,4 +1,4 @@ -use common::log::{debug, error, info}; +use common::log::{error, info}; use std::env; use std::path::PathBuf; #[cfg(not(target_os = "macos"))] @@ -44,10 +44,10 @@ mod unix_reexport { mod macos_reexport { pub use std::fs; pub const LAUNCH_CTL_COOL_DOWN_TIMEOUT_MS: u64 = 500; + use common::log::debug; pub use std::process::{Command, Stdio}; pub use std::thread::sleep; pub use std::time::Duration; - pub const LAUNCHCTL_MM2_ID: &str = "com.mm2.daemon"; } From 79d309fc239c2d1ffd17678ff2e9ac260c832f9c Mon Sep 17 00:00:00 2001 From: ec2-user Date: Thu, 6 Apr 2023 07:58:30 +0000 Subject: [PATCH 64/90] polished macos compilation --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 79510628f8..00cf79a2a4 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -44,7 +44,7 @@ mod unix_reexport { mod macos_reexport { pub use std::fs; pub const LAUNCH_CTL_COOL_DOWN_TIMEOUT_MS: u64 = 500; - use common::log::debug; + pub use common::log::debug; pub use std::process::{Command, Stdio}; pub use std::thread::sleep; pub use std::time::Duration; From 59b15da866846ba693b101271a1eaac5f55a6539 Mon Sep 17 00:00:00 2001 From: Onur Date: Thu, 6 Apr 2023 14:31:39 +0300 Subject: [PATCH 65/90] fix: hotfix `env_logger` (#1749) * hotfix `env_logger` Signed-off-by: ozkanonur * handle `env_logger` `AlreadyInitialized` err Signed-off-by: ozkanonur --------- Signed-off-by: ozkanonur Reviewed-by: cipig, shamardy --- mm2src/mm2_main/src/mm2.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mm2src/mm2_main/src/mm2.rs b/mm2src/mm2_main/src/mm2.rs index dcde7d5db0..3d8dafc35c 100644 --- a/mm2src/mm2_main/src/mm2.rs +++ b/mm2src/mm2_main/src/mm2.rs @@ -456,7 +456,19 @@ pub fn run_lp_main( version: String, datetime: String, ) -> Result<(), String> { - env_logger::from_env(env_logger::Env::default().default_filter_or("info")); + fn setup_env_logger() { + const MM2_LOG_ENV_KEY: &str = "RUST_LOG"; + + if env::var_os(MM2_LOG_ENV_KEY).is_none() { + env::set_var(MM2_LOG_ENV_KEY, "info"); + }; + + if let Err(e) = env_logger::try_init() { + common::log::debug!("env_logger is already initialized. {}", e); + }; + } + + setup_env_logger(); let conf = get_mm2config(first_arg)?; From 52a19cbd1a88a3891871417520dfbcc8953c9125 Mon Sep 17 00:00:00 2001 From: ec2-user Date: Thu, 6 Apr 2023 11:36:06 +0000 Subject: [PATCH 66/90] spit and polish --- mm2src/adex_cli/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index 116ddcaf8f..fb68669c23 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -22,7 +22,7 @@ sysinfo = "0.28" tiny-bip39 = "0.8.0" tokio = { version = "1.20", features = [ "macros" ] } -[target.'cfg(all(not(target_arch = "wasm32"), not(windows)))'.dependencies] +[target.'cfg(all(not(target_arch = "wasm32"), not(target_os = "macos"), not(windows)))'.dependencies] fork = "0.1" [target.'cfg(windows)'.dependencies] From aab6f3caadc6793af25016c721cea2cd4206fbe8 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Thu, 6 Apr 2023 18:05:19 +0500 Subject: [PATCH 67/90] spit and p --- mm2src/adex_cli/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index fb68669c23..e7ca05fb97 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -22,7 +22,7 @@ sysinfo = "0.28" tiny-bip39 = "0.8.0" tokio = { version = "1.20", features = [ "macros" ] } -[target.'cfg(all(not(target_arch = "wasm32"), not(target_os = "macos"), not(windows)))'.dependencies] +[target.'cfg(all(target_family = "unix", not(target_os = "macos")))'.dependencies] fork = "0.1" [target.'cfg(windows)'.dependencies] From 98befa166339fe114aa5a564ab2d31a3e9e827c7 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Thu, 6 Apr 2023 21:45:22 +0500 Subject: [PATCH 68/90] Polish processing of mm2 on start --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 00cf79a2a4..55930b0e4e 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -100,15 +100,20 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, } let Ok(mm2_binary) = get_mm2_binary_path() else { return; }; + if !mm2_binary.exists() { + error!("Failed to start mm2, no file: {mm2_binary:?}"); + return; + } start_process_impl(mm2_binary); } #[cfg(all(unix, not(target_os = "macos")))] pub fn start_process_impl(mm2_binary: PathBuf) { let mut command = Command::new(&mm2_binary); - let program = mm2_binary - .file_name() - .map_or("Undefined", |name: &OsStr| name.to_str().unwrap_or("Undefined")); + let Some(program) = mm2_binary.file_name() else { + error!("Failed to start mm2, no file_name: {mm2_binary:?}"); + return; + }; match daemon(true, true) { Ok(Fork::Child) => { From 72b440f71b17657c9800fb5c4c0ebce59a4b6009 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Thu, 6 Apr 2023 22:34:08 +0500 Subject: [PATCH 69/90] rollback some changes --- Cargo.lock | 232 +++++++++--------- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 5 +- 2 files changed, 117 insertions(+), 120 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5aa839ed07..b4a274f4b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -231,8 +231,8 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -248,8 +248,8 @@ version = "0.1.52" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "061a7acccaa286c011ddc30970520b98fa40e00c9d644633fb26b5fc63a265e3" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -725,7 +725,7 @@ dependencies = [ "borsh-derive-internal", "borsh-schema-derive-internal", "proc-macro-crate 0.1.5", - "proc-macro2 1.0.54", + "proc-macro2 1.0.39", "syn 1.0.95", ] @@ -735,8 +735,8 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5449c28a7b352f2d1e592a8a28bf139bc71afb0764a14f3c02500935d8c44065" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -746,8 +746,8 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdbd5696d8bfa21d53d9fe39a714a18538bad11492a42d066dbbc395fb1951c0" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -803,8 +803,8 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e215f8c2f9f79cb53c8335e687ffd07d5bfcb6fe5fc80723762d0be46e7cc54" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -1631,7 +1631,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fbaabec2c953050352311293be5c6aba8e141ba19d6811862b232d6fd020484" dependencies = [ - "quote 1.0.26", + "quote 1.0.18", "syn 1.0.95", ] @@ -1712,8 +1712,8 @@ dependencies = [ "cc", "codespan-reporting", "lazy_static", - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "scratch", "syn 1.0.95", ] @@ -1730,8 +1730,8 @@ version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b846f081361125bfc8dc9d3940c84e1fd83ba54bbca7b17cd29483c828be0704" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -1804,8 +1804,8 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -1815,8 +1815,8 @@ version = "0.99.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cb0e6161ad61ed084a36ba71fbba9e3ac5aee3606fb607fe08da6acbcf3d8c" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -2075,8 +2075,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21cdad81446a7f7dc43f6a77409efeb9733d2fa65553efef6018ef257c959b73" dependencies = [ "heck", - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -2087,7 +2087,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c375b9c5eadb68d0a6efee2999fef292f45854c3444c86f09d8ab086ba942b0e" dependencies = [ "num-traits", - "quote 1.0.26", + "quote 1.0.18", "syn 1.0.95", ] @@ -2096,8 +2096,8 @@ name = "enum_from" version = "0.1.0" dependencies = [ "itertools", - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -2258,8 +2258,8 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", "synstructure", ] @@ -2505,8 +2505,8 @@ version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -3131,8 +3131,8 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5dacb10c5b3bb92d46ba347505a9041e676bb20ad220101326bffb0c93031ee" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -3629,7 +3629,7 @@ name = "libp2p-swarm-derive" version = "0.27.2" source = "git+https://github.com/libp2p/rust-libp2p.git?tag=v0.45.1#802d00e645894d8895f2f9f665b921452d992b86" dependencies = [ - "quote 1.0.26", + "quote 1.0.18", "syn 1.0.95", ] @@ -4085,8 +4085,8 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49e30813093f757be5cf21e50389a24dc7dbb22c49f23b7e8f51d69b508a5ffa" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -4566,8 +4566,8 @@ version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3048ef3680533a27f9f8e7d6a0bce44dc61e4895ea0f42709337fa1c8616fefe" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -4610,8 +4610,8 @@ checksum = "fc076939022111618a5026d3be019fd8b366e76314538ff9a1b59ffbcbf98bcd" dependencies = [ "proc-macro-crate 1.1.3", "proc-macro-error", - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", "synstructure", ] @@ -4705,8 +4705,8 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -4769,8 +4769,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "486ea01961c4a818096de679a8b740b26d9033146ac5291b1c98557658f8cdd9" dependencies = [ "proc-macro-crate 1.1.3", - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -4844,8 +4844,8 @@ checksum = "44a0b52c2cbaef7dffa5fec1a43274afe8bd2a644fa9fc50a9ef4ff0269b1257" dependencies = [ "Inflector", "proc-macro-error", - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -4901,8 +4901,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c45ed1f39709f5a89338fab50e59816b2e8815f5bb58276e7ddf9afd495f73f8" dependencies = [ "proc-macro-crate 1.1.3", - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -4936,7 +4936,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f557c32c6d268a07c921471619c0295f5efad3a0e76d4f97a05c091a51d110b2" dependencies = [ - "proc-macro2 1.0.54", + "proc-macro2 1.0.39", "syn 1.0.95", "synstructure", ] @@ -5052,8 +5052,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5aa52829b8decbef693af90202711348ab001456803ba2a98eb4ec8fb70844c" dependencies = [ "peg-runtime", - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", ] [[package]] @@ -5102,8 +5102,8 @@ version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "044964427019eed9d49d9d5bbce6047ef18f37100ea400912a9fa4a3523ab12a" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -5113,8 +5113,8 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "744b6f092ba29c3650faf274db506afd39944f48420f6c86b17cfe0ee1cb36bb" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -5188,7 +5188,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f28f53e8b192565862cf99343194579a022eb9c7dd3a8d03134734803c7b3125" dependencies = [ - "proc-macro2 1.0.54", + "proc-macro2 1.0.39", "syn 1.0.95", ] @@ -5242,8 +5242,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", "version_check", ] @@ -5254,8 +5254,8 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "version_check", ] @@ -5276,9 +5276,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.54" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e472a104799c74b514a57226160104aa483546de37e839ec50e3c2e41dd87534" +checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" dependencies = [ "unicode-ident", ] @@ -5301,8 +5301,8 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8e12d01b9d66ad9eb4529c57666b6263fc1993cb30261d83ead658fdd932652" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -5346,8 +5346,8 @@ checksum = "7b670f45da57fb8542ebdbb6105a925fe571b67f9e7ed9f47a06a84e72b4e7cc" dependencies = [ "anyhow", "itertools", - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -5457,11 +5457,11 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.26" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" dependencies = [ - "proc-macro2 1.0.54", + "proc-macro2 1.0.39", ] [[package]] @@ -5806,8 +5806,8 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c523ccaed8ac4b0288948849a350b37d3035827413c458b6a40ddb614bb4f72" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -6173,8 +6173,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50e334bb10a245e28e5fd755cabcafd96cfcd167c99ae63a46924ca8d8703a3c" dependencies = [ "proc-macro-crate 1.1.3", - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -6328,8 +6328,8 @@ dependencies = [ name = "ser_error_derive" version = "0.1.0" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "ser_error", "syn 1.0.95", ] @@ -6369,8 +6369,8 @@ version = "1.0.136" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -6392,8 +6392,8 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dc6b7951b17b051f3210b063f12cc17320e2fe30ae05b0fe2a3abb068551c76" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -6869,8 +6869,8 @@ version = "1.9.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "402fffb54bf5d335e6df26fc1719feecfbd7a22fafdf6649fe78380de3c47384" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "rustc_version 0.4.0", "syn 1.0.95", ] @@ -7171,8 +7171,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c834b4e02ac911b13c13aed08b3f847e722f6be79d31b1c660c1dbd2dee83cdb" dependencies = [ "bs58", - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "rustversion", "syn 1.0.95", ] @@ -7295,8 +7295,8 @@ version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d676664972e22a0796176e81e7bec41df461d1edf52090955cdab55f2c956ff2" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -7325,8 +7325,8 @@ checksum = "22ecb916b9664ed9f90abef0ff5a3e61454c1efea5861b2997e03f39b59b955f" dependencies = [ "Inflector", "proc-macro-crate 1.1.3", - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -7473,8 +7473,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f9799e6d412271cb2414597581128b03f3285f260ea49f5363d07df6a332b3e" dependencies = [ "Inflector", - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "serde", "serde_json", "unicode-xid 0.2.0", @@ -7521,8 +7521,8 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "serde", "serde_derive", "syn 1.0.95", @@ -7535,8 +7535,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" dependencies = [ "base-x", - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "serde", "serde_derive", "serde_json", @@ -7611,8 +7611,8 @@ version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "unicode-ident", ] @@ -7637,8 +7637,8 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", "unicode-xid 0.2.0", ] @@ -7856,9 +7856,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.2.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" dependencies = [ "winapi-util", ] @@ -7921,8 +7921,8 @@ version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -7996,8 +7996,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" dependencies = [ "proc-macro-hack", - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "standback", "syn 1.0.95", ] @@ -8100,8 +8100,8 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -8193,9 +8193,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9263bf4c9bfaae7317c1c2faf7f18491d2fe476f70c414b73bf5d445b00ffa1" dependencies = [ "prettyplease", - "proc-macro2 1.0.54", + "proc-macro2 1.0.39", "prost-build", - "quote 1.0.26", + "quote 1.0.18", "syn 1.0.95", ] @@ -8269,8 +8269,8 @@ version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e65ce065b4b5c53e73bb28912318cb8c9e9ad3921f1d669eb0e68b4c8143a2b" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", ] @@ -8690,8 +8690,8 @@ dependencies = [ "bumpalo", "lazy_static", "log 0.4.14", - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", "wasm-bindgen-shared", ] @@ -8714,7 +8714,7 @@ version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9" dependencies = [ - "quote 1.0.26", + "quote 1.0.18", "wasm-bindgen-macro-support", ] @@ -8724,8 +8724,8 @@ version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", "wasm-bindgen-backend", "wasm-bindgen-shared", @@ -8757,8 +8757,8 @@ version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c2e18093f11c19ca4e188c177fecc7c372304c311189f12c2f9bea5b7324ac7" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", ] [[package]] @@ -9216,8 +9216,8 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f8f187641dad4f680d25c4bfc4225b418165984179f26ca76ec4fb6441d3a17" dependencies = [ - "proc-macro2 1.0.54", - "quote 1.0.26", + "proc-macro2 1.0.39", + "quote 1.0.18", "syn 1.0.95", "synstructure", ] diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 55930b0e4e..7b630c0117 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -110,10 +110,7 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, #[cfg(all(unix, not(target_os = "macos")))] pub fn start_process_impl(mm2_binary: PathBuf) { let mut command = Command::new(&mm2_binary); - let Some(program) = mm2_binary.file_name() else { - error!("Failed to start mm2, no file_name: {mm2_binary:?}"); - return; - }; + let program = mm2_binary.file_name().expect("No file_name in mm2_binary"); match daemon(true, true) { Ok(Fork::Child) => { From 688c1e0c10a7c7deccef65f7a3df0ea3fefd767d Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 7 Apr 2023 20:03:10 +0500 Subject: [PATCH 70/90] Fit logging after fork --- mm2src/adex_cli/Cargo.toml | 4 +++ mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 30 ++++++++++++++----- mm2src/common/log.rs | 2 +- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index e7ca05fb97..3e9ac0315a 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -6,6 +6,10 @@ authors = ["Rozhkov Dmitrii "] description = "Provides a CLI interface and facilitates interoperating to komodo atomic dex through the mm2 service" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +termion = "*" + [target.'cfg(not(target_arch = "wasm32"))'.dependencies] clap = "2.33.3" common = { path = "../common" } diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 7b630c0117..281d7ba4ff 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -1,6 +1,7 @@ use common::log::{error, info}; use std::env; use std::path::PathBuf; + #[cfg(not(target_os = "macos"))] pub use sysinfo::{PidExt, ProcessExt, System, SystemExt}; @@ -26,8 +27,16 @@ mod unix_not_macos_reexport { pub use std::ffi::OsStr; pub use std::process::{Command, Stdio}; pub use std::u32; + pub extern crate termion; + pub use common::log::{native_log, NativeLevel::Info}; + pub use std::io::{stderr, Write}; + pub use std::thread::sleep; + pub use std::time::Duration; + pub use termion::cursor; + pub use termion::raw::IntoRawMode; pub const KILL_CMD: &str = "kill"; + pub const START_PROC_COOLDOWN_TIMEOUT_MS: u64 = 10; } #[cfg(all(unix, not(target_os = "macos")))] @@ -111,16 +120,21 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, pub fn start_process_impl(mm2_binary: PathBuf) { let mut command = Command::new(&mm2_binary); let program = mm2_binary.file_name().expect("No file_name in mm2_binary"); + info!(""); - match daemon(true, true) { - Ok(Fork::Child) => { - command.output().expect("Failed to execute process"); - }, - Ok(Fork::Parent(pid)) => { - info!("Successfully started: {program:?}, forked pid: {pid}"); - }, - Err(error) => error!("Failed to fork a process: {error}"), + if let Ok(Fork::Child) = daemon(true, true) { + let _ = command.output(); + return; + }; + sleep(Duration::from_millis(START_PROC_COOLDOWN_TIMEOUT_MS)); + let mut stderr = stderr().into_raw_mode().unwrap(); + write!(stderr, "{}\r{}", cursor::Save, cursor::Up(1)).expect("Failed to write into stdderr"); + if find_proc_by_name(MM2_BINARY).is_empty() { + native_log!(Info, "Failed to start: {program:?}"); + } else { + native_log!(Info, "Successfully started: {program:?}"); } + write!(stderr, "{}", cursor::Restore).expect("Failed to write into stdderr"); } #[cfg(windows)] diff --git a/mm2src/common/log.rs b/mm2src/common/log.rs index 700dc0b9dd..3480afa77d 100644 --- a/mm2src/common/log.rs +++ b/mm2src/common/log.rs @@ -28,7 +28,7 @@ use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::{Arc, Weak}; use std::thread; -pub use log::{self as log_crate, debug, error, info, trace, warn, LevelFilter}; +pub use log::{self as log_crate, debug, error, info, log as native_log, trace, warn, Level as NativeLevel, LevelFilter}; #[cfg(target_arch = "wasm32")] #[path = "log/wasm_log.rs"] From c16d5cb056f6f8a840cef105ae09167889a5813d Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 7 Apr 2023 21:34:42 +0500 Subject: [PATCH 71/90] fork and setsid --- mm2src/adex_cli/Cargo.toml | 4 --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 36 +++++++++---------- mm2src/common/log.rs | 2 +- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index 3e9ac0315a..e7ca05fb97 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -6,10 +6,6 @@ authors = ["Rozhkov Dmitrii "] description = "Provides a CLI interface and facilitates interoperating to komodo atomic dex through the mm2 service" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -termion = "*" - [target.'cfg(not(target_arch = "wasm32"))'.dependencies] clap = "2.33.3" common = { path = "../common" } diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 281d7ba4ff..27a6d1e7f0 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -23,17 +23,12 @@ mod reexport { #[cfg(all(unix, not(target_os = "macos")))] mod unix_not_macos_reexport { - pub use fork::{daemon, Fork}; + pub use fork::{fork, setsid, Fork}; pub use std::ffi::OsStr; - pub use std::process::{Command, Stdio}; - pub use std::u32; - pub extern crate termion; - pub use common::log::{native_log, NativeLevel::Info}; pub use std::io::{stderr, Write}; + pub use std::process::{Command, Stdio}; pub use std::thread::sleep; pub use std::time::Duration; - pub use termion::cursor; - pub use termion::raw::IntoRawMode; pub const KILL_CMD: &str = "kill"; pub const START_PROC_COOLDOWN_TIMEOUT_MS: u64 = 10; @@ -120,21 +115,22 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, pub fn start_process_impl(mm2_binary: PathBuf) { let mut command = Command::new(&mm2_binary); let program = mm2_binary.file_name().expect("No file_name in mm2_binary"); - info!(""); - if let Ok(Fork::Child) = daemon(true, true) { - let _ = command.output(); - return; - }; - sleep(Duration::from_millis(START_PROC_COOLDOWN_TIMEOUT_MS)); - let mut stderr = stderr().into_raw_mode().unwrap(); - write!(stderr, "{}\r{}", cursor::Save, cursor::Up(1)).expect("Failed to write into stdderr"); - if find_proc_by_name(MM2_BINARY).is_empty() { - native_log!(Info, "Failed to start: {program:?}"); - } else { - native_log!(Info, "Successfully started: {program:?}"); + match fork() { + Ok(Fork::Parent(child)) => { + sleep(Duration::from_millis(START_PROC_COOLDOWN_TIMEOUT_MS)); + if find_proc_by_name(MM2_BINARY).is_empty() { + info!("Failed to start: {program:?}"); + } else { + info!("Successfully started: {program:?}, fork pid: {child}"); + } + }, + Ok(Fork::Child) => { + setsid().expect("Failed to setsid"); + let _ = command.output(); + }, + Err(_) => println!("Fork failed"), } - write!(stderr, "{}", cursor::Restore).expect("Failed to write into stdderr"); } #[cfg(windows)] diff --git a/mm2src/common/log.rs b/mm2src/common/log.rs index 3480afa77d..700dc0b9dd 100644 --- a/mm2src/common/log.rs +++ b/mm2src/common/log.rs @@ -28,7 +28,7 @@ use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::{Arc, Weak}; use std::thread; -pub use log::{self as log_crate, debug, error, info, log as native_log, trace, warn, Level as NativeLevel, LevelFilter}; +pub use log::{self as log_crate, debug, error, info, trace, warn, LevelFilter}; #[cfg(target_arch = "wasm32")] #[path = "log/wasm_log.rs"] From 1a386cf7713683db65586e23a93777b45ed243cf Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 7 Apr 2023 21:41:18 +0500 Subject: [PATCH 72/90] Fit logging after fork --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 27a6d1e7f0..27cd5cba4f 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -117,12 +117,12 @@ pub fn start_process_impl(mm2_binary: PathBuf) { let program = mm2_binary.file_name().expect("No file_name in mm2_binary"); match fork() { - Ok(Fork::Parent(child)) => { + Ok(Fork::Parent(_)) => { sleep(Duration::from_millis(START_PROC_COOLDOWN_TIMEOUT_MS)); if find_proc_by_name(MM2_BINARY).is_empty() { info!("Failed to start: {program:?}"); } else { - info!("Successfully started: {program:?}, fork pid: {child}"); + info!("Successfully started: {program:?}"); } }, Ok(Fork::Child) => { From 11b14feda451676c33769c0191f476e13596edd4 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 7 Apr 2023 21:46:57 +0500 Subject: [PATCH 73/90] Fit logging after fork --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 27cd5cba4f..4ad257869a 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -24,8 +24,6 @@ mod reexport { #[cfg(all(unix, not(target_os = "macos")))] mod unix_not_macos_reexport { pub use fork::{fork, setsid, Fork}; - pub use std::ffi::OsStr; - pub use std::io::{stderr, Write}; pub use std::process::{Command, Stdio}; pub use std::thread::sleep; pub use std::time::Duration; From 01fe98a9389bf9ffcaac47d2c36d55fe4d9ed948 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 7 Apr 2023 21:48:38 +0500 Subject: [PATCH 74/90] Fit logging after fork --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 4ad257869a..1c1aa40ec3 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -127,7 +127,7 @@ pub fn start_process_impl(mm2_binary: PathBuf) { setsid().expect("Failed to setsid"); let _ = command.output(); }, - Err(_) => println!("Fork failed"), + Err(error) => error!("Failed to fork a process: {error}"), } } From de43f3d268ec93700720e69cf0d90cba799110f6 Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Fri, 7 Apr 2023 21:59:52 +0500 Subject: [PATCH 75/90] Fit logging after fork --- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 1c1aa40ec3..3905fbc14a 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -118,7 +118,7 @@ pub fn start_process_impl(mm2_binary: PathBuf) { Ok(Fork::Parent(_)) => { sleep(Duration::from_millis(START_PROC_COOLDOWN_TIMEOUT_MS)); if find_proc_by_name(MM2_BINARY).is_empty() { - info!("Failed to start: {program:?}"); + info!("Failed to start: {mm2_binary:?}"); } else { info!("Successfully started: {program:?}"); } From 37a1d2afec8cd790c45452a0382e9e0e2daaaddb Mon Sep 17 00:00:00 2001 From: rozhkovdmitrii Date: Mon, 10 Apr 2023 19:09:14 +0500 Subject: [PATCH 76/90] Use std::mem::forget to detach mm2 process --- mm2src/adex_cli/Cargo.toml | 3 -- mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs | 30 +++++++------------ 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/mm2src/adex_cli/Cargo.toml b/mm2src/adex_cli/Cargo.toml index e7ca05fb97..2f1abdc0a0 100644 --- a/mm2src/adex_cli/Cargo.toml +++ b/mm2src/adex_cli/Cargo.toml @@ -22,8 +22,5 @@ sysinfo = "0.28" tiny-bip39 = "0.8.0" tokio = { version = "1.20", features = [ "macros" ] } -[target.'cfg(all(target_family = "unix", not(target_os = "macos")))'.dependencies] -fork = "0.1" - [target.'cfg(windows)'.dependencies] winapi = { version = "0.3.3", features = ["processthreadsapi", "winnt"] } diff --git a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs index 3905fbc14a..73a3460bbc 100644 --- a/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs +++ b/mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs @@ -23,13 +23,9 @@ mod reexport { #[cfg(all(unix, not(target_os = "macos")))] mod unix_not_macos_reexport { - pub use fork::{fork, setsid, Fork}; pub use std::process::{Command, Stdio}; - pub use std::thread::sleep; - pub use std::time::Duration; pub const KILL_CMD: &str = "kill"; - pub const START_PROC_COOLDOWN_TIMEOUT_MS: u64 = 10; } #[cfg(all(unix, not(target_os = "macos")))] @@ -112,23 +108,17 @@ pub fn start_process(mm2_cfg_file: &Option, coins_file: &Option, #[cfg(all(unix, not(target_os = "macos")))] pub fn start_process_impl(mm2_binary: PathBuf) { let mut command = Command::new(&mm2_binary); - let program = mm2_binary.file_name().expect("No file_name in mm2_binary"); - - match fork() { - Ok(Fork::Parent(_)) => { - sleep(Duration::from_millis(START_PROC_COOLDOWN_TIMEOUT_MS)); - if find_proc_by_name(MM2_BINARY).is_empty() { - info!("Failed to start: {mm2_binary:?}"); - } else { - info!("Successfully started: {program:?}"); - } - }, - Ok(Fork::Child) => { - setsid().expect("Failed to setsid"); - let _ = command.output(); + let file_name = mm2_binary.file_name().expect("No file_name in mm2_binary"); + let process = match command.stdout(Stdio::null()).stdout(Stdio::null()).spawn() { + Ok(process) => process, + Err(error) => { + error!("Failed to start process: {mm2_binary:?}, error: {error}"); + return; }, - Err(error) => error!("Failed to fork a process: {error}"), - } + }; + let pid = process.id(); + std::mem::forget(process); + info!("Started child process: {file_name:?}, pid: {pid}"); } #[cfg(windows)] From e56279226d7c858ce82f5a88c4499a13ba940872 Mon Sep 17 00:00:00 2001 From: Kadan Stadelmann Date: Mon, 10 Apr 2023 21:07:07 +0200 Subject: [PATCH 77/90] [docs] add release date to changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c90a734b62..3822515f1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## v1.0.2-beta - {inc-release-date} +## v1.0.2-beta - 2023-04-10 **Features:** From 54fd58a812b8744a6e3be3542d962d5c36b1f389 Mon Sep 17 00:00:00 2001 From: Onur Date: Tue, 11 Apr 2023 16:03:14 +0300 Subject: [PATCH 78/90] fix: stream stdout/err to a file (#1751) * stream stdout/err to a file Signed-off-by: ozkanonur * add changelog entry Signed-off-by: ozkanonur * use default target for `lightning::util::Logger` Signed-off-by: ozkanonur * add new config parameter `silent_console` Signed-off-by: ozkanonur * ignore mergetool temp files Signed-off-by: ozkanonur * sync back the `Cargo.lock` Signed-off-by: ozkanonur --------- Signed-off-by: ozkanonur Reviewed-by: cipig, shamardy --- .gitignore | 5 +- CHANGELOG.md | 4 + Cargo.lock | 79 +------------ mm2src/common/Cargo.toml | 2 +- mm2src/common/common.rs | 12 +- mm2src/common/log.rs | 19 +--- mm2src/common/log/native_log.rs | 105 ++++++------------ mm2src/gossipsub/Cargo.toml | 4 +- mm2src/mm2_libp2p/Cargo.toml | 2 +- mm2src/mm2_main/Cargo.toml | 1 - .../simple_market_maker_tests.rs | 10 +- mm2src/mm2_main/src/mm2.rs | 32 ++---- 12 files changed, 72 insertions(+), 203 deletions(-) diff --git a/.gitignore b/.gitignore index 6c5d310af4..db90f0d053 100755 --- a/.gitignore +++ b/.gitignore @@ -64,4 +64,7 @@ MM2.json [._]*.sw[a-p] [._]s[a-rt-v][a-z] [._]ss[a-gi-z] -[._]sw[a-p] \ No newline at end of file +[._]sw[a-p] + +# mergetool +*.orig \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index e0834045dc..cc857193e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ - Project root is simplified/refactored [#1738](https://github.com/KomodoPlatform/atomicDEX-API/pull/1738) - Created base image to provide more glibc compatible pre-built binaries for linux [#1741](https://github.com/KomodoPlatform/atomicDEX-API/pull/1741) - Set default log level as "info" [#1747](https://github.com/KomodoPlatform/atomicDEX-API/pull/1747) +- Refactor `native_log` module [#1751](https://github.com/KomodoPlatform/atomicDEX-API/pull/1751) + - implement stdout/err streaming to persistent file without dependencies + - Add new parameter `silent_console` to mm conf + ## v1.0.1-beta - 2023-03-17 diff --git a/Cargo.lock b/Cargo.lock index 4b5a62a9d9..c062b19c4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -155,12 +155,6 @@ version = "1.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "595d3cfa7a60d4555cb5067b99f07142a08ea778de5cf993f7b75c7d8fabc486" -[[package]] -name = "arc-swap" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dabe5a181f83789739c194cbe5a897dde195078fac08568d09221fd6137a7ba8" - [[package]] name = "arrayref" version = "0.3.6" @@ -284,7 +278,7 @@ dependencies = [ "byteorder 1.4.3", "bytes 0.5.6", "common", - "env_logger 0.7.1", + "env_logger", "fnv", "futures 0.3.15", "futures_codec", @@ -1182,6 +1176,7 @@ dependencies = [ "chrono", "crossbeam 0.8.2", "derive_more", + "env_logger", "findshlibs", "fnv", "futures 0.1.29", @@ -1200,7 +1195,6 @@ dependencies = [ "libc", "lightning", "log 0.4.14", - "log4rs", "parking_lot 0.12.0", "parking_lot_core 0.6.2", "primitive-types", @@ -2101,19 +2095,6 @@ dependencies = [ "syn 1.0.95", ] -[[package]] -name = "env_logger" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" -dependencies = [ - "atty", - "humantime 1.3.0", - "log 0.4.14", - "regex", - "termcolor", -] - [[package]] name = "env_logger" version = "0.9.0" @@ -2121,7 +2102,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" dependencies = [ "atty", - "humantime 2.1.0", + "humantime", "log 0.4.14", "regex", "termcolor", @@ -2967,15 +2948,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" -[[package]] -name = "humantime" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -dependencies = [ - "quick-error", -] - [[package]] name = "humantime" version = "2.1.0" @@ -3926,31 +3898,6 @@ dependencies = [ "value-bag", ] -[[package]] -name = "log-mdc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a94d21414c1f4a51209ad204c1776a3d0765002c76c6abcb602a6f09f1e881c7" - -[[package]] -name = "log4rs" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1572a880d1115ff867396eee7ae2bc924554225e67a0d3c85c745b3e60ca211" -dependencies = [ - "anyhow", - "arc-swap", - "chrono", - "derivative", - "fnv", - "libc", - "log 0.4.14", - "log-mdc", - "thiserror", - "thread-id", - "winapi", -] - [[package]] name = "lru" version = "0.7.5" @@ -4156,7 +4103,7 @@ dependencies = [ "atomicdex-gossipsub", "common", "derive_more", - "env_logger 0.7.1", + "env_logger", "futures 0.3.15", "futures-rustls 0.21.1", "getrandom 0.2.6", @@ -4357,7 +4304,6 @@ dependencies = [ "either", "enum-primitive-derive", "enum_from", - "env_logger 0.7.1", "ethereum-types", "futures 0.1.29", "futures 0.3.15", @@ -5423,8 +5369,6 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44883e74aa97ad63db83c4bf8ca490f02b2fc02f92575e720c8551e843c945f" dependencies = [ - "env_logger 0.7.1", - "log 0.4.14", "rand 0.7.3", "rand_core 0.5.1", ] @@ -6881,7 +6825,7 @@ version = "1.9.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "942dc59fc9da66d178362051b658646b65dc11cea0bc804e4ecd2528d3c1279f" dependencies = [ - "env_logger 0.9.0", + "env_logger", "lazy_static", "log 0.4.14", ] @@ -6902,7 +6846,7 @@ version = "1.9.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9774cd8309f599797b1612731fbc56df6c612879ab4923a3dc7234400eea419" dependencies = [ - "env_logger 0.9.0", + "env_logger", "gethostname", "lazy_static", "log 0.4.14", @@ -7926,17 +7870,6 @@ dependencies = [ "syn 1.0.95", ] -[[package]] -name = "thread-id" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7fbf4c9d56b320106cd64fd024dadfa0be7cb4706725fc44a7d7ce952d820c1" -dependencies = [ - "libc", - "redox_syscall 0.1.56", - "winapi", -] - [[package]] name = "time" version = "0.1.43" diff --git a/mm2src/common/Cargo.toml b/mm2src/common/Cargo.toml index d970affc63..8516e8c04d 100644 --- a/mm2src/common/Cargo.toml +++ b/mm2src/common/Cargo.toml @@ -19,6 +19,7 @@ backtrace = "0.3" bytes = "1.1" cfg-if = "1.0" crossbeam = "0.8" +env_logger = "0.9.0" derive_more = "0.99" fnv = "1.0.6" futures01 = { version = "0.1", package = "futures" } @@ -67,7 +68,6 @@ hyper = { version = "0.14.11", features = ["client", "http2", "server", "tcp"] } hyper-rustls = { version = "0.23", default-features = false, features = ["http1", "http2", "webpki-tokio"] } libc = { version = "0.2" } lightning = "0.0.113" -log4rs = { version = "1.0", default-features = false, features = ["console_appender", "pattern_encoder"] } tokio = { version = "1.20", features = ["io-util", "rt-multi-thread", "net"] } [target.'cfg(windows)'.dependencies] diff --git a/mm2src/common/common.rs b/mm2src/common/common.rs index b665a59305..67e7ff7ce8 100644 --- a/mm2src/common/common.rs +++ b/mm2src/common/common.rs @@ -183,11 +183,17 @@ pub const APPLICATION_GRPC_WEB_PROTO: &str = "application/grpc-web+proto"; pub const SATOSHIS: u64 = 100_000_000; pub const DEX_FEE_ADDR_PUBKEY: &str = "03bc2c7ba671bae4a6fc835244c9762b41647b9827d4780a89a949b984a8ddcc06"; + lazy_static! { pub static ref DEX_FEE_ADDR_RAW_PUBKEY: Vec = hex::decode(DEX_FEE_ADDR_PUBKEY).expect("DEX_FEE_ADDR_PUBKEY is expected to be a hexadecimal string"); } +#[cfg(not(target_arch = "wasm32"))] +lazy_static! { + pub(crate) static ref LOG_FILE: Mutex> = Mutex::new(open_log_file()); +} + pub auto trait NotSame {} impl !NotSame for (X, X) {} // Makes the error conversion work for structs/enums containing Box @@ -661,7 +667,7 @@ pub fn temp_dir() -> PathBuf { env::temp_dir() } /// Prints a warning to `stdout` if there's a problem opening the file. /// Returns `None` if `MM_LOG` variable is not present or if the specified path can't be opened. #[cfg(not(target_arch = "wasm32"))] -fn open_log_file() -> Option { +pub(crate) fn open_log_file() -> Option { let mm_log = match var("MM_LOG") { Ok(v) => v, Err(_) => return None, @@ -686,10 +692,6 @@ fn open_log_file() -> Option { pub fn writeln(line: &str) { use std::panic::catch_unwind; - lazy_static! { - static ref LOG_FILE: Mutex> = Mutex::new(open_log_file()); - } - // `catch_unwind` protects the tests from error // // thread 'CORE' panicked at 'cannot access stdout during shutdown' diff --git a/mm2src/common/log.rs b/mm2src/common/log.rs index 700dc0b9dd..a30b0b83de 100644 --- a/mm2src/common/log.rs +++ b/mm2src/common/log.rs @@ -995,7 +995,6 @@ impl LightningLogger for LogState { let record = Record::builder() .args(record.args) .level(level) - .target("mm_log") .module_path(Some(record.module_path)) .file(Some(record.file)) .line(Some(record.line)) @@ -1094,30 +1093,16 @@ impl fmt::Display for LogLevel { pub fn format_record(record: &Record) -> String { const DATE_FORMAT: &str = "%d %H:%M:%S"; - fn extract_crate_name(module_path: &str) -> &str { - match module_path.find("::") { - Some(ofs) => &module_path[0..ofs], - None => module_path, - } - } - let metadata = record.metadata(); let level = metadata.level(); let date = Utc::now().format(DATE_FORMAT); let line = record.line().unwrap_or(0); - let file = record.file().map(filename).unwrap_or("???"); - let module = record.module_path().unwrap_or(""); let message = record.args(); - let file = if module.contains("mm2") { - file.to_owned() - } else { - format!("{}:{}", extract_crate_name(module), file) - }; format!( - "{d}, {f}:{L}] {l} {m}", + "{d}, {p}:{L}] {l} {m}", d = date, - f = file, + p = record.module_path().unwrap_or(""), L = line, l = level, m = message diff --git a/mm2src/common/log/native_log.rs b/mm2src/common/log/native_log.rs index baa4148377..269b9fb28f 100644 --- a/mm2src/common/log/native_log.rs +++ b/mm2src/common/log/native_log.rs @@ -1,13 +1,9 @@ -use super::{chunk2log, format_record, LevelFilter, LogCallback}; -use log::Record; -use log4rs::encode::pattern; -use log4rs::{append, config}; +use super::{format_record, LogCallback}; +use std::env; +use std::io::Write; use std::os::raw::c_char; use std::str::FromStr; -const DEFAULT_CONSOLE_FORMAT: &str = "[{d(%Y-%m-%d %H:%M:%S %Z)(utc)} {h({l})} {M}:{f}:{L}] {m}\n"; -const DEFAULT_LEVEL_FILTER: LogLevel = LogLevel::Info; - #[derive(Clone, Copy, Debug, PartialEq, PartialOrd)] pub enum LogLevel { /// A level lower than all log levels. @@ -32,7 +28,7 @@ impl LogLevel { } impl Default for LogLevel { - fn default() -> Self { DEFAULT_LEVEL_FILTER } + fn default() -> Self { LogLevel::Info } } pub struct FfiCallback { @@ -52,84 +48,47 @@ impl LogCallback for FfiCallback { } } +#[derive(Default)] pub struct UnifiedLoggerBuilder { - console_format: String, - filter: LogLevel, - console: bool, - mm_log: bool, -} - -impl Default for UnifiedLoggerBuilder { - fn default() -> UnifiedLoggerBuilder { - UnifiedLoggerBuilder { - console_format: DEFAULT_CONSOLE_FORMAT.to_owned(), - filter: LogLevel::default(), - console: true, - mm_log: false, - } - } + /// Prevents writing to stdout/err + silent_console: bool, } impl UnifiedLoggerBuilder { pub fn new() -> UnifiedLoggerBuilder { UnifiedLoggerBuilder::default() } - pub fn console_format(mut self, console_format: &str) -> UnifiedLoggerBuilder { - self.console_format = console_format.to_owned(); + pub fn silent_console(mut self, silent_console: bool) -> UnifiedLoggerBuilder { + self.silent_console = silent_console; self } - pub fn level_filter(mut self, filter: LogLevel) -> UnifiedLoggerBuilder { - self.filter = filter; - self - } + pub fn init(self) { + const MM2_LOG_ENV_KEY: &str = "RUST_LOG"; - pub fn console(mut self, console: bool) -> UnifiedLoggerBuilder { - self.console = console; - self - } + if env::var_os(MM2_LOG_ENV_KEY).is_none() { + env::set_var(MM2_LOG_ENV_KEY, "info"); + }; - pub fn mm_log(mut self, mm_log: bool) -> UnifiedLoggerBuilder { - self.mm_log = mm_log; - self - } + let mut logger = env_logger::builder(); - pub fn try_init(self) -> Result<(), String> { - let mut appenders = Vec::new(); - - if self.mm_log { - appenders.push(config::Appender::builder().build("mm_log", Box::new(MmLogAppender))); - } - - if self.console { - let encoder = Box::new(pattern::PatternEncoder::new(&self.console_format)); - let appender = append::console::ConsoleAppender::builder() - .encoder(encoder) - .target(append::console::Target::Stdout) - .build(); - appenders.push(config::Appender::builder().build("console", Box::new(appender))); - } - - let app_names: Vec<_> = appenders.iter().map(|app| app.name()).collect(); - let root = config::Root::builder() - .appenders(app_names) - .build(LevelFilter::from(self.filter)); - let config = try_s!(config::Config::builder().appenders(appenders).build(root)); - - try_s!(log4rs::init_config(config)); - Ok(()) - } -} + logger.format(move |buf, record| { + let log = format_record(record); -#[derive(Debug)] -struct MmLogAppender; + if let Ok(mut log_file) = crate::LOG_FILE.lock() { + if let Some(ref mut log_file) = *log_file { + writeln!(log_file, "{}", log)?; + } + } -impl append::Append for MmLogAppender { - fn append(&self, record: &Record) -> anyhow::Result<()> { - let as_string = format_record(record); - let level = LogLevel::from(record.metadata().level()); - chunk2log(as_string, level); - Ok(()) - } + if !self.silent_console { + writeln!(buf, "{}", log)?; + } + + Ok(()) + }); - fn flush(&self) {} + if let Err(e) = logger.try_init() { + log::error!("env_logger is already initialized. {}", e); + }; + } } diff --git a/mm2src/gossipsub/Cargo.toml b/mm2src/gossipsub/Cargo.toml index ad7ddbc03e..1d09159115 100644 --- a/mm2src/gossipsub/Cargo.toml +++ b/mm2src/gossipsub/Cargo.toml @@ -32,10 +32,10 @@ wasm-timer = "0.2.4" [dev-dependencies] async-std = "1.6.2" -env_logger = "0.7.1" +env_logger = "0.9.0" libp2p-plaintext = { git = "https://github.com/libp2p/rust-libp2p.git", tag ="v0.45.1" } libp2p-yamux = { git = "https://github.com/libp2p/rust-libp2p.git", tag ="v0.45.1" } -quickcheck = "0.9.2" +quickcheck= { version = "0.9.2", default-features = false } [build-dependencies] prost-build = { version = "0.10.4", default-features = false } diff --git a/mm2src/mm2_libp2p/Cargo.toml b/mm2src/mm2_libp2p/Cargo.toml index 8098ac9358..c16025cef5 100644 --- a/mm2src/mm2_libp2p/Cargo.toml +++ b/mm2src/mm2_libp2p/Cargo.toml @@ -39,5 +39,5 @@ wasm-bindgen-futures = "0.4.21" [dev-dependencies] async-std = { version = "1.6.2", features = ["unstable"] } -env_logger = "0.7.1" +env_logger = "0.9.0" serde_json = { version = "1", features = ["preserve_order", "raw_value"] } diff --git a/mm2src/mm2_main/Cargo.toml b/mm2src/mm2_main/Cargo.toml index 443055e4d1..4d806ab933 100644 --- a/mm2src/mm2_main/Cargo.toml +++ b/mm2src/mm2_main/Cargo.toml @@ -42,7 +42,6 @@ either = "1.6" ethereum-types = { version = "0.13", default-features = false, features = ["std", "serialize"] } enum_from = { path = "../derives/enum_from" } enum-primitive-derive = "0.2" -env_logger = "0.7.1" futures01 = { version = "0.1", package = "futures" } futures = { version = "0.3.1", package = "futures", features = ["compat", "async-await"] } gstuff = { version = "0.7", features = ["nightly"] } diff --git a/mm2src/mm2_main/src/lp_ordermatch/simple_market_maker_tests.rs b/mm2src/mm2_main/src/lp_ordermatch/simple_market_maker_tests.rs index 230bb0d872..8928656415 100644 --- a/mm2src/mm2_main/src/lp_ordermatch/simple_market_maker_tests.rs +++ b/mm2src/mm2_main/src/lp_ordermatch/simple_market_maker_tests.rs @@ -49,7 +49,7 @@ mod tests { #[test] #[cfg(not(target_arch = "wasm32"))] fn test_vwap_single_base_side() { - UnifiedLoggerBuilder::default().try_init().unwrap_or(()); + UnifiedLoggerBuilder::default().init(); let base_swaps = generate_swaps_from_values(vec![(MmNumber::from("29.99997438"), MmNumber::from("222.76277576"))]); let rel_swaps = generate_swaps_from_values(vec![]); @@ -62,7 +62,7 @@ mod tests { #[test] #[cfg(not(target_arch = "wasm32"))] fn test_vwap_single_base_side_forced_price() { - UnifiedLoggerBuilder::default().try_init().unwrap_or(()); + UnifiedLoggerBuilder::default().init(); let base_swaps = generate_swaps_from_values(vec![(MmNumber::from("29.99997438"), MmNumber::from("222.76277576"))]); let rel_swaps = generate_swaps_from_values(vec![]); @@ -78,7 +78,7 @@ mod tests { #[test] #[cfg(not(target_arch = "wasm32"))] fn test_vwap_multiple_base_side() { - UnifiedLoggerBuilder::default().try_init().unwrap_or(()); + UnifiedLoggerBuilder::default().init(); let base_swaps = generate_swaps_from_values(vec![ (MmNumber::from("29.99997438"), MmNumber::from("222.76277576")), (MmNumber::from("14.99998719"), MmNumber::from("105.38138788")), @@ -96,7 +96,7 @@ mod tests { #[test] #[cfg(not(target_arch = "wasm32"))] fn test_vwap_multiple_base_side_forced_price() { - UnifiedLoggerBuilder::default().try_init().unwrap_or(()); + UnifiedLoggerBuilder::default().init(); let base_swaps = generate_swaps_from_values(vec![ (MmNumber::from("29.99997438"), MmNumber::from("222.76277576")), (MmNumber::from("29.99997438"), MmNumber::from("190.76277576")), @@ -112,7 +112,7 @@ mod tests { #[test] #[cfg(not(target_arch = "wasm32"))] fn test_vwap_single_reversed_side() { - UnifiedLoggerBuilder::default().try_init().unwrap_or(()); + UnifiedLoggerBuilder::default().init(); let base_swaps = generate_swaps_from_values(vec![]); let rel_swaps = generate_swaps_from_values(vec![(MmNumber::from("219.4709"), MmNumber::from("29.99999"))]); let mut calculated_price = MmNumber::from("7.14455729"); diff --git a/mm2src/mm2_main/src/mm2.rs b/mm2src/mm2_main/src/mm2.rs index 4d3e8543a4..e07218eaf4 100644 --- a/mm2src/mm2_main/src/mm2.rs +++ b/mm2src/mm2_main/src/mm2.rs @@ -123,7 +123,7 @@ pub async fn lp_main( let log_filter = params.filter.unwrap_or_default(); // Logger can be initialized once. // If `mm2` is linked as a library, and `mm2` is restarted, `init_logger` returns an error. - init_logger(log_filter).ok(); + init_logger(log_filter, params.conf["silent_console"].as_bool().unwrap_or_default()).ok(); let conf = params.conf; if !conf["rpc_password"].is_null() { @@ -342,20 +342,6 @@ pub fn run_lp_main( version: String, datetime: String, ) -> Result<(), String> { - fn setup_env_logger() { - const MM2_LOG_ENV_KEY: &str = "RUST_LOG"; - - if env::var_os(MM2_LOG_ENV_KEY).is_none() { - env::set_var(MM2_LOG_ENV_KEY, "info"); - }; - - if let Err(e) = env_logger::try_init() { - common::log::debug!("env_logger is already initialized. {}", e); - }; - } - - setup_env_logger(); - let conf = get_mm2config(first_arg)?; let log_filter = LogLevel::from_env(); @@ -395,17 +381,15 @@ fn on_update_config(args: &[OsString]) -> Result<(), String> { } #[cfg(not(target_arch = "wasm32"))] -fn init_logger(level: LogLevel) -> Result<(), String> { - use common::log::UnifiedLoggerBuilder; - - UnifiedLoggerBuilder::default() - .level_filter(level) - .console(false) - .mm_log(true) - .try_init() +fn init_logger(_level: LogLevel, silent_console: bool) -> Result<(), String> { + common::log::UnifiedLoggerBuilder::default() + .silent_console(silent_console) + .init(); + + Ok(()) } #[cfg(target_arch = "wasm32")] -fn init_logger(level: LogLevel) -> Result<(), String> { +fn init_logger(level: LogLevel, _silent_console: bool) -> Result<(), String> { common::log::WasmLoggerBuilder::default().level_filter(level).try_init() } From 8ce972da4c8f45bebd00f398f897c0c2276571ab Mon Sep 17 00:00:00 2001 From: Kadan Stadelmann Date: Tue, 11 Apr 2023 23:17:08 +0200 Subject: [PATCH 79/90] [docs] update 1.0.2 release date in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc857193e5..6e23dc19aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## v1.0.2-beta - 2023-04-10 +## v1.0.2-beta - 2023-04-11 **Features:** - `adex-cli` command line utility was introduced that supplies commands: `init`, `start`, `stop`, `status` [#1729](https://github.com/KomodoPlatform/atomicDEX-API/pull/1729) From f2bfeccb0ffeb519df277069c9a80af76421f11d Mon Sep 17 00:00:00 2001 From: Onur Date: Thu, 13 Apr 2023 22:31:15 +0300 Subject: [PATCH 80/90] ci: remove unnecessary deny.toml (#1754) Signed-off-by: ozkanonur Reviewed by: shamardy --- deny.toml | 322 ------------------------------------------------------ 1 file changed, 322 deletions(-) delete mode 100644 deny.toml diff --git a/deny.toml b/deny.toml deleted file mode 100644 index a58cbd21e0..0000000000 --- a/deny.toml +++ /dev/null @@ -1,322 +0,0 @@ -# This template contains all of the possible sections and their default values - -# Note that all fields that take a lint level have these possible values: -# * deny - An error will be produced and the check will fail -# * warn - A warning will be produced, but the check will not fail -# * allow - No warning or error will be produced, though in some cases a note -# will be - -# The values provided in this template are the default values that will be used -# when any section or field is not specified in your own configuration - -# If 1 or more target triples (and optionally, target_features) are specified, -# only the specified targets will be checked when running `cargo deny check`. -# This means, if a particular package is only ever used as a target specific -# dependency, such as, for example, the `nix` crate only being used via the -# `target_family = "unix"` configuration, that only having windows targets in -# this list would mean the nix crate, as well as any of its exclusive -# dependencies not shared by any other crates, would be ignored, as the target -# list here is effectively saying which targets you are building for. -targets = [ - # The triple can be any string, but only the target triples built in to - # rustc (as of 1.40) can be checked against actual config expressions - #{ triple = "x86_64-unknown-linux-musl" }, - # You can also specify which target_features you promise are enabled for a - # particular target. target_features are currently not validated against - # the actual valid features supported by the target architecture. - #{ triple = "wasm32-unknown-unknown", features = ["atomics"] }, -] - -# This section is considered when running `cargo deny check advisories` -# More documentation for the advisories section can be found here: -# https://embarkstudios.github.io/cargo-deny/checks/advisories/cfg.html -[advisories] -# The path where the advisory database is cloned/fetched into -db-path = "~/.cargo/advisory-db" -# The url(s) of the advisory databases to use -db-urls = ["https://github.com/rustsec/advisory-db"] -# The lint level for security vulnerabilities -vulnerability = "deny" -# The lint level for unmaintained crates -unmaintained = "warn" -# The lint level for crates that have been yanked from their source registry -yanked = "warn" -# The lint level for crates with security notices. Note that as of -# 2019-12-17 there are no security notice advisories in -# https://github.com/rustsec/advisory-db -notice = "warn" -# A list of advisory IDs to ignore. Note that ignored advisories will still -# output a note when they are encountered. - -# RUSTSEC-2020-0071 is related to time crate, which is used only by chrono in our deps tree, remove when https://github.com/chronotope/chrono/issues/700 is resolved -# RUSTSEC-2022-0040 is related to owning-ref, which seems unmaintained. We need to find a way to get rid of it. https://github.com/KomodoPlatform/atomicDEX-API/issues/1429 -ignore = [ - "RUSTSEC-2020-0071", - "RUSTSEC-2022-0040", - "RUSTSEC-2022-0041", - "RUSTSEC-2022-0070", - "RUSTSEC-2021-0145", - "RUSTSEC-2020-0056", - "RUSTSEC-2022-0080", - "RUSTSEC-2021-0059", - "RUSTSEC-2021-0060", - "RUSTSEC-2022-0090" -] -# Threshold for security vulnerabilities, any vulnerability with a CVSS score -# lower than the range specified will be ignored. Note that ignored advisories -# will still output a note when they are encountered. -# * None - CVSS Score 0.0 -# * Low - CVSS Score 0.1 - 3.9 -# * Medium - CVSS Score 4.0 - 6.9 -# * High - CVSS Score 7.0 - 8.9 -# * Critical - CVSS Score 9.0 - 10.0 -#severity-threshold = - -# This section is considered when running `cargo deny check licenses` -# More documentation for the licenses section can be found here: -# https://embarkstudios.github.io/cargo-deny/checks/licenses/cfg.html -[licenses] -# The lint level for crates which do not have a detectable license -unlicensed = "deny" -# List of explictly allowed licenses -# See https://spdx.org/licenses/ for list of possible licenses -# [possible values: any SPDX 3.11 short identifier (+ optional exception)]. -allow = [ - #"MIT", - #"Apache-2.0", - #"Apache-2.0 WITH LLVM-exception", -] -# List of explictly disallowed licenses -# See https://spdx.org/licenses/ for list of possible licenses -# [possible values: any SPDX 3.11 short identifier (+ optional exception)]. -deny = [ - #"Nokia", -] -# Lint level for licenses considered copyleft -copyleft = "warn" -# Blanket approval or denial for OSI-approved or FSF Free/Libre licenses -# * both - The license will be approved if it is both OSI-approved *AND* FSF -# * either - The license will be approved if it is either OSI-approved *OR* FSF -# * osi-only - The license will be approved if is OSI-approved *AND NOT* FSF -# * fsf-only - The license will be approved if is FSF *AND NOT* OSI-approved -# * neither - This predicate is ignored and the default lint level is used -allow-osi-fsf-free = "neither" -# Lint level used when no other predicates are matched -# 1. License isn't in the allow or deny lists -# 2. License isn't copyleft -# 3. License isn't OSI/FSF, or allow-osi-fsf-free = "neither" -default = "deny" -# The confidence threshold for detecting a license from license text. -# The higher the value, the more closely the license text must be to the -# canonical license text of a valid SPDX license file. -# [possible values: any between 0.0 and 1.0]. -confidence-threshold = 0.8 -# Allow 1 or more licenses on a per-crate basis, so that particular licenses -# aren't accepted for every possible crate as with the normal allow list -exceptions = [ - # Each entry is the crate and version constraint, and its specific allow - # list - #{ allow = ["Zlib"], name = "adler32", version = "*" }, -] - -# Some crates don't have (easily) machine readable licensing information, -# adding a clarification entry for it allows you to manually specify the -# licensing information -#[[licenses.clarify]] -# The name of the crate the clarification applies to -#name = "ring" -# The optional version constraint for the crate -#version = "*" -# The SPDX expression for the license requirements of the crate -#expression = "MIT AND ISC AND OpenSSL" -# One or more files in the crate's source used as the "source of truth" for -# the license expression. If the contents match, the clarification will be used -# when running the license check, otherwise the clarification will be ignored -# and the crate will be checked normally, which may produce warnings or errors -# depending on the rest of your configuration -#license-files = [ - # Each entry is a crate relative path, and the (opaque) hash of its contents - #{ path = "LICENSE", hash = 0xbd0eed23 } -#] - -[licenses.private] -# If true, ignores workspace crates that aren't published, or are only -# published to private registries -ignore = false -# One or more private registries that you might publish crates to, if a crate -# is only published to private registries, and ignore is true, the crate will -# not have its license(s) checked -registries = [ - #"https://sekretz.com/registry -] - -# This section is considered when running `cargo deny check bans`. -# More documentation about the 'bans' section can be found here: -# https://embarkstudios.github.io/cargo-deny/checks/bans/cfg.html -[bans] -# Lint level for when multiple versions of the same crate are detected -multiple-versions = "deny" -# Lint level for when a crate version requirement is `*` -wildcards = "allow" -# The graph highlighting used when creating dotgraphs for crates -# with multiple versions -# * lowest-version - The path to the lowest versioned duplicate is highlighted -# * simplest-path - The path to the version with the fewest edges is highlighted -# * all - Both lowest-version and simplest-path are used -highlight = "all" -# List of crates that are allowed. Use with care! -allow = [ - #{ name = "ansi_term", version = "=0.11.0" }, -] -# List of crates to deny -deny = [ - # Each entry the name of a crate and a version range. If version is - # not specified, all versions will be matched. - #{ name = "ansi_term", version = "=0.11.0" }, - # - # Wrapper crates can optionally be specified to allow the crate when it - # is a direct dependency of the otherwise banned crate - #{ name = "ansi_term", version = "=0.11.0", wrappers = [] }, -] -# Certain crates/versions that will be skipped when doing duplicate detection. -# The goal is to reduce this list as much as possible -skip = [ - { name = "aes", version = "*" }, - { name = "adler", version = "*" }, - { name = "ahash", version = "*" }, - { name = "arrayvec", version = "*" }, - { name = "autocfg", version = "*" }, - { name = "base64", version = "*" }, - { name = "bitvec", version = "*" }, - { name = "block-buffer", version = "*" }, - { name = "block-padding", version = "*" }, - { name = "byteorder", version = "*" }, - { name = "bytes", version = "*" }, - { name = "cfg-if", version = "*" }, - { name = "cipher", version = "*" }, - { name = "cloudabi", version = "*" }, - { name = "cpufeatures", version = "*" }, - { name = "crossbeam-channel", version = "*" }, - { name = "crossbeam-deque", version = "*" }, - { name = "crossbeam-epoch", version = "*" }, - { name = "crossbeam-utils", version = "*" }, - { name = "crunchy", version = "*" }, - { name = "crypto-mac", version = "*" }, - { name = "cuckoofilter", version = "*" }, - { name = "curve25519-dalek", version = "*" }, - { name = "derivation-path", version = "*" }, - { name = "digest", version = "*" }, - { name = "ed25519-dalek-bip32", version = "*" }, - { name = "env_logger", version = "*" }, - { name = "ethbloom", version = "*" }, - { name = "ethereum-types", version = "*" }, - { name = "ff", version = "*" }, - { name = "fixed-hash", version = "*" }, - { name = "funty", version = "*" }, - { name = "futures", version = "*" }, - { name = "futures-rustls", version = "*" }, - { name = "generic-array", version = "*" }, - { name = "getrandom", version = "*" }, - { name = "group", version = "*" }, - { name = "hashbrown", version = "*" }, - { name = "hex", version = "*" }, - { name = "hmac", version = "*" }, - { name = "http", version = "*" }, - { name = "http-body", version = "*" }, - { name = "humantime", version = "*" }, - { name = "idna", version = "*" }, - { name = "impl-codec", version = "*" }, - { name = "itoa", version = "*" }, - { name = "jsonrpc-core", version = "*" }, - { name = "libp2p-floodsub", version = "*" }, - { name = "libsecp256k1", version = "*" }, - { name = "libsecp256k1-core", version = "*" }, - { name = "libsecp256k1-gen-ecmult", version = "*" }, - { name = "libsecp256k1-gen-genmult", version = "*" }, - { name = "lock_api", version = "*" }, - { name = "log", version = "*" }, - { name = "memoffset", version = "*" }, - { name = "miniz_oxide", version = "*" }, - { name = "mio", version = "*" }, - { name = "num-bigint", version = "*" }, - { name = "opaque-debug", version = "*" }, - { name = "parking_lot", version = "*" }, - { name = "parking_lot_core", version = "*" }, - { name = "pbkdf2", version = "*" }, - { name = "percent-encoding", version = "*" }, - { name = "petgraph", version = "*" }, - { name = "pin-project", version = "*" }, - { name = "pin-project-internal", version = "*" }, - { name = "pin-project-lite", version = "*" }, - { name = "proc-macro-crate", version = "*" }, - { name = "proc-macro2", version = "*" }, - { name = "quote", version = "*" }, - { name = "radium", version = "*" }, - { name = "rand", version = "*" }, - { name = "rand_chacha", version = "*" }, - { name = "rand_core", version = "*" }, - { name = "rand_hc", version = "*" }, - { name = "rand_pcg", version = "*" }, - { name = "redox_syscall", version = "*" }, - { name = "redox_users", version = "*" }, - { name = "rlp", version = "*" }, - { name = "rustc-hex", version = "*" }, - { name = "rustc_version", version = "*" }, - { name = "rustls", version = "*" }, - { name = "rustls-pemfile", version = "*" }, - { name = "scopeguard", version = "*" }, - { name = "sct", version = "*" }, - { name = "secp256k1", version = "*" }, - { name = "secp256k1-sys", version = "*" }, - { name = "semver", version = "*" }, - { name = "send_wrapper", version = "*" }, - { name = "sha2", version = "*" }, - { name = "slab", version = "*" }, - { name = "smallvec", version = "*" }, - { name = "socket2", version = "*" }, - { name = "subtle", version = "*" }, - { name = "syn", version = "*" }, - { name = "time", version = "*" }, - { name = "time-macros", version = "*" }, - { name = "tiny-keccak", version = "*" }, - { name = "tokio-util", version = "*" }, - { name = "trie-root", version = "*" }, - { name = "unicode-xid", version = "*" }, - { name = "unsigned-varint", version = "*" }, - { name = "url", version = "*" }, - { name = "uuid", version = "*" }, - { name = "wasi", version = "*" }, - { name = "webpki", version = "*" }, - { name = "wyz", version = "*" }, -] -# Similarly to `skip` allows you to skip certain crates during duplicate -# detection. Unlike skip, it also includes the entire tree of transitive -# dependencies starting at the specified crate, up to a certain depth, which is -# by default infinite -skip-tree = [ - #{ name = "ansi_term", version = "=0.11.0", depth = 20 }, -] - -# This section is considered when running `cargo deny check sources`. -# More documentation about the 'sources' section can be found here: -# https://embarkstudios.github.io/cargo-deny/checks/sources/cfg.html -[sources] -# Lint level for what to happen when a crate from a crate registry that is not -# in the allow list is encountered -unknown-registry = "warn" -# Lint level for what to happen when a crate from a git repository that is not -# in the allow list is encountered -unknown-git = "warn" -# List of URLs for allowed crate registries. Defaults to the crates.io index -# if not specified. If it is specified but empty, no registries are allowed. -allow-registry = ["https://github.com/rust-lang/crates.io-index"] -# List of URLs for allowed Git repositories -allow-git = [] - -[sources.allow-org] -# 1 or more github.com organizations to allow git sources for -github = [""] -# 1 or more gitlab.com organizations to allow git sources for -gitlab = [""] -# 1 or more bitbucket.org organizations to allow git sources for -bitbucket = [""] From ef753cd14a2eac57013f3ba7a18b4ebc35bf53e3 Mon Sep 17 00:00:00 2001 From: shamardy <39480341+shamardy@users.noreply.github.com> Date: Tue, 18 Apr 2023 13:31:41 +0200 Subject: [PATCH 81/90] fix: avoid waiting for all EVM nodes to sync the latest nonce (#1757) Return latest nonce quickly without waiting for all nodes to sync. Send evm transactions to only the nodes that synced the latest nonce. --------- Reviewed-by: laruh, caglaryucekaya , ozkanonur --- CHANGELOG.md | 7 ++ mm2src/coins/eth.rs | 73 ++++++++++--------- mm2src/coins/eth/eth_tests.rs | 4 +- .../tests/mm2_tests/mm2_tests_inner.rs | 2 +- 4 files changed, 50 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e23dc19aa..47a39e85fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## ${next-version} - ${release-date} + +**Features:** + +**Enhancements/Fixes:** +- An issue was fixed where we don't have to wait for all EVM nodes to sync the latest account nonce [#1757](https://github.com/KomodoPlatform/atomicDEX-API/pull/1757) + ## v1.0.2-beta - 2023-04-11 **Features:** diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index 8c55c5c366..f610b91845 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -43,7 +43,7 @@ use ethereum_types::{Address, H160, H256, U256}; use ethkey::{public_to_address, KeyPair, Public, Signature}; use ethkey::{sign, verify_address}; use futures::compat::Future01CompatExt; -use futures::future::{join_all, Either, FutureExt, TryFutureExt}; +use futures::future::{join_all, select_ok, Either, FutureExt, TryFutureExt}; use futures01::Future; use http::StatusCode; use mm2_core::mm_ctx::{MmArc, MmWeak}; @@ -775,7 +775,7 @@ async fn withdraw_impl(coin: EthCoin, req: WithdrawRequest) -> WithdrawResult { let (tx_hash, tx_hex) = match coin.priv_key_policy { EthPrivKeyPolicy::KeyPair(ref key_pair) => { let _nonce_lock = coin.nonce_lock.lock().await; - let nonce = get_addr_nonce(coin.my_address, coin.web3_instances.clone()) + let (nonce, _) = get_addr_nonce(coin.my_address, coin.web3_instances.clone()) .compat() .timeout_secs(30.) .await? @@ -924,7 +924,7 @@ pub async fn withdraw_erc1155(ctx: MmArc, req: WithdrawErc1155) -> WithdrawNftRe let (gas, gas_price) = get_eth_gas_details(ð_coin, req.fee, eth_value, data.clone().into(), call_addr, false).await?; let _nonce_lock = eth_coin.nonce_lock.lock().await; - let nonce = get_addr_nonce(eth_coin.my_address, eth_coin.web3_instances.clone()) + let (nonce, _) = get_addr_nonce(eth_coin.my_address, eth_coin.web3_instances.clone()) .compat() .timeout_secs(30.) .await? @@ -992,7 +992,7 @@ pub async fn withdraw_erc721(ctx: MmArc, req: WithdrawErc721) -> WithdrawNftResu let (gas, gas_price) = get_eth_gas_details(ð_coin, req.fee, eth_value, data.clone().into(), call_addr, false).await?; let _nonce_lock = eth_coin.nonce_lock.lock().await; - let nonce = get_addr_nonce(eth_coin.my_address, eth_coin.web3_instances.clone()) + let (nonce, _) = get_addr_nonce(eth_coin.my_address, eth_coin.web3_instances.clone()) .compat() .timeout_secs(30.) .await? @@ -2005,7 +2005,7 @@ async fn sign_and_send_transaction_with_keypair( } let _nonce_lock = coin.nonce_lock.lock().await; status.status(tags!(), "get_addr_nonce…"); - let nonce = try_tx_s!( + let (nonce, web3_instances_with_latest_nonce) = try_tx_s!( get_addr_nonce(coin.my_address, coin.web3_instances.clone()) .compat() .await @@ -2026,14 +2026,10 @@ async fn sign_and_send_transaction_with_keypair( let bytes = Bytes(rlp::encode(&signed).to_vec()); status.status(tags!(), "send_raw_transaction…"); - try_tx_s!( - coin.web3 - .eth() - .send_raw_transaction(bytes) - .await - .map_err(|e| ERRL!("{}", e)), - signed - ); + let futures = web3_instances_with_latest_nonce + .into_iter() + .map(|web3_instance| web3_instance.web3.eth().send_raw_transaction(bytes.clone())); + try_tx_s!(select_ok(futures).await.map_err(|e| ERRL!("{}", e)), signed); status.status(tags!(), "get_addr_nonce…"); coin.wait_for_addr_nonce_increase(coin.my_address, nonce).await; @@ -4012,7 +4008,7 @@ impl EthCoin { Box::new(fut.boxed().compat()) } - /// Checks every second till ETH nodes recognize that nonce is increased. + /// Checks every second till at least one ETH node recognizes that nonce is increased. /// Parity has reliable "nextNonce" method that always returns correct nonce for address. /// But we can't expect that all nodes will always be Parity. /// Some of ETH forks use Geth only so they don't have Parity nodes at all. @@ -4025,8 +4021,8 @@ impl EthCoin { async fn wait_for_addr_nonce_increase(&self, addr: Address, prev_nonce: U256) { repeatable!(async { match get_addr_nonce(addr, self.web3_instances.clone()).compat().await { - Ok(new_nonce) if new_nonce > prev_nonce => Ready(()), - Ok(_nonce) => Retry(()), + Ok((new_nonce, _)) if new_nonce > prev_nonce => Ready(()), + Ok((_nonce, _)) => Retry(()), Err(e) => { error!("Error getting {} {} nonce: {}", self.ticker(), self.my_address, e); Retry(()) @@ -5015,31 +5011,37 @@ fn checksum_address(addr: &str) -> String { /// The input must be 0x prefixed hex string fn is_valid_checksum_addr(addr: &str) -> bool { addr == checksum_address(addr) } -/// Requests the nonce from all available nodes and checks that returned results equal. -/// Nodes might need some time to sync and there can be other coins that use same nodes in different order. -/// We need to be sure that nonce is updated on all of them before and after transaction is sent. +/// Requests the nonce from all available nodes and returns the highest nonce available with the list of nodes that returned the highest nonce. +/// Transactions will be sent using the nodes that returned the highest nonce. #[cfg_attr(test, mockable)] -fn get_addr_nonce(addr: Address, web3s: Vec) -> Box + Send> { +fn get_addr_nonce( + addr: Address, + web3s: Vec, +) -> Box), Error = String> + Send> { let fut = async move { let mut errors: u32 = 0; loop { - let futures: Vec<_> = web3s + let (futures, web3s): (Vec<_>, Vec<_>) = web3s .iter() .map(|web3| { if web3.is_parity { let parity: ParityNonce<_> = web3.web3.api(); - Either::Left(parity.parity_next_nonce(addr)) + (Either::Left(parity.parity_next_nonce(addr)), web3.clone()) } else { - Either::Right(web3.web3.eth().transaction_count(addr, Some(BlockNumber::Pending))) + ( + Either::Right(web3.web3.eth().transaction_count(addr, Some(BlockNumber::Pending))), + web3.clone(), + ) } }) - .collect(); + .unzip(); let nonces: Vec<_> = join_all(futures) .await .into_iter() - .filter_map(|nonce_res| match nonce_res { - Ok(n) => Some(n), + .zip(web3s.into_iter()) + .filter_map(|(nonce_res, web3)| match nonce_res { + Ok(n) => Some((n, web3)), Err(e) => { error!("Error getting nonce for addr {:?}: {}", addr, e); None @@ -5053,13 +5055,18 @@ fn get_addr_nonce(addr: Address, web3s: Vec) -> Box Date: Wed, 19 Apr 2023 15:00:18 +0300 Subject: [PATCH 82/90] remove ci compilation profile and optimize dev-release profiles (#1759) Signed-off-by: ozkanonur --- .docker/Dockerfile.dev-release | 2 +- .dockerignore | 2 +- .github/workflows/dev-build.yml | 54 +++++++++++++++--------------- .github/workflows/fmt-and-lint.yml | 4 +-- .github/workflows/test.yml | 14 ++++---- CHANGELOG.md | 1 + Cargo.toml | 14 +++++--- 7 files changed, 49 insertions(+), 42 deletions(-) diff --git a/.docker/Dockerfile.dev-release b/.docker/Dockerfile.dev-release index 33aa9c5d27..3167c38a59 100644 --- a/.docker/Dockerfile.dev-release +++ b/.docker/Dockerfile.dev-release @@ -1,5 +1,5 @@ FROM docker.io/debian:stable-slim WORKDIR /mm2 -COPY target/ci/mm2 /usr/local/bin/mm2 +COPY target/release/mm2 /usr/local/bin/mm2 EXPOSE 7783 CMD ["mm2"] diff --git a/.dockerignore b/.dockerignore index 1cc2f87bf7..5e4e3785e1 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,7 +5,7 @@ cmake-build-debug /Dockerfile !/target/release/mm2 -!/target/ci/mm2 +!/target/debug/mm2 /mm2src/*/target /build diff --git a/.github/workflows/dev-build.yml b/.github/workflows/dev-build.yml index e43b91bfe6..59ba122cc7 100644 --- a/.github/workflows/dev-build.yml +++ b/.github/workflows/dev-build.yml @@ -15,7 +15,7 @@ env: jobs: linux-x86-64: - timeout-minutes: 30 + timeout-minutes: 60 runs-on: ubuntu-latest container: komodoofficial/ci-container:latest steps: @@ -45,7 +45,7 @@ jobs: run: | rm -f ./MM_VERSION echo $COMMIT_HASH > ./MM_VERSION - cargo build --bin mm2 --profile ci + cargo build --bin mm2 --release - name: Compress build output env: @@ -53,7 +53,7 @@ jobs: if: ${{ env.AVAILABLE != '' }} run: | NAME="mm2_$COMMIT_HASH-linux-x86-64.zip" - zip $NAME target/ci/mm2 -j + zip $NAME target/release/mm2 -j mkdir $BRANCH_NAME mv $NAME ./$BRANCH_NAME/ @@ -83,7 +83,7 @@ jobs: docker push komodoofficial/atomicdexapi:dev-latest mac-x86-64: - timeout-minutes: 30 + timeout-minutes: 60 runs-on: macos-latest steps: - uses: actions/checkout@v3 @@ -104,7 +104,7 @@ jobs: run: | rm -f ./MM_VERSION echo $COMMIT_HASH > ./MM_VERSION - cargo build --bin mm2 --profile ci --target x86_64-apple-darwin + cargo build --bin mm2 --release --target x86_64-apple-darwin - name: Compress build output env: @@ -112,7 +112,7 @@ jobs: if: ${{ env.AVAILABLE != '' }} run: | NAME="mm2_$COMMIT_HASH-mac-x86-64.zip" - zip $NAME target/x86_64-apple-darwin/ci/mm2 -j + zip $NAME target/x86_64-apple-darwin/release/mm2 -j mkdir $BRANCH_NAME mv $NAME ./$BRANCH_NAME/ @@ -130,7 +130,7 @@ jobs: remote: "/uploads/${{ env.BRANCH_NAME }}" win-x86-64: - timeout-minutes: 30 + timeout-minutes: 60 runs-on: windows-latest steps: - uses: actions/checkout@v3 @@ -153,7 +153,7 @@ jobs: remove-item "./MM_VERSION" } echo $Env:COMMIT_HASH > ./MM_VERSION - cargo build --bin mm2 --profile ci + cargo build --bin mm2 --release - name: Compress build output env: @@ -161,7 +161,7 @@ jobs: if: ${{ env.AVAILABLE != '' }} run: | $NAME="mm2_$Env:COMMIT_HASH-win-x86-64.zip" - 7z a $NAME .\target\ci\mm2.exe .\target\ci\*.dll + 7z a $NAME .\target\release\mm2.exe .\target\release\*.dll mkdir $Env:BRANCH_NAME mv $NAME ./$Env:BRANCH_NAME/ @@ -179,7 +179,7 @@ jobs: remote: "/uploads/${{ env.BRANCH_NAME }}" mac-dylib-x86-64: - timeout-minutes: 30 + timeout-minutes: 60 runs-on: macos-latest steps: - uses: actions/checkout@v3 @@ -200,7 +200,7 @@ jobs: run: | rm -f ./MM_VERSION echo $COMMIT_HASH > ./MM_VERSION - cargo rustc --target x86_64-apple-darwin --lib --profile ci --package mm2_bin_lib --crate-type=staticlib + cargo rustc --target x86_64-apple-darwin --lib --release --package mm2_bin_lib --crate-type=staticlib - name: Compress build output env: @@ -208,8 +208,8 @@ jobs: if: ${{ env.AVAILABLE != '' }} run: | NAME="mm2_$COMMIT_HASH-mac-dylib-x86-64.zip" - mv target/x86_64-apple-darwin/ci/libmm2lib.a target/x86_64-apple-darwin/ci/libmm2.a - zip $NAME target/x86_64-apple-darwin/ci/libmm2.a -j + mv target/x86_64-apple-darwin/release/libmm2lib.a target/x86_64-apple-darwin/release/libmm2.a + zip $NAME target/x86_64-apple-darwin/release/libmm2.a -j mkdir $BRANCH_NAME mv $NAME ./$BRANCH_NAME/ @@ -227,7 +227,7 @@ jobs: remote: "/uploads/${{ env.BRANCH_NAME }}" wasm: - timeout-minutes: 30 + timeout-minutes: 60 runs-on: ubuntu-latest container: komodoofficial/ci-container:latest steps: @@ -261,7 +261,7 @@ jobs: run: | rm -f ./MM_VERSION echo $COMMIT_HASH > ./MM_VERSION - wasm-pack build mm2src/mm2_bin_lib --target web --out-dir ../../target/target-wasm-release + wasm-pack build --release mm2src/mm2_bin_lib --target web --out-dir ../../target/target-wasm-release - name: Compress build output env: @@ -287,7 +287,7 @@ jobs: remote: "/uploads/${{ env.BRANCH_NAME }}" ios-aarch64: - timeout-minutes: 30 + timeout-minutes: 60 runs-on: macos-latest steps: - uses: actions/checkout@v3 @@ -309,7 +309,7 @@ jobs: run: | rm -f ./MM_VERSION echo $COMMIT_HASH > ./MM_VERSION - cargo rustc --target aarch64-apple-ios --lib --profile ci --package mm2_bin_lib --crate-type=staticlib + cargo rustc --target aarch64-apple-ios --lib --release --package mm2_bin_lib --crate-type=staticlib - name: Compress build output env: @@ -317,8 +317,8 @@ jobs: if: ${{ env.AVAILABLE != '' }} run: | NAME="mm2_$COMMIT_HASH-ios-aarch64.zip" - mv target/aarch64-apple-ios/ci/libmm2lib.a target/aarch64-apple-ios/ci/libmm2.a - zip $NAME target/aarch64-apple-ios/ci/libmm2.a -j + mv target/aarch64-apple-ios/release/libmm2lib.a target/aarch64-apple-ios/release/libmm2.a + zip $NAME target/aarch64-apple-ios/release/libmm2.a -j mkdir $BRANCH_NAME mv $NAME ./$BRANCH_NAME/ @@ -336,7 +336,7 @@ jobs: remote: "/uploads/${{ env.BRANCH_NAME }}" android-aarch64: - timeout-minutes: 30 + timeout-minutes: 60 runs-on: ubuntu-latest container: komodoofficial/ci-container:latest steps: @@ -372,7 +372,7 @@ jobs: echo $COMMIT_HASH > ./MM_VERSION export PATH=$PATH:/android-ndk/bin - CC_aarch64_linux_android=aarch64-linux-android21-clang CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android21-clang cargo rustc --target=aarch64-linux-android --lib --profile ci --crate-type=staticlib --package mm2_bin_lib + CC_aarch64_linux_android=aarch64-linux-android21-clang CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android21-clang cargo rustc --target=aarch64-linux-android --lib --release --crate-type=staticlib --package mm2_bin_lib - name: Compress build output env: @@ -380,8 +380,8 @@ jobs: if: ${{ env.AVAILABLE != '' }} run: | NAME="mm2_$COMMIT_HASH-android-aarch64.zip" - mv target/aarch64-linux-android/ci/libmm2lib.a target/aarch64-linux-android/ci/libmm2.a - zip $NAME target/aarch64-linux-android/ci/libmm2.a -j + mv target/aarch64-linux-android/release/libmm2lib.a target/aarch64-linux-android/release/libmm2.a + zip $NAME target/aarch64-linux-android/release/libmm2.a -j mkdir $BRANCH_NAME mv $NAME ./$BRANCH_NAME/ @@ -399,7 +399,7 @@ jobs: remote: "/uploads/${{ env.BRANCH_NAME }}" android-armv7: - timeout-minutes: 30 + timeout-minutes: 60 runs-on: ubuntu-latest container: komodoofficial/ci-container:latest steps: @@ -435,7 +435,7 @@ jobs: echo $COMMIT_HASH > ./MM_VERSION export PATH=$PATH:/android-ndk/bin - CC_armv7_linux_androideabi=armv7a-linux-androideabi21-clang CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=armv7a-linux-androideabi21-clang cargo rustc --target=armv7-linux-androideabi --lib --profile ci --crate-type=staticlib --package mm2_bin_lib + CC_armv7_linux_androideabi=armv7a-linux-androideabi21-clang CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=armv7a-linux-androideabi21-clang cargo rustc --target=armv7-linux-androideabi --lib --release --crate-type=staticlib --package mm2_bin_lib - name: Compress build output env: @@ -443,8 +443,8 @@ jobs: if: ${{ env.AVAILABLE != '' }} run: | NAME="mm2_$COMMIT_HASH-android-armv7.zip" - mv target/armv7-linux-androideabi/ci/libmm2lib.a target/armv7-linux-androideabi/ci/libmm2.a - zip $NAME target/armv7-linux-androideabi/ci/libmm2.a -j + mv target/armv7-linux-androideabi/release/libmm2lib.a target/armv7-linux-androideabi/release/libmm2.a + zip $NAME target/armv7-linux-androideabi/release/libmm2.a -j mkdir $BRANCH_NAME mv $NAME ./$BRANCH_NAME/ diff --git a/.github/workflows/fmt-and-lint.yml b/.github/workflows/fmt-and-lint.yml index 09ab32ba8b..73b6bb1b1d 100644 --- a/.github/workflows/fmt-and-lint.yml +++ b/.github/workflows/fmt-and-lint.yml @@ -23,7 +23,7 @@ jobs: run: cargo fmt -- --check - name: x86-64 code lint - run: cargo clippy --all-targets --profile ci -- --D warnings + run: cargo clippy --all-targets -- --D warnings wasm-lint: timeout-minutes: 45 @@ -37,4 +37,4 @@ jobs: rustup target add wasm32-unknown-unknown - name: wasm code lint - run: cargo clippy --target wasm32-unknown-unknown --profile ci -- --D warnings + run: cargo clippy --target wasm32-unknown-unknown -- --D warnings diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5ff6f0e491..23f3b3d107 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,7 +28,7 @@ jobs: - name: Test run: | # wget -O - https://raw.githubusercontent.com/KomodoPlatform/komodo/master/zcutil/fetch-params-alt.sh | bash - cargo test --bins --lib --profile ci + cargo test --bins --lib mac-x86-64-unit: timeout-minutes: 90 @@ -50,7 +50,7 @@ jobs: - name: Test run: | # wget -O - https://raw.githubusercontent.com/KomodoPlatform/komodo/master/zcutil/fetch-params-alt.sh | bash - cargo test --bins --lib --target x86_64-apple-darwin --profile ci + cargo test --bins --lib --target x86_64-apple-darwin win-x86-64-unit: timeout-minutes: 90 @@ -86,7 +86,7 @@ jobs: # Restart-Service docker # Get-Service docker - cargo test --bins --lib --profile ci + cargo test --bins --lib linux-x86-64-mm2-integration: timeout-minutes: 90 @@ -105,7 +105,7 @@ jobs: rustup default nightly-2022-10-29 - name: Test - run: cargo test --test 'mm2_tests_main' --profile ci + run: cargo test --test 'mm2_tests_main' # https://docs.github.com/en/actions/learn-github-actions/usage-limits-billing-and-administration#usage-limits # https://github.com/KomodoPlatform/atomicDEX-API/actions/runs/4419618128/jobs/7748266141#step:4:1790 @@ -127,7 +127,7 @@ jobs: # rustup target add x86_64-apple-darwin # - name: Test - # run: cargo test --test 'mm2_tests_main' --target x86_64-apple-darwin --profile ci + # run: cargo test --test 'mm2_tests_main' --target x86_64-apple-darwin win-x86-64-mm2-integration: timeout-minutes: 90 @@ -146,7 +146,7 @@ jobs: rustup default nightly-2022-10-29 - name: Test - run: cargo test --test 'mm2_tests_main' --profile ci + run: cargo test --test 'mm2_tests_main' docker-tests: timeout-minutes: 90 @@ -167,7 +167,7 @@ jobs: - name: Test run: | wget -O - https://raw.githubusercontent.com/KomodoPlatform/komodo/master/zcutil/fetch-params-alt.sh | bash - cargo test --test 'docker_tests_main' --features run-docker-tests --profile ci + cargo test --test 'docker_tests_main' --features run-docker-tests wasm: timeout-minutes: 90 diff --git a/CHANGELOG.md b/CHANGELOG.md index 47a39e85fe..c131fc1494 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ **Enhancements/Fixes:** - An issue was fixed where we don't have to wait for all EVM nodes to sync the latest account nonce [#1757](https://github.com/KomodoPlatform/atomicDEX-API/pull/1757) +- optimized dev and release compilation profiles and removed ci [#1759](https://github.com/KomodoPlatform/atomicDEX-API/pull/1759) ## v1.0.2-beta - 2023-04-11 diff --git a/Cargo.toml b/Cargo.toml index 388116abd7..07bae2c797 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,6 +54,10 @@ debug-assertions = false # For some reason, opt-level 3 started causing infinite Windows builds after Cosmos integration # TODO troubleshoot it opt-level = 2 +# strip = true +codegen-units = 1 +# lto = true +panic = "abort" [profile.test] # required to avoid a long running process of librustcash additional chain validation that is enabled with debug assertions @@ -63,8 +67,10 @@ debug-assertions = false # Turns debugging symbols off for the out-of-workspace dependencies. debug = false -[profile.ci] -inherits = "dev" -# full debug info is not required +[profile.dev] +opt-level = 0 debug = 1 -debug-assertions = false \ No newline at end of file +debug-assertions = false +panic = 'unwind' +incremental = true +codegen-units = 256 \ No newline at end of file From 547a30a79b16da38769411772d837548922ee529 Mon Sep 17 00:00:00 2001 From: Onur Date: Sat, 22 Apr 2023 19:11:25 +0300 Subject: [PATCH 83/90] improve p2p stack (#1755) * optimize p2p network layer Signed-off-by: ozkanonur * update default gas limit for tendermint Signed-off-by: ozkanonur * rollback topic limit Signed-off-by: ozkanonur * remove unused arg from `lp_ordermatch::process_msg` Signed-off-by: ozkanonur * use OrderbookP2PHandlerResult for process_orders_keep_alive and process_maker_order_updated * return one error for failed SwapMsg, SwapStatus deserialization * fix process_swap_msg in wasm to return error if SwapMsg can't be deserialized * remove additional space in SwapMsg, SwapStatus decode error message * roll back crate visibility for new_protocol mod --------- Signed-off-by: ozkanonur Co-authored-by: shamardy --- CHANGELOG.md | 5 + mm2src/coins/tendermint/tendermint_coin.rs | 2 +- mm2src/mm2_libp2p/src/lib.rs | 2 +- mm2src/mm2_main/src/lp_network.rs | 99 +++++++++--- mm2src/mm2_main/src/lp_ordermatch.rs | 151 +++++++++++++----- mm2src/mm2_main/src/lp_swap.rs | 35 ++-- mm2src/mm2_main/src/lp_swap/swap_watcher.rs | 18 +-- .../tests/mm2_tests/mm2_tests_inner.rs | 9 +- .../dummy_files/iris_nimda_history.json | 20 +-- .../dummy_files/iris_test_history.json | 32 ++-- 10 files changed, 255 insertions(+), 118 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c131fc1494..cfbdd4604f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,14 @@ **Features:** **Enhancements/Fixes:** +- p2p stack is improved [#1755](https://github.com/KomodoPlatform/atomicDEX-API/pull/1755) +- - Validate topics if they are mixed or not. +- - Do early return if the message data is not valid (since no point to iterate over and over on the invalid message) +- - Break the loop right after processing any of `SWAP_PREFIX`, `WATCHER_PREFIX`, `TX_HELPER_PREFIX` topic. - An issue was fixed where we don't have to wait for all EVM nodes to sync the latest account nonce [#1757](https://github.com/KomodoPlatform/atomicDEX-API/pull/1757) - optimized dev and release compilation profiles and removed ci [#1759](https://github.com/KomodoPlatform/atomicDEX-API/pull/1759) + ## v1.0.2-beta - 2023-04-11 **Features:** diff --git a/mm2src/coins/tendermint/tendermint_coin.rs b/mm2src/coins/tendermint/tendermint_coin.rs index 594508a3af..6e5b4dad32 100644 --- a/mm2src/coins/tendermint/tendermint_coin.rs +++ b/mm2src/coins/tendermint/tendermint_coin.rs @@ -92,7 +92,7 @@ const ABCI_REQUEST_PROVE: bool = false; /// 0.25 is good average gas price on atom and iris const DEFAULT_GAS_PRICE: f64 = 0.25; pub(super) const TIMEOUT_HEIGHT_DELTA: u64 = 100; -pub const GAS_LIMIT_DEFAULT: u64 = 100_000; +pub const GAS_LIMIT_DEFAULT: u64 = 125_000; pub(crate) const TX_DEFAULT_MEMO: &str = ""; // https://github.com/irisnet/irismod/blob/5016c1be6fdbcffc319943f33713f4a057622f0a/modules/htlc/types/validation.go#L19-L22 diff --git a/mm2src/mm2_libp2p/src/lib.rs b/mm2src/mm2_libp2p/src/lib.rs index 8027121c8f..a99841329e 100644 --- a/mm2src/mm2_libp2p/src/lib.rs +++ b/mm2src/mm2_libp2p/src/lib.rs @@ -16,7 +16,7 @@ use secp256k1::{Message as SecpMessage, PublicKey as Secp256k1Pubkey, Secp256k1, use sha2::{Digest, Sha256}; pub use atomicdex_behaviour::{spawn_gossipsub, AdexBehaviourError, NodeType, WssCerts}; -pub use atomicdex_gossipsub::{GossipsubEvent, GossipsubMessage, MessageId}; +pub use atomicdex_gossipsub::{GossipsubEvent, GossipsubMessage, MessageId, TopicHash}; pub use libp2p::identity::error::DecodingError; pub use libp2p::identity::secp256k1::PublicKey as Libp2pSecpPublic; pub use libp2p::identity::PublicKey as Libp2pPublic; diff --git a/mm2src/mm2_main/src/lp_network.rs b/mm2src/mm2_main/src/lp_network.rs index ba10ee46c3..c1c58a722c 100644 --- a/mm2src/mm2_main/src/lp_network.rs +++ b/mm2src/mm2_main/src/lp_network.rs @@ -30,7 +30,7 @@ use mm2_libp2p::atomicdex_behaviour::{AdexBehaviourCmd, AdexBehaviourEvent, Adex AdexResponseChannel}; use mm2_libp2p::peers_exchange::PeerAddresses; use mm2_libp2p::{decode_message, encode_message, DecodingError, GossipsubMessage, Libp2pPublic, Libp2pSecpPublic, - MessageId, NetworkPorts, PeerId, TOPIC_SEPARATOR}; + MessageId, NetworkPorts, PeerId, TopicHash, TOPIC_SEPARATOR}; use mm2_metrics::{mm_label, mm_timing}; #[cfg(test)] use mocktopus::macros::*; use parking_lot::Mutex as PaMutex; @@ -39,7 +39,8 @@ use std::net::ToSocketAddrs; use std::sync::Arc; use wasm_timer::Instant; -use crate::mm2::{lp_ordermatch, lp_stats, lp_swap}; +use crate::mm2::lp_ordermatch; +use crate::mm2::{lp_stats, lp_swap}; pub type P2PRequestResult = Result>; @@ -138,36 +139,99 @@ async fn process_p2p_message( mut message: GossipsubMessage, i_am_relay: bool, ) { + fn is_valid(topics: &[TopicHash]) -> Result<(), String> { + if topics.is_empty() { + return Err("At least one topic must be provided.".to_string()); + } + + let first_topic_prefix = topics[0].as_str().split(TOPIC_SEPARATOR).next().unwrap_or_default(); + for item in topics.iter().skip(1) { + if !item.as_str().starts_with(first_topic_prefix) { + return Err(format!( + "Topics are invalid, received more than one topic kind. Topics '{:?}", + topics + )); + } + } + + Ok(()) + } + let mut to_propagate = false; - let mut orderbook_pairs = vec![]; message.topics.dedup(); drop_mutability!(message); - for topic in message.topics { + if let Err(err) = is_valid(&message.topics) { + log::error!("{}", err); + return; + } + + let inform_about_break = |used: &str, all: &[TopicHash]| { + log::debug!( + "Topic '{}' proceed and loop is killed. Whole topic list was '{:?}'", + used, + all + ); + }; + + for topic in message.topics.iter() { let mut split = topic.as_str().split(TOPIC_SEPARATOR); + match split.next() { Some(lp_ordermatch::ORDERBOOK_PREFIX) => { - if let Some(pair) = split.next() { - orderbook_pairs.push(pair.to_string()); + let fut = lp_ordermatch::handle_orderbook_msg( + ctx.clone(), + &message.topics, + peer_id.to_string(), + &message.data, + i_am_relay, + ); + + if let Err(e) = fut.await { + if e.get_inner().is_warning() { + log::warn!("{}", e); + } else { + log::error!("{}", e); + } + return; } + + to_propagate = true; + break; }, Some(lp_swap::SWAP_PREFIX) => { - lp_swap::process_msg(ctx.clone(), split.next().unwrap_or_default(), &message.data).await; + if let Err(e) = + lp_swap::process_swap_msg(ctx.clone(), split.next().unwrap_or_default(), &message.data).await + { + log::error!("{}", e); + return; + } + to_propagate = true; + + inform_about_break(topic.as_str(), &message.topics); + break; }, Some(lp_swap::WATCHER_PREFIX) => { if ctx.is_watcher() { - lp_swap::process_watcher_msg(ctx.clone(), &message.data).await; + if let Err(e) = lp_swap::process_watcher_msg(ctx.clone(), &message.data) { + log::error!("{}", e); + return; + } } + to_propagate = true; + + inform_about_break(topic.as_str(), &message.topics); + break; }, Some(lp_swap::TX_HELPER_PREFIX) => { if let Some(pair) = split.next() { if let Ok(Some(coin)) = lp_coinfind(&ctx, pair).await { if let Err(e) = coin.tx_enum_from_bytes(&message.data) { log::error!("Message cannot continue the process due to: {:?}", e); - continue; + return; }; let fut = coin.send_raw_tx_bytes(&message.data); @@ -182,25 +246,14 @@ async fn process_p2p_message( }) } } + + inform_about_break(topic.as_str(), &message.topics); + break; }, None | Some(_) => (), } } - if !orderbook_pairs.is_empty() { - let process_fut = lp_ordermatch::process_msg( - ctx.clone(), - orderbook_pairs, - peer_id.to_string(), - &message.data, - i_am_relay, - ); - - if process_fut.await { - to_propagate = true; - } - } - if to_propagate && i_am_relay { propagate_message(&ctx, message_id, peer_id); } diff --git a/mm2src/mm2_main/src/lp_ordermatch.rs b/mm2src/mm2_main/src/lp_ordermatch.rs index 5fc9d248db..ff55085d61 100644 --- a/mm2src/mm2_main/src/lp_ordermatch.rs +++ b/mm2src/mm2_main/src/lp_ordermatch.rs @@ -42,7 +42,8 @@ use http::Response; use keys::{AddressFormat, KeyPair}; use mm2_core::mm_ctx::{from_ctx, MmArc, MmWeak}; use mm2_err_handle::prelude::*; -use mm2_libp2p::{decode_signed, encode_and_sign, encode_message, pub_sub_topic, TopicPrefix, TOPIC_SEPARATOR}; +use mm2_libp2p::{decode_signed, encode_and_sign, encode_message, pub_sub_topic, TopicHash, TopicPrefix, + TOPIC_SEPARATOR}; use mm2_metrics::mm_gauge; use mm2_number::{construct_detailed, BigDecimal, BigRational, Fraction, MmNumber, MmNumberMultiRepr}; #[cfg(test)] use mocktopus::macros::*; @@ -61,7 +62,8 @@ use std::time::Duration; use trie_db::NodeCodec as NodeCodecT; use uuid::Uuid; -use crate::mm2::lp_network::{broadcast_p2p_msg, request_any_relay, request_one_peer, subscribe_to_topic, P2PRequest}; +use crate::mm2::lp_network::{broadcast_p2p_msg, request_any_relay, request_one_peer, subscribe_to_topic, P2PRequest, + P2PRequestError}; use crate::mm2::lp_swap::{calc_max_maker_vol, check_balance_for_maker_swap, check_balance_for_taker_swap, check_other_coin_balance_for_swap, get_max_maker_vol, insert_new_swap_to_db, is_pubkey_banned, lp_atomic_locktime, p2p_keypair_and_peer_id_to_broadcast, @@ -123,6 +125,39 @@ const TRIE_ORDER_HISTORY_TIMEOUT: u64 = 300; #[cfg(test)] const TRIE_ORDER_HISTORY_TIMEOUT: u64 = 3; +pub type OrderbookP2PHandlerResult = Result<(), MmError>; + +#[derive(Display)] +pub enum OrderbookP2PHandlerError { + #[display(fmt = "'{}' is an invalid topic for the orderbook handler.", _0)] + InvalidTopic(String), + + #[display(fmt = "Message decoding was failed. Error: {}", _0)] + DecodeError(String), + + #[display(fmt = "Pubkey '{}' is not allowed.", _0)] + PubkeyNotAllowed(String), + + #[display(fmt = "P2P request error: {}", _0)] + P2PRequestError(String), + + #[display( + fmt = "Couldn't find an order {}, ignoring, it will be synced upon pubkey keep alive", + _0 + )] + OrderNotFound(Uuid), + + Internal(String), +} + +impl OrderbookP2PHandlerError { + pub(crate) fn is_warning(&self) -> bool { matches!(self, OrderbookP2PHandlerError::OrderNotFound(_)) } +} + +impl From for OrderbookP2PHandlerError { + fn from(e: P2PRequestError) -> Self { OrderbookP2PHandlerError::P2PRequestError(e.to_string()) } +} + /// Alphabetically ordered orderbook pair type AlbOrderedOrderbookPair = String; type PubkeyOrders = Vec<(Uuid, OrderbookP2PItem)>; @@ -247,7 +282,7 @@ async fn process_orders_keep_alive( from_pubkey: String, keep_alive: new_protocol::PubkeyKeepAlive, i_am_relay: bool, -) -> bool { +) -> OrderbookP2PHandlerResult { let ordermatch_ctx = OrdermatchContext::from_ctx(&ctx).expect("from_ctx failed"); let to_request = ordermatch_ctx .orderbook @@ -257,17 +292,21 @@ async fn process_orders_keep_alive( let req = match to_request { Some(req) => req, // The message was processed, simply forward it - None => return true, + None => return Ok(()), }; - let resp = - request_one_peer::(ctx.clone(), P2PRequest::Ordermatch(req), propagated_from_peer) - .await; - - let response = match resp { - Ok(Some(resp)) => resp, - _ => return false, - }; + let response = request_one_peer::( + ctx.clone(), + P2PRequest::Ordermatch(req), + propagated_from_peer.clone(), + ) + .await? + .ok_or_else(|| { + MmError::new(OrderbookP2PHandlerError::P2PRequestError(format!( + "No response was received from peer {} for SyncPubkeyOrderbookState request!", + propagated_from_peer + ))) + })?; let mut orderbook = ordermatch_ctx.orderbook.lock(); for (pair, diff) in response.pair_orders_diff { @@ -282,27 +321,27 @@ async fn process_orders_keep_alive( DeltaOrFullTrie::FullTrie(values) => process_pubkey_full_trie(&mut orderbook, values, params), }; } - true + + Ok(()) } -fn process_maker_order_updated(ctx: MmArc, from_pubkey: String, updated_msg: new_protocol::MakerOrderUpdated) -> bool { +fn process_maker_order_updated( + ctx: MmArc, + from_pubkey: String, + updated_msg: new_protocol::MakerOrderUpdated, +) -> OrderbookP2PHandlerResult { let ordermatch_ctx = OrdermatchContext::from_ctx(&ctx).expect("from_ctx failed"); let uuid = updated_msg.uuid(); let mut orderbook = ordermatch_ctx.orderbook.lock(); - match orderbook.find_order_by_uuid_and_pubkey(&uuid, &from_pubkey) { - Some(mut order) => { - order.apply_updated(&updated_msg); - orderbook.insert_or_update_order_update_trie(order); - true - }, - None => { - log::warn!( - "Couldn't find an order {}, ignoring, it will be synced upon pubkey keep alive", - uuid - ); - false - }, - } + + let mut order = orderbook + .find_order_by_uuid_and_pubkey(&uuid, &from_pubkey) + .ok_or_else(|| MmError::new(OrderbookP2PHandlerError::OrderNotFound(uuid)))?; + order.apply_updated(&updated_msg); + drop_mutability!(order); + orderbook.insert_or_update_order_update_trie(order); + + Ok(()) } // fn verify_pubkey_orderbook(orderbook: &GetOrderbookPubkeyItem) -> Result<(), String> { @@ -468,19 +507,52 @@ fn remove_pubkey_pair_orders(orderbook: &mut Orderbook, pubkey: &str, alb_pair: pubkey_state.trie_roots.remove(alb_pair); } +pub async fn handle_orderbook_msg( + ctx: MmArc, + topics: &[TopicHash], + from_peer: String, + msg: &[u8], + i_am_relay: bool, +) -> OrderbookP2PHandlerResult { + if let Err(e) = decode_signed::(msg) { + return MmError::err(OrderbookP2PHandlerError::DecodeError(e.to_string())); + }; + + let mut orderbook_pairs = vec![]; + + for topic in topics { + let mut split = topic.as_str().split(TOPIC_SEPARATOR); + match (split.next(), split.next()) { + (Some(ORDERBOOK_PREFIX), Some(pair)) => { + orderbook_pairs.push(pair.to_string()); + }, + _ => { + return MmError::err(OrderbookP2PHandlerError::InvalidTopic(topic.as_str().to_owned())); + }, + }; + } + + drop_mutability!(orderbook_pairs); + + if !orderbook_pairs.is_empty() { + process_msg(ctx, from_peer, msg, i_am_relay).await?; + } + + Ok(()) +} + /// Attempts to decode a message and process it returning whether the message is valid and worth rebroadcasting -pub async fn process_msg(ctx: MmArc, _topics: Vec, from_peer: String, msg: &[u8], i_am_relay: bool) -> bool { +pub async fn process_msg(ctx: MmArc, from_peer: String, msg: &[u8], i_am_relay: bool) -> OrderbookP2PHandlerResult { match decode_signed::(msg) { Ok((message, _sig, pubkey)) => { if is_pubkey_banned(&ctx, &pubkey.unprefixed().into()) { - log::warn!("Pubkey {} is banned", pubkey.to_hex()); - return false; + return MmError::err(OrderbookP2PHandlerError::PubkeyNotAllowed(pubkey.to_hex())); } match message { new_protocol::OrdermatchMessage::MakerOrderCreated(created_msg) => { let order: OrderbookItem = (created_msg, hex::encode(pubkey.to_bytes().as_slice())).into(); insert_or_update_order(&ctx, order); - true + Ok(()) }, new_protocol::OrdermatchMessage::PubkeyKeepAlive(keep_alive) => { process_orders_keep_alive(ctx, from_peer, pubkey.to_hex(), keep_alive, i_am_relay).await @@ -488,36 +560,33 @@ pub async fn process_msg(ctx: MmArc, _topics: Vec, from_peer: String, ms new_protocol::OrdermatchMessage::TakerRequest(taker_request) => { let msg = TakerRequest::from_new_proto_and_pubkey(taker_request, pubkey.unprefixed().into()); process_taker_request(ctx, pubkey.unprefixed().into(), msg).await; - true + Ok(()) }, new_protocol::OrdermatchMessage::MakerReserved(maker_reserved) => { let msg = MakerReserved::from_new_proto_and_pubkey(maker_reserved, pubkey.unprefixed().into()); // spawn because process_maker_reserved may take significant time to run let spawner = ctx.spawner(); spawner.spawn(process_maker_reserved(ctx, pubkey.unprefixed().into(), msg)); - true + Ok(()) }, new_protocol::OrdermatchMessage::TakerConnect(taker_connect) => { process_taker_connect(ctx, pubkey.unprefixed().into(), taker_connect.into()).await; - true + Ok(()) }, new_protocol::OrdermatchMessage::MakerConnected(maker_connected) => { process_maker_connected(ctx, pubkey.unprefixed().into(), maker_connected.into()).await; - true + Ok(()) }, new_protocol::OrdermatchMessage::MakerOrderCancelled(cancelled_msg) => { delete_order(&ctx, &pubkey.to_hex(), cancelled_msg.uuid.into()); - true + Ok(()) }, new_protocol::OrdermatchMessage::MakerOrderUpdated(updated_msg) => { process_maker_order_updated(ctx, pubkey.to_hex(), updated_msg) }, } }, - Err(e) => { - error!("Error {} while decoding signed message", e); - false - }, + Err(e) => MmError::err(OrderbookP2PHandlerError::DecodeError(e.to_string())), } } diff --git a/mm2src/mm2_main/src/lp_swap.rs b/mm2src/mm2_main/src/lp_swap.rs index 53d5c1a1e2..280ed7babc 100644 --- a/mm2src/mm2_main/src/lp_swap.rs +++ b/mm2src/mm2_main/src/lp_swap.rs @@ -57,7 +57,8 @@ // marketmaker // -use crate::mm2::lp_network::{broadcast_p2p_msg, Libp2pPeerId}; +use super::lp_network::P2PRequestResult; +use crate::mm2::lp_network::{broadcast_p2p_msg, Libp2pPeerId, P2PRequestError}; use bitcrypto::{dhash160, sha256}; use coins::eth::Web3RpcError; use coins::{lp_coinfind, lp_coinfind_or_err, CoinFindError, MmCoinEnum, TradeFee, TransactionEnum}; @@ -97,7 +98,7 @@ use std::sync::atomic::{AtomicU64, Ordering}; #[path = "lp_swap/recreate_swap_data.rs"] mod recreate_swap_data; #[path = "lp_swap/saved_swap.rs"] mod saved_swap; #[path = "lp_swap/swap_lock.rs"] mod swap_lock; -#[path = "lp_swap/swap_watcher.rs"] mod swap_watcher; +#[path = "lp_swap/swap_watcher.rs"] pub(crate) mod swap_watcher; #[path = "lp_swap/taker_swap.rs"] mod taker_swap; #[path = "lp_swap/trade_preimage.rs"] mod trade_preimage; @@ -236,31 +237,35 @@ pub fn broadcast_p2p_tx_msg(ctx: &MmArc, topic: String, msg: &TransactionEnum, p broadcast_p2p_msg(ctx, vec![topic], encoded_msg, from); } -pub async fn process_msg(ctx: MmArc, topic: &str, msg: &[u8]) { - let uuid = match Uuid::from_str(topic) { - Ok(u) => u, - Err(_) => return, - }; +pub async fn process_swap_msg(ctx: MmArc, topic: &str, msg: &[u8]) -> P2PRequestResult<()> { + let uuid = Uuid::from_str(topic).map_to_mm(|e| P2PRequestError::DecodeError(e.to_string()))?; let msg = match decode_signed::(msg) { Ok(m) => m, Err(swap_msg_err) => { #[cfg(not(target_arch = "wasm32"))] - match json::from_slice::(msg) { + return match json::from_slice::(msg) { Ok(mut status) => { status.data.fetch_and_set_usd_prices().await; if let Err(e) = save_stats_swap(&ctx, &status.data).await { error!("Error saving the swap {} status: {}", status.data.uuid(), e); } + Ok(()) }, Err(swap_status_err) => { - error!("Couldn't deserialize 'SwapMsg': {:?}", swap_msg_err); - error!("Couldn't deserialize 'SwapStatus': {:?}", swap_status_err); + let error = format!( + "Couldn't deserialize swap msg to either 'SwapMsg': {} or to 'SwapStatus': {}", + swap_msg_err, swap_status_err + ); + MmError::err(P2PRequestError::DecodeError(error)) }, }; - // Drop it to avoid dead_code warning - drop(swap_msg_err); - return; + + #[cfg(target_arch = "wasm32")] + return MmError::err(P2PRequestError::DecodeError(format!( + "Couldn't deserialize 'SwapMsg': {}", + swap_msg_err + ))); }, }; @@ -280,7 +285,9 @@ pub async fn process_msg(ctx: MmArc, topic: &str, msg: &[u8]) { } else { warn!("Received message from unexpected sender for swap {}", uuid); } - } + }; + + Ok(()) } pub fn swap_topic(uuid: &Uuid) -> String { pub_sub_topic(SWAP_PREFIX, &uuid.to_string()) } diff --git a/mm2src/mm2_main/src/lp_swap/swap_watcher.rs b/mm2src/mm2_main/src/lp_swap/swap_watcher.rs index 7441a4a855..536e8fc691 100644 --- a/mm2src/mm2_main/src/lp_swap/swap_watcher.rs +++ b/mm2src/mm2_main/src/lp_swap/swap_watcher.rs @@ -1,5 +1,6 @@ use super::{broadcast_p2p_tx_msg, get_payment_locktime, lp_coinfind, min_watcher_reward, taker_payment_spend_deadline, tx_helper_topic, H256Json, SwapsContext, WAIT_CONFIRM_INTERVAL}; +use crate::mm2::lp_network::{P2PRequestError, P2PRequestResult}; use crate::mm2::MmError; use async_trait::async_trait; use coins::{CanRefundHtlc, ConfirmPaymentInput, FoundSwapTxSpend, MmCoinEnum, RefundPaymentArgs, @@ -11,6 +12,7 @@ use common::state_machine::prelude::*; use common::{now_ms, DEX_FEE_ADDR_RAW_PUBKEY}; use futures::compat::Future01CompatExt; use mm2_core::mm_ctx::MmArc; +use mm2_err_handle::prelude::MapToMmResult; use mm2_libp2p::{decode_signed, pub_sub_topic, TopicPrefix}; use serde::{Deserialize, Serialize}; use serde_json as json; @@ -513,16 +515,8 @@ impl LastState for Stopped { async fn on_changed(self: Box, _watcher_ctx: &mut Self::Ctx) -> Self::Result {} } -pub async fn process_watcher_msg(ctx: MmArc, msg: &[u8]) { - let msg = match decode_signed::(msg) { - Ok(m) => m, - Err(watcher_msg_err) => { - error!("Couldn't deserialize 'SwapWatcherMsg': {:?}", watcher_msg_err); - // Drop it to avoid dead_code warning - drop(watcher_msg_err); - return; - }, - }; +pub fn process_watcher_msg(ctx: MmArc, msg: &[u8]) -> P2PRequestResult<()> { + let msg = decode_signed::(msg).map_to_mm(|e| P2PRequestError::DecodeError(e.to_string()))?; let watcher_data = msg.0; let verified_pubkey = msg.2; @@ -530,7 +524,9 @@ pub async fn process_watcher_msg(ctx: MmArc, msg: &[u8]) { SwapWatcherMsg::TakerSwapWatcherMsg(watcher_data) => { spawn_taker_swap_watcher(ctx, watcher_data, verified_pubkey.to_bytes()) }, - } + }; + + Ok(()) } /// Currently, Taker Swap Watcher is supported only. diff --git a/mm2src/mm2_main/tests/mm2_tests/mm2_tests_inner.rs b/mm2src/mm2_main/tests/mm2_tests/mm2_tests_inner.rs index eb7dc91735..be706d1ccb 100644 --- a/mm2src/mm2_main/tests/mm2_tests/mm2_tests_inner.rs +++ b/mm2src/mm2_main/tests/mm2_tests/mm2_tests_inner.rs @@ -894,7 +894,14 @@ fn trade_test_electrum_and_eth_coins() { let bob_policy = Mm2InitPrivKeyPolicy::Iguana; let alice_policy = Mm2InitPrivKeyPolicy::GlobalHDAccount(0); let pairs = &[("ETH", "JST")]; - block_on(trade_base_rel_electrum(bob_policy, alice_policy, pairs, 1., 2., 0.01)); + block_on(trade_base_rel_electrum( + bob_policy, + alice_policy, + pairs, + 1., + 2., + 0.000001, + )); } #[test] diff --git a/mm2src/mm2_test_helpers/dummy_files/iris_nimda_history.json b/mm2src/mm2_test_helpers/dummy_files/iris_nimda_history.json index c3a6ff1580..e75d8aaf5a 100644 --- a/mm2src/mm2_test_helpers/dummy_files/iris_nimda_history.json +++ b/mm2src/mm2_test_helpers/dummy_files/iris_nimda_history.json @@ -16,7 +16,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.027385", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-NIMDA", "internal_id": "3930374535314439384537304239343431413230443630420000000000000000", @@ -45,7 +45,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.028433", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-NIMDA", "internal_id": "4138433845353931363133303743353941344143374536320000000000000000", @@ -74,7 +74,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.026403", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-NIMDA", "internal_id": "3436313245464444363537373544434341433838463935340000000000000000", @@ -103,7 +103,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.028433", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-NIMDA", "internal_id": "3931453345363544374341333833394331463141394435320000000000000000", @@ -134,7 +134,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.025763", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-NIMDA", "internal_id": "3643343243423346353232433844414333343138443338440000000000000000", @@ -162,7 +162,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.022114", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-NIMDA", "internal_id": "4631313139343742323142303344373639303343333441370000000000000000", @@ -190,7 +190,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.026861", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-NIMDA", "internal_id": "3236413546344639343144434531363135373046373530330000000000000000", @@ -218,7 +218,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.026861", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-NIMDA", "internal_id": "4344413036444433353735413332323330363430414634310000000000000000", @@ -246,7 +246,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.022114", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-NIMDA", "internal_id": "4339384239303045393643333738453237333945314344330000000000000000", @@ -274,7 +274,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.02316", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-NIMDA", "internal_id": "4136303630343838314237323638453734433246453537450000000000000000", diff --git a/mm2src/mm2_test_helpers/dummy_files/iris_test_history.json b/mm2src/mm2_test_helpers/dummy_files/iris_test_history.json index 6577282ea3..a5cc44de43 100644 --- a/mm2src/mm2_test_helpers/dummy_files/iris_test_history.json +++ b/mm2src/mm2_test_helpers/dummy_files/iris_test_history.json @@ -18,7 +18,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.022145", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-TEST", "internal_id": "3338384245443830413744344633314337443043303141460000000000000000", @@ -42,7 +42,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.027215", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-TEST", "internal_id": "3644333931323846453142423238354542363542413237300000000000000000", @@ -71,7 +71,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.027385", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-TEST", "internal_id": "0000000000000000423036443032413134343942303745383944313545373039", @@ -95,7 +95,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.028433", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-TEST", "internal_id": "0000000000000000323645374341344139354337303331363139354538433841", @@ -119,7 +119,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.026403", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-TEST", "internal_id": "0000000000000000343539463838434143434435373735364444464532313634", @@ -143,7 +143,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.02856", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-TEST", "internal_id": "3533313331314334433333384341323539443144423441380000000000000000", @@ -174,7 +174,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.022085", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-TEST", "internal_id": "3332313535443541424134344134343736463332363433370000000000000000", @@ -198,7 +198,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.026446", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-TEST", "internal_id": "3945383530394438433442384645464138413133443235320000000000000000", @@ -227,7 +227,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.026426", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-TEST", "internal_id": "4538314545353844354538344630413743344437364142360000000000000000", @@ -256,7 +256,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.028455", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-TEST", "internal_id": "4135353530353436314138373531433631443333364331460000000000000000", @@ -285,7 +285,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.02648", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-TEST", "internal_id": "4444394136304639344533383037313336353232394430310000000000000000", @@ -314,7 +314,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.028433", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-TEST", "internal_id": "0000000000000000323544394131463143393338334143374435364533453139", @@ -338,7 +338,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.025763", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-TEST", "internal_id": "0000000000000000443833443831343343414438433232354633424332344336", @@ -364,7 +364,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.026861", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-TEST", "internal_id": "3236413546344639343144434531363135373046373530330000000000000001", @@ -390,7 +390,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.026861", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-TEST", "internal_id": "4344413036444433353735413332323330363430414634310000000000000001", @@ -416,7 +416,7 @@ "type": "Tendermint", "coin": "IRIS-TEST", "amount": "0.2", - "gas_limit": 100000 + "gas_limit": 125000 }, "coin": "IRIS-TEST", "internal_id": "3846394537344334443745414531314244303741424145410000000000000000", From d85a9d7124d870708c0e74e3d8cf4cef1938d8e6 Mon Sep 17 00:00:00 2001 From: Onur Date: Tue, 25 Apr 2023 14:03:23 +0300 Subject: [PATCH 84/90] implement cosmos/iris ethermint account compatibility (#1765) Signed-off-by: ozkanonur --- CHANGELOG.md | 1 + .../coins/tendermint/iris/ethermint_account.rs | 9 +++++++++ mm2src/coins/tendermint/iris/mod.rs | 1 + mm2src/coins/tendermint/tendermint_coin.rs | 18 +++++++++++++++++- 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 mm2src/coins/tendermint/iris/ethermint_account.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index cfbdd4604f..2622275a4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ **Features:** **Enhancements/Fixes:** +- cosmos/iris ethermint account compatibility implemented [#1765](https://github.com/KomodoPlatform/atomicDEX-API/pull/1765) - p2p stack is improved [#1755](https://github.com/KomodoPlatform/atomicDEX-API/pull/1755) - - Validate topics if they are mixed or not. - - Do early return if the message data is not valid (since no point to iterate over and over on the invalid message) diff --git a/mm2src/coins/tendermint/iris/ethermint_account.rs b/mm2src/coins/tendermint/iris/ethermint_account.rs new file mode 100644 index 0000000000..7fd88ffcfb --- /dev/null +++ b/mm2src/coins/tendermint/iris/ethermint_account.rs @@ -0,0 +1,9 @@ +use cosmrs::proto::cosmos::auth::v1beta1::BaseAccount; + +#[derive(prost::Message)] +pub struct EthermintAccount { + #[prost(message, optional, tag = "1")] + pub base_account: core::option::Option, + #[prost(string, tag = "2")] + pub code_hash: prost::alloc::string::String, +} diff --git a/mm2src/coins/tendermint/iris/mod.rs b/mm2src/coins/tendermint/iris/mod.rs index 00c493c504..03331ac181 100644 --- a/mm2src/coins/tendermint/iris/mod.rs +++ b/mm2src/coins/tendermint/iris/mod.rs @@ -1,2 +1,3 @@ +pub(crate) mod ethermint_account; pub(crate) mod htlc; pub(crate) mod htlc_proto; diff --git a/mm2src/coins/tendermint/tendermint_coin.rs b/mm2src/coins/tendermint/tendermint_coin.rs index 6e5b4dad32..cdb5c541c2 100644 --- a/mm2src/coins/tendermint/tendermint_coin.rs +++ b/mm2src/coins/tendermint/tendermint_coin.rs @@ -1,5 +1,6 @@ use super::ibc::transfer_v1::MsgTransfer; use super::ibc::IBC_GAS_LIMIT_DEFAULT; +use super::iris::ethermint_account::EthermintAccount; use super::iris::htlc::{IrisHtlc, MsgClaimHtlc, MsgCreateHtlc, HTLC_STATE_COMPLETED, HTLC_STATE_OPEN, HTLC_STATE_REFUNDED}; use super::iris::htlc_proto::{CreateHtlcProtoRep, QueryHtlcRequestProto, QueryHtlcResponseProto}; @@ -995,7 +996,22 @@ impl TendermintCoin { let account = account_response .account .or_mm_err(|| TendermintCoinRpcError::InvalidResponse("Account is None".into()))?; - Ok(BaseAccount::decode(account.value.as_slice())?) + + let base_account = match BaseAccount::decode(account.value.as_slice()) { + Ok(account) => account, + Err(err) if &self.account_prefix == "iaa" => { + let ethermint_account = EthermintAccount::decode(account.value.as_slice())?; + + ethermint_account + .base_account + .or_mm_err(|| TendermintCoinRpcError::Prost(err))? + }, + Err(err) => { + return MmError::err(TendermintCoinRpcError::Prost(err)); + }, + }; + + Ok(base_account) } pub(super) async fn balance_for_denom(&self, denom: String) -> MmResult { From f59eb1d2c356ab5976202fcb91d759f41a55221c Mon Sep 17 00:00:00 2001 From: Onur Date: Tue, 25 Apr 2023 21:56:46 +0300 Subject: [PATCH 85/90] fix: improve `get_receiver_trade_fee` for tendermint (#1767) Signed-off-by: ozkanonur Reviewed-by: cipig, shamardy --- CHANGELOG.md | 1 + mm2src/coins/eth.rs | 2 +- mm2src/coins/eth/eth_tests.rs | 2 +- mm2src/coins/lightning.rs | 2 +- mm2src/coins/lp_coins.rs | 2 +- mm2src/coins/qrc20.rs | 2 +- mm2src/coins/qrc20/qrc20_tests.rs | 2 +- mm2src/coins/solana.rs | 4 +--- mm2src/coins/solana/spl.rs | 4 +--- mm2src/coins/tendermint/tendermint_coin.rs | 11 ++++++++--- mm2src/coins/tendermint/tendermint_token.rs | 9 +++++++-- mm2src/coins/test_coin.rs | 4 +--- mm2src/coins/utxo/bch.rs | 2 +- mm2src/coins/utxo/qtum.rs | 2 +- mm2src/coins/utxo/slp.rs | 2 +- mm2src/coins/utxo/utxo_standard.rs | 2 +- mm2src/coins/z_coin.rs | 2 +- mm2src/mm2_main/src/lp_ordermatch.rs | 12 ++++-------- mm2src/mm2_main/src/lp_swap/maker_swap.rs | 8 +++----- mm2src/mm2_main/src/lp_swap/taker_swap.rs | 8 +++----- 20 files changed, 40 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2622275a4f..d3d27598dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - - Break the loop right after processing any of `SWAP_PREFIX`, `WATCHER_PREFIX`, `TX_HELPER_PREFIX` topic. - An issue was fixed where we don't have to wait for all EVM nodes to sync the latest account nonce [#1757](https://github.com/KomodoPlatform/atomicDEX-API/pull/1757) - optimized dev and release compilation profiles and removed ci [#1759](https://github.com/KomodoPlatform/atomicDEX-API/pull/1759) +- fix receiver trade fee for cosmos swaps [#1767](https://github.com/KomodoPlatform/atomicDEX-API/pull/1767) ## v1.0.2-beta - 2023-04-11 diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index f610b91845..4f5e25cf34 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -4320,7 +4320,7 @@ impl MmCoin for EthCoin { }) } - fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, stage: FeeApproxStage) -> TradePreimageFut { + fn get_receiver_trade_fee(&self, stage: FeeApproxStage) -> TradePreimageFut { let coin = self.clone(); let fut = async move { let gas_price = coin.get_gas_price().compat().await?; diff --git a/mm2src/coins/eth/eth_tests.rs b/mm2src/coins/eth/eth_tests.rs index 2017765c7c..16764f0bf6 100644 --- a/mm2src/coins/eth/eth_tests.rs +++ b/mm2src/coins/eth/eth_tests.rs @@ -957,7 +957,7 @@ fn get_receiver_trade_preimage() { }; let actual = coin - .get_receiver_trade_fee(Default::default(), FeeApproxStage::WithoutApprox) + .get_receiver_trade_fee(FeeApproxStage::WithoutApprox) .wait() .expect("!get_sender_trade_fee"); assert_eq!(actual, expected_fee); diff --git a/mm2src/coins/lightning.rs b/mm2src/coins/lightning.rs index f5ca99c625..0b822dd7a3 100644 --- a/mm2src/coins/lightning.rs +++ b/mm2src/coins/lightning.rs @@ -1301,7 +1301,7 @@ impl MmCoin for LightningCoin { } // Todo: This uses dummy data for now for the sake of swap P.O.C., this should be implemented probably after agreeing on how fees will work for lightning - fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut { + fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut { Box::new(futures01::future::ok(TradeFee { coin: self.ticker().to_owned(), amount: Default::default(), diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index 78118f54b7..042238fb59 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -2190,7 +2190,7 @@ pub trait MmCoin: ) -> TradePreimageResult; /// Get fee to be paid by receiver per whole swap and check if the wallet has sufficient balance to pay the fee. - fn get_receiver_trade_fee(&self, send_amount: BigDecimal, stage: FeeApproxStage) -> TradePreimageFut; + fn get_receiver_trade_fee(&self, stage: FeeApproxStage) -> TradePreimageFut; /// Get transaction fee the Taker has to pay to send a `TakerFee` transaction and check if the wallet has sufficient balance to pay the fee. async fn get_fee_to_send_taker_fee( diff --git a/mm2src/coins/qrc20.rs b/mm2src/coins/qrc20.rs index 54219400cf..5064ae483c 100644 --- a/mm2src/coins/qrc20.rs +++ b/mm2src/coins/qrc20.rs @@ -1375,7 +1375,7 @@ impl MmCoin for Qrc20Coin { }) } - fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, stage: FeeApproxStage) -> TradePreimageFut { + fn get_receiver_trade_fee(&self, stage: FeeApproxStage) -> TradePreimageFut { let selfi = self.clone(); let fut = async move { // pass the dummy params diff --git a/mm2src/coins/qrc20/qrc20_tests.rs b/mm2src/coins/qrc20/qrc20_tests.rs index 2835752f0c..60d8a93527 100644 --- a/mm2src/coins/qrc20/qrc20_tests.rs +++ b/mm2src/coins/qrc20/qrc20_tests.rs @@ -916,7 +916,7 @@ fn test_receiver_trade_preimage() { check_tx_fee(&coin, ActualTxFee::FixedPerKb(EXPECTED_TX_FEE as u64)); let actual = coin - .get_receiver_trade_fee(Default::default(), FeeApproxStage::WithoutApprox) + .get_receiver_trade_fee(FeeApproxStage::WithoutApprox) .wait() .expect("!get_receiver_trade_fee"); // only one contract call should be included into the expected trade fee diff --git a/mm2src/coins/solana.rs b/mm2src/coins/solana.rs index ef3cc38c49..2dbcf091ed 100644 --- a/mm2src/coins/solana.rs +++ b/mm2src/coins/solana.rs @@ -727,9 +727,7 @@ impl MmCoin for SolanaCoin { unimplemented!() } - fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut { - unimplemented!() - } + fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut { unimplemented!() } async fn get_fee_to_send_taker_fee( &self, diff --git a/mm2src/coins/solana/spl.rs b/mm2src/coins/solana/spl.rs index 8aa917aed0..fc97512f77 100644 --- a/mm2src/coins/solana/spl.rs +++ b/mm2src/coins/solana/spl.rs @@ -520,9 +520,7 @@ impl MmCoin for SplToken { unimplemented!() } - fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut { - unimplemented!() - } + fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut { unimplemented!() } async fn get_fee_to_send_taker_fee( &self, diff --git a/mm2src/coins/tendermint/tendermint_coin.rs b/mm2src/coins/tendermint/tendermint_coin.rs index cdb5c541c2..803808ed9e 100644 --- a/mm2src/coins/tendermint/tendermint_coin.rs +++ b/mm2src/coins/tendermint/tendermint_coin.rs @@ -2004,13 +2004,18 @@ impl MmCoin for TendermintCoin { .await } - fn get_receiver_trade_fee(&self, send_amount: BigDecimal, stage: FeeApproxStage) -> TradePreimageFut { + fn get_receiver_trade_fee(&self, stage: FeeApproxStage) -> TradePreimageFut { let coin = self.clone(); let fut = async move { // We can't simulate Claim Htlc without having information about broadcasted htlc tx. // Since create and claim htlc fees are almost same, we can simply simulate create htlc tx. - coin.get_sender_trade_fee_for_denom(coin.ticker.clone(), coin.denom.clone(), coin.decimals, send_amount) - .await + coin.get_sender_trade_fee_for_denom( + coin.ticker.clone(), + coin.denom.clone(), + coin.decimals, + coin.min_tx_amount(), + ) + .await }; Box::new(fut.boxed().compat()) } diff --git a/mm2src/coins/tendermint/tendermint_token.rs b/mm2src/coins/tendermint/tendermint_token.rs index 54dc2dbc28..9088e4e12c 100644 --- a/mm2src/coins/tendermint/tendermint_token.rs +++ b/mm2src/coins/tendermint/tendermint_token.rs @@ -739,14 +739,19 @@ impl MmCoin for TendermintToken { .await } - fn get_receiver_trade_fee(&self, send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut { + fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut { let token = self.clone(); let fut = async move { // We can't simulate Claim Htlc without having information about broadcasted htlc tx. // Since create and claim htlc fees are almost same, we can simply simulate create htlc tx. token .platform_coin - .get_sender_trade_fee_for_denom(token.ticker.clone(), token.denom.clone(), token.decimals, send_amount) + .get_sender_trade_fee_for_denom( + token.ticker.clone(), + token.denom.clone(), + token.decimals, + token.min_tx_amount(), + ) .await }; Box::new(fut.boxed().compat()) diff --git a/mm2src/coins/test_coin.rs b/mm2src/coins/test_coin.rs index 01e4dda0cc..54bef3a6ba 100644 --- a/mm2src/coins/test_coin.rs +++ b/mm2src/coins/test_coin.rs @@ -318,9 +318,7 @@ impl MmCoin for TestCoin { unimplemented!() } - fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut { - unimplemented!() - } + fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut { unimplemented!() } async fn get_fee_to_send_taker_fee( &self, diff --git a/mm2src/coins/utxo/bch.rs b/mm2src/coins/utxo/bch.rs index 896600d0a3..7ccf3c7bac 100644 --- a/mm2src/coins/utxo/bch.rs +++ b/mm2src/coins/utxo/bch.rs @@ -1234,7 +1234,7 @@ impl MmCoin for BchCoin { utxo_common::get_sender_trade_fee(self, value, stage).await } - fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut { + fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut { utxo_common::get_receiver_trade_fee(self.clone()) } diff --git a/mm2src/coins/utxo/qtum.rs b/mm2src/coins/utxo/qtum.rs index 8fa047cfa1..772bf78575 100644 --- a/mm2src/coins/utxo/qtum.rs +++ b/mm2src/coins/utxo/qtum.rs @@ -924,7 +924,7 @@ impl MmCoin for QtumCoin { utxo_common::get_sender_trade_fee(self, value, stage).await } - fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut { + fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut { utxo_common::get_receiver_trade_fee(self.clone()) } diff --git a/mm2src/coins/utxo/slp.rs b/mm2src/coins/utxo/slp.rs index b5d1731169..1f1053a20b 100644 --- a/mm2src/coins/utxo/slp.rs +++ b/mm2src/coins/utxo/slp.rs @@ -1788,7 +1788,7 @@ impl MmCoin for SlpToken { }) } - fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut { + fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut { let coin = self.clone(); let fut = async move { diff --git a/mm2src/coins/utxo/utxo_standard.rs b/mm2src/coins/utxo/utxo_standard.rs index b21b2fda80..28c5ca0280 100644 --- a/mm2src/coins/utxo/utxo_standard.rs +++ b/mm2src/coins/utxo/utxo_standard.rs @@ -687,7 +687,7 @@ impl MmCoin for UtxoStandardCoin { utxo_common::get_sender_trade_fee(self, value, stage).await } - fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut { + fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut { utxo_common::get_receiver_trade_fee(self.clone()) } diff --git a/mm2src/coins/z_coin.rs b/mm2src/coins/z_coin.rs index 416b6292c1..59fe63d207 100644 --- a/mm2src/coins/z_coin.rs +++ b/mm2src/coins/z_coin.rs @@ -1618,7 +1618,7 @@ impl MmCoin for ZCoin { }) } - fn get_receiver_trade_fee(&self, _send_amount: BigDecimal, _stage: FeeApproxStage) -> TradePreimageFut { + fn get_receiver_trade_fee(&self, _stage: FeeApproxStage) -> TradePreimageFut { utxo_common::get_receiver_trade_fee(self.clone()) } diff --git a/mm2src/mm2_main/src/lp_ordermatch.rs b/mm2src/mm2_main/src/lp_ordermatch.rs index ff55085d61..b43def8222 100644 --- a/mm2src/mm2_main/src/lp_ordermatch.rs +++ b/mm2src/mm2_main/src/lp_ordermatch.rs @@ -4545,13 +4545,9 @@ async fn cancel_orders_on_error(ctx: &MmArc, req: &SetPriceReq, error: E) Err(error) } -pub async fn check_other_coin_balance_for_order_issue( - ctx: &MmArc, - other_coin: &MmCoinEnum, - my_coin_volume: BigDecimal, -) -> CheckBalanceResult<()> { +pub async fn check_other_coin_balance_for_order_issue(ctx: &MmArc, other_coin: &MmCoinEnum) -> CheckBalanceResult<()> { let trade_fee = other_coin - .get_receiver_trade_fee(my_coin_volume, FeeApproxStage::OrderIssue) + .get_receiver_trade_fee(FeeApproxStage::OrderIssue) .compat() .await .mm_err(|e| CheckBalanceError::from_trade_preimage_error(e, other_coin.ticker()))?; @@ -4605,7 +4601,7 @@ pub async fn create_maker_order(ctx: &MmArc, req: SetPriceReq) -> Result Result // Calculate order volume and add to update_msg if new_volume is found in the request let new_volume = if req.max.unwrap_or(false) { let max_volume = try_s!(get_max_maker_vol(ctx, &base_coin).await).volume + reserved_amount.clone(); - try_s!(check_other_coin_balance_for_order_issue(ctx, &rel_coin, max_volume.to_decimal()).await); + try_s!(check_other_coin_balance_for_order_issue(ctx, &rel_coin).await); update_msg.with_new_max_volume(max_volume.clone().into()); max_volume } else if Option::is_some(&req.volume_delta) { diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap.rs b/mm2src/mm2_main/src/lp_swap/maker_swap.rs index 320a65ff97..2bc438c7dc 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap.rs @@ -475,9 +475,7 @@ impl MakerSwap { )])) }, }; - let taker_payment_spend_trade_fee_fut = self - .taker_coin - .get_receiver_trade_fee(self.maker_amount.clone(), stage.clone()); + let taker_payment_spend_trade_fee_fut = self.taker_coin.get_receiver_trade_fee(stage.clone()); let taker_payment_spend_trade_fee = match taker_payment_spend_trade_fee_fut.compat().await { Ok(fee) => fee, Err(e) => { @@ -2149,7 +2147,7 @@ pub async fn check_balance_for_maker_swap( .await .mm_err(|e| CheckBalanceError::from_trade_preimage_error(e, my_coin.ticker()))?; let taker_payment_spend_trade_fee = other_coin - .get_receiver_trade_fee(volume.to_decimal(), stage) + .get_receiver_trade_fee(stage) .compat() .await .mm_err(|e| CheckBalanceError::from_trade_preimage_error(e, other_coin.ticker()))?; @@ -2203,7 +2201,7 @@ pub async fn maker_swap_trade_preimage( .await .mm_err(|e| TradePreimageRpcError::from_trade_preimage_error(e, base_coin_ticker))?; let rel_coin_fee = rel_coin - .get_receiver_trade_fee(volume.to_decimal(), FeeApproxStage::TradePreimage) + .get_receiver_trade_fee(FeeApproxStage::TradePreimage) .compat() .await .mm_err(|e| TradePreimageRpcError::from_trade_preimage_error(e, rel_coin_ticker))?; diff --git a/mm2src/mm2_main/src/lp_swap/taker_swap.rs b/mm2src/mm2_main/src/lp_swap/taker_swap.rs index 1a41f1128b..96ad3532e2 100644 --- a/mm2src/mm2_main/src/lp_swap/taker_swap.rs +++ b/mm2src/mm2_main/src/lp_swap/taker_swap.rs @@ -971,9 +971,7 @@ impl TakerSwap { )])) }, }; - let maker_payment_spend_trade_fee_fut = self - .maker_coin - .get_receiver_trade_fee(self.taker_amount.to_decimal(), stage.clone()); + let maker_payment_spend_trade_fee_fut = self.maker_coin.get_receiver_trade_fee(stage.clone()); let maker_payment_spend_trade_fee = match maker_payment_spend_trade_fee_fut.compat().await { Ok(fee) => fee, Err(e) => { @@ -2257,7 +2255,7 @@ pub async fn check_balance_for_taker_swap( .await .mm_err(|e| CheckBalanceError::from_trade_preimage_error(e, my_coin.ticker()))?; let maker_payment_spend_trade_fee = other_coin - .get_receiver_trade_fee(volume.to_decimal(), stage) + .get_receiver_trade_fee(stage) .compat() .await .mm_err(|e| CheckBalanceError::from_trade_preimage_error(e, other_coin.ticker()))?; @@ -2352,7 +2350,7 @@ pub async fn taker_swap_trade_preimage( .await .mm_err(|e| TradePreimageRpcError::from_trade_preimage_error(e, my_coin_ticker))?; let other_coin_trade_fee = other_coin - .get_receiver_trade_fee(my_coin_volume.to_decimal(), stage.clone()) + .get_receiver_trade_fee(stage.clone()) .compat() .await .mm_err(|e| TradePreimageRpcError::from_trade_preimage_error(e, other_coin_ticker))?; From 05b568291583cf653c3fd11728fa6e79fd9b49ca Mon Sep 17 00:00:00 2001 From: ozkanonur Date: Wed, 26 Apr 2023 00:12:23 +0300 Subject: [PATCH 86/90] bump mm2 to `v1.0.3-beta` Signed-off-by: ozkanonur --- CHANGELOG.md | 2 +- Cargo.lock | 2 +- mm2src/mm2_bin_lib/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3d27598dc..fc96edb378 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## ${next-version} - ${release-date} +## v1.0.3-beta - ${release-date} **Features:** diff --git a/Cargo.lock b/Cargo.lock index c062b19c4d..9fcb0a62d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4128,7 +4128,7 @@ dependencies = [ [[package]] name = "mm2_bin_lib" -version = "1.0.2-beta" +version = "1.0.3-beta" dependencies = [ "chrono", "common", diff --git a/mm2src/mm2_bin_lib/Cargo.toml b/mm2src/mm2_bin_lib/Cargo.toml index c216278742..3ed3fdcc61 100644 --- a/mm2src/mm2_bin_lib/Cargo.toml +++ b/mm2src/mm2_bin_lib/Cargo.toml @@ -5,7 +5,7 @@ [package] name = "mm2_bin_lib" -version = "1.0.2-beta" +version = "1.0.3-beta" authors = ["James Lee", "Artem Pikulin", "Artem Grinblat", "Omar S.", "Onur Ozkan", "Alina Sharon", "Caglar Kaya", "Cipi", "Sergey Boiko", "Samuel Onoja", "Roman Sztergbaum", "Kadan Stadelmann "] edition = "2018" default-run = "mm2" From 1a9dea434b86f63f6dce958990069ff7c10ce522 Mon Sep 17 00:00:00 2001 From: Kadan Stadelmann Date: Wed, 26 Apr 2023 09:30:11 +0200 Subject: [PATCH 87/90] [1.0.3] resolve conflict From ef82cb7b481fb9ddf60d0c81027f3fc7db0a5322 Mon Sep 17 00:00:00 2001 From: Rozhkov Dmitrii Date: Wed, 26 Apr 2023 13:11:06 +0500 Subject: [PATCH 88/90] Enable clippy --all-features on CI (#1760) * add fn is_sapling_state_synced for ZCoin * refactor: Move `enable_z_coin` function up into mm2_test_module * ci: get rid of clippy warnings on CI with --all-features flag * test: update PIRATE test urls * doc: Update CHANGELOG.md --------- Co-authored-by: rozhkovdmitrii --- .github/workflows/fmt-and-lint.yml | 8 +- CHANGELOG.md | 1 + mm2src/coins/solana.rs | 6 +- mm2src/coins/solana/solana_common_tests.rs | 8 +- mm2src/coins/solana/solana_tests.rs | 39 +- mm2src/coins/solana/spl_tests.rs | 22 +- mm2src/coins/z_coin.rs | 5 + mm2src/coins/z_coin/z_coin_native_tests.rs | 360 ++++++++++-------- .../tests/docker_tests/docker_tests_common.rs | 37 +- .../tests/docker_tests/docker_tests_inner.rs | 12 +- mm2src/mm2_main/tests/docker_tests/mod.rs | 1 + .../tests/docker_tests/qrc20_tests.rs | 6 +- .../tests/docker_tests/swap_watcher_tests.rs | 36 +- .../docker_tests/swaps_file_lock_tests.rs | 6 +- mm2src/mm2_main/tests/docker_tests_main.rs | 2 +- .../tests/mm2_tests/best_orders_tests.rs | 19 +- .../tests/mm2_tests/mm2_tests_inner.rs | 44 +-- mm2src/mm2_main/tests/mm2_tests/mod.rs | 32 ++ mm2src/mm2_test_helpers/src/for_tests.rs | 4 +- 19 files changed, 347 insertions(+), 301 deletions(-) diff --git a/.github/workflows/fmt-and-lint.yml b/.github/workflows/fmt-and-lint.yml index 73b6bb1b1d..2eb992bc8b 100644 --- a/.github/workflows/fmt-and-lint.yml +++ b/.github/workflows/fmt-and-lint.yml @@ -19,11 +19,17 @@ jobs: rustup toolchain install nightly-2022-10-29 --no-self-update --profile=minimal --component rustfmt clippy rustup default nightly-2022-10-29 + - name: Install OS dependencies + run: | + sudo apt-get update + sudo apt-get -y install libudev-dev + if: matrix.os == 'ubuntu-latest' + - name: fmt check run: cargo fmt -- --check - name: x86-64 code lint - run: cargo clippy --all-targets -- --D warnings + run: cargo clippy --all-targets --all-features -- --D warnings wasm-lint: timeout-minutes: 45 diff --git a/CHANGELOG.md b/CHANGELOG.md index d3d27598dc..e93838b03b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - An issue was fixed where we don't have to wait for all EVM nodes to sync the latest account nonce [#1757](https://github.com/KomodoPlatform/atomicDEX-API/pull/1757) - optimized dev and release compilation profiles and removed ci [#1759](https://github.com/KomodoPlatform/atomicDEX-API/pull/1759) - fix receiver trade fee for cosmos swaps [#1767](https://github.com/KomodoPlatform/atomicDEX-API/pull/1767) +- All features were enabled to be checked under x86-64 code lint CI step with `--all-features` option [#1760](https://github.com/KomodoPlatform/atomicDEX-API/pull/1760) ## v1.0.2-beta - 2023-04-11 diff --git a/mm2src/coins/solana.rs b/mm2src/coins/solana.rs index 2dbcf091ed..6652d5c704 100644 --- a/mm2src/coins/solana.rs +++ b/mm2src/coins/solana.rs @@ -46,9 +46,9 @@ pub mod solana_common; mod solana_decode_tx_helpers; pub mod spl; -mod solana_common_tests; -mod solana_tests; -mod spl_tests; +#[cfg(test)] mod solana_common_tests; +#[cfg(test)] mod solana_tests; +#[cfg(test)] mod spl_tests; pub const SOLANA_DEFAULT_DECIMALS: u64 = 9; pub const LAMPORTS_DUMMY_AMOUNT: u64 = 10; diff --git a/mm2src/coins/solana/solana_common_tests.rs b/mm2src/coins/solana/solana_common_tests.rs index 6a332a462b..32b030b425 100644 --- a/mm2src/coins/solana/solana_common_tests.rs +++ b/mm2src/coins/solana/solana_common_tests.rs @@ -32,7 +32,6 @@ pub fn generate_key_pair_from_seed(seed: String) -> Keypair { .unwrap() .derive(&derivation_path) .unwrap(); - let ref priv_key = ext.secret_key; let pub_key = ext.public_key(); let pair = ed25519_dalek::Keypair { secret: ext.secret_key, @@ -59,7 +58,7 @@ pub fn spl_coin_for_test( decimals: u8, token_contract_address: Pubkey, ) -> SplToken { - let spl_coin = SplToken { + SplToken { conf: Arc::new(SplTokenFields { decimals, ticker, @@ -67,8 +66,7 @@ pub fn spl_coin_for_test( abortable_system: AbortableQueue::default(), }), platform_coin: solana_coin, - }; - spl_coin + } } pub fn solana_coin_for_test(seed: String, net_type: SolanaNet) -> (MmArc, SolanaCoin) { @@ -81,7 +79,7 @@ pub fn solana_coin_for_test(seed: String, net_type: SolanaNet) -> (MmArc, Solana {"coin":"SOL","name":"solana","protocol":{"type":"SOL"},"rpcport":80,"mm2":1} ] }); - let ctx = MmCtxBuilder::new().with_conf(conf.clone()).into_mm_arc(); + let ctx = MmCtxBuilder::new().with_conf(conf).into_mm_arc(); let (ticker, decimals) = ("SOL".to_string(), 8); let key_pair = generate_key_pair_from_iguana_seed(seed); let my_address = key_pair.pubkey().to_string(); diff --git a/mm2src/coins/solana/solana_tests.rs b/mm2src/coins/solana/solana_tests.rs index 5004d05dd8..05939b68c5 100644 --- a/mm2src/coins/solana/solana_tests.rs +++ b/mm2src/coins/solana/solana_tests.rs @@ -75,7 +75,7 @@ fn solana_prerequisites() { #[cfg(not(target_arch = "wasm32"))] fn solana_coin_creation() { let passphrase = "federal stay trigger hour exist success game vapor become comfort action phone bright ill target wild nasty crumble dune close rare fabric hen iron".to_string(); - let (_, sol_coin) = solana_coin_for_test(passphrase.clone(), SolanaNet::Testnet); + let (_, sol_coin) = solana_coin_for_test(passphrase, SolanaNet::Testnet); assert_eq!( sol_coin.my_address().unwrap(), "FJktmyjV9aBHEShT4hfnLpr9ELywdwVtEL1w1rSWgbVf" @@ -86,7 +86,7 @@ fn solana_coin_creation() { #[cfg(not(target_arch = "wasm32"))] fn solana_my_balance() { let passphrase = "federal stay trigger hour exist success game vapor become comfort action phone bright ill target wild nasty crumble dune close rare fabric hen iron".to_string(); - let (_, sol_coin) = solana_coin_for_test(passphrase.clone(), SolanaNet::Testnet); + let (_, sol_coin) = solana_coin_for_test(passphrase, SolanaNet::Testnet); let res = block_on(sol_coin.my_balance().compat()).unwrap(); assert_ne!(res.spendable, BigDecimal::from(0)); } @@ -95,7 +95,7 @@ fn solana_my_balance() { #[cfg(not(target_arch = "wasm32"))] fn solana_block_height() { let passphrase = "federal stay trigger hour exist success game vapor become comfort action phone bright ill target wild nasty crumble dune close rare fabric hen iron".to_string(); - let (_, sol_coin) = solana_coin_for_test(passphrase.clone(), SolanaNet::Testnet); + let (_, sol_coin) = solana_coin_for_test(passphrase, SolanaNet::Testnet); let res = block_on(sol_coin.current_block().compat()).unwrap(); println!("block is : {}", res); assert!(res > 0); @@ -105,29 +105,28 @@ fn solana_block_height() { #[cfg(not(target_arch = "wasm32"))] fn solana_validate_address() { let passphrase = "federal stay trigger hour exist success game vapor become comfort action phone bright ill target wild nasty crumble dune close rare fabric hen iron".to_string(); - let (_, sol_coin) = solana_coin_for_test(passphrase.clone(), SolanaNet::Testnet); + let (_, sol_coin) = solana_coin_for_test(passphrase, SolanaNet::Testnet); // invalid len let res = sol_coin.validate_address("invalidaddressobviously"); - assert_eq!(res.is_valid, false); - + assert!(!res.is_valid); let res = sol_coin.validate_address("GMtMFbuVgjDnzsBd3LLBfM4X8RyYcDGCM92tPq2PG6B2"); - assert_eq!(res.is_valid, true); + assert!(res.is_valid); // Typo let res = sol_coin.validate_address("Fr8fraJXAe1cFU81mF7NhHTrUzXjZAJkQE1gUQ11riH"); - assert_eq!(res.is_valid, false); + assert!(!res.is_valid); // invalid len let res = sol_coin.validate_address("r8fraJXAe1cFU81mF7NhHTrUzXjZAJkQE1gUQ11riHn"); - assert_eq!(res.is_valid, false); + assert!(!res.is_valid); } #[test] #[cfg(not(target_arch = "wasm32"))] fn test_sign_message() { let passphrase = "spice describe gravity federal blast come thank unfair canal monkey style afraid".to_string(); - let (_, sol_coin) = solana_coin_for_test(passphrase.clone(), SolanaNet::Testnet); + let (_, sol_coin) = solana_coin_for_test(passphrase, SolanaNet::Testnet); let signature = sol_coin.sign_message("test").unwrap(); assert_eq!( signature, @@ -139,7 +138,7 @@ fn test_sign_message() { #[cfg(not(target_arch = "wasm32"))] fn test_verify_message() { let passphrase = "spice describe gravity federal blast come thank unfair canal monkey style afraid".to_string(); - let (_, sol_coin) = solana_coin_for_test(passphrase.clone(), SolanaNet::Testnet); + let (_, sol_coin) = solana_coin_for_test(passphrase, SolanaNet::Testnet); let is_valid = sol_coin .verify_message( "4dzKwEteN8nch76zPMEjPX19RsaQwGTxsbtfg2bwGTkGenLfrdm31zvn9GH5rvaJBwivp6ESXx1KYR672ngs3UfF", @@ -154,7 +153,7 @@ fn test_verify_message() { #[cfg(not(target_arch = "wasm32"))] fn solana_transaction_simulations() { let passphrase = "federal stay trigger hour exist success game vapor become comfort action phone bright ill target wild nasty crumble dune close rare fabric hen iron".to_string(); - let (_, sol_coin) = solana_coin_for_test(passphrase.clone(), SolanaNet::Devnet); + let (_, sol_coin) = solana_coin_for_test(passphrase, SolanaNet::Devnet); let request_amount = BigDecimal::try_from(0.0001).unwrap(); let valid_tx_details = block_on( sol_coin @@ -183,7 +182,7 @@ fn solana_transaction_simulations() { #[cfg(not(target_arch = "wasm32"))] fn solana_transaction_zero_balance() { let passphrase = "fake passphrase".to_string(); - let (_, sol_coin) = solana_coin_for_test(passphrase.clone(), SolanaNet::Devnet); + let (_, sol_coin) = solana_coin_for_test(passphrase, SolanaNet::Devnet); let invalid_tx_details = block_on( sol_coin .withdraw(WithdrawRequest { @@ -204,7 +203,7 @@ fn solana_transaction_zero_balance() { WithdrawError::NotSufficientBalance { required, .. } => { assert_eq!(required, sol_required); }, - e @ _ => panic!("Unexpected err {:?}", e), + e => panic!("Unexpected err {:?}", e), }; } @@ -212,7 +211,7 @@ fn solana_transaction_zero_balance() { #[cfg(not(target_arch = "wasm32"))] fn solana_transaction_simulations_not_enough_for_fees() { let passphrase = "non existent passphrase".to_string(); - let (_, sol_coin) = solana_coin_for_test(passphrase.clone(), SolanaNet::Devnet); + let (_, sol_coin) = solana_coin_for_test(passphrase, SolanaNet::Devnet); let invalid_tx_details = block_on( sol_coin .withdraw(WithdrawRequest { @@ -238,7 +237,7 @@ fn solana_transaction_simulations_not_enough_for_fees() { assert_eq!(available, 0.into()); assert_eq!(required, sol_required); }, - e @ _ => panic!("Unexpected err {:?}", e), + e => panic!("Unexpected err {:?}", e), }; } @@ -246,7 +245,7 @@ fn solana_transaction_simulations_not_enough_for_fees() { #[cfg(not(target_arch = "wasm32"))] fn solana_transaction_simulations_max() { let passphrase = "federal stay trigger hour exist success game vapor become comfort action phone bright ill target wild nasty crumble dune close rare fabric hen iron".to_string(); - let (_, sol_coin) = solana_coin_for_test(passphrase.clone(), SolanaNet::Devnet); + let (_, sol_coin) = solana_coin_for_test(passphrase, SolanaNet::Devnet); let valid_tx_details = block_on( sol_coin .withdraw(WithdrawRequest { @@ -275,7 +274,7 @@ fn solana_transaction_simulations_max() { #[cfg(not(target_arch = "wasm32"))] fn solana_test_transactions() { let passphrase = "federal stay trigger hour exist success game vapor become comfort action phone bright ill target wild nasty crumble dune close rare fabric hen iron".to_string(); - let (_, sol_coin) = solana_coin_for_test(passphrase.clone(), SolanaNet::Devnet); + let (_, sol_coin) = solana_coin_for_test(passphrase, SolanaNet::Devnet); let valid_tx_details = block_on( sol_coin .withdraw(WithdrawRequest { @@ -295,7 +294,7 @@ fn solana_test_transactions() { let tx_str = hex::encode(&*valid_tx_details.tx_hex.0); let res = block_on(sol_coin.send_raw_tx(&tx_str).compat()).unwrap(); - let res2 = block_on(sol_coin.send_raw_tx_bytes(&*valid_tx_details.tx_hex.0).compat()).unwrap(); + let res2 = block_on(sol_coin.send_raw_tx_bytes(&valid_tx_details.tx_hex.0).compat()).unwrap(); assert_eq!(res, res2); //println!("{:?}", res); @@ -307,7 +306,7 @@ fn solana_test_transactions() { #[cfg(not(target_arch = "wasm32"))] fn solana_test_tx_history() { let passphrase = "federal stay trigger hour exist success game vapor become comfort action phone bright ill target wild nasty crumble dune close rare fabric hen iron".to_string(); - let (_, sol_coin) = solana_coin_for_test(passphrase.clone(), SolanaNet::Testnet); + let (_, sol_coin) = solana_coin_for_test(passphrase, SolanaNet::Testnet); let res = sol_coin .client .get_signatures_for_address(&sol_coin.key_pair.pubkey()) diff --git a/mm2src/coins/solana/spl_tests.rs b/mm2src/coins/solana/spl_tests.rs index 22af85ef5c..c405f99b05 100644 --- a/mm2src/coins/solana/spl_tests.rs +++ b/mm2src/coins/solana/spl_tests.rs @@ -9,9 +9,9 @@ use std::str::FromStr; #[cfg(not(target_arch = "wasm32"))] fn spl_coin_creation() { let passphrase = "federal stay trigger hour exist success game vapor become comfort action phone bright ill target wild nasty crumble dune close rare fabric hen iron".to_string(); - let (_, sol_coin) = solana_coin_for_test(passphrase.clone(), SolanaNet::Testnet); + let (_, sol_coin) = solana_coin_for_test(passphrase, SolanaNet::Testnet); let sol_spl_usdc_coin = spl_coin_for_test( - sol_coin.clone(), + sol_coin, "USDC".to_string(), 6, solana_sdk::pubkey::Pubkey::from_str("CpMah17kQEL2wqyMKt3mZBdTnZbkbfx4nqmQMFDP5vwp").unwrap(), @@ -28,9 +28,9 @@ fn spl_coin_creation() { #[cfg(not(target_arch = "wasm32"))] fn test_sign_message() { let passphrase = "spice describe gravity federal blast come thank unfair canal monkey style afraid".to_string(); - let (_, sol_coin) = solana_coin_for_test(passphrase.clone(), SolanaNet::Testnet); + let (_, sol_coin) = solana_coin_for_test(passphrase, SolanaNet::Testnet); let sol_spl_usdc_coin = spl_coin_for_test( - sol_coin.clone(), + sol_coin, "USDC".to_string(), 6, solana_sdk::pubkey::Pubkey::from_str("CpMah17kQEL2wqyMKt3mZBdTnZbkbfx4nqmQMFDP5vwp").unwrap(), @@ -46,9 +46,9 @@ fn test_sign_message() { #[cfg(not(target_arch = "wasm32"))] fn test_verify_message() { let passphrase = "spice describe gravity federal blast come thank unfair canal monkey style afraid".to_string(); - let (_, sol_coin) = solana_coin_for_test(passphrase.clone(), SolanaNet::Testnet); + let (_, sol_coin) = solana_coin_for_test(passphrase, SolanaNet::Testnet); let sol_spl_usdc_coin = spl_coin_for_test( - sol_coin.clone(), + sol_coin, "USDC".to_string(), 6, solana_sdk::pubkey::Pubkey::from_str("CpMah17kQEL2wqyMKt3mZBdTnZbkbfx4nqmQMFDP5vwp").unwrap(), @@ -67,7 +67,7 @@ fn test_verify_message() { #[cfg(not(target_arch = "wasm32"))] fn spl_my_balance() { let passphrase = "federal stay trigger hour exist success game vapor become comfort action phone bright ill target wild nasty crumble dune close rare fabric hen iron".to_string(); - let (_, sol_coin) = solana_coin_for_test(passphrase.clone(), SolanaNet::Testnet); + let (_, sol_coin) = solana_coin_for_test(passphrase, SolanaNet::Testnet); let sol_spl_usdc_coin = spl_coin_for_test( sol_coin.clone(), "USDC".to_string(), @@ -80,7 +80,7 @@ fn spl_my_balance() { assert!(res.spendable < BigDecimal::from(10)); let sol_spl_wsol_coin = spl_coin_for_test( - sol_coin.clone(), + sol_coin, "WSOL".to_string(), 8, solana_sdk::pubkey::Pubkey::from_str("So11111111111111111111111111111111111111112").unwrap(), @@ -95,9 +95,9 @@ fn spl_my_balance() { #[cfg(not(target_arch = "wasm32"))] fn test_spl_transactions() { let passphrase = "federal stay trigger hour exist success game vapor become comfort action phone bright ill target wild nasty crumble dune close rare fabric hen iron".to_string(); - let (_, sol_coin) = solana_coin_for_test(passphrase.clone(), SolanaNet::Testnet); + let (_, sol_coin) = solana_coin_for_test(passphrase, SolanaNet::Testnet); let usdc_sol_coin = spl_coin_for_test( - sol_coin.clone(), + sol_coin, "USDC".to_string(), 6, solana_sdk::pubkey::Pubkey::from_str("CpMah17kQEL2wqyMKt3mZBdTnZbkbfx4nqmQMFDP5vwp").unwrap(), @@ -127,6 +127,6 @@ fn test_spl_transactions() { let res = block_on(usdc_sol_coin.send_raw_tx(&tx_str).compat()).unwrap(); println!("{:?}", res); - let res2 = block_on(usdc_sol_coin.send_raw_tx_bytes(&*valid_tx_details.tx_hex.0).compat()).unwrap(); + let res2 = block_on(usdc_sol_coin.send_raw_tx_bytes(&valid_tx_details.tx_hex.0).compat()).unwrap(); assert_eq!(res, res2); } diff --git a/mm2src/coins/z_coin.rs b/mm2src/coins/z_coin.rs index 59fe63d207..5816f8231b 100644 --- a/mm2src/coins/z_coin.rs +++ b/mm2src/coins/z_coin.rs @@ -284,6 +284,11 @@ impl ZCoin { #[inline] pub fn consensus_params_ref(&self) -> &ZcoinConsensusParams { &self.z_fields.consensus_params } + #[inline] + pub async fn is_sapling_state_synced(&self) -> bool { + matches!(self.sync_status().await, Ok(SyncStatus::Finished { block_number: _ })) + } + #[inline] pub async fn sync_status(&self) -> Result> { self.z_fields diff --git a/mm2src/coins/z_coin/z_coin_native_tests.rs b/mm2src/coins/z_coin/z_coin_native_tests.rs index fca156d0f7..07e5831d58 100644 --- a/mm2src/coins/z_coin/z_coin_native_tests.rs +++ b/mm2src/coins/z_coin/z_coin_native_tests.rs @@ -1,91 +1,96 @@ -use super::*; -use crate::z_coin::z_htlc::z_send_dex_fee; -use common::block_on; -use common::now_ms; +use bitcrypto::dhash160; +use common::{block_on, now_ms}; use mm2_core::mm_ctx::MmCtxBuilder; +use mm2_test_helpers::for_tests::zombie_conf; +use std::path::PathBuf; use std::time::Duration; use zcash_client_backend::encoding::decode_extended_spending_key; +use super::{z_coin_from_conf_and_params_with_z_key, z_mainnet_constants, Future, PrivKeyBuildPolicy, + RefundPaymentArgs, SendPaymentArgs, SpendPaymentArgs, SwapOps, ValidateFeeArgs, ValidatePaymentError, + ZTransaction}; +use crate::z_coin::{z_htlc::z_send_dex_fee, ZcoinActivationParams, ZcoinRpcMode}; +use crate::CoinProtocol; + #[test] fn zombie_coin_send_and_refund_maker_payment() { - let conf = json!({ - "coin": "ZOMBIE", - "asset": "ZOMBIE", - "fname": "ZOMBIE (TESTCOIN)", - "txversion": 4, - "overwintered": 1, - "mm2": 1, - }); - let req = json!({ - "method": "enable", - "coin": "ZOMBIE" - }); - let ctx = MmCtxBuilder::default().into_mm_arc(); - let priv_key = [1; 32]; + let mut conf = zombie_conf(); + let params = default_zcoin_activation_params(); + let pk_data = [1; 32]; + let db_dir = PathBuf::from("./for_tests"); let z_key = decode_extended_spending_key(z_mainnet_constants::HRP_SAPLING_EXTENDED_SPENDING_KEY, "secret-extended-key-main1q0k2ga2cqqqqpq8m8j6yl0say83cagrqp53zqz54w38ezs8ly9ly5ptamqwfpq85u87w0df4k8t2lwyde3n9v0gcr69nu4ryv60t0kfcsvkr8h83skwqex2nf0vr32794fmzk89cpmjptzc22lgu5wfhhp8lgf3f5vn2l3sge0udvxnm95k6dtxj2jwlfyccnum7nz297ecyhmd5ph526pxndww0rqq0qly84l635mec0x4yedf95hzn6kcgq8yxts26k98j9g32kjc8y83fe").unwrap().unwrap(); + let protocol_info = match serde_json::from_value::(conf["protocol"].take()).unwrap() { + CoinProtocol::ZHTLC(protocol_info) => protocol_info, + other_protocol => panic!("Failed to get protocol from config: {:?}", other_protocol), + }; - let db_dir = PathBuf::from("./for_tests"); - let params = UtxoActivationParams::from_legacy_req(&req).unwrap(); let coin = block_on(z_coin_from_conf_and_params_with_z_key( - &ctx, "ZOMBIE", &conf, ¶ms, &priv_key, db_dir, z_key, + &ctx, + "ZOMBIE", + &conf, + ¶ms, + PrivKeyBuildPolicy::IguanaPrivKey(pk_data.into()), + db_dir, + z_key, + protocol_info, )) .unwrap(); - let lock_time = (now_ms() / 1000) as u32 - 3600; + let time_lock = (now_ms() / 1000) as u32 - 3600; let taker_pub = coin.utxo_arc.priv_key_policy.key_pair_or_err().unwrap().public(); let secret_hash = [0; 20]; - let tx = coin - .send_maker_payment( - lock_time, - taker_pub, - taker_pub, - &secret_hash, - "0.01".parse().unwrap(), - &None, - &None, - ) - .wait() - .unwrap(); - println!("swap tx {}", hex::encode(&tx.tx_hash().0)); - - let refund_tx = coin - .send_maker_refunds_payment( - &tx.tx_hex().unwrap(), - lock_time, - &*taker_pub, - &secret_hash, - &priv_key, - &None, - ) - .wait() - .unwrap(); - println!("refund tx {}", hex::encode(&refund_tx.tx_hash().0)); + + let args = SendPaymentArgs { + time_lock_duration: 0, + time_lock, + other_pubkey: taker_pub, + secret_hash: &secret_hash, + amount: "0.01".parse().unwrap(), + swap_contract_address: &None, + swap_unique_data: &[], + payment_instructions: &None, + watcher_reward: None, + wait_for_confirmation_until: 0, + }; + let tx = coin.send_maker_payment(args).wait().unwrap(); + println!("swap tx {}", hex::encode(tx.tx_hash().0)); + + let refund_args = RefundPaymentArgs { + payment_tx: &tx.tx_hex(), + time_lock, + other_pubkey: taker_pub, + secret_hash: &secret_hash, + swap_contract_address: &None, + swap_unique_data: pk_data.as_slice(), + watcher_reward: false, + }; + let refund_tx = coin.send_maker_refunds_payment(refund_args).wait().unwrap(); + println!("refund tx {}", hex::encode(refund_tx.tx_hash().0)); } #[test] fn zombie_coin_send_and_spend_maker_payment() { - let conf = json!({ - "coin": "ZOMBIE", - "asset": "ZOMBIE", - "fname": "ZOMBIE (TESTCOIN)", - "txversion": 4, - "overwintered": 1, - "mm2": 1, - }); - let req = json!({ - "method": "enable", - "coin": "ZOMBIE" - }); - let ctx = MmCtxBuilder::default().into_mm_arc(); - let priv_key = [1; 32]; + let mut conf = zombie_conf(); + let params = default_zcoin_activation_params(); + let pk_data = [1; 32]; + let db_dir = PathBuf::from("./for_tests"); let z_key = decode_extended_spending_key(z_mainnet_constants::HRP_SAPLING_EXTENDED_SPENDING_KEY, "secret-extended-key-main1q0k2ga2cqqqqpq8m8j6yl0say83cagrqp53zqz54w38ezs8ly9ly5ptamqwfpq85u87w0df4k8t2lwyde3n9v0gcr69nu4ryv60t0kfcsvkr8h83skwqex2nf0vr32794fmzk89cpmjptzc22lgu5wfhhp8lgf3f5vn2l3sge0udvxnm95k6dtxj2jwlfyccnum7nz297ecyhmd5ph526pxndww0rqq0qly84l635mec0x4yedf95hzn6kcgq8yxts26k98j9g32kjc8y83fe").unwrap().unwrap(); + let protocol_info = match serde_json::from_value::(conf["protocol"].take()).unwrap() { + CoinProtocol::ZHTLC(protocol_info) => protocol_info, + other_protocol => panic!("Failed to get protocol from config: {:?}", other_protocol), + }; - let db_dir = PathBuf::from("./for_tests"); - let params = UtxoActivationParams::from_legacy_req(&req).unwrap(); let coin = block_on(z_coin_from_conf_and_params_with_z_key( - &ctx, "ZOMBIE", &conf, ¶ms, &priv_key, db_dir, z_key, + &ctx, + "ZOMBIE", + &conf, + ¶ms, + PrivKeyBuildPolicy::IguanaPrivKey(pk_data.into()), + db_dir, + z_key, + protocol_info, )) .unwrap(); @@ -93,51 +98,64 @@ fn zombie_coin_send_and_spend_maker_payment() { let taker_pub = coin.utxo_arc.priv_key_policy.key_pair_or_err().unwrap().public(); let secret = [0; 32]; let secret_hash = dhash160(&secret); - let tx = coin - .send_maker_payment( - lock_time, - taker_pub, - taker_pub, - &*secret_hash, - "0.01".parse().unwrap(), - &None, - &None, - ) - .wait() - .unwrap(); - println!("swap tx {}", hex::encode(&tx.tx_hash().0)); + + let maker_payment_args = SendPaymentArgs { + time_lock_duration: 0, + time_lock: lock_time, + other_pubkey: taker_pub, + secret_hash: secret_hash.as_slice(), + amount: "0.01".parse().unwrap(), + swap_contract_address: &None, + swap_unique_data: &[], + payment_instructions: &None, + watcher_reward: None, + wait_for_confirmation_until: 0, + }; + + let tx = coin.send_maker_payment(maker_payment_args).wait().unwrap(); + println!("swap tx {}", hex::encode(tx.tx_hash().0)); let maker_pub = taker_pub; + + let spends_payment_args = SpendPaymentArgs { + other_payment_tx: &tx.tx_hex(), + time_lock: lock_time, + other_pubkey: maker_pub, + secret: &secret, + secret_hash: &[], + swap_contract_address: &None, + swap_unique_data: pk_data.as_slice(), + watcher_reward: false, + }; let spend_tx = coin - .send_taker_spends_maker_payment(&tx.tx_hex(), lock_time, &*maker_pub, &secret, &priv_key, &None) + .send_taker_spends_maker_payment(spends_payment_args) .wait() .unwrap(); - println!("spend tx {}", hex::encode(&spend_tx.tx_hash().0)); + println!("spend tx {}", hex::encode(spend_tx.tx_hash().0)); } #[test] fn zombie_coin_send_dex_fee() { - let conf = json!({ - "coin": "ZOMBIE", - "asset": "ZOMBIE", - "fname": "ZOMBIE (TESTCOIN)", - "txversion": 4, - "overwintered": 1, - "mm2": 1, - }); - let req = json!({ - "method": "enable", - "coin": "ZOMBIE" - }); - let ctx = MmCtxBuilder::default().into_mm_arc(); - let priv_key = [1; 32]; + let mut conf = zombie_conf(); + let params = default_zcoin_activation_params(); + let priv_key = PrivKeyBuildPolicy::IguanaPrivKey([1; 32].into()); + let db_dir = PathBuf::from("./for_tests"); let z_key = decode_extended_spending_key(z_mainnet_constants::HRP_SAPLING_EXTENDED_SPENDING_KEY, "secret-extended-key-main1q0k2ga2cqqqqpq8m8j6yl0say83cagrqp53zqz54w38ezs8ly9ly5ptamqwfpq85u87w0df4k8t2lwyde3n9v0gcr69nu4ryv60t0kfcsvkr8h83skwqex2nf0vr32794fmzk89cpmjptzc22lgu5wfhhp8lgf3f5vn2l3sge0udvxnm95k6dtxj2jwlfyccnum7nz297ecyhmd5ph526pxndww0rqq0qly84l635mec0x4yedf95hzn6kcgq8yxts26k98j9g32kjc8y83fe").unwrap().unwrap(); + let protocol_info = match serde_json::from_value::(conf["protocol"].take()).unwrap() { + CoinProtocol::ZHTLC(protocol_info) => protocol_info, + other_protocol => panic!("Failed to get protocol from config: {:?}", other_protocol), + }; - let db_dir = PathBuf::from("./for_tests"); - let params = UtxoActivationParams::from_legacy_req(&req).unwrap(); let coin = block_on(z_coin_from_conf_and_params_with_z_key( - &ctx, "ZOMBIE", &conf, ¶ms, &priv_key, db_dir, z_key, + &ctx, + "ZOMBIE", + &conf, + ¶ms, + priv_key, + db_dir, + z_key, + protocol_info, )) .unwrap(); @@ -147,58 +165,56 @@ fn zombie_coin_send_dex_fee() { #[test] fn prepare_zombie_sapling_cache() { - let conf = json!({ - "coin": "ZOMBIE", - "asset": "ZOMBIE", - "fname": "ZOMBIE", - "txversion": 4, - "overwintered": 1, - "mm2": 1, - }); - let req = json!({ - "method": "enable", - "coin": "ZOMBIE" - }); - let ctx = MmCtxBuilder::default().into_mm_arc(); - let priv_key = [1; 32]; + let mut conf = zombie_conf(); + let params = default_zcoin_activation_params(); + let priv_key = PrivKeyBuildPolicy::IguanaPrivKey([1; 32].into()); + let db_dir = PathBuf::from("./for_tests"); let z_key = decode_extended_spending_key(z_mainnet_constants::HRP_SAPLING_EXTENDED_SPENDING_KEY, "secret-extended-key-main1q0k2ga2cqqqqpq8m8j6yl0say83cagrqp53zqz54w38ezs8ly9ly5ptamqwfpq85u87w0df4k8t2lwyde3n9v0gcr69nu4ryv60t0kfcsvkr8h83skwqex2nf0vr32794fmzk89cpmjptzc22lgu5wfhhp8lgf3f5vn2l3sge0udvxnm95k6dtxj2jwlfyccnum7nz297ecyhmd5ph526pxndww0rqq0qly84l635mec0x4yedf95hzn6kcgq8yxts26k98j9g32kjc8y83fe").unwrap().unwrap(); + let protocol_info = match serde_json::from_value::(conf["protocol"].take()).unwrap() { + CoinProtocol::ZHTLC(protocol_info) => protocol_info, + other_protocol => panic!("Failed to get protocol from config: {:?}", other_protocol), + }; - let db_dir = PathBuf::from("./for_tests"); - let params = UtxoActivationParams::from_legacy_req(&req).unwrap(); let coin = block_on(z_coin_from_conf_and_params_with_z_key( - &ctx, "ZOMBIE", &conf, ¶ms, &priv_key, db_dir, z_key, + &ctx, + "ZOMBIE", + &conf, + ¶ms, + priv_key, + db_dir, + z_key, + protocol_info, )) .unwrap(); - while !coin.is_sapling_state_synced() { + while !block_on(coin.is_sapling_state_synced()) { std::thread::sleep(Duration::from_secs(1)); } } #[test] fn zombie_coin_validate_dex_fee() { - let conf = json!({ - "coin": "ZOMBIE", - "asset": "ZOMBIE", - "fname": "ZOMBIE (TESTCOIN)", - "txversion": 4, - "overwintered": 1, - "mm2": 1, - }); - let req = json!({ - "method": "enable", - "coin": "ZOMBIE" - }); - let ctx = MmCtxBuilder::default().into_mm_arc(); - let priv_key = [1; 32]; + let mut conf = zombie_conf(); + let params = default_zcoin_activation_params(); + let priv_key = PrivKeyBuildPolicy::IguanaPrivKey([1; 32].into()); + let db_dir = PathBuf::from("./for_tests"); let z_key = decode_extended_spending_key(z_mainnet_constants::HRP_SAPLING_EXTENDED_SPENDING_KEY, "secret-extended-key-main1q0k2ga2cqqqqpq8m8j6yl0say83cagrqp53zqz54w38ezs8ly9ly5ptamqwfpq85u87w0df4k8t2lwyde3n9v0gcr69nu4ryv60t0kfcsvkr8h83skwqex2nf0vr32794fmzk89cpmjptzc22lgu5wfhhp8lgf3f5vn2l3sge0udvxnm95k6dtxj2jwlfyccnum7nz297ecyhmd5ph526pxndww0rqq0qly84l635mec0x4yedf95hzn6kcgq8yxts26k98j9g32kjc8y83fe").unwrap().unwrap(); + let protocol_info = match serde_json::from_value::(conf["protocol"].take()).unwrap() { + CoinProtocol::ZHTLC(protocol_info) => protocol_info, + other_protocol => panic!("Failed to get protocol from config: {:?}", other_protocol), + }; - let db_dir = PathBuf::from("./for_tests"); - let params = UtxoActivationParams::from_legacy_req(&req).unwrap(); let coin = block_on(z_coin_from_conf_and_params_with_z_key( - &ctx, "ZOMBIE", &conf, ¶ms, &priv_key, db_dir, z_key, + &ctx, + "ZOMBIE", + &conf, + ¶ms, + priv_key, + db_dir, + z_key, + protocol_info, )) .unwrap(); @@ -208,32 +224,70 @@ fn zombie_coin_validate_dex_fee() { let tx = ZTransaction::read(tx_bytes.as_slice()).unwrap(); let tx = tx.into(); + let validate_fee_args = ValidateFeeArgs { + fee_tx: &tx, + expected_sender: &[], + fee_addr: &[], + amount: &"0.001".parse().unwrap(), + min_block_number: 12000, + uuid: &[1; 16], + }; // Invalid amount should return an error - let err = coin - .validate_fee(&tx, &[], &[], &"0.001".parse().unwrap(), 12000, &[1; 16]) - .wait() - .unwrap_err(); - println!("{}", err); - assert!(err.contains("Dex fee has invalid amount")); + let err = coin.validate_fee(validate_fee_args).wait().unwrap_err().into_inner(); + match err { + ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("Dex fee has invalid amount")), + _ => panic!("Expected `WrongPaymentTx`: {:?}", err), + } // Invalid memo should return an error - let err = coin - .validate_fee(&tx, &[], &[], &"0.01".parse().unwrap(), 12000, &[2; 16]) - .wait() - .unwrap_err(); - println!("{}", err); - assert!(err.contains("Dex fee has invalid memo")); + let validate_fee_args = ValidateFeeArgs { + fee_tx: &tx, + expected_sender: &[], + fee_addr: &[], + amount: &"0.01".parse().unwrap(), + min_block_number: 12000, + uuid: &[2; 16], + }; + let err = coin.validate_fee(validate_fee_args).wait().unwrap_err().into_inner(); + match err { + ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("Dex fee has invalid memo")), + _ => panic!("Expected `WrongPaymentTx`: {:?}", err), + } // Confirmed before min block - let err = coin - .validate_fee(&tx, &[], &[], &"0.01".parse().unwrap(), 14000, &[1; 16]) - .wait() - .unwrap_err(); - println!("{}", err); - assert!(err.contains("confirmed before min block")); + let validate_fee_args = ValidateFeeArgs { + fee_tx: &tx, + expected_sender: &[], + fee_addr: &[], + amount: &"0.01".parse().unwrap(), + min_block_number: 14000, + uuid: &[1; 16], + }; + let err = coin.validate_fee(validate_fee_args).wait().unwrap_err().into_inner(); + match err { + ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("confirmed before min block")), + _ => panic!("Expected `WrongPaymentTx`: {:?}", err), + } // Success validation - coin.validate_fee(&tx, &[], &[], &"0.01".parse().unwrap(), 12000, &[1; 16]) - .wait() - .unwrap(); + let validate_fee_args = ValidateFeeArgs { + fee_tx: &tx, + expected_sender: &[], + fee_addr: &[], + amount: &"0.01".parse().unwrap(), + min_block_number: 12000, + uuid: &[1; 16], + }; + coin.validate_fee(validate_fee_args).wait().unwrap(); +} + +fn default_zcoin_activation_params() -> ZcoinActivationParams { + ZcoinActivationParams { + mode: ZcoinRpcMode::Native, + required_confirmations: None, + requires_notarization: None, + zcash_params_path: None, + scan_blocks_per_iteration: 0, + scan_interval_ms: 0, + } } diff --git a/mm2src/mm2_main/tests/docker_tests/docker_tests_common.rs b/mm2src/mm2_main/tests/docker_tests/docker_tests_common.rs index 40a6514c88..050e628dbe 100644 --- a/mm2src/mm2_main/tests/docker_tests/docker_tests_common.rs +++ b/mm2src/mm2_main/tests/docker_tests/docker_tests_common.rs @@ -332,7 +332,7 @@ pub fn utxo_asset_docker_node<'a>(docker: &'a Cli, ticker: &'static str, port: u "-v".into(), format!("{}:/root/.zcash-params", zcash_params_path().display()), "-p".into(), - format!("{}:{}", port, port).into(), + format!("{}:{}", port, port), ]; let image = GenericImage::new(UTXO_ASSET_DOCKER_IMAGE) .with_args(args) @@ -399,19 +399,13 @@ where pub fn qrc20_coin_from_privkey(ticker: &str, priv_key: Secp256k1Secret) -> (MmArc, Qrc20Coin) { let (contract_address, swap_contract_address) = unsafe { let contract_address = match ticker { - "QICK" => QICK_TOKEN_ADDRESS - .expect("QICK_TOKEN_ADDRESS must be set already") - .clone(), - "QORTY" => QORTY_TOKEN_ADDRESS - .expect("QORTY_TOKEN_ADDRESS must be set already") - .clone(), + "QICK" => QICK_TOKEN_ADDRESS.expect("QICK_TOKEN_ADDRESS must be set already"), + "QORTY" => QORTY_TOKEN_ADDRESS.expect("QORTY_TOKEN_ADDRESS must be set already"), _ => panic!("Expected QICK or QORTY ticker"), }; ( contract_address, - QRC20_SWAP_CONTRACT_ADDRESS - .expect("QRC20_SWAP_CONTRACT_ADDRESS must be set already") - .clone(), + QRC20_SWAP_CONTRACT_ADDRESS.expect("QRC20_SWAP_CONTRACT_ADDRESS must be set already"), ) }; let platform = "QTUM"; @@ -454,12 +448,8 @@ pub fn qrc20_coin_from_privkey(ticker: &str, priv_key: Secp256k1Secret) -> (MmAr fn qrc20_coin_conf_item(ticker: &str) -> Json { let contract_address = unsafe { match ticker { - "QICK" => QICK_TOKEN_ADDRESS - .expect("QICK_TOKEN_ADDRESS must be set already") - .clone(), - "QORTY" => QORTY_TOKEN_ADDRESS - .expect("QORTY_TOKEN_ADDRESS must be set already") - .clone(), + "QICK" => QICK_TOKEN_ADDRESS.expect("QICK_TOKEN_ADDRESS must be set already"), + "QORTY" => QORTY_TOKEN_ADDRESS.expect("QORTY_TOKEN_ADDRESS must be set already"), _ => panic!("Expected either QICK or QORTY ticker, found {}", ticker), } }; @@ -561,7 +551,7 @@ pub fn fill_qrc20_address(coin: &Qrc20Coin, amount: BigDecimal, timeout: u64) { let tx_bytes = client.get_transaction_bytes(&hash).wait().unwrap(); log!("{:02x}", tx_bytes); let confirm_payment_input = ConfirmPaymentInput { - payment_tx: tx_bytes.clone().0, + payment_tx: tx_bytes.0, confirmations: 1, requires_nota: false, wait_until: timeout, @@ -741,11 +731,8 @@ pub fn wait_for_estimate_smart_fee(timeout: u64) -> Result<(), String> { } pub async fn enable_qrc20_native(mm: &MarketMakerIt, coin: &str) -> Json { - let swap_contract_address = unsafe { - QRC20_SWAP_CONTRACT_ADDRESS - .expect("QRC20_SWAP_CONTRACT_ADDRESS must be set already") - .clone() - }; + let swap_contract_address = + unsafe { QRC20_SWAP_CONTRACT_ADDRESS.expect("QRC20_SWAP_CONTRACT_ADDRESS must be set already") }; let native = mm .rpc(&json! ({ @@ -984,7 +971,7 @@ pub fn solana_supplied_node() -> MarketMakerIt { {"coin":"ADEX-SOL-DEVNET","protocol":{"type":"SPLTOKEN","protocol_data":{"decimals":9,"token_contract_address":"5tSm6PqMosy1rz1AqV3kD28yYT5XqZW3QYmZommuFiPJ","platform":"SOL-DEVNET"}},"mm2": 1}, ]); - let mm = MarketMakerIt::start( + MarketMakerIt::start( json! ({ "gui": "nogui", "netid": 9000, @@ -997,9 +984,7 @@ pub fn solana_supplied_node() -> MarketMakerIt { "pass".to_string(), None, ) - .unwrap(); - - mm + .unwrap() } pub fn get_balance(mm: &MarketMakerIt, coin: &str) -> MyBalanceResponse { diff --git a/mm2src/mm2_main/tests/docker_tests/docker_tests_inner.rs b/mm2src/mm2_main/tests/docker_tests/docker_tests_inner.rs index 6a46d62661..83e53f87c4 100644 --- a/mm2src/mm2_main/tests/docker_tests/docker_tests_inner.rs +++ b/mm2src/mm2_main/tests/docker_tests/docker_tests_inner.rs @@ -74,7 +74,7 @@ fn test_search_for_swap_tx_spend_native_was_refunded_taker() { let search_input = SearchForSwapTxSpendInput { time_lock, - other_pub: &*coin.my_public_key().unwrap(), + other_pub: coin.my_public_key().unwrap(), secret_hash: &[0; 20], tx: &tx.tx_hex(), search_from_block: 0, @@ -162,7 +162,7 @@ fn test_search_for_swap_tx_spend_native_was_refunded_maker() { let search_input = SearchForSwapTxSpendInput { time_lock, - other_pub: &*coin.my_public_key().unwrap(), + other_pub: coin.my_public_key().unwrap(), secret_hash: &[0; 20], tx: &tx.tx_hex(), search_from_block: 0, @@ -233,7 +233,7 @@ fn test_search_for_taker_swap_tx_spend_native_was_spent_by_maker() { let search_input = SearchForSwapTxSpendInput { time_lock, - other_pub: &*coin.my_public_key().unwrap(), + other_pub: coin.my_public_key().unwrap(), secret_hash: &*dhash160(&secret), tx: &tx.tx_hex(), search_from_block: 0, @@ -304,7 +304,7 @@ fn test_search_for_maker_swap_tx_spend_native_was_spent_by_taker() { let search_input = SearchForSwapTxSpendInput { time_lock, - other_pub: &*coin.my_public_key().unwrap(), + other_pub: coin.my_public_key().unwrap(), secret_hash: &*dhash160(&secret), tx: &tx.tx_hex(), search_from_block: 0, @@ -2955,7 +2955,7 @@ fn test_utxo_merge() { thread::sleep(Duration::from_secs(2)); let (unspents, _) = - block_on(coin.get_unspent_ordered_list(&coin.as_ref().derivation_method.unwrap_single_addr())).unwrap(); + block_on(coin.get_unspent_ordered_list(coin.as_ref().derivation_method.unwrap_single_addr())).unwrap(); assert_eq!(unspents.len(), 1); } @@ -3009,7 +3009,7 @@ fn test_utxo_merge_max_merge_at_once() { thread::sleep(Duration::from_secs(2)); let (unspents, _) = - block_on(coin.get_unspent_ordered_list(&coin.as_ref().derivation_method.unwrap_single_addr())).unwrap(); + block_on(coin.get_unspent_ordered_list(coin.as_ref().derivation_method.unwrap_single_addr())).unwrap(); // 4 utxos are merged of 5 so the resulting unspents len must be 2 assert_eq!(unspents.len(), 2); } diff --git a/mm2src/mm2_main/tests/docker_tests/mod.rs b/mm2src/mm2_main/tests/docker_tests/mod.rs index 300ebbc63c..4ac4e6541d 100644 --- a/mm2src/mm2_main/tests/docker_tests/mod.rs +++ b/mm2src/mm2_main/tests/docker_tests/mod.rs @@ -12,4 +12,5 @@ mod swaps_file_lock_tests; // dummy test helping IDE to recognize this as test module #[test] +#[allow(clippy::assertions_on_constants)] fn dummy() { assert!(true) } diff --git a/mm2src/mm2_main/tests/docker_tests/qrc20_tests.rs b/mm2src/mm2_main/tests/docker_tests/qrc20_tests.rs index 3601baa886..ba3cbb5fe9 100644 --- a/mm2src/mm2_main/tests/docker_tests/qrc20_tests.rs +++ b/mm2src/mm2_main/tests/docker_tests/qrc20_tests.rs @@ -1199,7 +1199,7 @@ fn test_trade_preimage_not_sufficient_base_coin_balance_for_ticker() { // fill QTUM balance with 0.005 QTUM which is will be than expected transaction fee just to get our desired output for this test. let qick_balance = MmNumber::from("10").to_decimal(); let qtum_balance = MmNumber::from("0.005").to_decimal(); - let (_, _, priv_key) = generate_qrc20_coin_with_random_privkey("QICK", qtum_balance.clone(), qick_balance.clone()); + let (_, _, priv_key) = generate_qrc20_coin_with_random_privkey("QICK", qtum_balance.clone(), qick_balance); let qick_contract_address = format!("{:#02x}", unsafe { QICK_TOKEN_ADDRESS.expect("!QICK_TOKEN_ADDRESS") }); let confpath = unsafe { QTUM_CONF_PATH.as_ref().expect("Qtum config is not set yet") }; @@ -1569,7 +1569,7 @@ fn test_search_for_segwit_swap_tx_spend_native_was_refunded_maker() { let search_input = SearchForSwapTxSpendInput { time_lock, - other_pub: &*coin.my_public_key().unwrap(), + other_pub: coin.my_public_key().unwrap(), secret_hash: &[0; 20], tx: &tx.tx_hex(), search_from_block: 0, @@ -1638,7 +1638,7 @@ fn test_search_for_segwit_swap_tx_spend_native_was_refunded_taker() { let search_input = SearchForSwapTxSpendInput { time_lock, - other_pub: &*coin.my_public_key().unwrap(), + other_pub: coin.my_public_key().unwrap(), secret_hash: &[0; 20], tx: &tx.tx_hex(), search_from_block: 0, diff --git a/mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs b/mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs index 223b4f215c..37ad5acc52 100644 --- a/mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs +++ b/mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs @@ -95,7 +95,7 @@ fn test_watcher_spends_maker_payment_spend_eth_erc20() { block_on(mm_watcher.wait_for_log(180., |log| log.contains(MAKER_PAYMENT_SPEND_SENT_LOG))).unwrap(); thread::sleep(Duration::from_secs(25)); - let mm_alice = MarketMakerIt::start(alice_conf.conf.clone(), alice_conf.rpc_password.clone(), None).unwrap(); + let mm_alice = MarketMakerIt::start(alice_conf.conf.clone(), alice_conf.rpc_password, None).unwrap(); enable_eth_and_jst(&mm_alice); let alice_eth_balance_after = block_on(my_balance(&mm_alice, "ETH")).balance.with_scale(2); @@ -108,7 +108,7 @@ fn test_watcher_spends_maker_payment_spend_eth_erc20() { assert_eq!(alice_jst_balance_before - volume.clone(), alice_jst_balance_after); assert_eq!(bob_jst_balance_before + volume.clone(), bob_jst_balance_after); assert_eq!(alice_eth_balance_before + volume.clone(), alice_eth_balance_after); - assert_eq!(bob_eth_balance_before - volume.clone(), bob_eth_balance_after); + assert_eq!(bob_eth_balance_before - volume, bob_eth_balance_after); assert!(watcher_eth_balance_after > watcher_eth_balance_before); } @@ -176,7 +176,7 @@ fn test_two_watchers_spend_maker_payment_eth_erc20() { block_on(mm_watcher2.wait_for_log(180., |log| log.contains(MAKER_PAYMENT_SPEND_SENT_LOG))).unwrap(); thread::sleep(Duration::from_secs(25)); - let mm_alice = MarketMakerIt::start(alice_conf.conf.clone(), alice_conf.rpc_password.clone(), None).unwrap(); + let mm_alice = MarketMakerIt::start(alice_conf.conf.clone(), alice_conf.rpc_password, None).unwrap(); enable_eth_and_jst(&mm_alice); let alice_eth_balance_after = block_on(my_balance(&mm_alice, "ETH")).balance.with_scale(2); @@ -190,7 +190,7 @@ fn test_two_watchers_spend_maker_payment_eth_erc20() { assert_eq!(alice_jst_balance_before - volume.clone(), alice_jst_balance_after); assert_eq!(bob_jst_balance_before + volume.clone(), bob_jst_balance_after); assert_eq!(alice_eth_balance_before + volume.clone(), alice_eth_balance_after); - assert_eq!(bob_eth_balance_before - volume.clone(), bob_eth_balance_after); + assert_eq!(bob_eth_balance_before - volume, bob_eth_balance_after); if watcher1_eth_balance_after > watcher1_eth_balance_before { assert_eq!(watcher2_eth_balance_after, watcher2_eth_balance_after); } @@ -248,7 +248,7 @@ fn test_watcher_spends_maker_payment_spend_erc20_eth() { block_on(mm_watcher.wait_for_log(180., |log| log.contains(MAKER_PAYMENT_SPEND_SENT_LOG))).unwrap(); thread::sleep(Duration::from_secs(25)); - let mm_alice = MarketMakerIt::start(alice_conf.conf.clone(), alice_conf.rpc_password.clone(), None).unwrap(); + let mm_alice = MarketMakerIt::start(alice_conf.conf.clone(), alice_conf.rpc_password, None).unwrap(); enable_eth_and_jst(&mm_alice); let alice_eth_balance_after = block_on(my_balance(&mm_alice, "ETH")).balance.with_scale(2); @@ -262,7 +262,7 @@ fn test_watcher_spends_maker_payment_spend_erc20_eth() { assert_eq!(alice_jst_balance_before + volume.clone(), alice_jst_balance_after); assert_eq!(bob_jst_balance_before - volume.clone(), bob_jst_balance_after); assert_eq!(alice_eth_balance_before - volume.clone(), alice_eth_balance_after); - assert_eq!(bob_eth_balance_before + volume.clone(), bob_eth_balance_after); + assert_eq!(bob_eth_balance_before + volume, bob_eth_balance_after); assert!(watcher_eth_balance_after > watcher_eth_balance_before); } @@ -274,7 +274,7 @@ fn test_watcher_waits_for_taker_eth() { let alice_passphrase = String::from("spice describe gravity federal blast come thank unfair canal monkey style afraid"); let alice_conf = Mm2TestConf::seednode_using_watchers(&alice_passphrase, &coins); - let mut mm_alice = MarketMakerIt::start(alice_conf.conf.clone(), alice_conf.rpc_password.clone(), None).unwrap(); + let mut mm_alice = MarketMakerIt::start(alice_conf.conf.clone(), alice_conf.rpc_password, None).unwrap(); let (_alice_dump_log, _alice_dump_dashboard) = mm_alice.mm_dump(); log!("Alice log path: {}", mm_alice.log_path.display()); @@ -464,11 +464,7 @@ fn test_watcher_validate_taker_fee_eth() { let taker_amount = MmNumber::from((10, 1)); let fee_amount = dex_fee_amount_from_taker_coin(&MmCoinEnum::EthCoin(taker_coin.clone()), "ETH", &taker_amount); let taker_fee = taker_coin - .send_taker_fee( - &DEX_FEE_ADDR_RAW_PUBKEY, - fee_amount.clone().into(), - Uuid::new_v4().as_bytes(), - ) + .send_taker_fee(&DEX_FEE_ADDR_RAW_PUBKEY, fee_amount.into(), Uuid::new_v4().as_bytes()) .wait() .unwrap(); @@ -572,11 +568,7 @@ fn test_watcher_validate_taker_fee_erc20() { let taker_amount = MmNumber::from((10, 1)); let fee_amount = dex_fee_amount_from_taker_coin(&MmCoinEnum::EthCoin(taker_coin.clone()), "ETH", &taker_amount); let taker_fee = taker_coin - .send_taker_fee( - &DEX_FEE_ADDR_RAW_PUBKEY, - fee_amount.clone().into(), - Uuid::new_v4().as_bytes(), - ) + .send_taker_fee(&DEX_FEE_ADDR_RAW_PUBKEY, fee_amount.into(), Uuid::new_v4().as_bytes()) .wait() .unwrap(); @@ -1306,7 +1298,7 @@ fn test_watcher_waits_for_taker_utxo() { let coins = json!([mycoin_conf(1000), mycoin1_conf(1000)]); let alice_conf = Mm2TestConf::seednode_using_watchers(&format!("0x{}", hex::encode(alice_priv_key)), &coins).conf; - let mut mm_alice = MarketMakerIt::start(alice_conf.clone(), DEFAULT_RPC_PASSWORD.to_string(), None).unwrap(); + let mut mm_alice = MarketMakerIt::start(alice_conf, DEFAULT_RPC_PASSWORD.to_string(), None).unwrap(); let (_alice_dump_log, _alice_dump_dashboard) = mm_dump(&mm_alice.log_path); let bob_conf = @@ -1452,11 +1444,7 @@ fn test_watcher_validate_taker_fee_utxo() { ); let taker_fee = taker_coin - .send_taker_fee( - &DEX_FEE_ADDR_RAW_PUBKEY, - fee_amount.clone().into(), - Uuid::new_v4().as_bytes(), - ) + .send_taker_fee(&DEX_FEE_ADDR_RAW_PUBKEY, fee_amount.into(), Uuid::new_v4().as_bytes()) .wait() .unwrap(); @@ -1809,7 +1797,7 @@ fn test_send_taker_payment_refund_preimage_utxo() { let search_input = SearchForSwapTxSpendInput { time_lock, - other_pub: &*coin.my_public_key().unwrap(), + other_pub: coin.my_public_key().unwrap(), secret_hash: &[0; 20], tx: &tx.tx_hex(), search_from_block: 0, diff --git a/mm2src/mm2_main/tests/docker_tests/swaps_file_lock_tests.rs b/mm2src/mm2_main/tests/docker_tests/swaps_file_lock_tests.rs index 1ef18a8ed3..e69733cbff 100644 --- a/mm2src/mm2_main/tests/docker_tests/swaps_file_lock_tests.rs +++ b/mm2src/mm2_main/tests/docker_tests/swaps_file_lock_tests.rs @@ -25,7 +25,7 @@ fn swap_file_lock_prevents_double_swap_start_on_kick_start(swap_json: &str) { let swap_path = swaps_db_folder.join("5acb0e63-8b26-469e-81df-7dd9e4a9ad15.json"); let swap_lock_path = swaps_db_folder.join("5acb0e63-8b26-469e-81df-7dd9e4a9ad15.lock"); let lock = FileLock::lock(swap_lock_path, 10.).unwrap().unwrap(); - std::fs::write(&swap_path, swap_json).unwrap(); + std::fs::write(swap_path, swap_json).unwrap(); thread::spawn(move || loop { // touch the lock file to simulate that other process is running the swap already lock.touch().unwrap(); @@ -176,12 +176,12 @@ fn test_swaps_should_kick_start_if_process_was_killed() { fn addr_hash_for_privkey(priv_key: Secp256k1Secret) -> String { let private = Private { prefix: 1, - secret: priv_key.into(), + secret: priv_key, compressed: true, checksum_type: ChecksumType::DSHA256, }; let key_pair = KeyPair::from_private(private).unwrap(); - hex::encode(&*key_pair.public().address_hash()) + hex::encode(key_pair.public().address_hash()) } fn swap_should_not_kick_start_if_finished_during_waiting_for_file_lock( diff --git a/mm2src/mm2_main/tests/docker_tests_main.rs b/mm2src/mm2_main/tests/docker_tests_main.rs index 6ef9cba2d5..70b31bf0d3 100644 --- a/mm2src/mm2_main/tests/docker_tests_main.rs +++ b/mm2src/mm2_main/tests/docker_tests_main.rs @@ -89,7 +89,7 @@ pub fn docker_tests_runner(tests: &[&TestDescAndFn]) { }) .collect(); let args: Vec = std::env::args().collect(); - let _exit_code = test_main(&args, owned_tests, None); + test_main(&args, owned_tests, None); } fn pull_docker_image(name: &str) { diff --git a/mm2src/mm2_main/tests/mm2_tests/best_orders_tests.rs b/mm2src/mm2_main/tests/mm2_tests/best_orders_tests.rs index 0685731781..26bb064ed5 100644 --- a/mm2src/mm2_main/tests/mm2_tests/best_orders_tests.rs +++ b/mm2src/mm2_main/tests/mm2_tests/best_orders_tests.rs @@ -1019,13 +1019,16 @@ fn best_orders_must_return_duplicate_for_orderbook_tickers() { assert_eq!(best_orders[0].coin, "tBTC-Segwit"); } -#[cfg(feature = "zhtlc-native-tests")] #[test] +#[cfg(feature = "zhtlc-native-tests")] fn zhtlc_best_orders() { + use super::enable_z_coin; use mm2_test_helpers::for_tests::zombie_conf; - let bob_passphrase = get_passphrase!(".env.seed", "BOB_PASSPHRASE").unwrap(); - let alice_passphrase = get_passphrase!(".env.client", "ALICE_PASSPHRASE").unwrap(); + use mm2_test_helpers::electrums::rick_electrums; + + let bob_passphrase = get_passphrase(&".env.seed", "BOB_PASSPHRASE").unwrap(); + let alice_passphrase = get_passphrase(&".env.client", "ALICE_PASSPHRASE").unwrap(); let coins = json!([rick_conf(), zombie_conf()]); @@ -1042,10 +1045,7 @@ fn zhtlc_best_orders() { "i_am_seed": true, }), "pass".into(), - match var("LOCAL_THREAD_MM") { - Ok(ref e) if e == "bob" => Some(local_start()), - _ => None, - }, + None, ) .unwrap(); @@ -1087,10 +1087,7 @@ fn zhtlc_best_orders() { "rpc_password": "pass", }), "pass".into(), - match var("LOCAL_THREAD_MM") { - Ok(ref e) if e == "alice" => Some(local_start()), - _ => None, - }, + None, ) .unwrap(); diff --git a/mm2src/mm2_main/tests/mm2_tests/mm2_tests_inner.rs b/mm2src/mm2_main/tests/mm2_tests/mm2_tests_inner.rs index be706d1ccb..01ed93849c 100644 --- a/mm2src/mm2_main/tests/mm2_tests/mm2_tests_inner.rs +++ b/mm2src/mm2_main/tests/mm2_tests/mm2_tests_inner.rs @@ -1,3 +1,5 @@ +#[cfg(all(feature = "zhtlc-native-tests", not(target_arch = "wasm32")))] +use super::enable_z_coin; use crate::integration_tests_common::*; use common::executor::Timer; use common::{cfg_native, cfg_wasm32, get_utc_timestamp, log, new_uuid}; @@ -7,19 +9,19 @@ use mm2_main::mm2::lp_ordermatch::MIN_ORDER_KEEP_ALIVE_INTERVAL; use mm2_metrics::{MetricType, MetricsJson}; use mm2_number::{BigDecimal, BigRational, Fraction, MmNumber}; use mm2_test_helpers::electrums::*; -#[cfg(all(feature = "zhtlc-native-tests", not(target_arch = "wasm32")))] -use mm2_test_helpers::for_tests::init_z_coin_native; use mm2_test_helpers::for_tests::{btc_segwit_conf, btc_with_spv_conf, btc_with_sync_starting_header, - check_recent_swaps, check_stats_swap_status, enable_eth_coin, enable_qrc20, - eth_jst_testnet_conf, eth_testnet_conf, find_metrics_in_json, from_env_file, - get_shared_db_id, mm_spat, morty_conf, rick_conf, sign_message, start_swaps, - tbtc_with_spv_conf, test_qrc20_history_impl, tqrc20_conf, verify_message, + check_recent_swaps, enable_eth_coin, enable_qrc20, eth_jst_testnet_conf, + eth_testnet_conf, find_metrics_in_json, from_env_file, get_shared_db_id, mm_spat, + morty_conf, rick_conf, sign_message, start_swaps, tbtc_with_spv_conf, + test_qrc20_history_impl, tqrc20_conf, verify_message, wait_for_swap_contract_negotiation, wait_for_swap_negotiation_failure, wait_for_swaps_finish_and_check_status, wait_till_history_has_records, MarketMakerIt, Mm2InitPrivKeyPolicy, Mm2TestConf, Mm2TestConfForSwap, RaiiDump, ETH_DEV_NODES, ETH_DEV_SWAP_CONTRACT, ETH_MAINNET_NODE, ETH_MAINNET_SWAP_CONTRACT, - MAKER_SUCCESS_EVENTS, MORTY, QRC20_ELECTRUMS, RICK, RICK_ELECTRUM_ADDRS, - TAKER_SUCCESS_EVENTS}; + MORTY, QRC20_ELECTRUMS, RICK, RICK_ELECTRUM_ADDRS}; +#[cfg(all(not(target_arch = "wasm32"), not(feature = "zhtlc-native-tests")))] +use mm2_test_helpers::for_tests::{check_stats_swap_status, MAKER_SUCCESS_EVENTS, TAKER_SUCCESS_EVENTS}; + use mm2_test_helpers::get_passphrase; use mm2_test_helpers::structs::*; use serde_json::{self as json, json, Value as Json}; @@ -43,30 +45,6 @@ cfg_wasm32! { wasm_bindgen_test_configure!(run_in_browser); } -#[cfg(all(feature = "zhtlc-native-tests", not(target_arch = "wasm32")))] -async fn enable_z_coin(mm: &MarketMakerIt, coin: &str) -> CoinActivationResult { - use common::now_ms; - use mm2_test_helpers::for_tests::init_z_coin_status; - - let init = init_z_coin_native(mm, coin).await; - let init: RpcV2Response = json::from_value(init).unwrap(); - let timeout = now_ms() + 120000; - - loop { - if gstuff::now_ms() > timeout { - panic!("{} initialization timed out", coin); - } - - let status = init_z_coin_status(mm, init.result.task_id).await; - let status: RpcV2Response = json::from_value(status).unwrap(); - match status.result { - InitZcoinStatus::Ok(result) => break result, - InitZcoinStatus::Error(e) => panic!("{} initialization error {:?}", coin, e), - _ => Timer::sleep(1.).await, - } - } -} - /// Integration test for RPC server. /// Check that MM doesn't crash in case of invalid RPC requests #[test] @@ -788,12 +766,14 @@ async fn trade_base_rel_electrum( #[cfg(all(feature = "zhtlc-native-tests", not(target_arch = "wasm32")))] { + let bob_passphrase = get_passphrase!(".env.seed", "BOB_PASSPHRASE").unwrap(); Timer::sleep(1.).await; let rmd = rmd160_from_passphrase(&bob_passphrase); let bob_zombie_cache_path = mm_bob.folder.join("DB").join(hex::encode(rmd)).join("ZOMBIE_CACHE.db"); log!("bob_zombie_cache_path {}", bob_zombie_cache_path.display()); std::fs::copy("./mm2src/coins/for_tests/ZOMBIE_CACHE.db", bob_zombie_cache_path).unwrap(); + let alice_passphrase = get_passphrase!(".env.client", "ALICE_PASSPHRASE").unwrap(); let rmd = rmd160_from_passphrase(&alice_passphrase); let alice_zombie_cache_path = mm_alice .folder diff --git a/mm2src/mm2_main/tests/mm2_tests/mod.rs b/mm2src/mm2_main/tests/mm2_tests/mod.rs index d331a269c6..9c6cdd35e3 100644 --- a/mm2src/mm2_main/tests/mm2_tests/mod.rs +++ b/mm2src/mm2_main/tests/mm2_tests/mod.rs @@ -10,6 +10,38 @@ mod tendermint_ibc_asset_tests; mod tendermint_tests; mod z_coin_tests; +mod zhtlc_native_reexport { + pub use common::executor::Timer; + pub use common::now_ms; + pub use mm2_test_helpers::for_tests::MarketMakerIt; + pub use mm2_test_helpers::for_tests::{init_z_coin_native, init_z_coin_status}; + pub use mm2_test_helpers::structs::{CoinActivationResult, InitTaskResult, InitZcoinStatus, RpcV2Response}; +} + +#[cfg(all(feature = "zhtlc-native-tests", not(target_arch = "wasm32")))] +use zhtlc_native_reexport::*; + +#[cfg(all(feature = "zhtlc-native-tests", not(target_arch = "wasm32")))] +async fn enable_z_coin(mm: &MarketMakerIt, coin: &str) -> CoinActivationResult { + let init = init_z_coin_native(mm, coin).await; + let init: RpcV2Response = serde_json::from_value(init).unwrap(); + let timeout = now_ms() + 120000; + + loop { + if gstuff::now_ms() > timeout { + panic!("{} initialization timed out", coin); + } + + let status = init_z_coin_status(mm, init.result.task_id).await; + let status: RpcV2Response = serde_json::from_value(status).unwrap(); + match status.result { + InitZcoinStatus::Ok(result) => break result, + InitZcoinStatus::Error(e) => panic!("{} initialization error {:?}", coin, e), + _ => Timer::sleep(1.).await, + } + } +} + // dummy test helping IDE to recognize this as test module #[test] #[allow(clippy::assertions_on_constants)] diff --git a/mm2src/mm2_test_helpers/src/for_tests.rs b/mm2src/mm2_test_helpers/src/for_tests.rs index 910837c666..68c3ba4eaf 100644 --- a/mm2src/mm2_test_helpers/src/for_tests.rs +++ b/mm2src/mm2_test_helpers/src/for_tests.rs @@ -126,8 +126,8 @@ pub const ZOMBIE_TICKER: &str = "ZOMBIE"; pub const ARRR: &str = "ARRR"; pub const ZOMBIE_ELECTRUMS: &[&str] = &["zombie.dragonhound.info:10033"]; pub const ZOMBIE_LIGHTWALLETD_URLS: &[&str] = &["http://zombie.dragonhound.info:443"]; -pub const PIRATE_ELECTRUMS: &[&str] = &["pirate.dragonhound.info:10032"]; -pub const PIRATE_LIGHTWALLETD_URLS: &[&str] = &["http://pirate.dragonhound.info:443"]; +pub const PIRATE_ELECTRUMS: &[&str] = &["node1.chainkeeper.pro:10132"]; +pub const PIRATE_LIGHTWALLETD_URLS: &[&str] = &["http://node1.chainkeeper.pro:443"]; pub const DEFAULT_RPC_PASSWORD: &str = "pass"; pub const QRC20_ELECTRUMS: &[&str] = &[ "electrum1.cipig.net:10071", From c5fbee7ca7e7c4a29c1d7df9b7264c3173e32d4b Mon Sep 17 00:00:00 2001 From: Onur Date: Thu, 27 Apr 2023 00:53:27 +0300 Subject: [PATCH 89/90] improve p2p stack (#1755) (#1753) Signed-off-by: ozkanonur --- CHANGELOG.md | 1 + mm2src/coins/tendermint/tendermint_coin.rs | 14 ++++++++++---- mm2src/common/common.rs | 4 ++++ mm2src/mm2_main/src/lp_ordermatch.rs | 11 ++++++++++- mm2src/mm2_main/src/lp_swap/maker_swap.rs | 8 +++++--- .../tests/docker_tests/swap_watcher_tests.rs | 12 ++++++------ 6 files changed, 36 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e93838b03b..3b31613357 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - optimized dev and release compilation profiles and removed ci [#1759](https://github.com/KomodoPlatform/atomicDEX-API/pull/1759) - fix receiver trade fee for cosmos swaps [#1767](https://github.com/KomodoPlatform/atomicDEX-API/pull/1767) - All features were enabled to be checked under x86-64 code lint CI step with `--all-features` option [#1760](https://github.com/KomodoPlatform/atomicDEX-API/pull/1760) +- use OS generated secrets for cryptographically secure randomness in `maker_swap` and `tendermint_coin::get_sender_trade_fee_for_denom` [#1753](https://github.com/KomodoPlatform/atomicDEX-API/pull/1753) ## v1.0.2-beta - 2023-04-11 diff --git a/mm2src/coins/tendermint/tendermint_coin.rs b/mm2src/coins/tendermint/tendermint_coin.rs index 803808ed9e..2ae9ba07fe 100644 --- a/mm2src/coins/tendermint/tendermint_coin.rs +++ b/mm2src/coins/tendermint/tendermint_coin.rs @@ -63,7 +63,6 @@ use mm2_number::MmNumber; use parking_lot::Mutex as PaMutex; use primitives::hash::H256; use prost::{DecodeError, Message}; -use rand::{thread_rng, Rng}; use rpc::v1::types::Bytes as BytesJson; use serde_json::{self as json, Value as Json}; use std::collections::HashMap; @@ -1477,7 +1476,11 @@ impl TendermintCoin { amount: BigDecimal, ) -> TradePreimageResult { const TIME_LOCK: u64 = 1750; - let sec: [u8; 32] = thread_rng().gen(); + + let mut sec = [0u8; 32]; + common::os_rng(&mut sec).map_err(|e| MmError::new(TradePreimageError::InternalError(e.to_string())))?; + drop_mutability!(sec); + let to_address = account_id_from_pubkey_hex(&self.account_prefix, DEX_FEE_ADDR_PUBKEY) .map_err(|e| MmError::new(TradePreimageError::InternalError(e.into_inner().to_string())))?; @@ -2648,7 +2651,6 @@ pub mod tendermint_coin_tests { use common::{block_on, DEX_FEE_ADDR_RAW_PUBKEY}; use cosmrs::proto::cosmos::tx::v1beta1::{GetTxRequest, GetTxResponse, GetTxsEventResponse}; use crypto::privkey::key_pair_from_seed; - use rand::{thread_rng, Rng}; use std::mem::discriminant; pub const IRIS_TESTNET_HTLC_PAIR1_SEED: &str = "iris test seed"; @@ -2752,7 +2754,11 @@ pub mod tendermint_coin_tests { const UAMOUNT: u64 = 1; let amount: cosmrs::Decimal = UAMOUNT.into(); let amount_dec = big_decimal_from_sat_unsigned(UAMOUNT, coin.decimals); - let sec: [u8; 32] = thread_rng().gen(); + + let mut sec = [0u8; 32]; + common::os_rng(&mut sec).unwrap(); + drop_mutability!(sec); + let time_lock = 1000; let create_htlc_tx = coin diff --git a/mm2src/common/common.rs b/mm2src/common/common.rs index 67e7ff7ce8..6f23003fa3 100644 --- a/mm2src/common/common.rs +++ b/mm2src/common/common.rs @@ -138,6 +138,7 @@ use futures01::{future, Future}; use http::header::CONTENT_TYPE; use http::Response; use parking_lot::{Mutex as PaMutex, MutexGuard as PaMutexGuard}; +use rand::RngCore; use rand::{rngs::SmallRng, SeedableRng}; use serde::{de, ser}; use serde_json::{self as json, Value as Json}; @@ -747,6 +748,9 @@ pub fn writeln(line: &str) { pub fn small_rng() -> SmallRng { SmallRng::seed_from_u64(now_ms()) } +#[inline(always)] +pub fn os_rng(dest: &mut [u8]) -> Result<(), rand::Error> { rand::rngs::OsRng.try_fill_bytes(dest) } + #[derive(Debug, Clone)] /// Ordered from low to height inclusive range. pub struct OrdRange(RangeInclusive); diff --git a/mm2src/mm2_main/src/lp_ordermatch.rs b/mm2src/mm2_main/src/lp_ordermatch.rs index b43def8222..0827b40f24 100644 --- a/mm2src/mm2_main/src/lp_ordermatch.rs +++ b/mm2src/mm2_main/src/lp_ordermatch.rs @@ -2992,6 +2992,15 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO if let Err(e) = insert_new_swap_to_db(ctx.clone(), maker_coin.ticker(), taker_coin.ticker(), uuid, now).await { error!("Error {} on new swap insertion", e); } + + let secret = match MakerSwap::generate_secret() { + Ok(s) => s.into(), + Err(e) => { + error!("Error {} on secret generation", e); + return; + }, + }; + let maker_swap = MakerSwap::new( ctx.clone(), alice, @@ -3005,7 +3014,7 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO taker_coin, lock_time, maker_order.p2p_privkey.map(SerializableSecp256k1Keypair::into_inner), - MakerSwap::generate_secret().into(), + secret, ); run_maker_swap(RunMakerSwapInput::StartNew(maker_swap), ctx).await; }; diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap.rs b/mm2src/mm2_main/src/lp_swap/maker_swap.rs index 2bc438c7dc..c2ba8bce37 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap.rs @@ -31,7 +31,6 @@ use mm2_err_handle::prelude::*; use mm2_number::{BigDecimal, MmNumber}; use parking_lot::Mutex as PaMutex; use primitives::hash::{H256, H264}; -use rand::Rng; use rpc::v1::types::{Bytes as BytesJson, H256 as H256Json, H264 as H264Json}; use std::any::TypeId; use std::path::PathBuf; @@ -238,8 +237,11 @@ impl MakerSwap { #[inline] fn r(&self) -> RwLockReadGuard { self.mutable.read().unwrap() } - #[inline] - pub fn generate_secret() -> [u8; 32] { rand::thread_rng().gen() } + pub fn generate_secret() -> Result<[u8; 32], rand::Error> { + let mut sec = [0u8; 32]; + common::os_rng(&mut sec)?; + Ok(sec) + } #[inline] fn secret_hash(&self) -> Vec { diff --git a/mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs b/mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs index 37ad5acc52..c6493c1dfb 100644 --- a/mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs +++ b/mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs @@ -675,7 +675,7 @@ fn test_watcher_validate_taker_payment_eth() { let wait_for_confirmation_until = now_ms() / 1000 + time_lock_duration; let time_lock = wait_for_confirmation_until as u32; let amount = BigDecimal::from_str("0.01").unwrap(); - let secret_hash = dhash160(&MakerSwap::generate_secret()); + let secret_hash = dhash160(&MakerSwap::generate_secret().unwrap()); let watcher_reward = Some( block_on(watcher_reward_amount( &MmCoinEnum::from(taker_coin.clone()), @@ -801,7 +801,7 @@ fn test_watcher_validate_taker_payment_eth() { } // Used to get wrong swap id - let wrong_secret_hash = dhash160(&MakerSwap::generate_secret()); + let wrong_secret_hash = dhash160(&MakerSwap::generate_secret().unwrap()); let error = taker_coin .watcher_validate_taker_payment(coins::WatcherValidatePaymentInput { payment_tx: taker_payment.tx_hex(), @@ -949,7 +949,7 @@ fn test_watcher_validate_taker_payment_erc20() { let wait_for_confirmation_until = now_ms() / 1000 + time_lock_duration; let time_lock = wait_for_confirmation_until as u32; - let secret_hash = dhash160(&MakerSwap::generate_secret()); + let secret_hash = dhash160(&MakerSwap::generate_secret().unwrap()); let watcher_reward = Some( block_on(watcher_reward_amount( &MmCoinEnum::from(taker_coin.clone()), @@ -1074,7 +1074,7 @@ fn test_watcher_validate_taker_payment_erc20() { } // Used to get wrong swap id - let wrong_secret_hash = dhash160(&MakerSwap::generate_secret()); + let wrong_secret_hash = dhash160(&MakerSwap::generate_secret().unwrap()); let error = taker_coin .watcher_validate_taker_payment(WatcherValidatePaymentInput { payment_tx: taker_payment.tx_hex(), @@ -1565,7 +1565,7 @@ fn test_watcher_validate_taker_payment_utxo() { let (_ctx, maker_coin, _) = generate_utxo_coin_with_random_privkey("MYCOIN", 1000u64.into()); let maker_pubkey = maker_coin.my_public_key().unwrap(); - let secret_hash = dhash160(&MakerSwap::generate_secret()); + let secret_hash = dhash160(&MakerSwap::generate_secret().unwrap()); let taker_payment = taker_coin .send_taker_payment(SendPaymentArgs { @@ -1642,7 +1642,7 @@ fn test_watcher_validate_taker_payment_utxo() { _ => panic!("Expected `WrongPaymentTx` {INVALID_SENDER_ERR_LOG}, found {:?}", error), } - let wrong_secret_hash = dhash160(&MakerSwap::generate_secret()); + let wrong_secret_hash = dhash160(&MakerSwap::generate_secret().unwrap()); let error = taker_coin .watcher_validate_taker_payment(WatcherValidatePaymentInput { payment_tx: taker_payment.tx_hex(), From 30b173beaed37d656065db8985882c3f3824e062 Mon Sep 17 00:00:00 2001 From: Kadan Stadelmann Date: Fri, 28 Apr 2023 14:29:44 +0200 Subject: [PATCH 90/90] [docs] add 1.0.3 release date to changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc96edb378..699c97c76a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## v1.0.3-beta - ${release-date} +## v1.0.3-beta - 2023-04-28 **Features:**