Skip to content

Commit

Permalink
Merge pull request #2128 from CosmWasm/mergify/bp/release/2.0/pr-2125
Browse files Browse the repository at this point in the history
Deprecate compact serialization of Binary, HexBinary, Checksum (backport #2125)
  • Loading branch information
uint authored Apr 25, 2024
2 parents e51dae4 + 686fb6e commit 5aef3b7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to

## [Unreleased]

### Changed

- cosmwasm-std: Deprecate "compact" serialization of `Binary`, `HexBinary`,
`Checksum` ([#2128])

[#2128]: https://github.com/CosmWasm/cosmwasm/pull/2128

## [2.0.2] - 2024-04-24

### Fixed
Expand Down
12 changes: 10 additions & 2 deletions packages/std/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,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. If you are hitting this panic please open an issue at https://github.com/CosmWasm/cosmwasm describing your use case.")
}
}
}

Expand All @@ -230,7 +234,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. If you are hitting this panic please open an issue at https://github.com/CosmWasm/cosmwasm describing your use case.")
}
}
}

Expand Down
12 changes: 10 additions & 2 deletions packages/std/src/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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. If you are hitting this panic please open an issue at https://github.com/CosmWasm/cosmwasm describing your use case.")
}
}
}

Expand All @@ -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. If you are hitting this panic please open an issue at https://github.com/CosmWasm/cosmwasm describing your use case.")
}
}
}

Expand Down
12 changes: 10 additions & 2 deletions packages/std/src/hex_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,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. If you are hitting this panic please open an issue at https://github.com/CosmWasm/cosmwasm describing your use case.")
}
}
}

Expand All @@ -220,7 +224,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. If you are hitting this panic please open an issue at https://github.com/CosmWasm/cosmwasm describing your use case.")
}
}
}

Expand Down

0 comments on commit 5aef3b7

Please sign in to comment.