Skip to content

Commit

Permalink
add handle sudo error
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Oct 9, 2023
1 parent 23489f6 commit 450f983
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/Basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install stable toolchain
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.60.0
toolchain: 1.71
override: true
components: rustfmt, clippy

Expand Down
35 changes: 0 additions & 35 deletions .github/workflows/Release.yml

This file was deleted.

42 changes: 41 additions & 1 deletion src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use neutron_sdk::bindings::msg::{IbcFee, NeutronMsg};
use neutron_sdk::bindings::query::NeutronQuery;
use neutron_sdk::bindings::types::ProtobufAny;
use neutron_sdk::query::min_ibc_fee::query_min_ibc_fee;
use neutron_sdk::sudo::msg::{RequestPacketTimeoutHeight, SudoMsg};
use neutron_sdk::sudo::msg::{RequestPacket, RequestPacketTimeoutHeight, SudoMsg};
use neutron_sdk::{NeutronError, NeutronResult};

use crate::error::ContractError;
Expand Down Expand Up @@ -288,10 +288,28 @@ pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> StdResult<Response> {
counterparty_channel_id,
counterparty_version,
),
SudoMsg::Error { request, details } => sudo_error(deps, request, details),
SudoMsg::Timeout { request } => sudo_timeout(deps, request),
_ => Ok(Response::default()),
}
}

fn sudo_error(deps: DepsMut, _request: RequestPacket, _details: String) -> StdResult<Response> {
let current_stage = STAGE.load(deps.storage)?;
let stage = previous_stage(current_stage)?;
STAGE.save(deps.storage, &stage)?;

Ok(Response::default())
}

fn sudo_timeout(deps: DepsMut, _request: RequestPacket) -> StdResult<Response> {
let current_stage = STAGE.load(deps.storage)?;
let stage = previous_stage(current_stage)?;
STAGE.save(deps.storage, &stage)?;

Ok(Response::default())
}

fn sudo_open_ack(
deps: DepsMut,
_env: Env,
Expand Down Expand Up @@ -335,3 +353,25 @@ fn min_ntrn_ibc_fee(deps: Deps<NeutronQuery>) -> NeutronResult<IbcFee> {
.collect(),
})
}

fn previous_stage(stage: ExecuteMsg) -> StdResult<ExecuteMsg> {
let stages = [
ExecuteMsg::ClaimUnclaimed {},
ExecuteMsg::CreateHubICA {},
ExecuteMsg::SendClaimedTokensToICA {},
ExecuteMsg::FundCommunityPool {},
ExecuteMsg::Done {},
];
let i = stages
.iter()
.position(|s| *s == stage)
.ok_or_else(|| StdError::generic_err(format!("Incorrect stage: {:?}", stage)))?;

if i == 0 {
return Err(StdError::generic_err(
"no previous stage for the first stage",
));
}

Ok(stages[i - 1].clone())
}

0 comments on commit 450f983

Please sign in to comment.