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

Omit Payload from json if empty #519

Merged
merged 3 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions types/submessages.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type SubMsg struct {
// Unset/nil/null cannot be differentiated from empty data.
//
// On chains running CosmWasm 1.x this field will be ignored.
Payload []byte `json:"payload"`
Payload []byte `json:"payload,omitempty"`
// Gas limit measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).
//
// Setting this to `None` means unlimited. Then the submessage execution can consume all gas of
Expand All @@ -93,7 +93,7 @@ type Reply struct {
// Unset/nil/null cannot be differentiated from empty data.
//
// On chains running CosmWasm 1.x this field is never filled.
Payload []byte `json:"payload"`
Payload []byte `json:"payload,omitempty"`
}

// SubMsgResult is the raw response we return from wasmd after executing a SubMsg.
Expand Down
11 changes: 11 additions & 0 deletions types/submessages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ func TestReplySerialization(t *testing.T) {
serialized, err := json.Marshal(&reply1)
require.NoError(t, err)
require.Equal(t, `{"gas_used":4312324,"id":75,"result":{"ok":{"events":[{"type":"hi","attributes":[{"key":"si","value":"claro"}]}],"data":"PwCqXKs=","msg_responses":[{"type_url":"/cosmos.bank.v1beta1.MsgSendResponse","value":""}]}},"payload":"cGF5bG9hZA=="}`, string(serialized))

withoutPayload := Reply{
GasUsed: 4312324,
ID: 75,
Result: SubMsgResult{
Err: "some error",
},
}
serialized2, err := json.Marshal(&withoutPayload)
require.NoError(t, err)
require.Equal(t, `{"gas_used":4312324,"id":75,"result":{"error":"some error"}}`, string(serialized2))
}

func TestSubMsgResponseSerialization(t *testing.T) {
Expand Down
Loading