Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coin uses shorter format for Debug #1704

Merged
merged 4 commits into from
Jun 7, 2023
Merged

Coin uses shorter format for Debug #1704

merged 4 commits into from
Jun 7, 2023

Conversation

ethanfrey
Copy link
Member

@ethanfrey ethanfrey commented May 31, 2023

The Display is now like 123ucosm while Debug is like Coin { denom: "ucosm", amount: Uint128(123) }] (See example here: #1257).

This is quite annoying when outputing Debug for larger structs that include Vec<Coin>. Now the binary fields are well-encoded, this is the ugliest part of debugging view.

This will just align the Debug view with the Display view (as this seems like the canonical encoding format as per #1684)

Update: We agreed on Coin { 123 "ucosm" } as a more correct, yet still compact, encoding

@chipshort
Copy link
Collaborator

I think it would be good to use a different format for the debug view. For example, if the denom is empty, this would just output a number. Also, I think it would be nice to keep the type in there, such that the debug output of the Coin can be distinguished from a String.
I would propose, we just drop the field names and have something like Coin { 123 "ucosm" }.
What do you think?

@ethanfrey
Copy link
Member Author

Coin { 123 "ucosm" } that could work. It's not just field names, it's the Uint128(_) wrapper as well. This is much shorter for sure.

packages/std/src/coin.rs Outdated Show resolved Hide resolved
packages/std/src/coin.rs Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@ethanfrey
Copy link
Member Author

I made the suggested changes and rebased on main

Copy link
Collaborator

@chipshort chipshort left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ethanfrey ethanfrey merged commit 7cbb780 into main Jun 7, 2023
@ethanfrey ethanfrey deleted the better-debug-coin branch June 7, 2023 07:19
@ethanfrey ethanfrey changed the title Coin uses same output for Debug as Display Coin uses shorter format for Debug Jun 7, 2023
Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice change! Compact and still contains the type for a good debugging experience

@webmaster128 webmaster128 mentioned this pull request Jun 13, 2023
2 tasks
@webmaster128
Copy link
Member

Backported and shipped as part of 1.2.7 (#1719)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants