Skip to content

Commit a02e174

Browse files
julienrbrtmergify[bot]
authored andcommitted
refactor: remove .Type() and .Route() from msgs (#14751)
(cherry picked from commit 8dbdfea) # Conflicts: # CHANGELOG.md # x/distribution/types/msg.go # x/evidence/types/msgs.go # x/gov/client/utils/query_test.go # x/gov/simulation/operations.go # x/gov/simulation/operations_test.go # x/gov/types/v1/msgs.go # x/staking/simulation/operations_test.go
1 parent 146d4e2 commit a02e174

File tree

48 files changed

+636
-734
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+636
-734
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
6464

6565
### Improvements
6666

67+
<<<<<<< HEAD
6768
* [#14995](https://github.com/cosmos/cosmos-sdk/pull/14995) Allow unknown fields in `ParseTypedEvent`.
6869
* (store) [#14931](https://github.com/cosmos/cosmos-sdk/pull/14931) Exclude in-memory KVStores, i.e. `StoreTypeMemory`, from CommitInfo commitments.
6970
* (cli) [#14919](https://github.com/cosmos/cosmos-sdk/pull/14919) Fix never assigned error when write validators.
@@ -89,6 +90,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
8990
* (deps) [#14830](https://github.com/cosmos/cosmos-sdk/pull/14830) Bump to IAVL `v0.19.5-rc.1`.
9091
* (tools) [#14793](https://github.com/cosmos/cosmos-sdk/pull/14793) Dockerfile optimization.
9192
* (x/gov) [#13010](https://github.com/cosmos/cosmos-sdk/pull/13010) Partial cherry-pick of this issue for adding proposer migration.
93+
=======
94+
* (x/auth/tx) [#14751](https://github.com/cosmos/cosmos-sdk/pull/14751) Remove `.Type()` and `Route()` methods from all msgs and `legacytx.LegacyMsg` interface.
95+
>>>>>>> 8dbdfea9e (refactor: remove `.Type()` and `.Route()` from msgs (#14751))
9296
* [#14691](https://github.com/cosmos/cosmos-sdk/pull/14691) Change behavior of `sdk.StringifyEvents` to not flatten events attributes by events type.
9397
* This change only affects ABCI message logs, and not the events field.
9498
* [#14692](https://github.com/cosmos/cosmos-sdk/pull/14692) Improve RPC queries error message when app is at height 0.
@@ -170,6 +174,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
170174

171175
### API Breaking Changes
172176

177+
<<<<<<< HEAD
173178
* Migrate to CometBFT. Follow the migration instructions in the [upgrade guide](./UPGRADING.md#migration-to-cometbft-part-1).
174179
* (simulation) [#14728](https://github.com/cosmos/cosmos-sdk/pull/14728) Rename the `ParamChanges` field to `LegacyParamChange` and `Contents` to `LegacyProposalContents` in `simulation.SimulationState`. Additionally it adds a `ProposalMsgs` field to `simulation.SimulationState`.
175180
* (x/gov) [#14782](https://github.com/cosmos/cosmos-sdk/pull/14782) Move the `metadata` argument in `govv1.NewProposal` alongside `title` and `summary`.
@@ -182,6 +187,17 @@ Ref: https://keepachangelog.com/en/1.0.0/
182187
* Remove listening APIs from the caching layer (it should only listen to the `rootmulti.Store`)
183188
* Add three new options to file streaming service constructor.
184189
* Modify `ABCIListener` such that any error from any method will always halt the app via `panic`
190+
=======
191+
* (x/simulation) [#14751](https://github.com/cosmos/cosmos-sdk/pull/14751) Remove the `MsgType` field from `simulation.OperationInput` struct.
192+
* (crypto/keyring) [#13734](https://github.com/cosmos/cosmos-sdk/pull/13834) The keyring's `Sign` method now takes a new `signMode` argument. It is only used if the signing key is a Ledger hardware device. You can set it to 0 in all other cases.
193+
* (x/evidence) [14724](https://github.com/cosmos/cosmos-sdk/pull/14724) Extract Evidence in its own go.mod and rename the package to `cosmossdk.io/x/evidence`.
194+
* (x/nft) [#14725](https://github.com/cosmos/cosmos-sdk/pull/14725) Extract NFT in its own go.mod and rename the package to `cosmossdk.io/x/nft`.
195+
* (tx) [#14634](https://github.com/cosmos/cosmos-sdk/pull/14634) Move the `tx` go module to `x/tx`.
196+
* (snapshots) [#14597](https://github.com/cosmos/cosmos-sdk/pull/14597) Move `snapshots` to `store/snapshots`, rename and bump proto package to v1.
197+
* (crypto/keyring) [#14151](https://github.com/cosmos/cosmos-sdk/pull/14151) Move keys presentation from `crypto/keyring` to `client/keys`
198+
* (modules) [#13850](https://github.com/cosmos/cosmos-sdk/pull/13850) and [#14046](https://github.com/cosmos/cosmos-sdk/pull/14046) Remove gogoproto stringer annotations. This removes the custom `String()` methods on all types that were using the annotations.
199+
* (x/auth) [#13850](https://github.com/cosmos/cosmos-sdk/pull/13850/) Remove `MarshalYAML` methods from module (`x/...`) types.
200+
>>>>>>> 8dbdfea9e (refactor: remove `.Type()` and `.Route()` from msgs (#14751))
185201
* (x/auth) [#13877](https://github.com/cosmos/cosmos-sdk/pull/13877) Rename `AccountKeeper`'s `GetNextAccountNumber` to `NextAccountNumber`.
186202
* (x/evidence) [#13740](https://github.com/cosmos/cosmos-sdk/pull/13740) The `NewQueryEvidenceRequest` function now takes `hash` as a HEX encoded `string`.
187203
* (server) [#13485](https://github.com/cosmos/cosmos-sdk/pull/13485) The `Application` service now requires the `RegisterNodeService` method to be implemented.

baseapp/baseapp.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -850,11 +850,8 @@ func createEvents(events sdk.Events, msg sdk.Msg) sdk.Events {
850850

851851
// verify that events have no module attribute set
852852
if _, found := events.GetAttributes(sdk.AttributeKeyModule); !found {
853-
// here we assume that routes module name is the second element of the route
854-
// e.g. "cosmos.bank.v1beta1.MsgSend" => "bank"
855-
moduleName := strings.Split(eventMsgName, ".")
856-
if len(moduleName) > 1 {
857-
msgEvent = msgEvent.AppendAttributes(sdk.NewAttribute(sdk.AttributeKeyModule, moduleName[1]))
853+
if moduleName := sdk.GetModuleNameFromTypeURL(eventMsgName); moduleName != "" {
854+
msgEvent = msgEvent.AppendAttributes(sdk.NewAttribute(sdk.AttributeKeyModule, moduleName))
858855
}
859856
}
860857

docs/docs/building-modules/02-messages-and-queries.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/types/tx_msg.go#L14-L26
6363

6464
It extends `proto.Message` and contains the following methods:
6565

66-
* `Route() string`: Name of the route for this message. Typically all `message`s in a module have the same route, which is most often the module's name.
67-
* `Type() string`: Type of the message, used primarily in [events](../core/08-events.md). This should return a message-specific `string`, typically the denomination of the message itself.
6866
* [`ValidateBasic() error`](../basics/01-tx-lifecycle.md#ValidateBasic).
6967
* `GetSignBytes() []byte`: Return the canonical byte representation of the message. Used to generate a signature.
7068
* `GetSigners() []AccAddress`: Return the list of signers. The Cosmos SDK will make sure that each `message` contained in a transaction is signed by all the signers listed in the list returned by this method.

docs/docs/core/08-events.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ The following examples show how to query Events using the Cosmos SDK.
5757
| ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
5858
| `tx.height=23` | Query all transactions at height 23 |
5959
| `message.action='/cosmos.bank.v1beta1.Msg/Send'` | Query all transactions containing a x/bank `Send` [Service `Msg`](../building-modules/03-msg-services.md). Note the `'`s around the value. |
60-
| `message.action='send'` | Query all transactions containing a x/bank `Send` [legacy `Msg`](../building-modules/03-msg-services.md#legacy-amino-msgs). Note the `'`s around the value. |
6160
| `message.module='bank'` | Query all transactions containing messages from the x/bank module. Note the `'`s around the value. |
6261
| `create_validator.validator='cosmosval1...'` | x/staking-specific Event, see [x/staking SPEC](../modules/staking/README.md). |
6362

testutil/testdata/tx.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ func NewTestMsg(addrs ...sdk.AccAddress) *TestMsg {
7777

7878
var _ sdk.Msg = (*TestMsg)(nil)
7979

80-
func (msg *TestMsg) Route() string { return "TestMsg" }
81-
func (msg *TestMsg) Type() string { return "Test message" }
8280
func (msg *TestMsg) GetSignBytes() []byte {
8381
bz, err := json.Marshal(msg.Signers)
8482
if err != nil {

types/simulation/types.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ type OperationMsg struct {
7676
}
7777

7878
// NewOperationMsgBasic creates a new operation message from raw input.
79-
func NewOperationMsgBasic(route, name, comment string, ok bool, msg []byte) OperationMsg {
79+
func NewOperationMsgBasic(moduleName, msgType, comment string, ok bool, msg []byte) OperationMsg {
8080
return OperationMsg{
81-
Route: route,
82-
Name: name,
81+
Route: moduleName,
82+
Name: msgType,
8383
Comment: comment,
8484
OK: ok,
8585
Msg: msg,
@@ -88,18 +88,22 @@ func NewOperationMsgBasic(route, name, comment string, ok bool, msg []byte) Oper
8888

8989
// NewOperationMsg - create a new operation message from sdk.Msg
9090
func NewOperationMsg(msg sdk.Msg, ok bool, comment string, cdc *codec.ProtoCodec) OperationMsg {
91-
if legacyMsg, okType := msg.(legacytx.LegacyMsg); okType {
92-
return NewOperationMsgBasic(legacyMsg.Route(), legacyMsg.Type(), comment, ok, legacyMsg.GetSignBytes())
91+
msgType := sdk.MsgTypeURL(msg)
92+
moduleName := sdk.GetModuleNameFromTypeURL(msgType)
93+
if moduleName == "" {
94+
moduleName = msgType
9395
}
9496

95-
bz := cdc.MustMarshalJSON(msg)
97+
if legacyMsg, okType := msg.(legacytx.LegacyMsg); okType {
98+
return NewOperationMsgBasic(moduleName, msgType, comment, ok, legacyMsg.GetSignBytes())
99+
}
96100

97-
return NewOperationMsgBasic(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), comment, ok, bz)
101+
return NewOperationMsgBasic(moduleName, msgType, comment, ok, cdc.MustMarshalJSON(msg))
98102
}
99103

100104
// NoOpMsg - create a no-operation message
101-
func NoOpMsg(route, msgType, comment string) OperationMsg {
102-
return NewOperationMsgBasic(route, msgType, comment, false, nil)
105+
func NoOpMsg(moduleName, msgType, comment string) OperationMsg {
106+
return NewOperationMsgBasic(moduleName, msgType, comment, false, nil)
103107
}
104108

105109
// log entry text for this operation msg

types/tx_msg.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package types
33
import (
44
"encoding/json"
55
fmt "fmt"
6+
strings "strings"
67

78
"github.com/cosmos/gogoproto/proto"
89

@@ -102,3 +103,15 @@ func GetMsgFromTypeURL(cdc codec.Codec, input string) (Msg, error) {
102103

103104
return msg, nil
104105
}
106+
107+
// GetModuleNameFromTypeURL assumes that module name is the second element of the msg type URL
108+
// e.g. "cosmos.bank.v1beta1.MsgSend" => "bank"
109+
// It returns an empty string if the input is not a valid type URL
110+
func GetModuleNameFromTypeURL(input string) string {
111+
moduleName := strings.Split(input, ".")
112+
if len(moduleName) > 1 {
113+
return moduleName[1]
114+
}
115+
116+
return ""
117+
}

types/tx_msg_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ func (s *testMsgSuite) TestMsg() {
2525
msg := testdata.NewTestMsg(accAddr)
2626
s.Require().NotNil(msg)
2727
s.Require().True(accAddr.Equals(msg.GetSigners()[0]))
28-
s.Require().Equal("TestMsg", msg.Route())
29-
s.Require().Equal("Test message", msg.Type())
3028
s.Require().Nil(msg.ValidateBasic())
3129
s.Require().NotPanics(func() { msg.GetSignBytes() })
3230
}

x/auth/migrations/legacytx/stdsign.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,14 @@ import (
1717
"github.com/cosmos/cosmos-sdk/types/tx/signing"
1818
)
1919

20-
// LegacyMsg defines the old interface a message must fulfill, containing
21-
// Amino signing method and legacy router info.
20+
// LegacyMsg defines the old interface a message must fulfill,
21+
// containing Amino signing method.
2222
// Deprecated: Please use `Msg` instead.
2323
type LegacyMsg interface {
2424
sdk.Msg
2525

2626
// Get the canonical byte representation of the Msg.
2727
GetSignBytes() []byte
28-
29-
// Return the message type.
30-
// Must be alphanumeric or empty.
31-
Route() string
32-
33-
// Returns a human-readable string for the message, intended for utilization
34-
// within tags
35-
Type() string
3628
}
3729

3830
// StdSignDoc is replay-prevention structure.

x/auth/types/msgs.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@ package types
33
import (
44
sdk "github.com/cosmos/cosmos-sdk/types"
55
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
6+
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
67
)
78

8-
var _ sdk.Msg = &MsgUpdateParams{}
9+
var (
10+
_ sdk.Msg = &MsgUpdateParams{}
11+
_ legacytx.LegacyMsg = &MsgUpdateParams{}
12+
)
913

1014
// GetSignBytes implements the LegacyMsg interface.
1115
func (msg MsgUpdateParams) GetSignBytes() []byte {
1216
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
1317
}
1418

1519
// GetSigners returns the expected signers for a MsgUpdateParams message.
16-
func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress {
20+
func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress {
1721
addr, _ := sdk.AccAddressFromBech32(msg.Authority)
1822
return []sdk.AccAddress{addr}
1923
}
2024

2125
// ValidateBasic does a sanity check on the provided data.
22-
func (msg *MsgUpdateParams) ValidateBasic() error {
26+
func (msg MsgUpdateParams) ValidateBasic() error {
2327
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
2428
return sdkerrors.Wrap(err, "invalid authority address")
2529
}

0 commit comments

Comments
 (0)