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