1pub mod call;
8pub mod http;
9pub mod icrc;
10pub mod mgmt;
11pub mod provision;
12pub mod signature;
13pub mod timer;
14
15pub use mgmt::*;
16
17use crate::{Error, ThisError, ops::OpsError};
18
19#[derive(Debug, ThisError)]
24pub enum IcOpsError {
25 #[error(transparent)]
26 ProvisionOpsError(#[from] provision::ProvisionOpsError),
27
28 #[error(transparent)]
29 SignatureOpsError(#[from] signature::SignatureOpsError),
30}
31
32impl From<IcOpsError> for Error {
33 fn from(err: IcOpsError) -> Self {
34 OpsError::from(err).into()
35 }
36}
37
38#[derive(Clone, Copy, Debug, Eq, PartialEq)]
44pub enum Network {
45 Ic,
46 Local,
47}
48
49impl Network {
50 #[must_use]
51 pub const fn as_str(self) -> &'static str {
52 match self {
53 Self::Ic => "ic",
54 Self::Local => "local",
55 }
56 }
57}
58
59impl core::fmt::Display for Network {
60 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
61 f.write_str(self.as_str())
62 }
63}
64
65#[must_use]
71pub fn build_network_from_dfx_network(dfx_network: Option<&'static str>) -> Option<Network> {
72 match dfx_network {
73 Some("local") => Some(Network::Local),
74 Some("ic") => Some(Network::Ic),
75
76 _ => None,
77 }
78}
79
80#[must_use]
96pub fn build_network() -> Option<Network> {
97 build_network_from_dfx_network(option_env!("DFX_NETWORK"))
98}
99
100#[cfg(test)]
101mod tests {
102 use super::*;
103
104 #[test]
105 fn build_network_from_dfx_network_parses_ic() {
106 assert_eq!(
107 build_network_from_dfx_network(Some("ic")),
108 Some(Network::Ic)
109 );
110 }
111
112 #[test]
113 fn build_network_from_dfx_network_parses_local() {
114 assert_eq!(
115 build_network_from_dfx_network(Some("local")),
116 Some(Network::Local)
117 );
118 }
119
120 #[test]
121 fn build_network_from_dfx_network_rejects_unknown() {
122 assert_eq!(build_network_from_dfx_network(Some("nope")), None);
123 }
124
125 #[test]
126 fn build_network_from_dfx_network_handles_missing() {
127 assert_eq!(build_network_from_dfx_network(None), None);
128 }
129}