Skip to content

Commit

Permalink
Avoid unwrap() when parsing pubkeys
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
grunch and coderabbitai[bot] authored Dec 28, 2024
1 parent ea15cd9 commit a5f956b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/app/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,20 @@ async fn notify_invalid_amount(order: &Order, request_id: Option<u64>) {
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,
Expand Down

0 comments on commit a5f956b

Please sign in to comment.