Skip to content

Commit

Permalink
refactor(admin): Defined ContractResult type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
KirilMihaylov committed Apr 5, 2023
1 parent 987f7b4 commit 1ebe35b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
16 changes: 10 additions & 6 deletions contracts/admin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ use platform::response;
use sdk::cosmwasm_std::entry_point;
use sdk::{
cosmwasm_ext::Response,
cosmwasm_std::{ensure_eq, DepsMut, Env, MessageInfo, Reply, StdResult},
cosmwasm_std::{ensure_eq, DepsMut, Env, MessageInfo, Reply},
};
use versioning::{version, VersionSegment};

use self::{
error::ContractError,
msg::{InstantiateMsg, MigrateMsg, SudoMsg},
result::ContractResult,
state::{contracts as state_contracts, migration_release},
};

pub mod common;
pub mod error;
pub mod migrate_contracts;
pub mod msg;
pub mod result;
pub mod state;

// version info for migration info
Expand All @@ -29,7 +31,7 @@ pub fn instantiate(
_env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
) -> ContractResult<Response> {
versioning::initialize(deps.storage, version!(CONTRACT_STORAGE_VERSION))?;

msg.validate(&deps.querier)?;
Expand All @@ -40,14 +42,16 @@ pub fn instantiate(
}

#[cfg_attr(feature = "contract-with-bindings", entry_point)]
pub fn migrate(deps: DepsMut<'_>, _env: Env, _msg: MigrateMsg) -> StdResult<Response> {
pub fn migrate(deps: DepsMut<'_>, _env: Env, _msg: MigrateMsg) -> ContractResult<Response> {
versioning::update_software(deps.storage, version!(CONTRACT_STORAGE_VERSION))?;

response::response(versioning::release()).map(Into::into)
response::response(versioning::release())
.map(Into::into)
.map_err(Into::into)
}

#[cfg_attr(feature = "contract-with-bindings", entry_point)]
pub fn sudo(deps: DepsMut<'_>, env: Env, msg: SudoMsg) -> Result<Response, ContractError> {
pub fn sudo(deps: DepsMut<'_>, env: Env, msg: SudoMsg) -> ContractResult<Response> {
match msg {
SudoMsg::MigrateContracts(migrate_contracts) => {
migrate_contracts::migrate(deps.storage, env.contract.address, migrate_contracts)
Expand All @@ -56,7 +60,7 @@ pub fn sudo(deps: DepsMut<'_>, env: Env, msg: SudoMsg) -> Result<Response, Contr
}

#[cfg_attr(feature = "contract-with-bindings", entry_point)]
pub fn reply(deps: DepsMut<'_>, _env: Env, msg: Reply) -> Result<Response, ContractError> {
pub fn reply(deps: DepsMut<'_>, _env: Env, msg: Reply) -> ContractResult<Response> {
let expected_release: String = migration_release::load(deps.storage)?;

let reported_release: String =
Expand Down
3 changes: 3 additions & 0 deletions contracts/admin/src/result.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use crate::error::ContractError;

pub type ContractResult<T> = Result<T, ContractError>;

0 comments on commit 1ebe35b

Please sign in to comment.