Skip to content

Commit

Permalink
fix: handle parsing and network errors in address new
Browse files Browse the repository at this point in the history
  • Loading branch information
reez committed Nov 16, 2023
1 parent f2cd561 commit 08674fa
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions bdk-ffi/src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@ pub struct Address {

impl Address {
pub fn new(address: String, network: Network) -> Result<Self, BdkError> {
let parsed_address = address
.parse::<bdk::bitcoin::Address<NetworkUnchecked>>()
.map_err(|e| BdkError::Generic(e.to_string()))?;

let network_checked_address = parsed_address
.require_network(network.into())
.map_err(|e| BdkError::Generic(e.to_string()))?;

Ok(Address {
inner: address
.parse::<bdk::bitcoin::Address<NetworkUnchecked>>()
.unwrap() // TODO 11: Handle error correctly by rethrowing it as a BdkError
.require_network(network.into())
.map_err(|e| BdkError::Generic(e.to_string()))?,
inner: network_checked_address,
})
}

Expand Down

0 comments on commit 08674fa

Please sign in to comment.