feat: use display trait for string representation of address type

This commit is contained in:
thunderbiscuit
2024-06-04 13:25:41 -04:00
parent 53afd9c238
commit efef60082b
19 changed files with 33 additions and 31 deletions

View File

@@ -611,6 +611,7 @@ enum WordCount {
"Words24",
};
[Traits=(Display)]
interface Address {
[Throws=AddressError]
constructor(string address, Network network);
@@ -621,8 +622,6 @@ interface Address {
string to_qr_uri();
string as_string();
boolean is_valid_for_network(Network network);
};

View File

@@ -1,4 +1,5 @@
use crate::error::{AddressError, FeeRateError, PsbtError, PsbtParseError, TransactionError};
use std::fmt::Display;
use bdk_bitcoind_rpc::bitcoincore_rpc::jsonrpc::serde_json;
use bdk_wallet::bitcoin::address::{NetworkChecked, NetworkUnchecked};
@@ -100,10 +101,6 @@ impl Address {
self.0.to_qr_uri()
}
pub fn as_string(&self) -> String {
self.0.to_string()
}
pub fn is_valid_for_network(&self, network: Network) -> bool {
let address_str = self.0.to_string();
if let Ok(unchecked_address) = address_str.parse::<BdkAddress<NetworkUnchecked>>() {
@@ -114,6 +111,12 @@ impl Address {
}
}
impl Display for Address {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl From<Address> for BdkAddress {
fn from(address: Address) -> Self {
address.0