Skip to content

Commit

Permalink
rename to_binary -> to_json_binary & from_slice -> from_json
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Hartnell committed Apr 28, 2024
1 parent 781f2d7 commit 9eaf4c9
Show file tree
Hide file tree
Showing 20 changed files with 123 additions and 115 deletions.
10 changes: 5 additions & 5 deletions contracts/consumer/converter/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_std::{
ensure_eq, to_binary, Addr, BankMsg, Coin, CosmosMsg, Decimal, Deps, DepsMut, Event, Fraction,
MessageInfo, Reply, Response, SubMsg, SubMsgResponse, Uint128, Validator, WasmMsg,
ensure_eq, to_json_binary, Addr, BankMsg, Coin, CosmosMsg, Decimal, Deps, DepsMut, Event,
Fraction, MessageInfo, Reply, Response, SubMsg, SubMsgResponse, Uint128, Validator, WasmMsg,
};
use cw2::set_contract_version;
use cw_storage_plus::Item;
Expand Down Expand Up @@ -203,7 +203,7 @@ impl ConverterContract<'_> {
let msg = virtual_staking_api::ExecMsg::Bond { validator, amount };
let msg = WasmMsg::Execute {
contract_addr: self.virtual_stake.load(deps.storage)?.into(),
msg: to_binary(&msg)?,
msg: to_json_binary(&msg)?,
funds: vec![],
};

Expand All @@ -227,7 +227,7 @@ impl ConverterContract<'_> {
let msg = virtual_staking_api::ExecMsg::Unbond { validator, amount };
let msg = WasmMsg::Execute {
contract_addr: self.virtual_stake.load(deps.storage)?.into(),
msg: to_binary(&msg)?,
msg: to_json_binary(&msg)?,
funds: vec![],
};

Expand All @@ -254,7 +254,7 @@ impl ConverterContract<'_> {
};
let msg = WasmMsg::Execute {
contract_addr: self.virtual_stake.load(deps.storage)?.into(),
msg: to_binary(&msg)?,
msg: to_json_binary(&msg)?,
funds: vec![],
};

Expand Down
14 changes: 7 additions & 7 deletions contracts/consumer/converter/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use cosmwasm_std::entry_point;

