1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use clap::{App, Arg};
use std::collections::BTreeMap;
use std::{thread, time::Duration};
use libqaul;
pub fn get_argument(pattern: &str) -> Option<String> {
let matches = App::new("")
.arg(
Arg::with_name("name")
.short('n')
.long("name")
.takes_value(true)
.help("user name"),
)
.arg(
Arg::with_name("port")
.short('p')
.long("port")
.takes_value(true)
.help("port number"),
)
.get_matches();
if let Some(v) = matches.value_of(pattern) {
Some(v.to_string())
} else {
None
}
}
pub fn create_default_named() -> String {
let mut user_name: String;
user_name = "Community Node ".to_string();
user_name.push_str(
libqaul::utilities::timestamp::Timestamp::get_timestamp()
.to_string()
.as_str(),
);
user_name
}
#[async_std::main]
async fn main() {
let path = std::env::current_dir().unwrap();
let storage_path = path.as_path().to_str().unwrap().to_string();
let mut def_config: BTreeMap<String, String> = BTreeMap::new();
let possible_arguments = vec!["name", "port"];
for s in possible_arguments {
if let Some(v) = get_argument(&s) {
def_config.insert(s.to_string(), v.clone());
}
}
libqaul::api::start_with_config(storage_path, Some(def_config.clone()));
while libqaul::api::initialization_finished() == false {
std::thread::sleep(Duration::from_millis(10));
}
if libqaul::node::user_accounts::UserAccounts::len() == 0 {
let user_name: String;
if let Some(usr_name) = get_argument("name") {
user_name = usr_name.clone();
} else {
user_name = create_default_named();
}
libqaul::node::user_accounts::UserAccounts::create(user_name.clone());
}
loop {
thread::sleep(Duration::from_millis(10));
}
}