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

Better Debug encoding for Binary #1199

Closed
ethanfrey opened this issue Jan 4, 2022 · 2 comments · Fixed by #1201
Closed

Better Debug encoding for Binary #1199

ethanfrey opened this issue Jan 4, 2022 · 2 comments · Fixed by #1201

Comments

@ethanfrey
Copy link
Member

When debugging message calls, I get hard to read output like:

Execute { contract_addr: "Contract #1", msg: Binary([123, 34, 101, 120, 101, 99, 117, 116, 101, 34, 58, 123, 34, 99, 111, 110, 116, 114, 97, 99, 116, 95, 97, 100, 100, 114, 34, 58, 34, 67, 111, 110, 116, 114, 97, 99, 116, 32, 35, 50, 34, 44, 34, 109, 115, 103, 34, 58, 34, 101, 51, 48, 61, 34, 44, 34, 102, 117, 110, 100, 115, 34, 58, 91, 93, 125, 125]), funds: [] }

This is the Debug encoding of Binary and it should be improved from default. I have two ideas:

  1. Always hex-encode it (which is more debug friendly than base64... some of us can read ascii bytes in hex)
  2. If ASCII printable, encode it as a string. Otherwise prefix 0x and hex-encode (as 1)

Approach 2 is not very stable for any APIs you would depend on, but debug is only meant for test output for developers, so let's make this nice.

@webmaster128
Copy link
Member

  1. is cool and solid. Happy to implement.

The big question is to what degree that change would violate stability promises.

@ethanfrey
Copy link
Member Author

I am quite sure we never use Debug outside of test code.
We already have a custom Display implementation which uses base64, which might escape into some contract APIs.

I would not change display, only a Debug implementation which is just for unit tests.

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 a pull request may close this issue.

2 participants