This guide provides practical instructions for interacting with the Contract Manager module, including handling failures and resubmitting failed operations.
When developing contracts that use IBC functionality on Neutron, you need to properly handle acknowledgments:
Copy
Ask AI
// Example of a proper IBC acknowledgment handler in CosmWasm#[entry_point]pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> Result<Response, ContractError> { match msg { SudoMsg::Response { request, data } => { // Store the data instead of processing it immediately PENDING_RESPONSES.save(deps.storage, &data)?; // Return success - failures will be captured by Contract Manager Ok(Response::new().add_attribute("action", "response_received")) }, _ => Err(ContractError::UnknownSudoMsg {}), }}
Here’s a pattern for robust IBC acknowledgment handling:
Copy
Ask AI
// Store received acknowledgment for later processing#[entry_point]pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> Result<Response, ContractError> { match msg { SudoMsg::IbcAcknowledgement { ack, .. } => { // Just store the acknowledgment with minimal processing PENDING_ACKS.save(deps.storage, &ack)?; Ok(Response::new().add_attribute("action", "ack_stored")) }, _ => Err(ContractError::UnknownSudoMsg {}), }}// Process stored acknowledgments with separate message#[entry_point]pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> Result<Response, ContractError> { match msg { ExecuteMsg::ProcessPendingAcks {} => { let acks = PENDING_ACKS.load(deps.storage)?; // Process acks with full gas available // ... Ok(Response::new().add_attribute("action", "processed_acks")) }, // Handle resubmission of failures ExecuteMsg::ResubmitFailure { id } => { Ok(Response::new() .add_message(NeutronMsg::ResubmitFailure { failure_id: id }) .add_attribute("action", "resubmit")) }, // Other execute messages // ... }}