Skip to content

Commit

Permalink
New CLI flags in binaries (#277)
Browse files Browse the repository at this point in the history
* cli: Add cli flags for server types.

* bin: Use cli flags in server bin.
  • Loading branch information
ceyhunsen authored Sep 5, 2024
1 parent 171e7a3 commit d1d27c8
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 54 deletions.
103 changes: 49 additions & 54 deletions core/src/bin/server.rs
Original file line number Diff line number Diff line change
@@ -1,71 +1,66 @@
#[cfg(feature = "aggregator_server")]
use clementine_core::servers::create_aggregator_server;

#[cfg(feature = "operator_server")]
use clementine_core::servers::create_operator_server;

#[cfg(feature = "verifier_server")]
use clementine_core::servers::create_verifier_server;
use clementine_core::{cli, database::common::Database, extended_rpc::ExtendedRpc};
use std::process::exit;

#[tokio::main]
async fn main() {
#[cfg(any(
feature = "verifier_server",
feature = "operator_server",
feature = "aggregator_server"
))]
{
use clementine_core::{cli, database::common::Database, extended_rpc::ExtendedRpc};
let args = match cli::parse() {
Ok(args) => args,
Err(e) => {
eprintln!("{e}");
exit(1);
}
};

let mut config = cli::get_configuration();
let rpc = ExtendedRpc::<bitcoincore_rpc::Client>::new(
config.bitcoin_rpc_url.clone(),
config.bitcoin_rpc_user.clone(),
config.bitcoin_rpc_password.clone(),
);
let mut config = cli::get_configuration();
let rpc = ExtendedRpc::<bitcoincore_rpc::Client>::new(
config.bitcoin_rpc_url.clone(),
config.bitcoin_rpc_user.clone(),
config.bitcoin_rpc_password.clone(),
);

let database = Database::new(config.clone()).await.unwrap();
database.init_from_schema().await.unwrap();
database.close().await;
let database = Database::new(config.clone()).await.unwrap();
database.init_from_schema().await.unwrap();
database.close().await;

let mut handles = vec![];
let mut handles = vec![];

#[cfg(feature = "verifier_server")]
{
handles.push(
create_verifier_server(config.clone(), rpc.clone())
.await
.unwrap()
.1
.stopped(),
);
config.port += 1;
}
if args.verifier_server {
handles.push(
create_verifier_server(config.clone(), rpc.clone())
.await
.unwrap()
.1
.stopped(),
);
config.port += 1;

#[cfg(feature = "operator_server")]
{
handles.push(
create_operator_server(config.clone(), rpc.clone())
.await
.unwrap()
.1
.stopped(),
);
config.port += 1;
}
tracing::trace!("Verifier servers are started.");
}

#[cfg(feature = "aggregator_server")]
handles.push(create_aggregator_server(config).await.unwrap().1.stopped());
if args.operator_server {
handles.push(
create_operator_server(config.clone(), rpc.clone())
.await
.unwrap()
.1
.stopped(),
);
config.port += 1;

futures::future::join_all(handles).await;
tracing::trace!("Operator servers are started.");
}

#[cfg(not(any(
feature = "verifier_server",
feature = "operator_server",
feature = "aggregator_server"
)))]
{
println!("No server features are enabled. Exiting...");
if args.aggregator_server {
handles.push(create_aggregator_server(config).await.unwrap().1.stopped());
}

if !args.verifier_server && !args.operator_server && !args.aggregator_server {
eprintln!("No servers are specified. Please specify one.");
exit(1);
}

futures::future::join_all(handles).await;
}
9 changes: 9 additions & 0 deletions core/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ use std::process::exit;
pub struct Args {
/// TOML formatted configuration file.
pub config_file: PathBuf,
/// Enable verifier server.
#[clap(short, long)]
pub verifier_server: bool,
/// Enable operator server.
#[clap(short, long)]
pub operator_server: bool,
/// Enable aggregator server.
#[clap(short, long)]
pub aggregator_server: bool,
}

/// Parse all the command line arguments and generate a `BridgeConfig`.
Expand Down

0 comments on commit d1d27c8

Please sign in to comment.