Skip to content

Commit 6ede782

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

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/utils/common.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ 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+
_ => return Err(Error::GenericError(format!("Unknown value for network: {}", value)))
58+
};
59+
Ok(res)
60+
}
61+
}
62+
4963
/// A silent payment address struct that can be used to deserialize a silent payment address string.
5064
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
5165
pub struct SilentPaymentAddress {

0 commit comments

Comments
 (0)