The "omitempty" option specifies that the field should be omitted from the encoding if the field has an empty value, defined as false, 0, a nil pointer, a nil interface value, and any empty array, slice, map, or string.
type Height struct {
RevisionNumber int `json:"revision_number,omitempty"`
RevisionHeight int `json:"revision_height,omitempty"`
}
h := Height{RevisionNumber: 0, RevisionHeight: 12}
hJSON, _ := json.Marshal(h)
fmt.Printf("%s", hJSON) // {"revision_height":12}
Bug Summary
With a wasm light client, compiled from ibc-rs, ibc-go fails to query
TimestampAtHeight
. The error it raises:Details
This happens as ibc-go omits
revision_number
field if it is set to zero while mashaling to JSON. Fromjson
go package:To make it work, we need to annotate our
revision_number
field with#[serde(default)]
. https://github.com/cosmos/ibc-rs/blob/8424f6903045b203614f12a5839c330a3559cece/ibc-core/ics02-client/types/src/height.rs#L32-L34Version
v0.53.0