dfx_core/interface/
dfx.rs1use crate::DfxInterfaceBuilder;
2use crate::config::model::dfinity::{Config, NetworksConfig};
3use crate::config::model::network_descriptor::NetworkDescriptor;
4use crate::error::builder::BuildDfxInterfaceError;
5use ic_agent::{Agent, Identity};
6use std::sync::Arc;
7
8pub struct DfxInterface {
9 pub(crate) config: Option<Arc<Config>>,
10 pub(crate) agent: Agent,
11 pub(crate) identity: Arc<dyn Identity>,
12 pub(crate) networks_config: NetworksConfig,
13 pub(crate) network_descriptor: NetworkDescriptor,
14}
15
16impl DfxInterface {
17 pub fn builder() -> DfxInterfaceBuilder {
18 DfxInterfaceBuilder::new()
19 }
20
21 pub async fn anonymous() -> Result<DfxInterface, BuildDfxInterfaceError> {
22 DfxInterfaceBuilder::new().anonymous().build().await
23 }
24
25 pub fn config(&self) -> Option<Arc<Config>> {
26 self.config.clone()
27 }
28
29 pub fn agent(&self) -> &Agent {
30 &self.agent
31 }
32
33 pub fn identity(&self) -> Arc<dyn Identity> {
34 self.identity.clone()
35 }
36
37 pub fn networks_config(&self) -> &NetworksConfig {
38 &self.networks_config
39 }
40
41 pub fn network_descriptor(&self) -> &NetworkDescriptor {
42 &self.network_descriptor
43 }
44}