From 6ba1e986024c163bf594c205d095e8deb5f9508f Mon Sep 17 00:00:00 2001 From: Attiss Ngo <92927591+AttissNgo@users.noreply.github.com> Date: Thu, 2 Jan 2025 14:00:35 -0600 Subject: [PATCH] feat(interchain-token-service): parameterize execute error - replace panic_with_error with proper error handling using Result - this changes the AxelarExecutableInterface to return Result<(), soroban_sdk::Error> --- contracts/axelar-gateway/src/executable.rs | 2 +- contracts/example/src/contract.rs | 4 +++- contracts/interchain-token-service/src/contract.rs | 10 ++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/contracts/axelar-gateway/src/executable.rs b/contracts/axelar-gateway/src/executable.rs index e55659bc..a5ba21cf 100644 --- a/contracts/axelar-gateway/src/executable.rs +++ b/contracts/axelar-gateway/src/executable.rs @@ -24,7 +24,7 @@ pub trait AxelarExecutableInterface { message_id: String, source_address: String, payload: Bytes, - ); + ) -> Result<(), soroban_sdk::Error>; /// Validate if a gateway has approved a message. /// This should be called from an implementation of `execute` before executing custom app logic. diff --git a/contracts/example/src/contract.rs b/contracts/example/src/contract.rs index f67cf2aa..5a32f958 100644 --- a/contracts/example/src/contract.rs +++ b/contracts/example/src/contract.rs @@ -23,10 +23,12 @@ impl AxelarExecutableInterface for Example { message_id: String, source_address: String, payload: Bytes, - ) { + ) -> Result<(), soroban_sdk::Error> { let _ = Self::validate_message(&env, &source_chain, &message_id, &source_address, &payload); event::executed(&env, source_chain, message_id, source_address, payload); + + Ok(()) } } diff --git a/contracts/interchain-token-service/src/contract.rs b/contracts/interchain-token-service/src/contract.rs index e3607a6e..5390c1ac 100644 --- a/contracts/interchain-token-service/src/contract.rs +++ b/contracts/interchain-token-service/src/contract.rs @@ -9,7 +9,7 @@ use axelar_soroban_std::{ use interchain_token::InterchainTokenClient; use soroban_sdk::token::{self, StellarAssetClient}; use soroban_sdk::xdr::{FromXdr, ToXdr}; -use soroban_sdk::{contract, contractimpl, panic_with_error, Address, Bytes, BytesN, Env, String}; +use soroban_sdk::{contract, contractimpl, Address, Bytes, BytesN, Env, String}; use soroban_token_sdk::metadata::TokenMetadata; use crate::abi::{get_message_type, MessageType as EncodedMessageType}; @@ -420,12 +420,14 @@ impl AxelarExecutableInterface for InterchainTokenService { message_id: String, source_address: String, payload: Bytes, - ) { + ) -> Result<(), soroban_sdk::Error> { Self::validate_message(&env, &source_chain, &message_id, &source_address, &payload) - .unwrap_or_else(|err| panic_with_error!(env, err)); + .map_err(Into::::into)?; Self::execute_message(&env, source_chain, message_id, source_address, payload) - .unwrap_or_else(|err| panic_with_error!(env, err)); + .map_err(Into::::into)?; + + Ok(()) } }