diff --git a/crates/context/config/src/client.rs b/crates/context/config/src/client.rs index 3378e0368..2cba2ae7b 100644 --- a/crates/context/config/src/client.rs +++ b/crates/context/config/src/client.rs @@ -45,7 +45,8 @@ impl Client { })) } ClientSelectedSigner::Local => { - let local_client = Self::from_local_config(&config.signer.local); + let local_client = + Self::from_local_config(&config.signer.local).expect("validation error"); Either::Right(local_client.transport) } @@ -54,7 +55,7 @@ impl Client { Self::new(transport) } - pub fn from_local_config(config: &LocalConfig) -> Client { + pub fn from_local_config(config: &LocalConfig) -> eyre::Result> { let near_transport = near::NearTransport::new(&near::NearConfig { networks: config .near @@ -66,19 +67,22 @@ impl Client { credentials.secret_key.clone(), ), Credentials::Starknet(_) | Credentials::Icp(_) => { - panic!("Expected Near credentials but got {:?}", config.credentials) + eyre::bail!( + "Expected Near credentials but got {:?}", + config.credentials + ) } }; - ( + Ok(( network.clone().into(), near::NetworkConfig { rpc_url: config.rpc_url.clone(), account_id, access_key: secret_key, }, - ) + )) }) - .collect(), + .collect::>()?, }); let starknet_transport = starknet::StarknetTransport::new(&starknet::StarknetConfig { @@ -91,22 +95,22 @@ impl Client { (credentials.account_id, credentials.secret_key) } Credentials::Near(_) | Credentials::Icp(_) => { - panic!( + eyre::bail!( "Expected Starknet credentials but got {:?}", config.credentials ) } }; - ( + Ok(( network.clone().into(), starknet::NetworkConfig { rpc_url: config.rpc_url.clone(), account_id, access_key: secret_key, }, - ) + )) }) - .collect(), + .collect::>()?, }); let icp_transport = icp::IcpTransport::new(&icp::IcpConfig { @@ -120,19 +124,19 @@ impl Client { credentials.secret_key.clone(), ), Credentials::Near(_) | Credentials::Starknet(_) => { - panic!("Expected ICP credentials but got {:?}", config.credentials) + eyre::bail!("Expected ICP credentials but got {:?}", config.credentials) } }; - ( + Ok(( network.clone().into(), icp::NetworkConfig { rpc_url: config.rpc_url.clone(), account_id, secret_key, }, - ) + )) }) - .collect(), + .collect::>()?, }); let all_transports = Both { @@ -143,7 +147,7 @@ impl Client { }, }; - Client::new(all_transports) + Ok(Client::new(all_transports)) } } diff --git a/crates/merod/src/cli/relay.rs b/crates/merod/src/cli/relay.rs index b63bde22b..059f18177 100644 --- a/crates/merod/src/cli/relay.rs +++ b/crates/merod/src/cli/relay.rs @@ -51,7 +51,7 @@ impl RelayCommand { let (tx, mut rx) = mpsc::channel::(32); - let transports = Client::from_local_config(&config.context.client.signer.local); + let transports = Client::from_local_config(&config.context.client.signer.local)?; let handle = async move { while let Some((request, res_tx)) = rx.recv().await {