@@ -4,20 +4,10 @@ use alloy_signer_local::PrivateKeySigner;
44use clap:: Parser ;
55use ethereum_keys:: signer_local:: { read_from_keystore, write_to_keystore} ;
66use ibc_attestor:: {
7- adapter:: {
8- AdapterBuilder ,
9- cosmos:: { CosmosAdapterBuilder , CosmosAdapterConfig } ,
10- evm:: { EvmAdapterBuilder , EvmAdapterConfig } ,
11- solana:: { SolanaAdapterBuilder , SolanaAdapterConfig } ,
12- } ,
13- config:: { AttestorConfig , TracingConfig } ,
7+ config:: RuntimeConfig ,
148 logging:: init_logging,
159 rpc:: { RpcError , health, server} ,
16- signer:: {
17- SignerBuilder ,
18- local:: { DEFAULT_KEYSTORE_NAME , LocalSigner , LocalSignerConfig } ,
19- remote:: { RemoteSigner , RemoteSignerConfig } ,
20- } ,
10+ signer:: local:: DEFAULT_KEYSTORE_NAME ,
2111} ;
2212
2313use tokio:: {
@@ -27,7 +17,7 @@ use tokio::{
2717} ;
2818use tracing:: info;
2919
30- use crate :: cli:: { AttestorCli , ChainType , Commands , SignerType , key:: KeyCommands } ;
20+ use crate :: cli:: { AttestorCli , Commands , key:: KeyCommands } ;
3121
3222mod cli;
3323
@@ -43,12 +33,14 @@ fn default_attestor_dir() -> Result<PathBuf, anyhow::Error> {
4333 Ok ( PathBuf :: from ( home) . join ( ".ibc-attestor" ) )
4434}
4535
46- fn run_servers < B : AdapterBuilder + ' static , S : SignerBuilder + ' static > (
47- config : AttestorConfig < B :: Config , S :: Config > ,
36+ type ServerHandles = ( JoinHandle < Result < ( ) , RpcError > > , JoinHandle < ( ) > ) ;
37+
38+ fn run_servers (
39+ config : RuntimeConfig ,
4840 shutdown_tx : & broadcast:: Sender < ( ) > ,
49- ) -> Result < ( JoinHandle < Result < ( ) , RpcError > > , JoinHandle < ( ) > ) , anyhow:: Error > {
50- let adapter = B :: build ( config. adapter ) ? ;
51- let signer = S :: build ( config. signer ) ? ;
41+ ) -> Result < ServerHandles , anyhow:: Error > {
42+ let adapter_name = config. adapter . adapter_name ( ) ;
43+ let signer_name = config. signer . signer_name ( ) ;
5244 let server_config = config. server ;
5345
5446 let grpc_shutdown_rx = shutdown_tx. subscribe ( ) ;
@@ -60,10 +52,10 @@ fn run_servers<B: AdapterBuilder + 'static, S: SignerBuilder + 'static>(
6052 let grpc_handle = tokio:: spawn ( async move {
6153 server:: start (
6254 grpc_addr,
63- adapter,
64- B :: adapter_name ( ) ,
65- signer,
66- S :: signer_name ( ) ,
55+ config . adapter ,
56+ adapter_name,
57+ config . signer ,
58+ signer_name,
6759 grpc_shutdown_rx,
6860 )
6961 . await
@@ -82,55 +74,17 @@ async fn main() -> Result<(), anyhow::Error> {
8274
8375 match cli. command {
8476 Commands :: Server ( args) => {
85- // Load tracing config first to initialize logging before parsing full config
86- let tracing_config = TracingConfig :: from_file ( & args. config ) ?;
87- let _tracing_guard = init_logging ( tracing_config) ;
77+ let config = RuntimeConfig :: from_file (
78+ & args. config ,
79+ & args. chain_type . into ( ) ,
80+ & args. signer_type . into ( ) ,
81+ ) ?;
82+ let _tracing_guard = init_logging ( config. tracing . clone ( ) ) ;
8883
8984 // Create shutdown broadcast channel
9085 let ( shutdown_tx, _shutdown_rx) = broadcast:: channel ( 1 ) ;
9186
92- let ( grpc_handle, health_handle) = match ( args. chain_type , args. signer_type ) {
93- ( ChainType :: Evm , SignerType :: Local ) => {
94- let config = AttestorConfig :: < EvmAdapterConfig , LocalSignerConfig > :: from_file (
95- & args. config ,
96- ) ?;
97- run_servers :: < EvmAdapterBuilder , LocalSigner > ( config, & shutdown_tx) ?
98- }
99- ( ChainType :: Evm , SignerType :: Remote ) => {
100- let config = AttestorConfig :: < EvmAdapterConfig , RemoteSignerConfig > :: from_file (
101- & args. config ,
102- ) ?;
103- run_servers :: < EvmAdapterBuilder , RemoteSigner > ( config, & shutdown_tx) ?
104- }
105- ( ChainType :: Solana , SignerType :: Local ) => {
106- let config =
107- AttestorConfig :: < SolanaAdapterConfig , LocalSignerConfig > :: from_file (
108- & args. config ,
109- ) ?;
110- run_servers :: < SolanaAdapterBuilder , LocalSigner > ( config, & shutdown_tx) ?
111- }
112- ( ChainType :: Solana , SignerType :: Remote ) => {
113- let config =
114- AttestorConfig :: < SolanaAdapterConfig , RemoteSignerConfig > :: from_file (
115- & args. config ,
116- ) ?;
117- run_servers :: < SolanaAdapterBuilder , RemoteSigner > ( config, & shutdown_tx) ?
118- }
119- ( ChainType :: Cosmos , SignerType :: Local ) => {
120- let config =
121- AttestorConfig :: < CosmosAdapterConfig , LocalSignerConfig > :: from_file (
122- & args. config ,
123- ) ?;
124- run_servers :: < CosmosAdapterBuilder , LocalSigner > ( config, & shutdown_tx) ?
125- }
126- ( ChainType :: Cosmos , SignerType :: Remote ) => {
127- let config =
128- AttestorConfig :: < CosmosAdapterConfig , RemoteSignerConfig > :: from_file (
129- & args. config ,
130- ) ?;
131- run_servers :: < CosmosAdapterBuilder , RemoteSigner > ( config, & shutdown_tx) ?
132- }
133- } ;
87+ let ( grpc_handle, health_handle) = run_servers ( config, & shutdown_tx) ?;
13488
13589 _ = wait_for_shutdown_signal ( ) . await ;
13690 info ! ( "shutdown signal received, starting graceful shutdown" ) ;
0 commit comments