Skip to content

Commit

Permalink
feat(client): try get evm network from env by default on client::init…
Browse files Browse the repository at this point in the history
…(_local)
  • Loading branch information
mickvandijke committed Jan 9, 2025
1 parent d19d5e3 commit 2360b17
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
6 changes: 2 additions & 4 deletions ant-cli/src/actions/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// KIND, either express or implied. Please review the Licences for the specific language governing
// permissions and limitations relating to use of the SAFE Network Software.

use autonomi::Client;
use autonomi::Multiaddr;
use autonomi::{get_evm_network_from_env, Client};
use color_eyre::eyre::bail;
use color_eyre::eyre::Result;
use indicatif::ProgressBar;
Expand All @@ -23,9 +23,7 @@ pub async fn connect_to_network(peers: Vec<Multiaddr>) -> Result<Client> {
progress_bar.set_message("Connecting to The Autonomi Network...");

match Client::init_with_peers(peers).await {
Ok(mut client) => {
let evm_network = get_evm_network_from_env()?;
client.set_evm_network(evm_network);
Ok(client) => {
info!("Connected to the Network");
progress_bar.finish_with_message("Connected to the Network");
Ok(client)
Expand Down
10 changes: 3 additions & 7 deletions autonomi/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Default for ClientConfig {
#[cfg(not(feature = "local"))]
local: false,
peers: None,
evm_network: Default::default(),
evm_network: EvmNetwork::try_from_env().unwrap_or_default(),
}
}
}
Expand Down Expand Up @@ -155,7 +155,7 @@ impl Client {
Self::init_with_config(ClientConfig {
local,
peers: Some(peers),
evm_network: Default::default(),
evm_network: EvmNetwork::try_from_env().unwrap_or_default(),
})
.await
}
Expand Down Expand Up @@ -262,7 +262,7 @@ impl Client {
Ok(Self {
network,
client_event_sender: Arc::new(None),
evm_network: Default::default(),
evm_network: EvmNetwork::try_from_env().unwrap_or_default(),
})
}

Expand All @@ -275,10 +275,6 @@ impl Client {

client_event_receiver
}

pub fn set_evm_network(&mut self, evm_network: EvmNetwork) {
self.evm_network = evm_network;
}
}

fn build_client_and_run_swarm(local: bool) -> (Network, mpsc::Receiver<NetworkEvent>) {
Expand Down
7 changes: 7 additions & 0 deletions evmlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// permissions and limitations relating to use of the SAFE Network Software.

use crate::common::Address;
use crate::utils::get_evm_network_from_env;
use alloy::primitives::address;
use alloy::transports::http::reqwest;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -103,6 +104,12 @@ impl std::fmt::Display for Network {
}

impl Network {
pub fn try_from_env() -> Result<Self, utils::Error> {
get_evm_network_from_env().inspect_err(|err| {
warn!("Failed to select EVM network from ENV: {err}");
})
}

pub fn new_custom(rpc_url: &str, payment_token_addr: &str, chunk_payments_addr: &str) -> Self {
Self::Custom(CustomNetwork::new(
rpc_url,
Expand Down

0 comments on commit 2360b17

Please sign in to comment.