Unnecessery clones + removed unused Enum value (#1557)

* Unnecessary clone

* Removed unused Enum value

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone
This commit is contained in:
Branislav Kontur
2022-08-26 22:25:23 +02:00
committed by Bastian Köcher
parent 793321fcfc
commit effe0f11c8
4 changed files with 8 additions and 10 deletions
@@ -80,7 +80,7 @@ pub struct Client<C: Chain> {
/// Tokio runtime handle.
tokio: Arc<tokio::runtime::Runtime>,
/// Client connection params.
params: ConnectionParams,
params: Arc<ConnectionParams>,
/// Substrate RPC client.
client: Arc<RpcClient>,
/// Genesis block hash.
@@ -99,7 +99,7 @@ impl<C: Chain> relay_utils::relay_loop::Client for Client<C> {
type Error = Error;
async fn reconnect(&mut self) -> Result<()> {
let (tokio, client) = Self::build_client(self.params.clone()).await?;
let (tokio, client) = Self::build_client(&self.params).await?;
self.tokio = tokio;
self.client = client;
Ok(())
@@ -131,6 +131,7 @@ impl<C: Chain> Client<C> {
/// This function will keep connecting to given Substrate node until connection is established
/// and is functional. If attempt fail, it will wait for `RECONNECT_DELAY` and retry again.
pub async fn new(params: ConnectionParams) -> Self {
let params = Arc::new(params);
loop {
match Self::try_connect(params.clone()).await {
Ok(client) => return client,
@@ -149,8 +150,8 @@ impl<C: Chain> Client<C> {
/// Try to connect to Substrate node over websocket. Returns Substrate RPC client if connection
/// has been established or error otherwise.
pub async fn try_connect(params: ConnectionParams) -> Result<Self> {
let (tokio, client) = Self::build_client(params.clone()).await?;
pub async fn try_connect(params: Arc<ConnectionParams>) -> Result<Self> {
let (tokio, client) = Self::build_client(&params).await?;
let number: C::BlockNumber = Zero::zero();
let genesis_hash_client = client.clone();
@@ -173,7 +174,7 @@ impl<C: Chain> Client<C> {
/// Build client to use in connection.
async fn build_client(
params: ConnectionParams,
params: &ConnectionParams,
) -> Result<(Arc<tokio::runtime::Runtime>, Arc<RpcClient>)> {
let tokio = tokio::runtime::Runtime::new()?;
let uri = format!(