From a49c769d7b46a672e66da4239b76267176586fab Mon Sep 17 00:00:00 2001 From: Tomasz Kurcz Date: Wed, 24 Apr 2024 10:14:33 +0200 Subject: [PATCH 1/4] deprecate compact serialization of some types Binary, HexBinary, Checksum --- packages/core/src/binary.rs | 12 ++++++++++-- packages/core/src/hex_binary.rs | 12 ++++++++++-- packages/std/src/checksum.rs | 12 ++++++++++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/packages/core/src/binary.rs b/packages/core/src/binary.rs index 1d445c7a5a..3dcdf23627 100644 --- a/packages/core/src/binary.rs +++ b/packages/core/src/binary.rs @@ -209,7 +209,11 @@ impl Serialize for Binary { where S: ser::Serializer, { - serializer.serialize_str(&self.to_base64()) + if serializer.is_human_readable() { + serializer.serialize_str(&self.to_base64()) + } else { + panic!("Binary is only intended to be used with JSON serialization for now") + } } } @@ -219,7 +223,11 @@ impl<'de> Deserialize<'de> for Binary { where D: Deserializer<'de>, { - deserializer.deserialize_str(Base64Visitor) + if deserializer.is_human_readable() { + deserializer.deserialize_str(Base64Visitor) + } else { + panic!("Binary is only intended to be used with JSON serialization for now") + } } } diff --git a/packages/core/src/hex_binary.rs b/packages/core/src/hex_binary.rs index f55a8daeae..fdb5a5fb32 100644 --- a/packages/core/src/hex_binary.rs +++ b/packages/core/src/hex_binary.rs @@ -212,7 +212,11 @@ impl Serialize for HexBinary { where S: ser::Serializer, { - serializer.serialize_str(&self.to_hex()) + if serializer.is_human_readable() { + serializer.serialize_str(&self.to_hex()) + } else { + panic!("HexBinary is only intended to be used with JSON serialization for now") + } } } @@ -222,7 +226,11 @@ impl<'de> Deserialize<'de> for HexBinary { where D: Deserializer<'de>, { - deserializer.deserialize_str(HexVisitor) + if deserializer.is_human_readable() { + deserializer.deserialize_str(HexVisitor) + } else { + panic!("HexBinary is only intended to be used with JSON serialization for now") + } } } diff --git a/packages/std/src/checksum.rs b/packages/std/src/checksum.rs index e56735640d..ff3b37bdc9 100644 --- a/packages/std/src/checksum.rs +++ b/packages/std/src/checksum.rs @@ -71,7 +71,11 @@ impl Serialize for Checksum { where S: ser::Serializer, { - serializer.serialize_str(&self.to_hex()) + if serializer.is_human_readable() { + serializer.serialize_str(&self.to_hex()) + } else { + panic!("Checksum is only intended to be used with JSON serialization for now") + } } } @@ -81,7 +85,11 @@ impl<'de> Deserialize<'de> for Checksum { where D: Deserializer<'de>, { - deserializer.deserialize_str(ChecksumVisitor) + if deserializer.is_human_readable() { + deserializer.deserialize_str(ChecksumVisitor) + } else { + panic!("Checksum is only intended to be used with JSON serialization for now") + } } } From b8da044534734caef440a26f4373c67e598c5674 Mon Sep 17 00:00:00 2001 From: Tomasz Kurcz Date: Wed, 24 Apr 2024 10:22:29 +0200 Subject: [PATCH 2/4] changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca12c32e53..4d4301180f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,8 @@ and this project adheres to - cosmwasm-schema: `#[cw_serde]` now doesn't add `#[serde(deny_unknown_fields)]` to the expanded code anymore ([#2080]) - cosmwasm-std: Improve performance of `Uint{64,128,256,512}::isqrt` ([#2108]) +- cosmwasm-std: Deprecate "compact" serialization of `Binary`, `HexBinary`, + `Checksum` ([#2125]) [#2044]: https://github.com/CosmWasm/cosmwasm/pull/2044 [#2051]: https://github.com/CosmWasm/cosmwasm/pull/2051 @@ -60,6 +62,7 @@ and this project adheres to [#2070]: https://github.com/CosmWasm/cosmwasm/pull/2070 [#2080]: https://github.com/CosmWasm/cosmwasm/pull/2080 [#2108]: https://github.com/CosmWasm/cosmwasm/pull/2108 +[#2125]: https://github.com/CosmWasm/cosmwasm/pull/2125 ## [2.0.1] - 2024-04-03 From fea397c472bc9b67c0b082157a1e89256eb8b286 Mon Sep 17 00:00:00 2001 From: Tomasz Kurcz Date: Wed, 24 Apr 2024 14:47:09 +0200 Subject: [PATCH 3/4] elaborate on panic msg for Binary/HexBinary --- packages/core/src/binary.rs | 4 ++-- packages/core/src/hex_binary.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/src/binary.rs b/packages/core/src/binary.rs index 3dcdf23627..7564916240 100644 --- a/packages/core/src/binary.rs +++ b/packages/core/src/binary.rs @@ -212,7 +212,7 @@ impl Serialize for Binary { if serializer.is_human_readable() { serializer.serialize_str(&self.to_base64()) } else { - panic!("Binary is only intended to be used with JSON serialization for now") + panic!("Binary is only intended to be used with JSON serialization for now. If you are hitting this panic please open an issue at https://github.com/CosmWasm/cosmwasm describing your use case.") } } } @@ -226,7 +226,7 @@ impl<'de> Deserialize<'de> for Binary { if deserializer.is_human_readable() { deserializer.deserialize_str(Base64Visitor) } else { - panic!("Binary is only intended to be used with JSON serialization for now") + panic!("Binary is only intended to be used with JSON serialization for now. If you are hitting this panic please open an issue at https://github.com/CosmWasm/cosmwasm describing your use case.") } } } diff --git a/packages/core/src/hex_binary.rs b/packages/core/src/hex_binary.rs index fdb5a5fb32..bce0df2179 100644 --- a/packages/core/src/hex_binary.rs +++ b/packages/core/src/hex_binary.rs @@ -215,7 +215,7 @@ impl Serialize for HexBinary { if serializer.is_human_readable() { serializer.serialize_str(&self.to_hex()) } else { - panic!("HexBinary is only intended to be used with JSON serialization for now") + panic!("HexBinary is only intended to be used with JSON serialization for now. If you are hitting this panic please open an issue at https://github.com/CosmWasm/cosmwasm describing your use case.") } } } @@ -229,7 +229,7 @@ impl<'de> Deserialize<'de> for HexBinary { if deserializer.is_human_readable() { deserializer.deserialize_str(HexVisitor) } else { - panic!("HexBinary is only intended to be used with JSON serialization for now") + panic!("HexBinary is only intended to be used with JSON serialization for now. If you are hitting this panic please open an issue at https://github.com/CosmWasm/cosmwasm describing your use case.") } } } From 82464e5fbce509fbcdd073f296743c69b4d768be Mon Sep 17 00:00:00 2001 From: Tomasz Kurcz Date: Wed, 24 Apr 2024 14:47:53 +0200 Subject: [PATCH 4/4] elaborate on panic msg for Checksum --- packages/std/src/checksum.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/std/src/checksum.rs b/packages/std/src/checksum.rs index ff3b37bdc9..b2b1a79e9a 100644 --- a/packages/std/src/checksum.rs +++ b/packages/std/src/checksum.rs @@ -74,7 +74,7 @@ impl Serialize for Checksum { if serializer.is_human_readable() { serializer.serialize_str(&self.to_hex()) } else { - panic!("Checksum is only intended to be used with JSON serialization for now") + panic!("Checksum is only intended to be used with JSON serialization for now. If you are hitting this panic please open an issue at https://github.com/CosmWasm/cosmwasm describing your use case.") } } } @@ -88,7 +88,7 @@ impl<'de> Deserialize<'de> for Checksum { if deserializer.is_human_readable() { deserializer.deserialize_str(ChecksumVisitor) } else { - panic!("Checksum is only intended to be used with JSON serialization for now") + panic!("Checksum is only intended to be used with JSON serialization for now. If you are hitting this panic please open an issue at https://github.com/CosmWasm/cosmwasm describing your use case.") } } }