use cosmwasm_std::{
from_slice, to_binary, DepsMut, Env, Event, Ibc3ChannelOpenResponse, IbcBasicResponse,
from_json, to_json_binary, DepsMut, Env, Event, Ibc3ChannelOpenResponse, IbcBasicResponse,
IbcChannel, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg,
IbcChannelOpenResponse, IbcMsg, IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg,
IbcReceiveResponse, IbcTimeout, Validator,
Expand Down Expand Up @@ -73,7 +73,7 @@ pub fn ibc_channel_open(
version: SUPPORTED_IBC_PROTOCOL_VERSION.to_string(),
}
} else {
let v: ProtocolVersion = from_slice(channel.version.as_bytes())?;
let v: ProtocolVersion = from_json(channel.version.as_bytes())?;
// if we can build a response to this, then it is compatible. And we use the highest version there
v.build_response(SUPPORTED_IBC_PROTOCOL_VERSION, MIN_IBC_PROTOCOL_VERSION)?
};
Expand Down Expand Up @@ -108,7 +108,7 @@ pub fn ibc_channel_connect(

// Ensure the counterparty responded with a version we support.
// Note: here, we error if it is higher than what we proposed originally
let v: ProtocolVersion = from_slice(counterparty_version.as_bytes())?;
let v: ProtocolVersion = from_json(counterparty_version.as_bytes())?;
v.verify_compatibility(SUPPORTED_IBC_PROTOCOL_VERSION, MIN_IBC_PROTOCOL_VERSION)?;

// store the channel
Expand Down Expand Up @@ -162,7 +162,7 @@ pub(crate) fn valset_update_msg(
};
let msg = IbcMsg::SendPacket {
channel_id: channel.endpoint.channel_id.clone(),
data: to_binary(&packet)?,
data: to_json_binary(&packet)?,
timeout: packet_timeout_validator(env),
};
Ok(msg)
Expand All @@ -188,7 +188,7 @@ pub fn ibc_packet_receive(
_env: Env,
msg: IbcPacketReceiveMsg,
) -> Result<IbcReceiveResponse, ContractError> {
let packet: ProviderPacket = from_slice(&msg.packet.data)?;
let packet: ProviderPacket = from_json(&msg.packet.data)?;
let contract = ConverterContract::new();
let res = match packet {
ProviderPacket::Stake {
Expand Down Expand Up @@ -246,7 +246,7 @@ pub fn ibc_packet_ack(
_env: Env,
msg: IbcPacketAckMsg,
) -> Result<IbcBasicResponse, ContractError> {
let ack: AckWrapper = from_slice(&msg.acknowledgement.data)?;
let ack: AckWrapper = from_json(&msg.acknowledgement.data)?;
let mut res = IbcBasicResponse::new();
match ack {
AckWrapper::Result(_) => {}
Expand Down Expand Up @@ -286,7 +286,7 @@ pub(crate) fn make_ibc_packet(
let channel = IBC_CHANNEL.load(ctx.deps.storage)?;
Ok(IbcMsg::SendPacket {
channel_id: channel.endpoint.channel_id,
data: to_binary(&packet)?,
data: to_json_binary(&packet)?,
timeout: packet_timeout_rewards(&ctx.env),
})
}
8 changes: 4 additions & 4 deletions contracts/consumer/remote-price-feed/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use cosmwasm_std::entry_point;

use cosmwasm_std::{
from_slice, to_binary, DepsMut, Env, Ibc3ChannelOpenResponse, IbcBasicResponse, IbcChannel,
from_json, to_json_binary, DepsMut, Env, Ibc3ChannelOpenResponse, IbcBasicResponse, IbcChannel,
IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, IbcChannelOpenResponse, IbcMsg,
IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, IbcTimeout,
Timestamp,
Expand Down Expand Up @@ -65,7 +65,7 @@ pub fn ibc_channel_open(
}

// we handshake with the counterparty version, it must not be empty
let v: ProtocolVersion = from_slice(counterparty_version.as_bytes())?;
let v: ProtocolVersion = from_json(counterparty_version.as_bytes())?;
// if we can build a response to this, then it is compatible. And we use the highest version there
let version = v.build_response(SUPPORTED_IBC_PROTOCOL_VERSION, MIN_IBC_PROTOCOL_VERSION)?;

Expand Down Expand Up @@ -125,7 +125,7 @@ pub fn ibc_packet_ack(
_env: Env,
msg: IbcPacketAckMsg,
) -> Result<IbcBasicResponse, ContractError> {
let ack: PriceFeedProviderAck = from_slice(&msg.acknowledgement.data)?;
let ack: PriceFeedProviderAck = from_json(&msg.acknowledgement.data)?;
let PriceFeedProviderAck::Update { time, twap } = ack;
let contract = RemotePriceFeedContract::new();
contract.update_twap(deps, time, twap)?;
Expand All @@ -149,7 +149,7 @@ pub(crate) fn make_ibc_packet(
) -> Result<IbcMsg, ContractError> {
Ok(IbcMsg::SendPacket {
channel_id: channel.endpoint.channel_id,
data: to_binary(&packet)?,
data: to_json_binary(&packet)?,
timeout: packet_timeout(now),
})
}
14 changes: 7 additions & 7 deletions contracts/consumer/virtual-staking/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::cmp::Ordering;
use std::collections::{BTreeMap, HashMap, HashSet};

use cosmwasm_std::{
coin, ensure_eq, entry_point, to_binary, Coin, CosmosMsg, CustomQuery, DepsMut,
coin, ensure_eq, entry_point, to_json_binary, Coin, CosmosMsg, CustomQuery, DepsMut,
DistributionMsg, Env, Event, Reply, Response, StdResult, Storage, SubMsg, Uint128, Validator,
WasmMsg,
};
Expand Down Expand Up @@ -262,7 +262,7 @@ impl VirtualStakingContract<'_> {
};
let msg = WasmMsg::Execute {
contract_addr: cfg.converter.to_string(),
msg: to_binary(&msg)?,
msg: to_json_binary(&msg)?,
funds: vec![],
};
let resp = Response::new().add_message(msg);
Expand Down Expand Up @@ -338,7 +338,7 @@ impl VirtualStakingContract<'_> {
};
let msg = WasmMsg::Execute {
contract_addr: cfg.converter.into_string(),
msg: to_binary(&msg)?,
msg: to_json_binary(&msg)?,
funds: vec![coin(total.into(), cfg.denom)],
};
Ok(Response::new().add_message(msg))
Expand Down Expand Up @@ -644,7 +644,7 @@ mod tests {
};

use cosmwasm_std::{
coins, from_binary,
coins, from_json,
testing::{mock_env, mock_info, MockApi, MockQuerier, MockStorage},
Decimal,
};
Expand Down Expand Up @@ -1221,12 +1221,12 @@ mod tests {
match msg {
mesh_bindings::VirtualStakeQuery::BondStatus { .. } => {
cosmwasm_std::SystemResult::Ok(cosmwasm_std::ContractResult::Ok(
to_binary(&*bs_copy.borrow()).unwrap(),
to_json_binary(&*bs_copy.borrow()).unwrap(),
))
}
mesh_bindings::VirtualStakeQuery::SlashRatio {} => {
cosmwasm_std::SystemResult::Ok(cosmwasm_std::ContractResult::Ok(
to_binary(&*slash_ratio.borrow()).unwrap(),
to_json_binary(&*slash_ratio.borrow()).unwrap(),
))
}
}
Expand Down Expand Up @@ -1515,7 +1515,7 @@ mod tests {
..
}] => {
if let converter_api::ExecMsg::DistributeRewards { mut payments } =
from_binary(bin_msg).unwrap()
from_json(bin_msg).unwrap()
{
payments.sort();
Self::Batch(payments)
Expand Down
15 changes: 10 additions & 5 deletions contracts/osmosis-price-provider/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use cosmwasm_std::entry_point;

use cosmwasm_std::{
from_slice, to_binary, DepsMut, Env, Ibc3ChannelOpenResponse, IbcBasicResponse,
from_json, to_json_binary, DepsMut, Env, Ibc3ChannelOpenResponse, IbcBasicResponse,
IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, IbcChannelOpenResponse,
IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, IbcTimeout,
StdError, Timestamp,
Expand Down Expand Up @@ -46,7 +46,7 @@ pub fn ibc_channel_open(
version: SUPPORTED_IBC_PROTOCOL_VERSION.to_string(),
}
} else {
let v: ProtocolVersion = from_slice(channel.version.as_bytes())?;
let v: ProtocolVersion = from_json(channel.version.as_bytes())?;
// if we can build a response to this, then it is compatible. And we use the highest version there
v.build_response(SUPPORTED_IBC_PROTOCOL_VERSION, MIN_IBC_PROTOCOL_VERSION)?
};
Expand Down Expand Up @@ -77,7 +77,7 @@ pub fn ibc_channel_connect(

// Ensure the counterparty responded with a version we support.
// Note: here, we error if it is higher than what we proposed originally
let v: ProtocolVersion = from_slice(counterparty_version.as_bytes())?;
let v: ProtocolVersion = from_json(counterparty_version.as_bytes())?;
v.verify_compatibility(SUPPORTED_IBC_PROTOCOL_VERSION, MIN_IBC_PROTOCOL_VERSION)?;

let contract = OsmosisPriceProvider::new();
Expand Down Expand Up @@ -124,12 +124,17 @@ pub fn ibc_packet_receive(
pool_id,
base_asset,
quote_asset,
} = from_slice(&msg.packet.data)?;
} = from_json(&msg.packet.data)?;
let contract = OsmosisPriceProvider::new();

let time = env.block.time;
let twap = contract.query_twap(deps, pool_id, base_asset, quote_asset)?;
Ok(IbcReceiveResponse::new().set_ack(to_binary(&PriceFeedProviderAck::Update { time, twap })?))
Ok(
IbcReceiveResponse::new().set_ack(to_json_binary(&PriceFeedProviderAck::Update {
time,
twap,
})?),
)
}

#[cfg_attr(not(feature = "library"), entry_point)]
Expand Down
30 changes: 15 additions & 15 deletions contracts/provider/external-staking/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_std::{
coin, ensure, ensure_eq, to_binary, Coin, Decimal, DepsMut, Env, Event, IbcMsg, Order,
coin, ensure, ensure_eq, to_json_binary, Coin, Decimal, DepsMut, Env, Event, IbcMsg, Order,
Response, StdResult, Storage, Uint128, Uint256, WasmMsg,
};
use cw2::set_contract_version;
Expand Down Expand Up @@ -306,7 +306,7 @@ impl ExternalStakingContract<'_> {
};
let msg = IbcMsg::SendPacket {
channel_id: channel.endpoint.channel_id,
data: to_binary(&packet)?,
data: to_json_binary(&packet)?,
timeout: packet_timeout(&env),
};
// send packet if we are ibc enabled
Expand Down Expand Up @@ -783,7 +783,7 @@ impl ExternalStakingContract<'_> {
let channel_id = IBC_CHANNEL.load(ctx.deps.storage)?.endpoint.channel_id;
let send_msg = IbcMsg::SendPacket {
channel_id,
data: to_binary(&packet)?,
data: to_json_binary(&packet)?,
timeout: packet_timeout(&ctx.env),
};

Expand Down Expand Up @@ -1206,7 +1206,7 @@ pub mod cross_staking {
use crate::msg::ReceiveVirtualStake;

use super::*;
use cosmwasm_std::{from_binary, Binary};
use cosmwasm_std::{from_json, Binary};
use mesh_apis::{cross_staking_api::CrossStakingApi, local_staking_api::SlashRatioResponse};

#[contract(module=crate::contract)]
Expand Down Expand Up @@ -1236,7 +1236,7 @@ pub mod cross_staking {
let owner = ctx.deps.api.addr_validate(&owner)?;

// parse and validate message
let msg: ReceiveVirtualStake = from_binary(&msg)?;
let msg: ReceiveVirtualStake = from_json(&msg)?;
if !self
.val_set
.is_active_validator(ctx.deps.storage, &msg.validator)?
Expand Down Expand Up @@ -1276,7 +1276,7 @@ pub mod cross_staking {
};
let msg = IbcMsg::SendPacket {
channel_id: channel.endpoint.channel_id,
data: to_binary(&packet)?,
data: to_json_binary(&packet)?,
timeout: packet_timeout(&ctx.env),
};
// add ibc packet if we are ibc enabled (skip in tests)
Expand Down Expand Up @@ -1402,7 +1402,7 @@ pub mod cross_staking {
};
let msg = IbcMsg::SendPacket {
channel_id: channel.endpoint.channel_id,
data: to_binary(&packet)?,
data: to_json_binary(&packet)?,
timeout: packet_timeout(&ctx.env),
};
let mut resp = Response::new();
Expand Down Expand Up @@ -1620,7 +1620,7 @@ mod tests {
OWNER.to_string(),
coin(100, "uosmo"),
1,
to_binary(&ReceiveVirtualStake {
to_json_binary(&ReceiveVirtualStake {
validator: "bob".to_string(),
})
.unwrap(),
Expand Down Expand Up @@ -1670,7 +1670,7 @@ mod tests {
msgs[0],
WasmMsg::Execute {
contract_addr: "vault_addr".to_string(),
msg: to_binary(&CrossSlash {
msg: to_json_binary(&CrossSlash {
slashes: vec![SlashInfo {
user: OWNER.to_string(),
slash: Uint128::new(10),
Expand Down Expand Up @@ -1751,7 +1751,7 @@ mod tests {
OWNER.to_string(),
coin(100, "uosmo"),
1,
to_binary(&ReceiveVirtualStake {
to_json_binary(&ReceiveVirtualStake {
validator: "bob".to_string(),
})
.unwrap(),
Expand Down Expand Up @@ -1800,7 +1800,7 @@ mod tests {
msgs[0],
WasmMsg::Execute {
contract_addr: "vault_addr".to_string(),
msg: to_binary(&CrossSlash {
msg: to_json_binary(&CrossSlash {
slashes: vec![SlashInfo {
user: OWNER.to_string(),
slash: Uint128::new(10),
Expand Down Expand Up @@ -1881,7 +1881,7 @@ mod tests {
OWNER.to_string(),
coin(100, "uosmo"),
1,
to_binary(&ReceiveVirtualStake {
to_json_binary(&ReceiveVirtualStake {
validator: "bob".to_string(),
})
.unwrap(),
Expand Down Expand Up @@ -1944,7 +1944,7 @@ mod tests {
msgs[0],
WasmMsg::Execute {
contract_addr: "vault_addr".to_string(),
msg: to_binary(&CrossSlash {
msg: to_json_binary(&CrossSlash {
slashes: vec![SlashInfo {
user: OWNER.to_string(),
slash: Uint128::new(10), // Owner is slashed over the full stake, including pending
Expand Down Expand Up @@ -2295,7 +2295,7 @@ mod tests {
OWNER.to_string(),
coin(100, "uosmo"),
1,
to_binary(&ReceiveVirtualStake {
to_json_binary(&ReceiveVirtualStake {
validator: "bob".to_string(),
})
.unwrap(),
Expand Down Expand Up @@ -2345,7 +2345,7 @@ mod tests {
msgs[0],
WasmMsg::Execute {
contract_addr: "vault_addr".to_string(),
msg: to_binary(&CrossSlash {
msg: to_json_binary(&CrossSlash {
slashes: vec![SlashInfo {
user: OWNER.to_string(),
slash: Uint128::new(10),
Expand Down
Loading

0 comments on commit 9eaf4c9

Please sign in to comment.