diff --git a/CHANGELOG.md b/CHANGELOG.md index 7380f7fb7a..a93f88179d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ and this project adheres to - cosmwasm-vm: Add `.wasm` extension to stored wasm files ([#1686]). - cosmwasm-vm: Upgrade Wasmer to version 3.3.0. - cosmwasm-check: Update clap dependency to version 4 ([#1677]) +- cosmwasm-std: Coin uses shorter `Coin { 123 "ucosm" }` format for Debug + ([#1704]) [#1511]: https://github.com/CosmWasm/cosmwasm/issues/1511 [#1629]: https://github.com/CosmWasm/cosmwasm/pull/1629 @@ -42,6 +44,7 @@ and this project adheres to [#1667]: https://github.com/CosmWasm/cosmwasm/pull/1667 [#1677]: https://github.com/CosmWasm/cosmwasm/pull/1677 [#1686]: https://github.com/CosmWasm/cosmwasm/pull/1686 +[#1704]: https://github.com/CosmWasm/cosmwasm/pull/1704 ### Deprecated diff --git a/packages/std/src/coin.rs b/packages/std/src/coin.rs index b88a6da3ee..0838958efa 100644 --- a/packages/std/src/coin.rs +++ b/packages/std/src/coin.rs @@ -4,7 +4,7 @@ use std::{fmt, str::FromStr}; use crate::{errors::CoinFromStrError, math::Uint128}; -#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, JsonSchema)] pub struct Coin { pub denom: String, pub amount: Uint128, @@ -19,6 +19,12 @@ impl Coin { } } +impl fmt::Debug for Coin { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Coin {{ {} \"{}\" }}", self.amount, self.denom) + } +} + impl FromStr for Coin { type Err = CoinFromStrError; @@ -235,4 +241,10 @@ mod tests { "Invalid amount: number too large to fit in target type" ); } + + #[test] + fn debug_coin() { + let coin = Coin::new(123, "ucosm"); + assert_eq!(format!("{:?}", coin), r#"Coin { 123 "ucosm" }"#); + } }