Skip to content

Commit

Permalink
Merge pull request #89 from CosmWasm/55-msgpack_from_cosmwasm_std
Browse files Browse the repository at this point in the history
Use the msgpack impl provided by cosmwasm_std
  • Loading branch information
uint authored Jan 15, 2025
2 parents 866e75f + 70c14ed commit a03f6ab
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/cw-storey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2021"
license = { workspace = true }

[dependencies]
cosmwasm-std = "2"
cosmwasm-std = "2.2"
rmp-serde = "1.1"
serde = "1"

Expand Down
25 changes: 2 additions & 23 deletions packages/cw-storey/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ where
T: serde::Serialize,
{
fn encode_impl(self) -> Result<Vec<u8>, StdError> {
cosmwasm_std_new::to_msgpack_vec(self.0)
cosmwasm_std::to_msgpack_vec(self.0)
}
}

Expand All @@ -32,27 +32,6 @@ where
T: serde::de::DeserializeOwned,
{
fn decode_impl(data: &[u8]) -> Result<Self, StdError> {
cosmwasm_std_new::from_msgpack(data).map(Cover)
}
}

// TODO: remove this module once the following PR is released on crates.io:
// https://github.com/CosmWasm/cosmwasm/pull/2118
mod cosmwasm_std_new {
use core::any::type_name;

use cosmwasm_std::{StdError, StdResult};
use serde::de::DeserializeOwned;
use serde::Serialize;

pub(super) fn from_msgpack<T: DeserializeOwned>(value: impl AsRef<[u8]>) -> StdResult<T> {
rmp_serde::from_read(value.as_ref()).map_err(|e| StdError::parse_err(type_name::<T>(), e))
}

pub(super) fn to_msgpack_vec<T>(data: &T) -> StdResult<Vec<u8>>
where
T: Serialize + ?Sized,
{
rmp_serde::to_vec_named(data).map_err(|e| StdError::serialize_err(type_name::<T>(), e))
cosmwasm_std::from_msgpack(data).map(Cover)
}
}

0 comments on commit a03f6ab

Please sign in to comment.