feat: add is_valid_for_network method on address type

This commit is contained in:
thunderbiscuit 2024-01-17 11:12:24 -05:00
parent b305f8f44e
commit 25a48e0565
No known key found for this signature in database
GPG Key ID: 88253696EB836462
2 changed files with 11 additions and 0 deletions

View File

@ -469,6 +469,8 @@ interface Address {
string to_qr_uri();
boolean is_valid_for_network(Network network);
string as_string();
};

View File

@ -423,6 +423,15 @@ impl Address {
self.inner.to_qr_uri()
}
pub fn is_valid_for_network(&self, network: Network) -> bool {
let address_str = self.inner.to_string();
if let Ok(unchecked_address) = address_str.parse::<BdkAddress<NetworkUnchecked>>() {
unchecked_address.is_valid_for_network(network.into())
} else {
false
}
}
fn as_string(&self) -> String {
self.inner.to_string()
}