From e79ce982958b912c82de2e2eb6065438a98e8e62 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 16 Nov 2023 10:06:49 -0600 Subject: [PATCH] fix: handle parsing and network errors in address new --- bdk-ffi/src/bitcoin.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bdk-ffi/src/bitcoin.rs b/bdk-ffi/src/bitcoin.rs index b6e19de3..39ed6eda 100644 --- a/bdk-ffi/src/bitcoin.rs +++ b/bdk-ffi/src/bitcoin.rs @@ -74,12 +74,16 @@ pub struct Address { impl Address { pub fn new(address: String, network: Network) -> Result { + let parsed_address = address + .parse::>() + .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::>() - .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, }) }