Skip to content

Commit

Permalink
style: improved linter complience
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Nov 23, 2023
1 parent e3451ad commit b6a3681
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 24 deletions.
34 changes: 21 additions & 13 deletions src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//! This module handles the execution logic of the contract.
// Clippy pedantic is disabled for `entry_point` functions since they require a certain signature.
#![allow(clippy::pedantic)]

use cosmwasm_std::entry_point;
use cosmwasm_std::{to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};

Expand All @@ -16,6 +13,7 @@ use crate::types::ContractError;

/// Instantiates the contract.
#[entry_point]
#[allow(clippy::pedantic)]
pub fn instantiate(
deps: DepsMut,
env: Env,
Expand Down Expand Up @@ -55,6 +53,7 @@ pub fn instantiate(

/// Handles the execution of the contract.
#[entry_point]
#[allow(clippy::pedantic)]
pub fn execute(
deps: DepsMut,
env: Env,
Expand Down Expand Up @@ -84,6 +83,7 @@ pub fn execute(

/// Handles the query of the contract.
#[entry_point]
#[allow(clippy::pedantic)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::GetContractState {} => to_json_binary(&query::state(deps)?),
Expand All @@ -95,6 +95,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {

/// Migrate contract if version is lower than current version
#[entry_point]
#[allow(clippy::pedantic)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {
migrate::validate_semver(deps.as_ref())?;

Expand All @@ -108,9 +109,13 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, C
mod execute {
use crate::{ibc::types::packet::IcaPacketData, types::msg::options::ChannelOpenInitOptions};

use super::*;
use super::{
new_ica_channel_open_init_cosmos_msg, Binary, ContractError, DepsMut, Env, MessageInfo,
Response, STATE,
};

/// Submits a stargate MsgChannelOpenInit to the chain.
/// Submits a stargate `MsgChannelOpenInit` to the chain.
#[allow(clippy::needless_pass_by_value)]
pub fn create_channel(
deps: DepsMut,
env: Env,
Expand All @@ -135,6 +140,7 @@ mod execute {
}

// Sends custom messages to the ICA host.
#[allow(clippy::needless_pass_by_value)]
pub fn send_custom_ica_messages(
deps: DepsMut,
env: Env,
Expand All @@ -155,6 +161,7 @@ mod execute {
}

/// Update the ownership of the contract.
#[allow(clippy::needless_pass_by_value)]
pub fn update_ownership(
deps: DepsMut,
env: Env,
Expand All @@ -171,6 +178,7 @@ mod execute {
}

/// Updates the callback address.
#[allow(clippy::needless_pass_by_value)]
pub fn update_callback_address(
deps: DepsMut,
info: MessageInfo,
Expand All @@ -191,7 +199,10 @@ mod execute {
}

mod query {
use super::*;
use super::{
CallbackCounter, ChannelState, ContractState, Deps, StdResult, CALLBACK_COUNTER,
CHANNEL_STATE, STATE,
};

/// Returns the saved contract state.
pub fn state(deps: Deps) -> StdResult<ContractState> {
Expand All @@ -210,7 +221,7 @@ mod query {
}

mod migrate {
use super::*;
use super::{ContractError, Deps, CONTRACT_NAME, CONTRACT_VERSION};

pub fn validate_semver(deps: Deps) -> Result<(), ContractError> {
let prev_cw2_version = cw2::get_contract_version(deps.storage)?;
Expand All @@ -225,7 +236,7 @@ mod migrate {
let prev_version: semver::Version = prev_cw2_version.version.parse()?;
if prev_version >= version {
return Err(ContractError::InvalidMigrationVersion {
expected: format!("> {}", prev_version),
expected: format!("> {prev_version}"),
actual: CONTRACT_VERSION.to_string(),
});
}
Expand Down Expand Up @@ -306,7 +317,7 @@ mod tests {

// Ensure the contract admin can send custom messages
let custom_msg_str = r#"{"@type": "/cosmos.bank.v1beta1.MsgSend", "from_address": "cosmos15ulrf36d4wdtrtqzkgaan9ylwuhs7k7qz753uk", "to_address": "cosmos15ulrf36d4wdtrtqzkgaan9ylwuhs7k7qz753uk", "amount": [{"denom": "stake", "amount": "5000"}]}"#;
let messages_str = format!(r#"{{"messages": [{}]}}"#, custom_msg_str);
let messages_str = format!(r#"{{"messages": [{custom_msg_str}]}}"#);
let base64_json_messages = base64::encode(messages_str.as_bytes());
let messages = Binary::from_base64(&base64_json_messages).unwrap();

Expand Down Expand Up @@ -428,10 +439,7 @@ mod tests {
let res = migrate(deps.as_mut(), mock_env(), MigrateMsg {});
assert_eq!(
res.unwrap_err().to_string(),
format!(
"invalid migration version: expected > 100.0.0, got {}",
CONTRACT_VERSION
)
format!("invalid migration version: expected > 100.0.0, got {CONTRACT_VERSION}")
);
}
}
18 changes: 13 additions & 5 deletions src/ibc/handshake.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//! This module contains the entry points for the IBC handshake.
// Clippy pedantic is disabled for `entry_point` functions since they require a certain signature.
#![allow(clippy::pedantic)]

use cosmwasm_std::entry_point;
use cosmwasm_std::{
DepsMut, Env, Ibc3ChannelOpenResponse, IbcBasicResponse, IbcChannel, IbcChannelCloseMsg,
Expand All @@ -18,6 +15,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
#[entry_point]
#[allow(clippy::pedantic)]
pub fn ibc_channel_open(
deps: DepsMut,
_env: Env,
Expand All @@ -32,6 +30,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
#[entry_point]
#[allow(clippy::pedantic)]
pub fn ibc_channel_connect(
deps: DepsMut,
_env: Env,
Expand All @@ -48,6 +47,7 @@ pub fn ibc_channel_connect(

/// Handles the `ChanCloseInit` and `ChanCloseConfirm` for the IBC module.
#[entry_point]
#[allow(clippy::pedantic)]
pub fn ibc_channel_close(
deps: DepsMut,
_env: Env,
Expand All @@ -62,9 +62,14 @@ pub fn ibc_channel_close(
mod ibc_channel_open {
use crate::types::callbacks::IcaControllerCallbackMsg;

use super::*;
use super::{
ChannelState, ContractError, DepsMut, Ibc3ChannelOpenResponse, IbcBasicResponse,
IbcChannel, IbcChannelOpenResponse, IbcOrder, IcaMetadata, CHANNEL_STATE, HOST_PORT_ID,
STATE,
};

/// Handles the `OpenInit` part of the IBC handshake.
#[allow(clippy::needless_pass_by_value)]
pub fn init(
deps: DepsMut,
channel: IbcChannel,
Expand Down Expand Up @@ -121,6 +126,7 @@ mod ibc_channel_open {
}

/// Handles the `OpenAck` part of the IBC handshake.
#[allow(clippy::needless_pass_by_value)]
pub fn on_acknowledgement(
deps: DepsMut,
mut channel: IbcChannel,
Expand Down Expand Up @@ -182,8 +188,10 @@ mod ibc_channel_open {
}

mod ibc_channel_close {
use super::*;
use super::{ContractError, DepsMut, IbcBasicResponse, IbcChannel, CHANNEL_STATE};

/// Handles the `ChanCloseConfirm` for the IBC module.
#[allow(clippy::needless_pass_by_value)]
pub fn confirm(deps: DepsMut, channel: IbcChannel) -> Result<IbcBasicResponse, ContractError> {
// Validate that this is the stored channel
let mut channel_state = CHANNEL_STATE.load(deps.storage)?;
Expand Down
13 changes: 8 additions & 5 deletions src/ibc/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
//! - The IBC packet timeout.
//! - The IBC packet receive.
// Clippy pedantic is disabled for `entry_point` functions since they require a certain signature.
#![allow(clippy::pedantic)]

use cosmwasm_std::entry_point;
use cosmwasm_std::{
from_json, DepsMut, Env, IbcBasicResponse, IbcPacketAckMsg, IbcPacketReceiveMsg,
Expand All @@ -21,6 +18,7 @@ use super::types::{events, packet::acknowledgement::Data as AcknowledgementData}

/// Implements the IBC module's `OnAcknowledgementPacket` handler.
#[entry_point]
#[allow(clippy::pedantic)]
pub fn ibc_packet_ack(
deps: DepsMut,
_env: Env,
Expand All @@ -39,6 +37,7 @@ pub fn ibc_packet_ack(

/// Implements the IBC module's `OnTimeoutPacket` handler.
#[entry_point]
#[allow(clippy::pedantic)]
pub fn ibc_packet_timeout(
deps: DepsMut,
_env: Env,
Expand All @@ -58,6 +57,7 @@ pub fn ibc_packet_timeout(

/// Handles the `PacketReceive` for the IBC module.
#[entry_point]
#[allow(clippy::pedantic)]
pub fn ibc_packet_receive(
_deps: DepsMut,
_env: Env,
Expand All @@ -76,10 +76,11 @@ mod ibc_packet_ack {
state::{CALLBACK_COUNTER, STATE},
};

use super::*;
use super::{events, AcknowledgementData, ContractError, DepsMut, IbcBasicResponse};

/// Handles the successful acknowledgement of an ica packet. This means that the
/// transaction was successfully executed on the host chain.
#[allow(clippy::needless_pass_by_value)]
pub fn success(
deps: DepsMut,
packet: IbcPacket,
Expand Down Expand Up @@ -113,6 +114,7 @@ mod ibc_packet_ack {

/// Handles the unsuccessful acknowledgement of an ica packet. This means that the
/// transaction failed to execute on the host chain.
#[allow(clippy::needless_pass_by_value)]
pub fn error(
deps: DepsMut,
packet: IbcPacket,
Expand Down Expand Up @@ -150,9 +152,10 @@ mod ibc_packet_timeout {

use crate::types::{callbacks::IcaControllerCallbackMsg, state::STATE};

use super::*;
use super::{ContractError, DepsMut, IbcBasicResponse, CALLBACK_COUNTER};

/// Handles the timeout callbacks.
#[allow(clippy::needless_pass_by_value)]
pub fn callback(
deps: DepsMut,
packet: IbcPacket,
Expand Down
4 changes: 3 additions & 1 deletion src/types/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ pub const CALLBACK_COUNTER: Item<CallbackCounter> = Item::new("callback_counter"
mod contract {
use crate::ibc::types::metadata::TxEncoding;

use cosmwasm_schema::schemars::JsonSchema;

use super::{cw_serde, Addr, ContractError};

/// State is the state of the contract.
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq)]
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[allow(clippy::derive_partial_eq_without_eq)]
pub struct State {
/// The Interchain Account (ICA) info needed to send packets.
Expand Down

0 comments on commit b6a3681

Please sign in to comment.