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

docs: guidelines for proto message's String() method #13364

Merged
merged 7 commits into from
Sep 22, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/core/encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,18 @@ Module should register interfaces using `InterfaceRegistry` which provides a mec

In addition, an `UnpackInterfaces` phase should be introduced to deserialization to unpack interfaces before they're needed. Protobuf types that contain a protobuf `Any` either directly or via one of their members should implement the `UnpackInterfacesMessage` interface:

### Custom Stringer

Using `option (gogoproto.goproto_stringer) = false;` in a proto message definition leads to unexpected behaviour, like returning wrong output or having missing fields in the output.
For that reason a proto Message's `String()` must not be customized, and the `goproto_stringer` option must be avoided.
A correct YAML output can be obtained through ProtoJSON, using the `JSONToYAML` function:
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved

+++ https://github.com/cosmos/cosmos-sdk/blob/v0.46.0/codec/yaml.go#L8-L20

For example:
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved

+++ https://github.com/cosmos/cosmos-sdk/blob/v0.46.0/x/auth/types/account.go#L139-L151

```go
type UnpackInterfacesMessage interface {
UnpackInterfaces(InterfaceUnpacker) error
Expand Down