Skip to content

Commit

Permalink
no panic in relayer
Browse files Browse the repository at this point in the history
  • Loading branch information
miraclx committed Dec 6, 2024
1 parent ea399e1 commit 6a69271
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
34 changes: 19 additions & 15 deletions crates/context/config/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ impl Client<AnyTransport> {
}))
}
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)
}
Expand All @@ -54,7 +55,7 @@ impl Client<AnyTransport> {
Self::new(transport)
}

pub fn from_local_config(config: &LocalConfig) -> Client<LocalTransports> {
pub fn from_local_config(config: &LocalConfig) -> eyre::Result<Client<LocalTransports>> {
let near_transport = near::NearTransport::new(&near::NearConfig {
networks: config
.near
Expand All @@ -66,19 +67,22 @@ impl Client<AnyTransport> {
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::<eyre::Result<_>>()?,
});

let starknet_transport = starknet::StarknetTransport::new(&starknet::StarknetConfig {
Expand All @@ -91,22 +95,22 @@ impl Client<AnyTransport> {
(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::<eyre::Result<_>>()?,
});

let icp_transport = icp::IcpTransport::new(&icp::IcpConfig {
Expand All @@ -120,19 +124,19 @@ impl Client<AnyTransport> {
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::<eyre::Result<_>>()?,
});

let all_transports = Both {
Expand All @@ -143,7 +147,7 @@ impl Client<AnyTransport> {
},
};

Client::new(all_transports)
Ok(Client::new(all_transports))
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/merod/src/cli/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl RelayCommand {

let (tx, mut rx) = mpsc::channel::<RequestPayload>(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 {
Expand Down

0 comments on commit 6a69271

Please sign in to comment.