Remove ServiceMsgs from ADR-031 (#9139)
* wip * wip * wip * wip on refactoring adr 031 type URLs * Fix msg_service_router * Fix gov client queries * Fix some modules tests * Remove all instances of "*.Msg/*" * Uncomment code * Remove commented code * // simulation.NewWeightedOperation( * Fix CopyTx * Fix more tests * Fix x/gov test * proto.MessageName->sdk.MsgName * Fix authz tests * Use MsgRoute in feegrant and staking/authz * Fix more tests * Fix sims? * Add norace tag * Add CL * rebuild rosetta api test data * Update ADR * Rename MsgRoute -> MsgTypeURL * Fix codec registration * Remove sdk.GetLegacySignBytes * Update types/tx_msg.go * Update x/authz/simulation/operations.go * Move LegacyMsg to legacytx * Update CHANGELOG.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Remove NewAnyWithCustomTypeURL * Keep support for ServiceMsgs * Fix TxBody UnpackInterfaces * Fix test * Address review * Remove support for ServiceMsg typeURLs * Fix lint * Update changelog * Fix tests * Use sdk.MsgTypeURL everywhere * Fix tests * Fix rosetta, run make rosetta-data * Fix rosetta thanks to froydi * Address reviews * Fix test * Remove stray log * Update CL Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com> Co-authored-by: Alessio Treglia <alessio@tendermint.com> Co-authored-by: Aaron Craelius <aaron@regen.network>
This commit is contained in:
co-authored by
Aaron Craelius
Aaron Craelius
Alessio Treglia
parent
6fbded9664
commit
dfe3e7a8d7
@@ -251,19 +251,7 @@ func (s *IntegrationTestSuite) TestCLIQueryTxCmd() {
|
||||
|
||||
sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 10)
|
||||
|
||||
// Send coins, try both with legacy Msg and with Msg service.
|
||||
// Legacy proto Msg.
|
||||
legacyTxRes, err := bankcli.LegacyGRPCProtoMsgSend(
|
||||
val.ClientCtx, val.Moniker,
|
||||
val.Address,
|
||||
account2.GetAddress(),
|
||||
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))),
|
||||
sdk.NewCoins(sendTokens),
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
// Service Msg.
|
||||
// Send coins.
|
||||
out, err := s.createBankMsg(
|
||||
val, account2.GetAddress(),
|
||||
sdk.NewCoins(sendTokens),
|
||||
@@ -292,16 +280,10 @@ func (s *IntegrationTestSuite) TestCLIQueryTxCmd() {
|
||||
"",
|
||||
},
|
||||
{
|
||||
"happy case (legacy Msg)",
|
||||
[]string{legacyTxRes.TxResponse.TxHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
|
||||
false,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"happy case (service Msg)",
|
||||
"happy case",
|
||||
[]string{txRes.TxHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
|
||||
false,
|
||||
"/cosmos.bank.v1beta1.Msg/Send",
|
||||
"/cosmos.bank.v1beta1.MsgSend",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,24 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/types/tx/signing"
|
||||
)
|
||||
|
||||
// LegacyMsg defines the old interface a message must fulfill, containing
|
||||
// Amino signing method and legacy router info.
|
||||
// Deprecated: Please use `Msg` instead.
|
||||
type LegacyMsg interface {
|
||||
sdk.Msg
|
||||
|
||||
// Get the canonical byte representation of the Msg.
|
||||
GetSignBytes() []byte
|
||||
|
||||
// Return the message type.
|
||||
// Must be alphanumeric or empty.
|
||||
Route() string
|
||||
|
||||
// Returns a human-readable string for the message, intended for utilization
|
||||
// within tags
|
||||
Type() string
|
||||
}
|
||||
|
||||
// StdSignDoc is replay-prevention structure.
|
||||
// It includes the result of msg.GetSignBytes(),
|
||||
// as well as the ChainID (prevent cross chain replay)
|
||||
@@ -38,7 +56,7 @@ func StdSignBytes(chainID string, accnum, sequence, timeout uint64, fee StdFee,
|
||||
// If msg is a legacy Msg, then GetSignBytes is implemented.
|
||||
// If msg is a ServiceMsg, then GetSignBytes has graceful support of
|
||||
// calling GetSignBytes from its underlying Msg.
|
||||
msgsBytes = append(msgsBytes, json.RawMessage(msg.GetSignBytes()))
|
||||
msgsBytes = append(msgsBytes, json.RawMessage(msg.(LegacyMsg).GetSignBytes()))
|
||||
}
|
||||
|
||||
bz, err := legacy.Cdc.MarshalJSON(StdSignDoc{
|
||||
|
||||
@@ -29,25 +29,7 @@ func (s *StdTxBuilder) GetTx() authsigning.Tx {
|
||||
|
||||
// SetMsgs implements TxBuilder.SetMsgs
|
||||
func (s *StdTxBuilder) SetMsgs(msgs ...sdk.Msg) error {
|
||||
stdTxMsgs := make([]sdk.Msg, len(msgs))
|
||||
|
||||
for i, msg := range msgs {
|
||||
switch msg := msg.(type) {
|
||||
case sdk.ServiceMsg:
|
||||
// Since ServiceMsg isn't registered with amino, we unpack msg.Request
|
||||
// into a Msg so that it's handled gracefully for the legacy
|
||||
// GET /txs/{hash} and /txs endpoints.
|
||||
sdkMsg, ok := msg.Request.(sdk.Msg)
|
||||
if !ok {
|
||||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "Expecting %T at %d to implement sdk.Msg", msg.Request, i)
|
||||
}
|
||||
stdTxMsgs[i] = sdkMsg
|
||||
default:
|
||||
// legacy sdk.Msg
|
||||
stdTxMsgs[i] = msg
|
||||
}
|
||||
}
|
||||
s.Msgs = stdTxMsgs
|
||||
s.Msgs = msgs
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -204,12 +204,7 @@ func (w *wrapper) SetMsgs(msgs ...sdk.Msg) error {
|
||||
|
||||
for i, msg := range msgs {
|
||||
var err error
|
||||
switch msg := msg.(type) {
|
||||
case sdk.ServiceMsg:
|
||||
anys[i], err = codectypes.NewAnyWithCustomTypeURL(msg.Request, msg.MethodName)
|
||||
default:
|
||||
anys[i], err = codectypes.NewAnyWithValue(msg)
|
||||
}
|
||||
anys[i], err = codectypes.NewAnyWithValue(msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+14
-11
@@ -32,6 +32,8 @@ import (
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
)
|
||||
|
||||
var bankMsgSendEventAction = fmt.Sprintf("message.action='%s'", sdk.MsgTypeURL(&banktypes.MsgSend{}))
|
||||
|
||||
type IntegrationTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
@@ -192,7 +194,7 @@ func (s IntegrationTestSuite) TestGetTxEvents_GRPC() {
|
||||
{
|
||||
"request with order-by",
|
||||
&tx.GetTxsEventRequest{
|
||||
Events: []string{"message.action='/cosmos.bank.v1beta1.Msg/Send'"},
|
||||
Events: []string{bankMsgSendEventAction},
|
||||
OrderBy: tx.OrderBy_ORDER_BY_ASC,
|
||||
},
|
||||
false, "",
|
||||
@@ -200,14 +202,14 @@ func (s IntegrationTestSuite) TestGetTxEvents_GRPC() {
|
||||
{
|
||||
"without pagination",
|
||||
&tx.GetTxsEventRequest{
|
||||
Events: []string{"message.action='/cosmos.bank.v1beta1.Msg/Send'"},
|
||||
Events: []string{bankMsgSendEventAction},
|
||||
},
|
||||
false, "",
|
||||
},
|
||||
{
|
||||
"with pagination",
|
||||
&tx.GetTxsEventRequest{
|
||||
Events: []string{"message.action='/cosmos.bank.v1beta1.Msg/Send'"},
|
||||
Events: []string{bankMsgSendEventAction},
|
||||
Pagination: &query.PageRequest{
|
||||
CountTotal: false,
|
||||
Offset: 0,
|
||||
@@ -219,7 +221,7 @@ func (s IntegrationTestSuite) TestGetTxEvents_GRPC() {
|
||||
{
|
||||
"with multi events",
|
||||
&tx.GetTxsEventRequest{
|
||||
Events: []string{"message.action='/cosmos.bank.v1beta1.Msg/Send'", "message.module='bank'"},
|
||||
Events: []string{bankMsgSendEventAction, "message.module='bank'"},
|
||||
},
|
||||
false, "",
|
||||
},
|
||||
@@ -262,43 +264,43 @@ func (s IntegrationTestSuite) TestGetTxEvents_GRPCGateway() {
|
||||
},
|
||||
{
|
||||
"without pagination",
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s", val.APIAddress, "message.action='/cosmos.bank.v1beta1.Msg/Send'"),
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s", val.APIAddress, bankMsgSendEventAction),
|
||||
false,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"with pagination",
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&pagination.offset=%d&pagination.limit=%d", val.APIAddress, "message.action='/cosmos.bank.v1beta1.Msg/Send'", 0, 10),
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&pagination.offset=%d&pagination.limit=%d", val.APIAddress, bankMsgSendEventAction, 0, 10),
|
||||
false,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"valid request: order by asc",
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&events=%s&order_by=ORDER_BY_ASC", val.APIAddress, "message.action='/cosmos.bank.v1beta1.Msg/Send'", "message.module='bank'"),
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&events=%s&order_by=ORDER_BY_ASC", val.APIAddress, bankMsgSendEventAction, "message.module='bank'"),
|
||||
false,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"valid request: order by desc",
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&events=%s&order_by=ORDER_BY_DESC", val.APIAddress, "message.action='/cosmos.bank.v1beta1.Msg/Send'", "message.module='bank'"),
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&events=%s&order_by=ORDER_BY_DESC", val.APIAddress, bankMsgSendEventAction, "message.module='bank'"),
|
||||
false,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"invalid request: invalid order by",
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&events=%s&order_by=invalid_order", val.APIAddress, "message.action='/cosmos.bank.v1beta1.Msg/Send'", "message.module='bank'"),
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&events=%s&order_by=invalid_order", val.APIAddress, bankMsgSendEventAction, "message.module='bank'"),
|
||||
true,
|
||||
"is not a valid tx.OrderBy",
|
||||
},
|
||||
{
|
||||
"expect pass with multiple-events",
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&events=%s", val.APIAddress, "message.action='/cosmos.bank.v1beta1.Msg/Send'", "message.module='bank'"),
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&events=%s", val.APIAddress, bankMsgSendEventAction, "message.module='bank'"),
|
||||
false,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"expect pass with escape event",
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s", val.APIAddress, "message.action%3D'%2Fcosmos.bank.v1beta1.Msg%2FSend'"),
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s", val.APIAddress, "message.action%3D'/cosmos.bank.v1beta1.MsgSend'"),
|
||||
false,
|
||||
"",
|
||||
},
|
||||
@@ -584,6 +586,7 @@ func (s IntegrationTestSuite) mkTxBuilder() client.TxBuilder {
|
||||
)
|
||||
txBuilder.SetFeeAmount(feeAmount)
|
||||
txBuilder.SetGasLimit(gasLimit)
|
||||
txBuilder.SetMemo("foobar")
|
||||
|
||||
// setup txFactory
|
||||
txFactory := clienttx.Factory{}.
|
||||
|
||||
Reference in New Issue
Block a user