From d75bbcf4a7cc7f4113476bb29d264c735b8596d5 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 15 Nov 2023 15:51:31 +0100 Subject: [PATCH] Use Any field for new AnyMsg --- types/msg.go | 18 +++++++++--------- types/msg_test.go | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/types/msg.go b/types/msg.go index bc50bec07..d8ada04d1 100644 --- a/types/msg.go +++ b/types/msg.go @@ -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"` } @@ -116,9 +116,9 @@ 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) @@ -126,9 +126,9 @@ func (m *CosmosMsg) UnmarshalJSON(data []byte) error { 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{ @@ -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 @@ -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"` } diff --git a/types/msg_test.go b/types/msg_test.go index cf63a1045..5da14be4d 100644 --- a/types/msg_test.go +++ b/types/msg_test.go @@ -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, },