use ic_agent::{Agent, Identity};
use ic_oss_types::format_error;
use std::sync::Arc;
pub async fn build_agent(host: &str, identity: Arc<dyn Identity>) -> Result<Agent, String> {
let agent = Agent::builder()
.with_url(host)
.with_arc_identity(identity)
.with_verify_query_signatures(false);
let agent = if host.starts_with("https://") {
agent
.with_background_dynamic_routing()
.build()
.map_err(format_error)?
} else {
agent.build().map_err(format_error)?
};
if host.starts_with("http://") {
let _ = agent.fetch_root_key().await;
}
Ok(agent)
}