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

Change ics20 packet data to use standard json library for marshaling #3915

Closed
3 tasks
Tracked by #3916
colin-axner opened this issue Jun 21, 2023 · 1 comment · Fixed by #5778
Closed
3 tasks
Tracked by #3916

Change ics20 packet data to use standard json library for marshaling #3915

colin-axner opened this issue Jun 21, 2023 · 1 comment · Fixed by #5778
Labels
20-transfer help wanted Issues for which we would appreciate help/support from the community type: code hygiene Clean up code but without changing functionality or interfaces

Comments

@colin-axner
Copy link
Contributor

Summary

Change ICS 20 packet data FungibileTokenPacketData function GetBytes to use "encoding/json" library, rather than the sdk proto codec function MustMarshalJSON

Problem Definition

The ibc spec states that the ics20 packet data should be JSON marshaled, it does not state it should be proto3 json marshaled. To avoid accidental non-conformance when adding additional fields to the existing packet data we should switch from the proto codec MustMarshalJSON (which uses proto3 json) to the standard library json.Marshal.

The change would not be breaking because proto3 json maps strings to json strings (all fungible token packet data fields are strings)

In addition, this would remove the dependency on sdk.MustSortJSON which is being deprecated. The sorting of the json could be removed regardless since sorting of keys does not affect the ability of the counterparty to unmarshal the packet data

This also removes the maintenance burden of the modified MustMarshalJSON function. The standard library handles not emitting empty defaults via the omitempty json tag which is included by default on our .pb.go (we should ensure this doesn't change)

Proposal

Change FungibleTokenPacketData.GetBytes() to use json.Marshal(). Add documentation to the function to explain the usage of omitempty

In addition, when cosmos/ibc#987 is addressed, our marshal should link to the encoding spec


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged/assigned
@colin-axner colin-axner added 20-transfer type: code hygiene Clean up code but without changing functionality or interfaces labels Jun 21, 2023
@colin-axner
Copy link
Contributor Author

We should probably also decode the packet using the standard json library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
20-transfer help wanted Issues for which we would appreciate help/support from the community type: code hygiene Clean up code but without changing functionality or interfaces
Projects
Status: Done 🥳
Development

Successfully merging a pull request may close this issue.

2 participants