dfx_core/interface/
dfx.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::config::model::dfinity::{Config, NetworksConfig};
use crate::config::model::network_descriptor::NetworkDescriptor;
use crate::error::builder::BuildDfxInterfaceError;
use crate::DfxInterfaceBuilder;
use ic_agent::{Agent, Identity};
use std::sync::Arc;

pub struct DfxInterface {
    pub(crate) config: Option<Arc<Config>>,
    pub(crate) agent: Agent,
    pub(crate) identity: Arc<dyn Identity>,
    pub(crate) networks_config: NetworksConfig,
    pub(crate) network_descriptor: NetworkDescriptor,
}

impl DfxInterface {
    pub fn builder() -> DfxInterfaceBuilder {
        DfxInterfaceBuilder::new()
    }

    pub async fn anonymous() -> Result<DfxInterface, BuildDfxInterfaceError> {
        DfxInterfaceBuilder::new().anonymous().build().await
    }

    pub fn config(&self) -> Option<Arc<Config>> {
        self.config.clone()
    }

    pub fn agent(&self) -> &Agent {
        &self.agent
    }

    pub fn identity(&self) -> Arc<dyn Identity> {
        self.identity.clone()
    }

    pub fn networks_config(&self) -> &NetworksConfig {
        &self.networks_config
    }

    pub fn network_descriptor(&self) -> &NetworkDescriptor {
        &self.network_descriptor
    }
}