Skip to content

Commit

Permalink
chore: removes panics from wallet burn task (#6163)
Browse files Browse the repository at this point in the history
Description
---
Removes panics from wallet burn task
  • Loading branch information
SWvheerden authored Mar 1, 2024
1 parent b759316 commit a875934
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions applications/minotari_console_wallet/src/ui/state/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,19 @@ pub async fn send_burn_transaction_task(
// burning minotari
// ----------------------------------------------------------------------------

let (burn_tx_id, original_proof) = transaction_service_handle
let (burn_tx_id, original_proof) = match transaction_service_handle
.burn_tari(amount, selection_criteria, fee_per_gram, message, claim_public_key)
.await
.map_err(|err| {
log::error!("failed to burn minotari: {:?}", err);

{
Ok((burn_tx_id, original_proof)) => (burn_tx_id, original_proof),
Err(e) => {
error!(target: LOG_TARGET, "failed to burn minotari: {:?}", e);
result_tx
.send(UiTransactionBurnStatus::Error(UiError::from(err).to_string()))
.send(UiTransactionBurnStatus::Error(format!("burn error: {}", e)))
.unwrap();
})
.unwrap();

return;
},
};
// ----------------------------------------------------------------------------
// starting a feedback loop to wait for the answer from the transaction service
// ----------------------------------------------------------------------------
Expand All @@ -292,14 +293,38 @@ pub async fn send_burn_transaction_task(
range_proof: original_proof.range_proof.0,
};

let serialized_proof =
serde_json::to_string_pretty(&wrapped_proof).expect("failed to serialize burn proof");
let serialized_proof = match serde_json::to_string_pretty(&wrapped_proof) {
Ok(proof) => proof,
Err(e) => {
error!(target: LOG_TARGET, "failed to serialize burn proof: {:?}", e);
result_tx
.send(UiTransactionBurnStatus::Error(format!(
"failure to create proof {:?}",
e
)))
.unwrap();
return;
},
};

let proof_id = random::<u32>();

let filepath =
burn_proof_filepath.unwrap_or_else(|| PathBuf::from(format!("{}.json", proof_id)));

std::fs::write(filepath, serialized_proof.as_bytes()).expect("failed to save burn proof");
match std::fs::write(filepath, serialized_proof.as_bytes()) {
Ok(()) => {},
Err(e) => {
error!(target: LOG_TARGET, "failed to write burn proof: {:?}", e);
result_tx
.send(UiTransactionBurnStatus::Error(format!(
"failure to write proof {:?}",
e
)))
.unwrap();
return;
},
};

let result = db.create_burnt_proof(
proof_id,
Expand Down

0 comments on commit a875934

Please sign in to comment.