Skip to content

Commit

Permalink
Add errors and enum
Browse files Browse the repository at this point in the history
  • Loading branch information
albertandrejev committed Dec 7, 2023
1 parent 38f6891 commit 4a058c3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
6 changes: 6 additions & 0 deletions packages/interchain-interceptor-base/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = Result<T, ContractError>;
12 changes: 6 additions & 6 deletions packages/interchain-interceptor-base/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -56,10 +56,10 @@ where
) -> ContractResult<Response<NeutronMsg>> {
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());
Expand All @@ -70,7 +70,7 @@ where
&State {
last_processed_height: None,
ica: None,
under_execution: true,
ica_state: IcaState::InProgress,
},
)?;

Expand Down
11 changes: 10 additions & 1 deletion packages/interchain-interceptor-base/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,
pub ica: Option<String>,
pub under_execution: bool,
pub ica_state: IcaState,
}

pub type Recipient = str;
Expand Down
4 changes: 2 additions & 2 deletions packages/interchain-interceptor-base/src/sudo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 4a058c3

Please sign in to comment.