diff --git a/PENDING.md b/PENDING.md index d773e4645261..fd8cfbace327 100644 --- a/PENDING.md +++ b/PENDING.md @@ -86,6 +86,7 @@ BREAKING CHANGES * [x/stake] \#2531 Remove all inflation logic * [x/mint] \#2531 Add minting module and inflation logic * [x/auth] [\#2540](https://github.com/cosmos/cosmos-sdk/issues/2540) Rename `AccountMapper` to `AccountKeeper`. + * [types] \#2456 Renamed msg.Name() and msg.Type() to msg.Type() and msg.Route() respectively * Tendermint * Update tendermint version from v0.23.0 to v0.25.0, notable changes diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index b390e38417af..17942b976aa9 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -528,10 +528,10 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (re var code sdk.ABCICodeType for msgIdx, msg := range msgs { // Match route. - msgType := msg.Type() - handler := app.router.Route(msgType) + msgRoute := msg.Route() + handler := app.router.Route(msgRoute) if handler == nil { - return sdk.ErrUnknownRequest("Unrecognized Msg type: " + msgType).Result() + return sdk.ErrUnknownRequest("Unrecognized Msg type: " + msgRoute).Result() } var msgResult sdk.Result @@ -539,7 +539,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (re if mode != runTxModeCheck { msgResult = handler(ctx, msg) } - msgResult.Tags = append(msgResult.Tags, sdk.MakeTag("action", []byte(msg.Name()))) + msgResult.Tags = append(msgResult.Tags, sdk.MakeTag("action", []byte(msg.Type()))) // NOTE: GasWanted is determined by ante handler and // GasUsed by the GasMeter diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 0137a3f7d7be..ff6cbb83418f 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -290,8 +290,8 @@ type txTest struct { func (tx txTest) GetMsgs() []sdk.Msg { return tx.Msgs } const ( - typeMsgCounter = "msgCounter" - typeMsgCounter2 = "msgCounter2" + routeMsgCounter = "msgCounter" + routeMsgCounter2 = "msgCounter2" ) // ValidateBasic() fails on negative counters. @@ -301,8 +301,8 @@ type msgCounter struct { } // Implements Msg -func (msg msgCounter) Type() string { return typeMsgCounter } -func (msg msgCounter) Name() string { return "counter1" } +func (msg msgCounter) Route() string { return routeMsgCounter } +func (msg msgCounter) Type() string { return "counter1" } func (msg msgCounter) GetSignBytes() []byte { return nil } func (msg msgCounter) GetSigners() []sdk.AccAddress { return nil } func (msg msgCounter) ValidateBasic() sdk.Error { @@ -325,14 +325,14 @@ type msgNoRoute struct { msgCounter } -func (tx msgNoRoute) Type() string { return "noroute" } +func (tx msgNoRoute) Route() string { return "noroute" } // a msg we dont know how to decode type msgNoDecode struct { msgCounter } -func (tx msgNoDecode) Type() string { return typeMsgCounter } +func (tx msgNoDecode) Route() string { return routeMsgCounter } // Another counter msg. Duplicate of msgCounter type msgCounter2 struct { @@ -340,8 +340,8 @@ type msgCounter2 struct { } // Implements Msg -func (msg msgCounter2) Type() string { return typeMsgCounter2 } -func (msg msgCounter2) Name() string { return "counter2" } +func (msg msgCounter2) Route() string { return routeMsgCounter2 } +func (msg msgCounter2) Type() string { return "counter2" } func (msg msgCounter2) GetSignBytes() []byte { return nil } func (msg msgCounter2) GetSigners() []sdk.AccAddress { return nil } func (msg msgCounter2) ValidateBasic() sdk.Error { @@ -440,7 +440,7 @@ func TestCheckTx(t *testing.T) { anteOpt := func(bapp *BaseApp) { bapp.SetAnteHandler(anteHandlerTxTest(t, capKey1, counterKey)) } routerOpt := func(bapp *BaseApp) { // TODO: can remove this once CheckTx doesnt process msgs. - bapp.Router().AddRoute(typeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) sdk.Result { return sdk.Result{} }) + bapp.Router().AddRoute(routeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) sdk.Result { return sdk.Result{} }) } app := setupBaseApp(t, anteOpt, routerOpt) @@ -486,7 +486,9 @@ func TestDeliverTx(t *testing.T) { // test increments in the handler deliverKey := []byte("deliver-key") - routerOpt := func(bapp *BaseApp) { bapp.Router().AddRoute(typeMsgCounter, handlerMsgCounter(t, capKey1, deliverKey)) } + routerOpt := func(bapp *BaseApp) { + bapp.Router().AddRoute(routeMsgCounter, handlerMsgCounter(t, capKey1, deliverKey)) + } app := setupBaseApp(t, anteOpt, routerOpt) @@ -527,8 +529,8 @@ func TestMultiMsgDeliverTx(t *testing.T) { deliverKey := []byte("deliver-key") deliverKey2 := []byte("deliver-key2") routerOpt := func(bapp *BaseApp) { - bapp.Router().AddRoute(typeMsgCounter, handlerMsgCounter(t, capKey1, deliverKey)) - bapp.Router().AddRoute(typeMsgCounter2, handlerMsgCounter(t, capKey1, deliverKey2)) + bapp.Router().AddRoute(routeMsgCounter, handlerMsgCounter(t, capKey1, deliverKey)) + bapp.Router().AddRoute(routeMsgCounter2, handlerMsgCounter(t, capKey1, deliverKey2)) } app := setupBaseApp(t, anteOpt, routerOpt) @@ -538,7 +540,7 @@ func TestMultiMsgDeliverTx(t *testing.T) { registerTestCodec(codec) // run a multi-msg tx - // with all msgs the same type + // with all msgs the same route { app.BeginBlock(abci.RequestBeginBlock{}) tx := newTxCounter(0, 0, 1, 2) @@ -604,7 +606,7 @@ func TestSimulateTx(t *testing.T) { } routerOpt := func(bapp *BaseApp) { - bapp.Router().AddRoute(typeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) sdk.Result { + bapp.Router().AddRoute(routeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) sdk.Result { ctx.GasMeter().ConsumeGas(gasConsumed, "test") return sdk.Result{GasUsed: ctx.GasMeter().GasConsumed()} }) @@ -666,7 +668,7 @@ func TestRunInvalidTransaction(t *testing.T) { }) } routerOpt := func(bapp *BaseApp) { - bapp.Router().AddRoute(typeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) (res sdk.Result) { return }) + bapp.Router().AddRoute(routeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) (res sdk.Result) { return }) } app := setupBaseApp(t, anteOpt, routerOpt) @@ -771,7 +773,7 @@ func TestTxGasLimits(t *testing.T) { } routerOpt := func(bapp *BaseApp) { - bapp.Router().AddRoute(typeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) sdk.Result { + bapp.Router().AddRoute(routeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) sdk.Result { count := msg.(msgCounter).Counter ctx.GasMeter().ConsumeGas(count, "counter-handler") return sdk.Result{} diff --git a/baseapp/query_test.go b/baseapp/query_test.go index 579874e21745..d9d4001eb437 100644 --- a/baseapp/query_test.go +++ b/baseapp/query_test.go @@ -21,7 +21,7 @@ func TestQuery(t *testing.T) { } routerOpt := func(bapp *BaseApp) { - bapp.Router().AddRoute(typeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) sdk.Result { + bapp.Router().AddRoute(routeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) sdk.Result { store := ctx.KVStore(capKey1) store.Set(key, value) return sdk.Result{} diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index a173ac0e271d..bff2260abcda 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -345,7 +345,7 @@ func TestCoinSendGenerateSignAndBroadcast(t *testing.T) { var msg auth.StdTx require.Nil(t, cdc.UnmarshalJSON([]byte(body), &msg)) require.Equal(t, len(msg.Msgs), 1) - require.Equal(t, msg.Msgs[0].Type(), "bank") + require.Equal(t, msg.Msgs[0].Route(), "bank") require.Equal(t, msg.Msgs[0].GetSigners(), []sdk.AccAddress{addr}) require.Equal(t, 0, len(msg.Signatures)) gasEstimate := msg.Fee.Gas diff --git a/docs/sdk/core/app1.md b/docs/sdk/core/app1.md index 9338d30d99b6..a1aa76f72e39 100644 --- a/docs/sdk/core/app1.md +++ b/docs/sdk/core/app1.md @@ -14,10 +14,10 @@ Developers can create messages by implementing the `Msg` interface: ```go type Msg interface { - // Return the message type. + // Return the message Route. // Must be alphanumeric or empty. // Must correspond to name of message handler (XXX). - Type() string + Route() string // ValidateBasic does a simple validation check that // doesn't require access to any other information. @@ -49,7 +49,7 @@ type MsgSend struct { } // Implements Msg. -func (msg MsgSend) Type() string { return "send" } +func (msg MsgSend) Route() string { return "send" } ``` It specifies that the message should be JSON marshaled and signed by the sender: diff --git a/docs/sdk/core/app2.md b/docs/sdk/core/app2.md index 6477617fb13d..d8040a850014 100644 --- a/docs/sdk/core/app2.md +++ b/docs/sdk/core/app2.md @@ -28,11 +28,11 @@ type MsgIssue struct { } // Implements Msg. -func (msg MsgIssue) Type() string { return "issue" } +func (msg MsgIssue) Route() string { return "issue" } ``` -Note the `Type()` method returns `"issue"`, so this message is of a different -type and will be executed by a different handler than `MsgSend`. The other +Note the `Route()` method returns `"issue"`, so this message is of a different +route and will be executed by a different handler than `MsgSend`. The other methods for `MsgIssue` are similar to `MsgSend`. ## Handler diff --git a/docs/sdk/core/examples/app1.go b/docs/sdk/core/examples/app1.go index 13798345523f..8ee34fca59e7 100644 --- a/docs/sdk/core/examples/app1.go +++ b/docs/sdk/core/examples/app1.go @@ -56,8 +56,9 @@ func NewMsgSend(from, to sdk.AccAddress, amt sdk.Coins) MsgSend { } // Implements Msg. -func (msg MsgSend) Type() string { return "send" } -func (msg MsgSend) Name() string { return "send" } +// nolint +func (msg MsgSend) Route() string { return "send" } +func (msg MsgSend) Type() string { return "send" } // Implements Msg. Ensure the addresses are good and the // amount is positive. diff --git a/docs/sdk/core/examples/app2.go b/docs/sdk/core/examples/app2.go index 3ff9d1dea3fa..c1ae43666824 100644 --- a/docs/sdk/core/examples/app2.go +++ b/docs/sdk/core/examples/app2.go @@ -76,8 +76,9 @@ type MsgIssue struct { } // Implements Msg. -func (msg MsgIssue) Type() string { return "issue" } -func (msg MsgIssue) Name() string { return "issue" } +// nolint +func (msg MsgIssue) Route() string { return "issue" } +func (msg MsgIssue) Type() string { return "issue" } // Implements Msg. Ensures addresses are valid and Coin is positive func (msg MsgIssue) ValidateBasic() sdk.Error { diff --git a/examples/democoin/x/cool/handler.go b/examples/democoin/x/cool/handler.go index a4c6ce7be6af..98da59690adb 100644 --- a/examples/democoin/x/cool/handler.go +++ b/examples/democoin/x/cool/handler.go @@ -25,7 +25,7 @@ func NewHandler(k Keeper) sdk.Handler { case MsgQuiz: return handleMsgQuiz(ctx, k, msg) default: - errMsg := fmt.Sprintf("Unrecognized cool Msg type: %v", msg.Name()) + errMsg := fmt.Sprintf("Unrecognized cool Msg type: %v", msg.Type()) return sdk.ErrUnknownRequest(errMsg).Result() } } diff --git a/examples/democoin/x/cool/types.go b/examples/democoin/x/cool/types.go index f04811b14a90..11d3dde6bc7c 100644 --- a/examples/democoin/x/cool/types.go +++ b/examples/democoin/x/cool/types.go @@ -32,8 +32,8 @@ func NewMsgSetTrend(sender sdk.AccAddress, cool string) MsgSetTrend { var _ sdk.Msg = MsgSetTrend{} // nolint -func (msg MsgSetTrend) Type() string { return "cool" } -func (msg MsgSetTrend) Name() string { return "set_trend" } +func (msg MsgSetTrend) Route() string { return "cool" } +func (msg MsgSetTrend) Type() string { return "set_trend" } func (msg MsgSetTrend) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.Sender} } func (msg MsgSetTrend) String() string { return fmt.Sprintf("MsgSetTrend{Sender: %v, Cool: %v}", msg.Sender, msg.Cool) @@ -83,8 +83,8 @@ func NewMsgQuiz(sender sdk.AccAddress, coolerthancool string) MsgQuiz { var _ sdk.Msg = MsgQuiz{} // nolint -func (msg MsgQuiz) Type() string { return "cool" } -func (msg MsgQuiz) Name() string { return "quiz" } +func (msg MsgQuiz) Route() string { return "cool" } +func (msg MsgQuiz) Type() string { return "quiz" } func (msg MsgQuiz) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.Sender} } func (msg MsgQuiz) String() string { return fmt.Sprintf("MsgQuiz{Sender: %v, CoolAnswer: %v}", msg.Sender, msg.CoolAnswer) diff --git a/examples/democoin/x/oracle/README.md b/examples/democoin/x/oracle/README.md index b840dc0e8b6c..605e5c5bd408 100644 --- a/examples/democoin/x/oracle/README.md +++ b/examples/democoin/x/oracle/README.md @@ -15,7 +15,7 @@ type MyPayload struct { } ``` -When you write a payload, its `.Type()` should return same name with your module is registered on the router. It is because `oracle.Msg` inherits `.Type()` from its embedded payload and it should be handled on the user modules. +When you write a payload, its `.Route()` should return same route with your module is registered on the router. It is because `oracle.Msg` inherits `.Route()` from its embedded payload and it should be handled on the user modules. Then route every incoming `oracle.Msg` to `oracle.Keeper.Handler()` with the function that implements `oracle.Handler`. diff --git a/examples/democoin/x/oracle/oracle_test.go b/examples/democoin/x/oracle/oracle_test.go index 0b921e9d95c9..7621ea86090f 100644 --- a/examples/democoin/x/oracle/oracle_test.go +++ b/examples/democoin/x/oracle/oracle_test.go @@ -31,10 +31,10 @@ type seqOracle struct { Nonce int } -func (o seqOracle) Type() string { +func (o seqOracle) Route() string { return "seq" } -func (o seqOracle) Name() string { +func (o seqOracle) Type() string { return "seq" } diff --git a/examples/democoin/x/oracle/types.go b/examples/democoin/x/oracle/types.go index 5e47597b80a8..06590e3a0c62 100644 --- a/examples/democoin/x/oracle/types.go +++ b/examples/democoin/x/oracle/types.go @@ -28,7 +28,7 @@ func (msg Msg) GetSigners() []sdk.AccAddress { // Payload defines inner data for actual execution type Payload interface { + Route() string Type() string - Name() string ValidateBasic() sdk.Error } diff --git a/examples/democoin/x/pow/handler.go b/examples/democoin/x/pow/handler.go index 246246e96ec1..5aa4cbab5e01 100644 --- a/examples/democoin/x/pow/handler.go +++ b/examples/democoin/x/pow/handler.go @@ -10,7 +10,7 @@ func (pk Keeper) Handler(ctx sdk.Context, msg sdk.Msg) sdk.Result { case MsgMine: return handleMsgMine(ctx, pk, msg) default: - errMsg := "Unrecognized pow Msg type: " + msg.Name() + errMsg := "Unrecognized pow Msg type: " + msg.Type() return sdk.ErrUnknownRequest(errMsg).Result() } } diff --git a/examples/democoin/x/pow/types.go b/examples/democoin/x/pow/types.go index 4f808cbedcec..80bad3a584d1 100644 --- a/examples/democoin/x/pow/types.go +++ b/examples/democoin/x/pow/types.go @@ -31,8 +31,8 @@ func NewMsgMine(sender sdk.AccAddress, difficulty uint64, count uint64, nonce ui } // nolint -func (msg MsgMine) Type() string { return "pow" } -func (msg MsgMine) Name() string { return "mine" } +func (msg MsgMine) Route() string { return "pow" } +func (msg MsgMine) Type() string { return "mine" } func (msg MsgMine) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.Sender} } func (msg MsgMine) String() string { return fmt.Sprintf("MsgMine{Sender: %s, Difficulty: %d, Count: %d, Nonce: %d, Proof: %s}", msg.Sender, msg.Difficulty, msg.Count, msg.Nonce, msg.Proof) diff --git a/examples/democoin/x/pow/types_test.go b/examples/democoin/x/pow/types_test.go index dbe6ad35e953..44f79899dd9f 100644 --- a/examples/democoin/x/pow/types_test.go +++ b/examples/democoin/x/pow/types_test.go @@ -19,7 +19,7 @@ func TestNewMsgMine(t *testing.T) { func TestMsgMineType(t *testing.T) { addr := sdk.AccAddress([]byte("sender")) msg := MsgMine{addr, 0, 0, 0, []byte("")} - require.Equal(t, msg.Type(), "pow") + require.Equal(t, msg.Route(), "pow") } func TestMsgMineValidation(t *testing.T) { diff --git a/examples/democoin/x/simplestake/msgs.go b/examples/democoin/x/simplestake/msgs.go index aea984d18bb6..f3edb4ce0d84 100644 --- a/examples/democoin/x/simplestake/msgs.go +++ b/examples/democoin/x/simplestake/msgs.go @@ -26,8 +26,8 @@ func NewMsgBond(addr sdk.AccAddress, stake sdk.Coin, pubKey crypto.PubKey) MsgBo } //nolint -func (msg MsgBond) Type() string { return moduleName } //TODO update "stake/createvalidator" -func (msg MsgBond) Name() string { return "bond" } +func (msg MsgBond) Route() string { return moduleName } //TODO update "stake/createvalidator" +func (msg MsgBond) Type() string { return "bond" } func (msg MsgBond) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.Address} } // basic validation of the bond message @@ -66,8 +66,8 @@ func NewMsgUnbond(addr sdk.AccAddress) MsgUnbond { } //nolint -func (msg MsgUnbond) Type() string { return moduleName } //TODO update "stake/createvalidator" -func (msg MsgUnbond) Name() string { return "unbond" } +func (msg MsgUnbond) Route() string { return moduleName } //TODO update "stake/createvalidator" +func (msg MsgUnbond) Type() string { return "unbond" } func (msg MsgUnbond) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.Address} } func (msg MsgUnbond) ValidateBasic() sdk.Error { return nil } diff --git a/examples/kvstore/tx.go b/examples/kvstore/tx.go index bb3075ae4212..9c9cb8955677 100644 --- a/examples/kvstore/tx.go +++ b/examples/kvstore/tx.go @@ -14,11 +14,11 @@ type kvstoreTx struct { bytes []byte } -func (tx kvstoreTx) Type() string { +func (tx kvstoreTx) Route() string { return "kvstore" } -func (tx kvstoreTx) Name() string { +func (tx kvstoreTx) Type() string { return "kvstore" } diff --git a/server/mock/tx.go b/server/mock/tx.go index 3bd248c7441b..750d6984d213 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -27,11 +27,11 @@ func NewTx(key, value string) kvstoreTx { } } -func (tx kvstoreTx) Type() string { +func (tx kvstoreTx) Route() string { return "kvstore" } -func (tx kvstoreTx) Name() string { +func (tx kvstoreTx) Type() string { return "kvstore_tx" } diff --git a/types/tx_msg.go b/types/tx_msg.go index 9b4aab9370cd..7882b25d3193 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -9,11 +9,11 @@ type Msg interface { // Return the message type. // Must be alphanumeric or empty. - Type() string + Route() string // Returns a human-readable string for the message, intended for utilization // within tags - Name() string + Type() string // ValidateBasic does a simple validation check that // doesn't require access to any other information. @@ -58,8 +58,8 @@ func NewTestMsg(addrs ...AccAddress) *TestMsg { } //nolint -func (msg *TestMsg) Type() string { return "TestMsg" } -func (msg *TestMsg) Name() string { return "Test message" } +func (msg *TestMsg) Route() string { return "TestMsg" } +func (msg *TestMsg) Type() string { return "Test message" } func (msg *TestMsg) GetSignBytes() []byte { bz, err := json.Marshal(msg.signers) if err != nil { diff --git a/x/bank/handler.go b/x/bank/handler.go index cd60ac835122..e02043d7b4f1 100644 --- a/x/bank/handler.go +++ b/x/bank/handler.go @@ -13,7 +13,7 @@ func NewHandler(k Keeper) sdk.Handler { case MsgIssue: return handleMsgIssue(ctx, k, msg) default: - errMsg := "Unrecognized bank Msg type: %s" + msg.Name() + errMsg := "Unrecognized bank Msg type: %s" + msg.Type() return sdk.ErrUnknownRequest(errMsg).Result() } } diff --git a/x/bank/msgs.go b/x/bank/msgs.go index ed2d9a780f17..a1c346a88d80 100644 --- a/x/bank/msgs.go +++ b/x/bank/msgs.go @@ -21,8 +21,8 @@ func NewMsgSend(in []Input, out []Output) MsgSend { // Implements Msg. // nolint -func (msg MsgSend) Type() string { return "bank" } // TODO: "bank/send" -func (msg MsgSend) Name() string { return "send" } +func (msg MsgSend) Route() string { return "bank" } // TODO: "bank/send" +func (msg MsgSend) Type() string { return "send" } // Implements Msg. func (msg MsgSend) ValidateBasic() sdk.Error { @@ -104,8 +104,8 @@ func NewMsgIssue(banker sdk.AccAddress, out []Output) MsgIssue { // Implements Msg. // nolint -func (msg MsgIssue) Type() string { return "bank" } // TODO: "bank/issue" -func (msg MsgIssue) Name() string { return "issue" } +func (msg MsgIssue) Route() string { return "bank" } // TODO: "bank/issue" +func (msg MsgIssue) Type() string { return "issue" } // Implements Msg. func (msg MsgIssue) ValidateBasic() sdk.Error { diff --git a/x/bank/msgs_test.go b/x/bank/msgs_test.go index e082bdac4227..157cc9b5b95b 100644 --- a/x/bank/msgs_test.go +++ b/x/bank/msgs_test.go @@ -11,7 +11,7 @@ import ( func TestNewMsgSend(t *testing.T) {} -func TestMsgSendType(t *testing.T) { +func TestMsgSendRoute(t *testing.T) { // Construct a MsgSend addr1 := sdk.AccAddress([]byte("input")) addr2 := sdk.AccAddress([]byte("output")) @@ -22,7 +22,7 @@ func TestMsgSendType(t *testing.T) { } // TODO some failures for bad result - require.Equal(t, msg.Type(), "bank") + require.Equal(t, msg.Route(), "bank") } func TestInputValidation(t *testing.T) { @@ -231,7 +231,7 @@ func TestNewMsgIssue(t *testing.T) { // TODO } -func TestMsgIssueType(t *testing.T) { +func TestMsgIssueRoute(t *testing.T) { // Construct an MsgIssue addr := sdk.AccAddress([]byte("loan-from-bank")) coins := sdk.Coins{sdk.NewInt64Coin("atom", 10)} @@ -241,7 +241,7 @@ func TestMsgIssueType(t *testing.T) { } // TODO some failures for bad result - require.Equal(t, msg.Type(), "bank") + require.Equal(t, msg.Route(), "bank") } func TestMsgIssueValidation(t *testing.T) { diff --git a/x/distribution/types/msg.go b/x/distribution/types/msg.go index f00dceae1f5d..f7c80c2122ce 100644 --- a/x/distribution/types/msg.go +++ b/x/distribution/types/msg.go @@ -6,7 +6,7 @@ import ( ) // name to identify transaction types -const MsgType = "distr" +const MsgRoute = "distr" // Verify interface at compile time var _, _ sdk.Msg = &MsgSetWithdrawAddress{}, &MsgWithdrawDelegatorRewardsAll{} @@ -27,8 +27,8 @@ func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) MsgSetWithdr } } -func (msg MsgSetWithdrawAddress) Type() string { return MsgType } -func (msg MsgSetWithdrawAddress) Name() string { return "set_withdraw_address" } +func (msg MsgSetWithdrawAddress) Route() string { return MsgRoute } +func (msg MsgSetWithdrawAddress) Type() string { return "set_withdraw_address" } // Return address that must sign over msg.GetSignBytes() func (msg MsgSetWithdrawAddress) GetSigners() []sdk.AccAddress { @@ -68,8 +68,8 @@ func NewMsgWithdrawDelegatorRewardsAll(delAddr sdk.AccAddress) MsgWithdrawDelega } } -func (msg MsgWithdrawDelegatorRewardsAll) Type() string { return MsgType } -func (msg MsgWithdrawDelegatorRewardsAll) Name() string { return "withdraw_delegation_rewards_all" } +func (msg MsgWithdrawDelegatorRewardsAll) Route() string { return MsgRoute } +func (msg MsgWithdrawDelegatorRewardsAll) Type() string { return "withdraw_delegation_rewards_all" } // Return address that must sign over msg.GetSignBytes() func (msg MsgWithdrawDelegatorRewardsAll) GetSigners() []sdk.AccAddress { @@ -108,8 +108,8 @@ func NewMsgWithdrawDelegatorReward(delAddr sdk.AccAddress, valAddr sdk.ValAddres } } -func (msg MsgWithdrawDelegatorReward) Type() string { return MsgType } -func (msg MsgWithdrawDelegatorReward) Name() string { return "withdraw_delegation_reward" } +func (msg MsgWithdrawDelegatorReward) Route() string { return MsgRoute } +func (msg MsgWithdrawDelegatorReward) Type() string { return "withdraw_delegation_reward" } // Return address that must sign over msg.GetSignBytes() func (msg MsgWithdrawDelegatorReward) GetSigners() []sdk.AccAddress { @@ -149,8 +149,8 @@ func NewMsgWithdrawValidatorRewardsAll(valAddr sdk.ValAddress) MsgWithdrawValida } } -func (msg MsgWithdrawValidatorRewardsAll) Type() string { return MsgType } -func (msg MsgWithdrawValidatorRewardsAll) Name() string { return "withdraw_validator_rewards_all" } +func (msg MsgWithdrawValidatorRewardsAll) Route() string { return MsgRoute } +func (msg MsgWithdrawValidatorRewardsAll) Type() string { return "withdraw_validator_rewards_all" } // Return address that must sign over msg.GetSignBytes() func (msg MsgWithdrawValidatorRewardsAll) GetSigners() []sdk.AccAddress { diff --git a/x/gov/msgs.go b/x/gov/msgs.go index ac2b2c170402..847c04ab0d7d 100644 --- a/x/gov/msgs.go +++ b/x/gov/msgs.go @@ -7,7 +7,7 @@ import ( ) // name to idetify transaction types -const MsgType = "gov" +const MsgRoute = "gov" var _, _, _ sdk.Msg = MsgSubmitProposal{}, MsgDeposit{}, MsgVote{} @@ -31,9 +31,9 @@ func NewMsgSubmitProposal(title string, description string, proposalType Proposa } } -// Implements Msg. -func (msg MsgSubmitProposal) Type() string { return MsgType } -func (msg MsgSubmitProposal) Name() string { return "submit_proposal" } +//nolint +func (msg MsgSubmitProposal) Route() string { return MsgRoute } +func (msg MsgSubmitProposal) Type() string { return "submit_proposal" } // Implements Msg. func (msg MsgSubmitProposal) ValidateBasic() sdk.Error { @@ -99,8 +99,8 @@ func NewMsgDeposit(depositer sdk.AccAddress, proposalID int64, amount sdk.Coins) // Implements Msg. // nolint -func (msg MsgDeposit) Type() string { return MsgType } -func (msg MsgDeposit) Name() string { return "deposit" } +func (msg MsgDeposit) Route() string { return MsgRoute } +func (msg MsgDeposit) Type() string { return "deposit" } // Implements Msg. func (msg MsgDeposit) ValidateBasic() sdk.Error { @@ -160,8 +160,8 @@ func NewMsgVote(voter sdk.AccAddress, proposalID int64, option VoteOption) MsgVo // Implements Msg. // nolint -func (msg MsgVote) Type() string { return MsgType } -func (msg MsgVote) Name() string { return "vote" } +func (msg MsgVote) Route() string { return MsgRoute } +func (msg MsgVote) Type() string { return "vote" } // Implements Msg. func (msg MsgVote) ValidateBasic() sdk.Error { diff --git a/x/ibc/handler.go b/x/ibc/handler.go index 4a9eebaebc45..c7bffc529348 100644 --- a/x/ibc/handler.go +++ b/x/ibc/handler.go @@ -13,7 +13,7 @@ func NewHandler(ibcm Mapper, ck bank.Keeper) sdk.Handler { case IBCReceiveMsg: return handleIBCReceiveMsg(ctx, ibcm, ck, msg) default: - errMsg := "Unrecognized IBC Msg type: " + msg.Name() + errMsg := "Unrecognized IBC Msg type: " + msg.Type() return sdk.ErrUnknownRequest(errMsg).Result() } } diff --git a/x/ibc/types.go b/x/ibc/types.go index 64b7d1f4c945..72dae0d389d0 100644 --- a/x/ibc/types.go +++ b/x/ibc/types.go @@ -71,8 +71,8 @@ type IBCTransferMsg struct { } // nolint -func (msg IBCTransferMsg) Type() string { return "ibc" } -func (msg IBCTransferMsg) Name() string { return "transfer" } +func (msg IBCTransferMsg) Route() string { return "ibc" } +func (msg IBCTransferMsg) Type() string { return "transfer" } // x/bank/tx.go MsgSend.GetSigners() func (msg IBCTransferMsg) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.SrcAddr} } @@ -100,8 +100,8 @@ type IBCReceiveMsg struct { } // nolint -func (msg IBCReceiveMsg) Type() string { return "ibc" } -func (msg IBCReceiveMsg) Name() string { return "receive" } +func (msg IBCReceiveMsg) Route() string { return "ibc" } +func (msg IBCReceiveMsg) Type() string { return "receive" } func (msg IBCReceiveMsg) ValidateBasic() sdk.Error { return msg.IBCPacket.ValidateBasic() } // x/bank/tx.go MsgSend.GetSigners() diff --git a/x/ibc/types_test.go b/x/ibc/types_test.go index e7c51d6b2477..7e0f537d6e24 100644 --- a/x/ibc/types_test.go +++ b/x/ibc/types_test.go @@ -37,7 +37,7 @@ func TestIBCTransferMsg(t *testing.T) { packet := constructIBCPacket(true) msg := IBCTransferMsg{packet} - require.Equal(t, msg.Type(), "ibc") + require.Equal(t, msg.Route(), "ibc") } func TestIBCTransferMsgValidation(t *testing.T) { @@ -69,7 +69,7 @@ func TestIBCReceiveMsg(t *testing.T) { packet := constructIBCPacket(true) msg := IBCReceiveMsg{packet, sdk.AccAddress([]byte("relayer")), 0} - require.Equal(t, msg.Type(), "ibc") + require.Equal(t, msg.Route(), "ibc") } func TestIBCReceiveMsgValidation(t *testing.T) { diff --git a/x/mock/app_test.go b/x/mock/app_test.go index 6835d50b131f..9e12cac8ecc4 100644 --- a/x/mock/app_test.go +++ b/x/mock/app_test.go @@ -9,7 +9,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" ) -const msgType = "testMsg" +const msgRoute = "testMsg" var ( numAccts = 2 @@ -23,8 +23,8 @@ type testMsg struct { positiveNum int64 } -func (tx testMsg) Type() string { return msgType } -func (tx testMsg) Name() string { return "test" } +func (tx testMsg) Route() string { return msgRoute } +func (tx testMsg) Type() string { return "test" } func (tx testMsg) GetMsg() sdk.Msg { return tx } func (tx testMsg) GetMemo() string { return "" } func (tx testMsg) GetSignBytes() []byte { return nil } @@ -41,7 +41,7 @@ func (tx testMsg) ValidateBasic() sdk.Error { func getMockApp(t *testing.T) *App { mApp := NewApp() - mApp.Router().AddRoute(msgType, func(ctx sdk.Context, msg sdk.Msg) (res sdk.Result) { return }) + mApp.Router().AddRoute(msgRoute, func(ctx sdk.Context, msg sdk.Msg) (res sdk.Result) { return }) require.NoError(t, mApp.CompleteSetup()) return mApp diff --git a/x/slashing/msg.go b/x/slashing/msg.go index 3ba7f9273aa8..51864d4e2656 100644 --- a/x/slashing/msg.go +++ b/x/slashing/msg.go @@ -8,7 +8,7 @@ import ( var cdc = codec.New() // name to identify transaction types -const MsgType = "slashing" +const MsgRoute = "slashing" // verify interface at compile time var _ sdk.Msg = &MsgUnjail{} @@ -25,8 +25,8 @@ func NewMsgUnjail(validatorAddr sdk.ValAddress) MsgUnjail { } //nolint -func (msg MsgUnjail) Type() string { return MsgType } -func (msg MsgUnjail) Name() string { return "unjail" } +func (msg MsgUnjail) Route() string { return MsgRoute } +func (msg MsgUnjail) Type() string { return "unjail" } func (msg MsgUnjail) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{sdk.AccAddress(msg.ValidatorAddr)} } diff --git a/x/stake/types/msg.go b/x/stake/types/msg.go index da46415d254f..da7d684de71d 100644 --- a/x/stake/types/msg.go +++ b/x/stake/types/msg.go @@ -7,8 +7,8 @@ import ( "github.com/tendermint/tendermint/crypto" ) -// name to identify transaction types -const MsgType = "stake" +// name to identify transaction routes +const MsgRoute = "stake" // Verify interface at compile time var _, _, _ sdk.Msg = &MsgCreateValidator{}, &MsgEditValidator{}, &MsgDelegate{} @@ -48,8 +48,8 @@ func NewMsgCreateValidatorOnBehalfOf(delAddr sdk.AccAddress, valAddr sdk.ValAddr } //nolint -func (msg MsgCreateValidator) Type() string { return MsgType } -func (msg MsgCreateValidator) Name() string { return "create_validator" } +func (msg MsgCreateValidator) Route() string { return MsgRoute } +func (msg MsgCreateValidator) Type() string { return "create_validator" } // Return address(es) that must sign over msg.GetSignBytes() func (msg MsgCreateValidator) GetSigners() []sdk.AccAddress { @@ -129,8 +129,8 @@ func NewMsgEditValidator(valAddr sdk.ValAddress, description Description, newRat } //nolint -func (msg MsgEditValidator) Type() string { return MsgType } -func (msg MsgEditValidator) Name() string { return "edit_validator" } +func (msg MsgEditValidator) Route() string { return MsgRoute } +func (msg MsgEditValidator) Type() string { return "edit_validator" } func (msg MsgEditValidator) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{sdk.AccAddress(msg.ValidatorAddr)} } @@ -181,8 +181,8 @@ func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, delegation s } //nolint -func (msg MsgDelegate) Type() string { return MsgType } -func (msg MsgDelegate) Name() string { return "delegate" } +func (msg MsgDelegate) Route() string { return MsgRoute } +func (msg MsgDelegate) Type() string { return "delegate" } func (msg MsgDelegate) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.DelegatorAddr} } @@ -232,8 +232,8 @@ func NewMsgBeginRedelegate(delAddr sdk.AccAddress, valSrcAddr, } //nolint -func (msg MsgBeginRedelegate) Type() string { return MsgType } -func (msg MsgBeginRedelegate) Name() string { return "begin_redelegate" } +func (msg MsgBeginRedelegate) Route() string { return MsgRoute } +func (msg MsgBeginRedelegate) Type() string { return "begin_redelegate" } func (msg MsgBeginRedelegate) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.DelegatorAddr} } @@ -292,8 +292,8 @@ func NewMsgBeginUnbonding(delAddr sdk.AccAddress, valAddr sdk.ValAddress, shares } //nolint -func (msg MsgBeginUnbonding) Type() string { return MsgType } -func (msg MsgBeginUnbonding) Name() string { return "begin_unbonding" } +func (msg MsgBeginUnbonding) Route() string { return MsgRoute } +func (msg MsgBeginUnbonding) Type() string { return "begin_unbonding" } func (msg MsgBeginUnbonding) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.DelegatorAddr} } // get the bytes for the message signer to sign on