Skip to content

Commit a341b70

Browse files
committed
Impl TryFrom<&str> for Network
1 parent a0d5c5b commit a341b70

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/utils/common.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,25 @@ impl From<Network> for &str {
4646
}
4747
}
4848

49+
impl TryFrom<&str> for Network {
50+
type Error = crate::Error;
51+
52+
fn try_from(value: &str) -> std::result::Result<Self, Self::Error> {
53+
let res = match value {
54+
"bitcoin" | "main" => Self::Mainnet, // We also take the core style argument
55+
"regtest" => Self::Regtest,
56+
"testnet" | "signet" | "test" => Self::Testnet, // core arg
57+
_ => {
58+
return Err(Error::GenericError(format!(
59+
"Unknown value for network: {}",
60+
value
61+
)))
62+
}
63+
};
64+
Ok(res)
65+
}
66+
}
67+
4968
/// A silent payment address struct that can be used to deserialize a silent payment address string.
5069
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
5170
pub struct SilentPaymentAddress {

0 commit comments

Comments
 (0)