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