From a58b5c47331d6bf6c76e34e5183c678d554c23d4 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Sat, 28 Oct 2023 16:34:29 +0300 Subject: [PATCH] refactor: refactored contract --- src/contract.rs | 14 +++++--------- src/ibc/handshake.rs | 7 +++---- src/ibc/mod.rs | 2 ++ src/ibc/relay.rs | 7 +++---- src/lib.rs | 1 + src/types/keys.rs | 9 +++++++++ src/types/mod.rs | 1 + 7 files changed, 24 insertions(+), 17 deletions(-) create mode 100644 src/types/keys.rs diff --git a/src/contract.rs b/src/contract.rs index ef1c1eb2..02c5ace9 100644 --- a/src/contract.rs +++ b/src/contract.rs @@ -1,22 +1,18 @@ //! This module handles the execution logic of the contract. -#[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult}; use crate::ibc::types::stargate::channel::ica_contract_channel_init; +use crate::types::keys::{CONTRACT_NAME, CONTRACT_VERSION}; use crate::types::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; use crate::types::state::{ CallbackCounter, ChannelState, ContractState, CALLBACK_COUNTER, CHANNEL_STATE, STATE, }; use crate::types::ContractError; -// version info for migration -const CONTRACT_NAME: &str = "crates.io:cw-ica-controller"; -const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); - /// Instantiates the contract. -#[cfg_attr(not(feature = "library"), entry_point)] +#[entry_point] pub fn instantiate( deps: DepsMut, env: Env, @@ -53,7 +49,7 @@ pub fn instantiate( } /// Handles the execution of the contract. -#[cfg_attr(not(feature = "library"), entry_point)] +#[entry_point] pub fn execute( deps: DepsMut, env: Env, @@ -81,7 +77,7 @@ pub fn execute( } /// Handles the query of the contract. -#[cfg_attr(not(feature = "library"), entry_point)] +#[entry_point] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { QueryMsg::GetContractState {} => to_binary(&query::state(deps)?), @@ -91,7 +87,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { } /// Migrate contract if version is lower than current version -#[cfg_attr(not(feature = "library"), entry_point)] +#[entry_point] pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { migrate::validate_semver(deps.as_ref())?; diff --git a/src/ibc/handshake.rs b/src/ibc/handshake.rs index 371b1930..ebc57358 100644 --- a/src/ibc/handshake.rs +++ b/src/ibc/handshake.rs @@ -1,6 +1,5 @@ //! This module contains the entry points for the IBC handshake. -#[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ DepsMut, Env, Ibc3ChannelOpenResponse, IbcBasicResponse, IbcChannel, IbcChannelCloseMsg, @@ -15,7 +14,7 @@ use crate::types::{ /// Handles the `OpenInit` and `OpenTry` parts of the IBC handshake. /// In this application, we only handle `OpenInit` messages since we are the ICA controller -#[cfg_attr(not(feature = "library"), entry_point)] +#[entry_point] pub fn ibc_channel_open( deps: DepsMut, _env: Env, @@ -29,7 +28,7 @@ pub fn ibc_channel_open( /// Handles the `OpenAck` and `OpenConfirm` parts of the IBC handshake. /// In this application, we only handle `OpenAck` messages since we are the ICA controller -#[cfg_attr(not(feature = "library"), entry_point)] +#[entry_point] pub fn ibc_channel_connect( deps: DepsMut, _env: Env, @@ -45,7 +44,7 @@ pub fn ibc_channel_connect( } /// Handles the `ChanCloseInit` and `ChanCloseConfirm` for the IBC module. -#[cfg_attr(not(feature = "library"), entry_point)] +#[entry_point] pub fn ibc_channel_close( deps: DepsMut, _env: Env, diff --git a/src/ibc/mod.rs b/src/ibc/mod.rs index 67476f77..34b5e863 100644 --- a/src/ibc/mod.rs +++ b/src/ibc/mod.rs @@ -2,6 +2,8 @@ //! //! The IBC module is responsible for handling the IBC channel handshake and handling IBC packets. +#[cfg(not(feature = "library"))] pub mod handshake; +#[cfg(not(feature = "library"))] pub mod relay; pub mod types; diff --git a/src/ibc/relay.rs b/src/ibc/relay.rs index 26e85f71..db904cde 100644 --- a/src/ibc/relay.rs +++ b/src/ibc/relay.rs @@ -3,7 +3,6 @@ //! - The IBC packet timeout. //! - The IBC packet receive. -#[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ from_binary, DepsMut, Env, IbcBasicResponse, IbcPacketAckMsg, IbcPacketReceiveMsg, @@ -18,7 +17,7 @@ use crate::types::{ use super::types::{events, packet::acknowledgement::AcknowledgementData}; /// Implements the IBC module's `OnAcknowledgementPacket` handler. -#[cfg_attr(not(feature = "library"), entry_point)] +#[entry_point] pub fn ibc_packet_ack( deps: DepsMut, _env: Env, @@ -32,7 +31,7 @@ pub fn ibc_packet_ack( } /// Handles the `PacketTimeout` for the IBC module. -#[cfg_attr(not(feature = "library"), entry_point)] +#[entry_point] pub fn ibc_packet_timeout( deps: DepsMut, _env: Env, @@ -56,7 +55,7 @@ pub fn ibc_packet_timeout( } /// Handles the `PacketReceive` for the IBC module. -#[cfg_attr(not(feature = "library"), entry_point)] +#[entry_point] pub fn ibc_packet_receive( _deps: DepsMut, _env: Env, diff --git a/src/lib.rs b/src/lib.rs index d23d0252..f5874f06 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ #![doc = include_str!("../README.md")] #![deny(missing_docs)] +#[cfg(not(feature = "library"))] pub mod contract; pub mod helpers; pub mod ibc; diff --git a/src/types/keys.rs b/src/types/keys.rs new file mode 100644 index 00000000..9d95e836 --- /dev/null +++ b/src/types/keys.rs @@ -0,0 +1,9 @@ +//! # Keys +//! +//! Contains key constants definitions for the contract such as version info for migrations. + +/// CONTRACT_NAME is the name of the contract recorded with cw2 +pub const CONTRACT_NAME: &str = "crates.io:cw-ica-controller"; +/// CONTRACT_VERSION is the version of the cargo package. +/// This is also the version of the contract recorded in cw2 +pub const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/src/types/mod.rs b/src/types/mod.rs index a0af24b0..6a16c49d 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -2,6 +2,7 @@ pub mod cosmos_msg; mod error; +pub mod keys; pub mod msg; pub mod state;