Skip to content

Commit

Permalink
Use Any field for new AnyMsg
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Nov 15, 2023
1 parent 29e59b3 commit d75bbcf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ type CosmosMsg struct {
Gov *GovMsg `json:"gov,omitempty"`
IBC *IBCMsg `json:"ibc,omitempty"`
Staking *StakingMsg `json:"staking,omitempty"`
Stargate *StargateMsg `json:"any,omitempty"`
Any *AnyMsg `json:"any,omitempty"`
Wasm *WasmMsg `json:"wasm,omitempty"`
}

Expand All @@ -116,19 +116,19 @@ func (m *CosmosMsg) UnmarshalJSON(data []byte) error {
Gov *GovMsg `json:"gov,omitempty"`
IBC *IBCMsg `json:"ibc,omitempty"`
Staking *StakingMsg `json:"staking,omitempty"`
Any *StargateMsg `json:"any,omitempty"`
Any *AnyMsg `json:"any,omitempty"`
Wasm *WasmMsg `json:"wasm,omitempty"`
Stargate *StargateMsg `json:"stargate,omitempty"`
Stargate *AnyMsg `json:"stargate,omitempty"`
}
var tmp InternalCosmosMsg
err := json.Unmarshal(data, &tmp)
if err != nil {
return err
}

// Use "Stargate" for both variants
if tmp.Stargate == nil && tmp.Any != nil {
tmp.Stargate = tmp.Any
// Use "Any" for both variants
if tmp.Any == nil && tmp.Stargate != nil {
tmp.Any = tmp.Stargate
}

*m = CosmosMsg{
Expand All @@ -138,7 +138,7 @@ func (m *CosmosMsg) UnmarshalJSON(data []byte) error {
Gov: tmp.Gov,
IBC: tmp.IBC,
Staking: tmp.Staking,
Stargate: tmp.Stargate,
Any: tmp.Any,
Wasm: tmp.Wasm,
}
return nil
Expand Down Expand Up @@ -309,9 +309,9 @@ type FundCommunityPoolMsg struct {
Amount Coins `json:"amount"`
}

// StargateMsg is encoded the same way as a protobof [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto).
// AnyMsg is encoded the same way as a protobof [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto).
// This is the same structure as messages in `TxBody` from [ADR-020](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-020-protobuf-transaction-encoding.md)
type StargateMsg struct {
type AnyMsg struct {
TypeURL string `json:"type_url"`
Value []byte `json:"value"`
}
Expand Down
2 changes: 1 addition & 1 deletion types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestAnyMsgSerialization(t *testing.T) {
err = json.Unmarshal(document1, &res)
require.NoError(t, err)
require.Equal(t, CosmosMsg{
Stargate: &StargateMsg{
Any: &AnyMsg{
TypeURL: "/cosmos.foo.v1beta.MsgBar",
Value: expectedData,
},
Expand Down

0 comments on commit d75bbcf

Please sign in to comment.