From 39e5c26e8b0c37eb26f8acdfd17c47a7d7eda101 Mon Sep 17 00:00:00 2001 From: alenmestrov Date: Fri, 20 Dec 2024 16:36:28 +0100 Subject: [PATCH] fix: check the transfer result before doing cross contract call --- .../res/calimero_context_proxy_icp.did | 1 - contracts/icp/context-proxy/src/mutate.rs | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/contracts/icp/context-proxy/res/calimero_context_proxy_icp.did b/contracts/icp/context-proxy/res/calimero_context_proxy_icp.did index 7dd442d89..566c10fff 100644 --- a/contracts/icp/context-proxy/res/calimero_context_proxy_icp.did +++ b/contracts/icp/context-proxy/res/calimero_context_proxy_icp.did @@ -17,7 +17,6 @@ type ICProposalAction = variant { }; }; type ICProposalApprovalWithSigner = record { - added_timestamp : nat64; signer_id : blob; proposal_id : blob; }; diff --git a/contracts/icp/context-proxy/src/mutate.rs b/contracts/icp/context-proxy/src/mutate.rs index b9ab239f2..1c9e721c5 100644 --- a/contracts/icp/context-proxy/src/mutate.rs +++ b/contracts/icp/context-proxy/src/mutate.rs @@ -106,13 +106,24 @@ async fn execute_proposal(proposal_id: &ProposalId) -> Result<(), String> { created_at_time: None, }; - let _: (Result,) = + // Call transfer and explicitly handle the result + let transfer_result: (Result,) = ic_cdk::call(Principal::from(ledger_id), "transfer", (transfer_args,)) .await - .map_err(|e| format!("Transfer failed: {:?}", e))?; + .map_err(|e| format!("Transfer call failed: {:?}", e))?; + + // Check if the transfer was successful + match transfer_result.0 { + Ok(_block_height) => { + // Transfer succeeded, proceed with cross-contract call + } + Err(transfer_error) => { + return Err(format!("Transfer failed: {:?}", transfer_error)); + } + } } - // Then make the actual cross-contract call + // Proceed with cross-contract call only if there was no deposit or transfer succeeded let args_bytes = candid::encode_one(args) .map_err(|e| format!("Failed to encode args: {}", e))?;