Parse the FVM network and set the global value.
(s: &str)
| 67 | |
| 68 | /// Parse the FVM network and set the global value. |
| 69 | fn parse_network(s: &str) -> Result<Network, String> { |
| 70 | match s.to_lowercase().as_str() { |
| 71 | "main" | "mainnet" | "f" => Ok(Network::Mainnet), |
| 72 | "test" | "testnet" | "t" => Ok(Network::Testnet), |
| 73 | n => { |
| 74 | let n: u8 = n |
| 75 | .parse() |
| 76 | .map_err(|e| format!("expected 0 or 1 for network: {e}"))?; |
| 77 | |
| 78 | let n = Network::from_u8(n).ok_or_else(|| format!("unexpected network: {s}"))?; |
| 79 | |
| 80 | Ok(n) |
| 81 | } |
| 82 | } |
| 83 | } |