Skip to content

Commit

Permalink
feat: Add new main.rs, derived from bin/server.rs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyhunsen committed Mar 4, 2025
1 parent 1ef0f61 commit 61c515e
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 68 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ ark-groth16 = "0.5.0"
ark-serialize = "0.5.0"
ark-bn254 = { version = "0.5.0", features = ["curve", "scalar_field"], default-features = false }



[patch.crates-io]
bitcoincore-rpc = { version = "0.18.0", git = "https://github.com/chainwayxyz/rust-bitcoincore-rpc.git", rev = "44f9bba" }
secp256k1 = { git = "https://github.com/jlest01/rust-secp256k1", rev = "1cc7410df436b73d06db3c8ff7cbb29a78916b06" }
Expand Down
4 changes: 0 additions & 4 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,5 @@ serial_test = { workspace = true }
bitcoin-script = { workspace = true }
citrea-e2e = { workspace = true }

[[bin]]
name = "server"
path = "src/bin/server.rs"

[lints.clippy]
unwrap_used = { level = "deny" }
62 changes: 0 additions & 62 deletions core/src/bin/server.rs

This file was deleted.

3 changes: 3 additions & 0 deletions core/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub struct Args {
/// Enable aggregator server.
#[clap(long)]
pub aggregator_server: bool,
/// Enable watchtower server.
#[clap(long)]
pub watchtower_server: bool,
}

/// Parse all the command line arguments and generate a `BridgeConfig`.
Expand Down
81 changes: 81 additions & 0 deletions core/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use clementine_core::database::Database;
use clementine_core::servers::{
create_aggregator_grpc_server, create_operator_grpc_server, create_verifier_grpc_server,
create_watchtower_grpc_server,
};
use clementine_core::utils::get_configuration_for_binaries;
use std::process::exit;

#[tokio::main]
async fn main() {
eprintln!("\nBEWARE: Current behavior of this binary might be incorrect! It is in active development.\n");

let (mut config, args) = get_configuration_for_binaries();

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

Database::run_schema_script(&config)
.await
.expect("Can't run schema script");

let mut handles = vec![];

if args.verifier_server {
handles.push(
create_verifier_grpc_server(config.clone())
.await
.expect("Can't create verifier server")
.1,
);
config.port += 1;

println!("Verifier server is started.");
}

if args.operator_server {
handles.push(
create_operator_grpc_server(config.clone())
.await
.expect("Can't create operator server")
.1,
);
config.port += 1;

println!("Operator server is started.");
}

if args.aggregator_server {
handles.push(
create_aggregator_grpc_server(config.clone())
.await
.expect("Can't create aggregator server")
.1,
);
config.port += 1;

println!("Aggregator server is started.");
}

if args.watchtower_server {
handles.push(
create_watchtower_grpc_server(config)
.await
.expect("Can't create watchtower server")
.1,
);

println!("Watchtower server is started.");
}

// Wait for servers to close, A.K.A. run forever.
for mut handle in handles {
handle.closed().await;
}
}

0 comments on commit 61c515e

Please sign in to comment.