-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.rs
171 lines (160 loc) · 4.85 KB
/
main.rs
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*******************************************************************************
* Copyright (c) 2018-2019 Aion foundation.
*
* This file is part of the aion network project.
*
* The aion network project is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or any later version.
*
* The aion network project is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the aion network project source files.
* If not, see <https://www.gnu.org/licenses/>.
*
******************************************************************************/
//! Aionr client application.
//!
//! # core
//! * [acore](../acore/index.html) : Aionr core, the dispatch center of each module manages the
//! entire life process of blocks and txs.
//!
//! # db
//! * [db](../db/index.html) : Blockchain key value database implementation.
//! * [journaldb](../journaldb/index.html) JournalDB interface and implementation.
//!
//! # json
//! * [ajson](../ajson/index.html) : Json converter, for loading genesis spec.
//!
//! # keystore
//! * [key](../key/index.html) : Keys generator and validator.
//! * [keychain](../keychain/index.html) : Account secret store.
//!
//! # machine
//! * [aion_machine](../aion_machine/index.html) : Generalization of types surrounding
//! blockchain-suitable state machines.
//!
//! # p2p
//! * [p2p](../p2p/index.html) : peer to peer library support aion wire protocol.
//!
//! # rpc
//! * [aion_rpc](../aion_rpc/index.html) : Aionr core api daemon for aion binary api protocol and
//! web3 protocol client.
//!
//! # vms
//! Contract VM module for interacting with FastVM and AVM.
//! * [avm](../avm/index.html) : Aion Virtual Machine for java contract
//! * [fastvm](../fastvm/index.html) : Fast Virtual Machine for solidity contract
//!
//! # util
//! Aionr core common library.
#![warn(unused_extern_crates)]
extern crate ansi_term;
extern crate ctrlc;
#[macro_use]
extern crate clap;
extern crate dir;
extern crate fdlimit;
extern crate jsonrpc_core;
extern crate num_cpus;
extern crate parking_lot;
extern crate rlp;
extern crate rpassword;
extern crate rustc_hex;
extern crate serde;
extern crate serde_json;
#[macro_use]
extern crate serde_derive;
extern crate toml;
extern crate acore;
extern crate acore_bytes as bytes;
extern crate acore_io as io;
extern crate logger;
extern crate aion_types;
extern crate key;
extern crate keychain;
extern crate panic_hook;
extern crate aion_rpc;
extern crate aion_version;
extern crate journaldb;
extern crate tokio;
extern crate p2p;
#[macro_use]
extern crate log as rlog;
#[cfg(test)]
#[macro_use]
extern crate pretty_assertions;
#[cfg(test)]
extern crate tempdir;
#[cfg(test)]
extern crate regex;
mod account;
mod blockchain;
mod cache;
mod cli;
mod configuration;
mod helpers;
mod params;
mod rpc;
mod rpc_apis;
mod run;
mod user_defaults;
use std::{process, env};
use std::io::{self as stdio, Write};
use cli::Args;
use configuration::{Cmd, Execute, Configuration};
use logger::{setup_compression_log};
/// execution result to post
enum PostExecutionAction {
Print(String),
Quit,
}
/// setup logger and excute command
fn execute(command: Execute) -> Result<PostExecutionAction, String> {
let _ = setup_compression_log(command.logger.config)?;
match command.cmd {
Cmd::Run(run_cmd) => {
run::execute(run_cmd)?;
Ok(PostExecutionAction::Quit)
}
Cmd::Version => Ok(PostExecutionAction::Print(Args::print_version())),
Cmd::Account(account_cmd) => {
account::execute(account_cmd).map(|s| PostExecutionAction::Print(s))
}
Cmd::Blockchain(blockchain_cmd) => {
blockchain::execute(blockchain_cmd).map(|_| PostExecutionAction::Quit)
}
}
}
/// Read command line arguments and execute the command
fn start() -> Result<PostExecutionAction, String> {
let args: Vec<String> = env::args().collect();
let conf = Configuration::parse(&args).unwrap_or_else(|e| e.exit());
let cmd = conf.into_command()?;
execute(cmd)
}
/// run kernel
fn main() {
panic_hook::set();
let res = match start() {
Ok(result) => {
match result {
PostExecutionAction::Print(s) => {
println!("{}", s);
0
}
PostExecutionAction::Quit => 0,
}
}
Err(err) => {
writeln!(&mut stdio::stderr(), "{}", err).expect("StdErr available; qed");
1
}
};
process::exit(res);
}