Skip to content

Commit

Permalink
clippy chill
Browse files Browse the repository at this point in the history
  • Loading branch information
bekauz committed Apr 24, 2024
1 parent 8d05abb commit cf23de2
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 43 deletions.
6 changes: 3 additions & 3 deletions contracts/accessories/listener/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};
use cosmwasm_std::{to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};
use cw2::set_contract_version;

use crate::error::ContractError;
Expand Down Expand Up @@ -60,11 +60,11 @@ pub fn execute(
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Note {} => to_binary(&NOTE.load(deps.storage)?),
QueryMsg::Note {} => to_json_binary(&NOTE.load(deps.storage)?),
QueryMsg::Result {
initiator,
initiator_msg,
} => to_binary(&ResultResponse {
} => to_json_binary(&ResultResponse {
callback: RESULTS.load(deps.storage, (initiator, initiator_msg))?,
}),
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/accessories/listener/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{to_binary, Addr, Empty, Uint64};
use cosmwasm_std::{to_json_binary, Addr, Empty, Uint64};

use cw_multi_test::{App, Contract, ContractWrapper, Executor};
use polytone::callbacks::{Callback, CallbackMessage};
Expand Down Expand Up @@ -87,7 +87,7 @@ fn test() {
// Allows note to execute callback.
let callback = CallbackMessage {
initiator: Addr::unchecked(INITIATOR_ADDR),
initiator_msg: to_binary(INITIATOR_MSG).unwrap(),
initiator_msg: to_json_binary(INITIATOR_MSG).unwrap(),
result: Callback::Execute(Result::Err("ERROR".to_string())),
};
app.execute_contract(
Expand Down Expand Up @@ -118,7 +118,7 @@ fn test() {
listener,
&QueryMsg::Result {
initiator: INITIATOR_ADDR.to_string(),
initiator_msg: to_binary(INITIATOR_MSG).unwrap().to_string(),
initiator_msg: to_json_binary(INITIATOR_MSG).unwrap().to_string(),
},
)
.unwrap();
Expand Down
8 changes: 4 additions & 4 deletions contracts/accessories/polytone-tester/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, WasmMsg,
to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, WasmMsg,
};
use cw2::set_contract_version;

Expand Down Expand Up @@ -58,7 +58,7 @@ pub fn execute(
}
ExecuteMsg::RunOutOfGas {} => Ok(Response::default().add_message(WasmMsg::Execute {
contract_addr: env.contract.address.into_string(),
msg: to_binary(&ExecuteMsg::RunOutOfGas {}).unwrap(),
msg: to_json_binary(&ExecuteMsg::RunOutOfGas {}).unwrap(),
funds: vec![],
})),
}
Expand All @@ -67,10 +67,10 @@ pub fn execute(
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::History {} => to_binary(&CallbackHistoryResponse {
QueryMsg::History {} => to_json_binary(&CallbackHistoryResponse {
history: CALLBACK_HISTORY.load(deps.storage)?,
}),
QueryMsg::HelloHistory {} => to_binary(&HelloHistoryResponse {
QueryMsg::HelloHistory {} => to_json_binary(&HelloHistoryResponse {
history: HELLO_CALL_HISTORY.load(deps.storage)?,
}),
}
Expand Down
13 changes: 7 additions & 6 deletions contracts/main/note/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, Binary, Deps, DepsMut, Env, IbcMsg, IbcTimeout, MessageInfo, Response, StdResult,
to_json_binary, Binary, Deps, DepsMut, Env, IbcMsg, IbcTimeout, MessageInfo, Response,
StdResult,
};
use cw2::set_contract_version;
use polytone::callbacks::CallbackRequestType;
Expand Down Expand Up @@ -106,7 +107,7 @@ pub fn execute(
.add_attribute("method", "execute")
.add_message(IbcMsg::SendPacket {
channel_id,
data: to_binary(&ibc::Packet {
data: to_json_binary(&ibc::Packet {
sender: info.sender.into_string(),
msg,
})
Expand All @@ -118,18 +119,18 @@ pub fn execute(
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::ActiveChannel => to_binary(&CHANNEL.may_load(deps.storage)?),
QueryMsg::Pair => to_binary(&CONNECTION_REMOTE_PORT.may_load(deps.storage)?.map(
QueryMsg::ActiveChannel => to_json_binary(&CHANNEL.may_load(deps.storage)?),
QueryMsg::Pair => to_json_binary(&CONNECTION_REMOTE_PORT.may_load(deps.storage)?.map(
|(connection_id, remote_port)| Pair {
connection_id,
remote_port,
},
)),
QueryMsg::RemoteAddress { local_address } => to_binary(&accounts::query_account(
QueryMsg::RemoteAddress { local_address } => to_json_binary(&accounts::query_account(
deps.storage,
deps.api.addr_validate(&local_address)?,
)?),
QueryMsg::BlockMaxGas => to_binary(&BLOCK_MAX_GAS.load(deps.storage)?),
QueryMsg::BlockMaxGas => to_json_binary(&BLOCK_MAX_GAS.load(deps.storage)?),
}
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/main/note/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_std::{
testing::{mock_dependencies, mock_env, mock_info},
to_binary, Uint64, WasmMsg,
to_json_binary, Uint64, WasmMsg,
};

use crate::{
Expand Down Expand Up @@ -35,7 +35,7 @@ fn simple_note() {
on_behalf_of: None,
msgs: vec![WasmMsg::Execute {
contract_addr: "some_addr".to_string(),
msg: to_binary("some_msg").unwrap(),
msg: to_json_binary("some_msg").unwrap(),
funds: vec![],
}
.into()],
Expand Down
4 changes: 2 additions & 2 deletions contracts/main/proxy/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult, SubMsg,
to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult, SubMsg,
SubMsgResponse, SubMsgResult,
};
use cw2::set_contract_version;
Expand Down Expand Up @@ -65,7 +65,7 @@ pub fn execute(
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Instantiator {} => to_binary(&INSTANTIATOR.load(deps.storage)?),
QueryMsg::Instantiator {} => to_json_binary(&INSTANTIATOR.load(deps.storage)?),
}
}

Expand Down
17 changes: 9 additions & 8 deletions contracts/main/voice/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
from_binary, instantiate2_address, to_binary, to_vec, Binary, CodeInfoResponse, ContractResult,
Deps, DepsMut, Env, MessageInfo, Response, StdResult, SubMsg, SystemResult, Uint64, WasmMsg,
from_json, instantiate2_address, to_json_binary, to_json_vec, Binary, CodeInfoResponse,
ContractResult, Deps, DepsMut, Env, MessageInfo, Response, StdResult, SubMsg, SystemResult,
Uint64, WasmMsg,
};
use cw2::set_contract_version;

Expand Down Expand Up @@ -59,12 +60,12 @@ pub fn execute(
if info.sender != env.contract.address {
Err(ContractError::NotSelf)
} else {
let Packet { sender, msg } = from_binary(&data)?;
let Packet { sender, msg } = from_json(&data)?;

Check warning on line 63 in contracts/main/voice/src/contract.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> contracts/main/voice/src/contract.rs:63:56 | 63 | let Packet { sender, msg } = from_json(&data)?; | ^^^^^ help: change this to: `data` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args = note: `#[warn(clippy::needless_borrows_for_generic_args)]` on by default
match msg {
Msg::Query { msgs } => {
let mut results = Vec::with_capacity(msgs.len());
for msg in msgs {
let query_result = deps.querier.raw_query(&to_vec(&msg)?);
let query_result = deps.querier.raw_query(&to_json_vec(&msg)?);
let error = match query_result {
SystemResult::Ok(ContractResult::Err(error)) => {
format!("contract: {error}")
Expand Down Expand Up @@ -119,7 +120,7 @@ pub fn execute(
admin: None,
code_id,
label: format!("polytone-proxy {sender}"),
msg: to_binary(&polytone_proxy::msg::InstantiateMsg {})?,
msg: to_json_binary(&polytone_proxy::msg::InstantiateMsg {})?,
funds: vec![],
salt,
}),
Expand All @@ -132,7 +133,7 @@ pub fn execute(
.add_submessage(SubMsg::reply_always(
WasmMsg::Execute {
contract_addr: proxy.into_string(),
msg: to_binary(&polytone_proxy::msg::ExecuteMsg::Proxy {
msg: to_json_binary(&polytone_proxy::msg::ExecuteMsg::Proxy {
msgs,
})?,
funds: vec![],
Expand Down Expand Up @@ -168,8 +169,8 @@ fn salt(local_connection: &str, counterparty_port: &str, remote_sender: &str) ->
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::BlockMaxGas => to_binary(&BLOCK_MAX_GAS.load(deps.storage)?),
QueryMsg::ProxyCodeId => to_binary(&PROXY_CODE_ID.load(deps.storage)?),
QueryMsg::BlockMaxGas => to_json_binary(&BLOCK_MAX_GAS.load(deps.storage)?),
QueryMsg::ProxyCodeId => to_json_binary(&PROXY_CODE_ID.load(deps.storage)?),
}
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/main/voice/src/ibc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
from_binary, to_binary, DepsMut, Env, IbcBasicResponse, IbcChannelCloseMsg,
from_json, to_json_binary, DepsMut, Env, IbcBasicResponse, IbcChannelCloseMsg,
IbcChannelConnectMsg, IbcChannelOpenMsg, IbcChannelOpenResponse, IbcPacketAckMsg,
IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, Never, Reply, Response, SubMsg,
SubMsgResult, WasmMsg,
Expand Down Expand Up @@ -94,7 +94,7 @@ pub fn ibc_packet_receive(
id: REPLY_ACK,
msg: WasmMsg::Execute {
contract_addr: env.contract.address.into_string(),
msg: to_binary(&ExecuteMsg::Rx {
msg: to_json_binary(&ExecuteMsg::Rx {
connection_id,
counterparty_port: msg.packet.src.port_id,
data: msg.packet.data,
Expand Down Expand Up @@ -125,7 +125,7 @@ pub fn reply(_deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, Contract
.expect("execution succeeded")
.data
.expect("reply_forward_data sets data");
match from_binary::<Callback>(&data) {
match from_json::<Callback>(&data) {
Ok(_) => Response::default().set_data(data),
Err(e) => Response::default()
.set_data(ack_fail(format!("unmarshalling callback data: ({e})"))),
Expand Down
12 changes: 6 additions & 6 deletions packages/polytone/src/ack.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{from_json, to_binary, Binary, IbcAcknowledgement, SubMsgResponse, Uint64};
use cosmwasm_std::{from_json, to_json_binary, Binary, IbcAcknowledgement, SubMsgResponse, Uint64};

pub use crate::callbacks::Callback;
use crate::callbacks::{ErrorResponse, ExecutionResponse};
Expand All @@ -12,12 +12,12 @@ pub type Ack = Callback;

/// Serializes an ACK-SUCCESS containing the provided data.
pub fn ack_query_success(result: Vec<Binary>) -> Binary {
to_binary(&Callback::Query(Ok(result))).unwrap()
to_json_binary(&Callback::Query(Ok(result))).unwrap()
}

/// Serializes an ACK-SUCCESS for a query that failed.
pub fn ack_query_fail(message_index: Uint64, error: String) -> Binary {
to_binary(&Callback::Query(Err(ErrorResponse {
to_json_binary(&Callback::Query(Err(ErrorResponse {
message_index,
error,
})))
Expand All @@ -26,7 +26,7 @@ pub fn ack_query_fail(message_index: Uint64, error: String) -> Binary {

/// Serializes an ACK-SUCCESS for execution that succeeded.
pub fn ack_execute_success(result: Vec<SubMsgResponse>, executed_by: String) -> Binary {
to_binary(&Callback::Execute(Ok(ExecutionResponse {
to_json_binary(&Callback::Execute(Ok(ExecutionResponse {
result,
executed_by,
})))
Expand All @@ -35,12 +35,12 @@ pub fn ack_execute_success(result: Vec<SubMsgResponse>, executed_by: String) ->

/// Serializes an ACK-SUCCESS for execution that failed.
pub fn ack_execute_fail(error: String) -> Binary {
to_binary(&Callback::Execute(Err(error))).unwrap()
to_json_binary(&Callback::Execute(Err(error))).unwrap()
}

/// Serializes an ACK-FAIL containing the provided error.
pub fn ack_fail(err: String) -> Binary {
to_binary(&Callback::FatalError(err)).unwrap()
to_json_binary(&Callback::FatalError(err)).unwrap()
}

/// Unmarshals an ACK from an acknowledgement returned by the SDK. If
Expand Down
4 changes: 2 additions & 2 deletions packages/polytone/src/callbacks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{
to_binary, Addr, Api, Binary, CosmosMsg, IbcPacketAckMsg, IbcPacketTimeoutMsg, StdResult,
to_json_binary, Addr, Api, Binary, CosmosMsg, IbcPacketAckMsg, IbcPacketTimeoutMsg, StdResult,
Storage, SubMsgResponse, Uint64, WasmMsg,
};
use cw_storage_plus::Map;
Expand Down Expand Up @@ -178,7 +178,7 @@ fn callback_message(request: PendingCallback, result: Callback) -> CosmosMsg {
}
WasmMsg::Execute {
contract_addr: request.receiver.into_string(),
msg: to_binary(&C::Callback(CallbackMessage {
msg: to_json_binary(&C::Callback(CallbackMessage {
initiator: request.initiator,
initiator_msg: request.initiator_msg,
result,
Expand Down
4 changes: 2 additions & 2 deletions packages/polytone/src/handshake/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_std::{
to_binary, Ibc3ChannelOpenResponse, IbcChannelOpenMsg, IbcChannelOpenResponse, IbcOrder,
to_json_binary, Ibc3ChannelOpenResponse, IbcChannelOpenMsg, IbcChannelOpenResponse, IbcOrder,
};

use error::HandshakeError;
Expand Down Expand Up @@ -59,7 +59,7 @@ fn open(
Err(HandshakeError::ExpectUnordered)
} else {
Ok(Some(Ibc3ChannelOpenResponse {
version: to_binary(extensions).unwrap().to_base64(),
version: to_json_binary(extensions).unwrap().to_base64(),
}))
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/polytone/src/handshake/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn connect(msg: &IbcChannelConnectMsg, extensions: &[&str]) -> Result<(), Ha
counterparty_version,
} => {
let proposed_version: Vec<String> =
from_json(&Binary::from_base64(counterparty_version).unwrap()).unwrap();
from_json(Binary::from_base64(counterparty_version).unwrap()).unwrap();
let subseteq_violation = extensions
.iter()
.find(|e| !proposed_version.contains(&e.to_string()));
Expand Down
2 changes: 1 addition & 1 deletion packages/polytone/src/handshake/voice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn connect(msg: &IbcChannelConnectMsg, extensions: &[&str]) -> Result<(), Ha
counterparty_version,
} => {
let proposed_version: Vec<String> =
from_json(&Binary::from_base64(counterparty_version).unwrap()).unwrap();
from_json(Binary::from_base64(counterparty_version).unwrap()).unwrap();
let subseteq_violation = proposed_version
.iter()
.find(|e| !extensions.contains(&e.as_str()));
Expand Down

0 comments on commit cf23de2

Please sign in to comment.