From a5f956b6a1b8e29b6986ea6617c3158ed2b0c14d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Calder=C3=B3n?= Date: Sat, 28 Dec 2024 13:45:35 -0300 Subject: [PATCH] Avoid unwrap() when parsing pubkeys Using unwrap() can cause panics if the public keys are malformed. Handle the error gracefully or log a warning Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/app/release.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/app/release.rs b/src/app/release.rs index 2513540a..d40de74e 100644 --- a/src/app/release.rs +++ b/src/app/release.rs @@ -409,8 +409,20 @@ async fn notify_invalid_amount(order: &Order, request_id: Option) { if let (Some(buyer_pubkey), Some(seller_pubkey)) = (order.buyer_pubkey.as_ref(), order.seller_pubkey.as_ref()) { - let buyer_pubkey = PublicKey::from_str(buyer_pubkey).unwrap(); - let seller_pubkey = PublicKey::from_str(seller_pubkey).unwrap(); + let buyer_pubkey = match PublicKey::from_str(buyer_pubkey) { + Ok(pk) => pk, + Err(e) => { + error!("Failed to parse buyer pubkey: {:?}", e); + return; + } + }; + let seller_pubkey = match PublicKey::from_str(seller_pubkey) { + Ok(pk) => pk, + Err(e) => { + error!("Failed to parse seller pubkey: {:?}", e); + return; + } + }; send_cant_do_msg( None,