Skip to content

Commit d0873d1

Browse files
committed
refactor(silentpayments): use BDKCliError in parse_sp_code_value_pairs error return value
1 parent 4154a33 commit d0873d1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/utils.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,22 @@ pub(crate) fn parse_recipient(s: &str) -> Result<(ScriptBuf, u64), String> {
5252
}
5353

5454
#[cfg(feature = "sp")]
55-
pub(crate) fn parse_sp_code_value_pairs(s: &str) -> Result<(SilentPaymentCode, u64), String> {
55+
pub(crate) fn parse_sp_code_value_pairs(s: &str) -> Result<(SilentPaymentCode, u64), Error> {
5656
let parts: Vec<&str> = s.split(':').collect();
5757
if parts.len() != 2 {
58-
return Err(format!("Invalid format '{}'. Expected 'key:value'", s));
58+
return Err(Error::Generic(format!(
59+
"Invalid format '{}'. Expected 'key:value'",
60+
s
61+
)));
5962
}
6063

6164
let value_0 = parts[0].trim();
62-
let key = SilentPaymentCode::try_from(value_0)
63-
.map_err(|_| format!("Invalid silent payment address: {}", value_0))?;
65+
let key = SilentPaymentCode::try_from(value_0)?;
6466

6567
let value = parts[1]
6668
.trim()
6769
.parse::<u64>()
68-
.map_err(|_| format!("Invalid number '{}' for key '{}'", parts[1], key))?;
70+
.map_err(|_| Error::Generic(format!("Invalid number '{}' for key '{}'", parts[1], key)))?;
6971

7072
Ok((key, value))
7173
}

0 commit comments

Comments
 (0)