forked from jl777/SuperNET
-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adex tool was introduced #1729
Merged
ca333
merged 78 commits into
KomodoPlatform:dev
from
rozhkovdmitrii:feature-1682-introduce-adex
Apr 10, 2023
Merged
adex tool was introduced #1729
Changes from all commits
Commits
Show all changes
78 commits
Select commit
Hold shift + click to select a range
6cddedb
feat: introduce adex cli utility, that is aimed to facilitate using m…
f480d2d
CHANGELOG was changed
8ffaf33
CHANGELOG header style changed
7896139
Use winapi crate to manage mm2 process
59f0621
rollback changes
4355e72
use common::log proxy instead of log
117a3f2
Get rid of log4rs
e890d94
Spit on init_coins and polish
abafc9b
Get rid of hyper
ae4808c
Spit and polish
4ef0f6f
Spit on init_log and polish
523fa9d
Merge remote-tracking branch 'komodo/dev' into feature-1682-introduce…
7de4766
spit and polish
fa0747b
spit and polish
7ffff62
spit and polish
d536767
roll back cli
6ea0ce9
roll back cli
b371fd7
Merge remote-tracking branch 'komodo/dev' into feature-1682-introduce…
e0bab19
squash changes
34d08fc
Got rid of userhome from mm2 help
6addf5f
Use default gui configuration value
3f93b33
Spti and polish
aaff7f5
Merge remote-tracking branch 'komodo/dev' into feature-1682-introduce…
4aac321
Provide macos configuration
2cd70d8
Merge remote-tracking branch 'komodo/dev' into feature-1682-introduce…
04f4f14
Inline each inquire method on initializing mm configuration
addf3b0
Fix errors related to macos configuration
11518ca
Fix errors related to macos configuration
52767e2
Try to ignore adex-cli for wasm32
4395e97
Avoid macos related warnings
65459bb
disable wasm32 ))
1cdb693
disable all for macos
a6dc002
try again
fd254e3
Fix windows clippy after all
cb4593e
Roll back CHANGELOG.md
75d31ca
Made password generating rule stronger
7a3aa73
Provide different rules for seedphrase
3b9f9f3
Merge remote-tracking branch 'komodo/dev' into feature-1682-introduce…
f289c47
Provide an empty value for passphrase
f6b6446
Made default password to be generated until it conforms to password p…
1cc68df
Spit and polish
7762435
Spit and polish
fd1aecd
Spit and polish
6bbdfca
introduce macos mm2 process managing
7b84f02
Merge remote-tracking branch 'origin/macoschanges' into feature-1682-…
ca170ed
spit and polish
4431f65
Merge remote-tracking branch 'rozhkov/feature-1682-introduce-adex' in…
f629668
Merge remote-tracking branch 'origin/feature-1682-introduce-adex' int…
caa9d67
Spit and polish
ddcc683
provid process pid on macos
4399211
Spit and polish
d060480
Rollback some changes
da0e693
exclude adex-cli from the mm2 workspace
62288e4
Referred to an PR rather than an issue
c09e924
Use the certain version of gstuff to avoid worning related to depreca…
c13f0e2
Use the certain version of gstuff to avoid worning related to depreca…
691ae4c
Revert "Use the certain version of gstuff to avoid worning related to…
817e9cf
spit and polish
469a4f3
enable com.mm2.daemon first
1c4721a
spit and polish
500db1b
Rollback RunAtLoad, KeepAlive
2df6f48
spit and polish
cc757a9
Spit and polish
e64dcf1
Spit and polish
3c95565
Spit and polish
3d52467
Fix bug
79d309f
polished macos compilation
52a19cb
spit and polish
aab6f3c
spit and p
98befa1
Polish processing of mm2 on start
72b440f
rollback some changes
688c1e0
Fit logging after fork
c16d5cb
fork and setsid
1a386cf
Fit logging after fork
11b14fe
Fit logging after fork
01fe98a
Fit logging after fork
de43f3d
Fit logging after fork
37a1d2a
Use std::mem::forget to detach mm2 process
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[package] | ||
name = "adex-cli" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["Rozhkov Dmitrii <rozhkov@komodoplatform.com>"] | ||
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] | ||
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" } | ||
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", features = [ "macros" ] } | ||
|
||
[target.'cfg(windows)'.dependencies] | ||
winapi = { version = "0.3.3", features = ["processthreadsapi", "winnt"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
use clap::{App, Arg, SubCommand}; | ||
use log::error; | ||
use std::env; | ||
|
||
use crate::scenarios::{get_status, init, start_process, stop_process}; | ||
|
||
enum Command { | ||
Init { | ||
mm_coins_path: String, | ||
mm_conf_path: String, | ||
}, | ||
Start { | ||
mm_conf_path: Option<String>, | ||
mm_coins_path: Option<String>, | ||
mm_log: Option<String>, | ||
}, | ||
Stop, | ||
Status, | ||
} | ||
|
||
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 instance")) | ||
.subcommand(SubCommand::with_name("status").about("Get mm2 running status")); | ||
|
||
let matches = app.clone().get_matches(); | ||
|
||
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, | ||
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, | ||
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(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use log::LevelFilter; | ||
use std::io::Write; | ||
|
||
pub fn init_logging() { | ||
onur-ozkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let mut builder = env_logger::builder(); | ||
let level = std::env::var("RUST_LOG") | ||
.map(|s| s.parse().expect("Failed to parse RUST_LOG")) | ||
.unwrap_or(LevelFilter::Info); | ||
builder | ||
.filter_level(level) | ||
.format(|buf, record| writeln!(buf, "{}", record.args())); | ||
builder.init(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#[cfg(not(target_arch = "wasm32"))] mod cli; | ||
#[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(); | ||
cli::process_cli(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use common::log::error; | ||
use serde::Serialize; | ||
use std::fs::OpenOptions; | ||
use std::io::Write; | ||
use std::ops::Deref; | ||
|
||
pub fn rewrite_data_file<T>(data: T, file: &str) -> Result<(), ()> | ||
where | ||
T: Deref<Target = [u8]>, | ||
{ | ||
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<T>(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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use common::log::{error, info}; | ||
use derive_more::Display; | ||
use mm2_net::transport::slurp_url; | ||
|
||
use super::helpers::rewrite_data_file; | ||
|
||
#[derive(Clone, Copy, Debug, Display)] | ||
pub enum CoinSet { | ||
Empty, | ||
Full, | ||
} | ||
|
||
#[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: &[u8] = b"[]\n"; | ||
let coin_set = inquire_coin_set(coins_file)?; | ||
info!("Start getting mm2 coins"); | ||
let coins_data = match coin_set { | ||
CoinSet::Empty => Vec::<u8>::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| { | ||
error!("Failed to get coin set from: {FULL_COIN_SET_ADDRESS}, error: {error}"); | ||
})?; | ||
data | ||
}, | ||
}; | ||
|
||
rewrite_data_file(coins_data, coins_file)?; | ||
info!("Got coins data, written into: {coins_file}"); | ||
Ok(()) | ||
} | ||
|
||
fn inquire_coin_set(coins_file: &str) -> Result<CoinSet, ()> { | ||
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}"); | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we can remove the
Command
enum completely by calling theinit(&mm_coins_path, &mm_conf_path)
function here straight away, same with start/stop/status.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
It's a common, trditional way to build cli with
clap 2.33.3
, and I would left it to be able to use gpt 4 to bring it back to the lastclap
version.