Skip to content

Commit

Permalink
fix: check the transfer result before doing cross contract call
Browse files Browse the repository at this point in the history
  • Loading branch information
alenmestrov committed Dec 20, 2024
1 parent 545b72d commit 39e5c26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type ICProposalAction = variant {
};
};
type ICProposalApprovalWithSigner = record {
added_timestamp : nat64;
signer_id : blob;
proposal_id : blob;
};
Expand Down
17 changes: 14 additions & 3 deletions contracts/icp/context-proxy/src/mutate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,24 @@ async fn execute_proposal(proposal_id: &ProposalId) -> Result<(), String> {
created_at_time: None,
};

let _: (Result<u64, TransferError>,) =
// Call transfer and explicitly handle the result
let transfer_result: (Result<u64, TransferError>,) =
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))?;

Expand Down

0 comments on commit 39e5c26

Please sign in to comment.