diff --git a/packages/interchain-interceptor-base/src/error.rs b/packages/interchain-interceptor-base/src/error.rs index a7276b1f..c5f7f275 100644 --- a/packages/interchain-interceptor-base/src/error.rs +++ b/packages/interchain-interceptor-base/src/error.rs @@ -15,6 +15,12 @@ pub enum ContractError { #[error("ICA is not registered")] IcaNotRegistered {}, + + #[error("ICA registration is in progress right now")] + IcaInProgress {}, + + #[error("ICA is already registered")] + IcaAlreadyRegistered {}, } pub type ContractResult = Result; diff --git a/packages/interchain-interceptor-base/src/execute.rs b/packages/interchain-interceptor-base/src/execute.rs index 06f2770e..e53ed00d 100644 --- a/packages/interchain-interceptor-base/src/execute.rs +++ b/packages/interchain-interceptor-base/src/execute.rs @@ -13,7 +13,7 @@ use serde::{de::DeserializeOwned, Serialize}; use crate::{ error::{ContractError, ContractResult}, msg::ExecuteMsg, - state::{BaseConfig, InterchainIntercaptorBase, State, ICA_ID, LOCAL_DENOM}, + state::{BaseConfig, IcaState, InterchainIntercaptorBase, State, ICA_ID, LOCAL_DENOM}, }; impl<'a, T, C> InterchainIntercaptorBase<'a, T, C> @@ -56,10 +56,10 @@ where ) -> ContractResult> { let config = self.config.load(deps.storage)?; let state: State = self.state.load(deps.storage)?; - if state.under_execution { - Err(ContractError::Std(cosmwasm_std::StdError::GenericErr { - msg: "ICA is already registered or under execution".to_string(), - })) + if state.ica_state == IcaState::InProgress { + Err(ContractError::IcaInProgress {}) + } else if state.ica_state == IcaState::Registered { + Err(ContractError::IcaAlreadyRegistered {}) } else { let register = NeutronMsg::register_interchain_account(config.connection_id(), ICA_ID.to_string()); @@ -70,7 +70,7 @@ where &State { last_processed_height: None, ica: None, - under_execution: true, + ica_state: IcaState::InProgress, }, )?; diff --git a/packages/interchain-interceptor-base/src/state.rs b/packages/interchain-interceptor-base/src/state.rs index 4f0e711d..ad6bc4a0 100644 --- a/packages/interchain-interceptor-base/src/state.rs +++ b/packages/interchain-interceptor-base/src/state.rs @@ -64,12 +64,21 @@ pub struct Transfer { pub amount: String, } +#[cw_serde] +#[derive(Default)] +pub enum IcaState { + #[default] + None, + InProgress, + Registered, +} + #[cw_serde] #[derive(Default)] pub struct State { pub last_processed_height: Option, pub ica: Option, - pub under_execution: bool, + pub ica_state: IcaState, } pub type Recipient = str; diff --git a/packages/interchain-interceptor-base/src/sudo.rs b/packages/interchain-interceptor-base/src/sudo.rs index 319da598..4de23632 100644 --- a/packages/interchain-interceptor-base/src/sudo.rs +++ b/packages/interchain-interceptor-base/src/sudo.rs @@ -20,7 +20,7 @@ use serde::{de::DeserializeOwned, Serialize}; use crate::{ msg::OpenAckVersion, - state::{BaseConfig, InterchainIntercaptorBase, State, Transfer}, + state::{BaseConfig, IcaState, InterchainIntercaptorBase, State, Transfer}, }; impl<'a, T, C> InterchainIntercaptorBase<'a, T, C> @@ -132,7 +132,7 @@ where &State { last_processed_height: None, ica: Some(parsed_version.address), - under_execution: true, + ica_state: IcaState::Registered, }, )?; return Ok(Response::default());