Use service Msgs in CLI tx commands (#8512)
* Use service Msgs in CLI tx commands * Update comment * Gracefully support amino signing * CLI to use svc msg * Fix lint * Use fq method name in events * Update tests * Fix quering events * Add docs * Fix test build * Fix events * Fix search for events * Handle old andd new event quering * Use merge events * Better encCfg * Add page in search * Fix tests * Update test and comments * Update x/auth/legacy/legacytx/stdsign.go Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com> * Fix conflict for weighted vote * Make CopyTx actually run * Fix CopyTx * Fix test * Add changelog entry * Remove useless code * Add msgs tests * Remove testing proto Msg via CLI * Fix lint * Fix test * Implement GetSignBytes on ServiceMsg * Fix %T Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
b4820fe491
commit
73e38e4009
@ -38,7 +38,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### Client Breaking Changes
|
||||
|
||||
* [\#8363](https://github.com/cosmos/cosmos-sdk/issues/8363) Addresses no longer have a fixed 20-byte length. From the SDK modules' point of view, any 1-255 bytes-long byte array is a valid address.
|
||||
* [\#8363](https://github.com/cosmos/cosmos-sdk/pull/8363) Addresses no longer have a fixed 20-byte length. From the SDK modules' point of view, any 1-255 bytes-long byte array is a valid address.
|
||||
* [\#8346](https://github.com/cosmos/cosmos-sdk/pull/8346) All CLI `tx` commands generate ServiceMsgs by default. Graceful Amino support has been added to ServiceMsgs to support signing legacy Msgs.
|
||||
|
||||
### API Breaking Changes
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/simapp/params"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
signing2 "github.com/cosmos/cosmos-sdk/types/tx/signing"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/signing"
|
||||
@ -23,14 +24,13 @@ import (
|
||||
const (
|
||||
memo = "waboom"
|
||||
gas = uint64(10000)
|
||||
timeoutHeight = 5
|
||||
timeoutHeight = uint64(5)
|
||||
)
|
||||
|
||||
var (
|
||||
fee = types.NewCoins(types.NewInt64Coin("bam", 100))
|
||||
_, pub1, addr1 = testdata.KeyTestPubAddr()
|
||||
_, _, addr2 = testdata.KeyTestPubAddr()
|
||||
msg = banktypes.NewMsgSend(addr1, addr2, types.NewCoins(types.NewInt64Coin("wack", 10000)))
|
||||
sig = signing2.SignatureV2{
|
||||
PubKey: pub1,
|
||||
Data: &signing2.SingleSignatureData{
|
||||
@ -38,13 +38,18 @@ var (
|
||||
Signature: []byte("dummy"),
|
||||
},
|
||||
}
|
||||
msg0 = banktypes.NewMsgSend(addr1, addr2, types.NewCoins(types.NewInt64Coin("wack", 1)))
|
||||
msg1 = sdk.ServiceMsg{
|
||||
MethodName: "/cosmos.bank.v1beta1.Msg/Send",
|
||||
Request: banktypes.NewMsgSend(addr1, addr2, types.NewCoins(types.NewInt64Coin("wack", 2))),
|
||||
}
|
||||
)
|
||||
|
||||
func buildTestTx(t *testing.T, builder client.TxBuilder) {
|
||||
builder.SetMemo(memo)
|
||||
builder.SetGasLimit(gas)
|
||||
builder.SetFeeAmount(fee)
|
||||
err := builder.SetMsgs(msg)
|
||||
err := builder.SetMsgs(msg0, msg1)
|
||||
require.NoError(t, err)
|
||||
err = builder.SetSignatures(sig)
|
||||
require.NoError(t, err)
|
||||
@ -75,11 +80,15 @@ func (s *TestSuite) TestCopyTx() {
|
||||
protoBuilder2 := s.protoCfg.NewTxBuilder()
|
||||
err = tx2.CopyTx(aminoBuilder.GetTx(), protoBuilder2, false)
|
||||
s.Require().NoError(err)
|
||||
bz, err := s.protoCfg.TxEncoder()(protoBuilder.GetTx())
|
||||
// Check sigs, signers and msgs.
|
||||
sigsV2_1, err := protoBuilder.GetTx().GetSignaturesV2()
|
||||
s.Require().NoError(err)
|
||||
bz2, err := s.protoCfg.TxEncoder()(protoBuilder2.GetTx())
|
||||
sigsV2_2, err := protoBuilder2.GetTx().GetSignaturesV2()
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(bz, bz2)
|
||||
s.Require().Equal(sigsV2_1, sigsV2_2)
|
||||
s.Require().Equal(protoBuilder.GetTx().GetSigners(), protoBuilder2.GetTx().GetSigners())
|
||||
s.Require().Equal(protoBuilder.GetTx().GetMsgs()[0], protoBuilder2.GetTx().GetMsgs()[0])
|
||||
s.Require().Equal(protoBuilder.GetTx().GetMsgs()[1].(sdk.ServiceMsg).Request, protoBuilder2.GetTx().GetMsgs()[1]) // We lose the "ServiceMsg" information
|
||||
|
||||
// amino -> proto -> amino
|
||||
aminoBuilder = s.aminoCfg.NewTxBuilder()
|
||||
@ -90,11 +99,15 @@ func (s *TestSuite) TestCopyTx() {
|
||||
aminoBuilder2 := s.aminoCfg.NewTxBuilder()
|
||||
err = tx2.CopyTx(protoBuilder.GetTx(), aminoBuilder2, false)
|
||||
s.Require().NoError(err)
|
||||
bz, err = s.aminoCfg.TxEncoder()(aminoBuilder.GetTx())
|
||||
// Check sigs, signers, and msgs
|
||||
sigsV2_1, err = aminoBuilder.GetTx().GetSignaturesV2()
|
||||
s.Require().NoError(err)
|
||||
bz2, err = s.aminoCfg.TxEncoder()(aminoBuilder2.GetTx())
|
||||
sigsV2_2, err = aminoBuilder2.GetTx().GetSignaturesV2()
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(bz, bz2)
|
||||
s.Require().Equal(sigsV2_1, sigsV2_2)
|
||||
s.Require().Equal(aminoBuilder.GetTx().GetSigners(), aminoBuilder2.GetTx().GetSigners())
|
||||
s.Require().Equal(aminoBuilder.GetTx().GetMsgs()[0], aminoBuilder2.GetTx().GetMsgs()[0])
|
||||
s.Require().Equal(aminoBuilder.GetTx().GetMsgs()[1], aminoBuilder2.GetTx().GetMsgs()[1]) // We lose the "ServiceMsg" information
|
||||
}
|
||||
|
||||
func (s *TestSuite) TestConvertTxToStdTx() {
|
||||
@ -106,7 +119,8 @@ func (s *TestSuite) TestConvertTxToStdTx() {
|
||||
s.Require().Equal(memo, stdTx.Memo)
|
||||
s.Require().Equal(gas, stdTx.Fee.Gas)
|
||||
s.Require().Equal(fee, stdTx.Fee.Amount)
|
||||
s.Require().Equal(msg, stdTx.Msgs[0])
|
||||
s.Require().Equal(msg0, stdTx.Msgs[0])
|
||||
s.Require().Equal(msg1.Request, stdTx.Msgs[1])
|
||||
s.Require().Equal(timeoutHeight, stdTx.TimeoutHeight)
|
||||
s.Require().Equal(sig.PubKey, stdTx.Signatures[0].PubKey)
|
||||
s.Require().Equal(sig.Data.(*signing2.SingleSignatureData).Signature, stdTx.Signatures[0].Signature)
|
||||
@ -125,7 +139,8 @@ func (s *TestSuite) TestConvertTxToStdTx() {
|
||||
s.Require().Equal(memo, stdTx.Memo)
|
||||
s.Require().Equal(gas, stdTx.Fee.Gas)
|
||||
s.Require().Equal(fee, stdTx.Fee.Amount)
|
||||
s.Require().Equal(msg, stdTx.Msgs[0])
|
||||
s.Require().Equal(msg0, stdTx.Msgs[0])
|
||||
s.Require().Equal(msg1.Request, stdTx.Msgs[1])
|
||||
s.Require().Equal(timeoutHeight, stdTx.TimeoutHeight)
|
||||
s.Require().Empty(stdTx.Signatures)
|
||||
|
||||
@ -158,3 +173,7 @@ func (s *TestSuite) TestConvertAndEncodeStdTx() {
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(stdTx, decodedTx)
|
||||
}
|
||||
|
||||
func TestTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(TestSuite))
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ take the form of: `{eventType}.{eventAttribute}={value}`.
|
||||
|
||||
Events contain:
|
||||
|
||||
- A `type`, which is meant to categorize an event at a high-level (e.g. by module or action).
|
||||
- A `type`, which is meant to categorize an event at a high-level (e.g. by module (e.g. `module=bank`) or action (e.g. `action=/cosmos.bank.v1beta1.Msg/Send`)).
|
||||
- A list of `attributes`, which are key-value pairs that give more information about
|
||||
the categorized `event`.
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/7d7821b9af132b0f6131640195326aa02b6751db/types/events.go#L51-L56
|
||||
|
||||
@ -13,15 +13,13 @@ import (
|
||||
"google.golang.org/grpc/metadata"
|
||||
rpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
|
||||
|
||||
clienttx "github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
|
||||
"github.com/cosmos/cosmos-sdk/types/tx"
|
||||
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
|
||||
"github.com/cosmos/cosmos-sdk/types/tx/signing"
|
||||
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
|
||||
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/client/testutil"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
)
|
||||
|
||||
@ -37,6 +35,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
|
||||
s.T().Log("setting up integration test suite")
|
||||
|
||||
s.cfg = network.DefaultConfig()
|
||||
s.cfg.NumValidators = 1
|
||||
s.network = network.New(s.T(), s.cfg)
|
||||
s.Require().NotNil(s.network)
|
||||
|
||||
@ -130,42 +129,9 @@ func (s *IntegrationTestSuite) TestGRPCServer_GetTxsEvent() {
|
||||
func (s *IntegrationTestSuite) TestGRPCServer_BroadcastTx() {
|
||||
val0 := s.network.Validators[0]
|
||||
|
||||
// prepare txBuilder with msg
|
||||
txBuilder := val0.ClientCtx.TxConfig.NewTxBuilder()
|
||||
feeAmount := sdk.Coins{sdk.NewInt64Coin(s.cfg.BondDenom, 10)}
|
||||
gasLimit := testdata.NewTestGasLimit()
|
||||
s.Require().NoError(
|
||||
txBuilder.SetMsgs(&banktypes.MsgSend{
|
||||
FromAddress: val0.Address.String(),
|
||||
ToAddress: val0.Address.String(),
|
||||
Amount: sdk.Coins{sdk.NewInt64Coin(s.cfg.BondDenom, 10)},
|
||||
}),
|
||||
)
|
||||
txBuilder.SetFeeAmount(feeAmount)
|
||||
txBuilder.SetGasLimit(gasLimit)
|
||||
|
||||
// setup txFactory
|
||||
txFactory := clienttx.Factory{}.
|
||||
WithChainID(val0.ClientCtx.ChainID).
|
||||
WithKeybase(val0.ClientCtx.Keyring).
|
||||
WithTxConfig(val0.ClientCtx.TxConfig).
|
||||
WithSignMode(signing.SignMode_SIGN_MODE_DIRECT)
|
||||
|
||||
// Sign Tx.
|
||||
err := authclient.SignTx(txFactory, val0.ClientCtx, val0.Moniker, txBuilder, false, true)
|
||||
s.Require().NoError(err)
|
||||
|
||||
txBytes, err := val0.ClientCtx.TxConfig.TxEncoder()(txBuilder.GetTx())
|
||||
s.Require().NoError(err)
|
||||
|
||||
// Broadcast the tx via gRPC.
|
||||
queryClient := tx.NewServiceClient(s.conn)
|
||||
grpcRes, err := queryClient.BroadcastTx(
|
||||
context.Background(),
|
||||
&tx.BroadcastTxRequest{
|
||||
Mode: tx.BroadcastMode_BROADCAST_MODE_SYNC,
|
||||
TxBytes: txBytes,
|
||||
},
|
||||
grpcRes, err := banktestutil.LegacyGRPCProtoMsgSend(val0.ClientCtx,
|
||||
val0.Moniker, val0.Address, val0.Address,
|
||||
sdk.Coins{sdk.NewInt64Coin(s.cfg.BondDenom, 10)}, sdk.Coins{sdk.NewInt64Coin(s.cfg.BondDenom, 10)},
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(uint32(0), grpcRes.TxResponse.Code)
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
)
|
||||
|
||||
@ -18,7 +20,7 @@ type MsgRequest interface {
|
||||
}
|
||||
|
||||
// ServiceMsg is the struct into which an Any whose typeUrl matches a service
|
||||
// method format (ex. `/cosmos.gov.Msg/SubmitProposal`) unpacks.
|
||||
// method format (ex. `/cosmos.gov.v1beta1.Msg/SubmitProposal`) unpacks.
|
||||
type ServiceMsg struct {
|
||||
// MethodName is the fully-qualified service method name.
|
||||
MethodName string
|
||||
@ -44,7 +46,17 @@ func (msg ServiceMsg) ValidateBasic() error {
|
||||
|
||||
// GetSignBytes implements Msg.GetSignBytes method.
|
||||
func (msg ServiceMsg) GetSignBytes() []byte {
|
||||
panic("ServiceMsg does not have a GetSignBytes method")
|
||||
// Here, we're gracefully supporting Amino JSON for service
|
||||
// Msgs.
|
||||
// ref: https://github.com/cosmos/cosmos-sdk/issues/8346
|
||||
// If `msg` is a service Msg, then we cast its `Request` to a sdk.Msg
|
||||
// and call GetSignBytes on the `Request`.
|
||||
msgRequest, ok := msg.Request.(Msg)
|
||||
if !ok {
|
||||
panic(fmt.Errorf("cannot convert ServiceMsg request to sdk.Msg, got %T", msgRequest))
|
||||
}
|
||||
|
||||
return msgRequest.GetSignBytes()
|
||||
}
|
||||
|
||||
// GetSigners implements Msg.GetSigners method.
|
||||
|
||||
@ -230,23 +230,19 @@ func (s *IntegrationTestSuite) TestCLIQueryTxCmd() {
|
||||
sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 10)
|
||||
|
||||
// Send coins, try both with legacy Msg and with Msg service.
|
||||
// Legacy Msg.
|
||||
legacyMsgOut, err := bankcli.MsgSendExec(
|
||||
val.ClientCtx,
|
||||
// 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),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
fmt.Sprintf("--gas=%d", flags.DefaultGasLimit),
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
var legacyMsgTxRes sdk.TxResponse
|
||||
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(legacyMsgOut.Bytes(), &legacyMsgTxRes))
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
// Service Msg.
|
||||
out, err := bankcli.ServiceMsgSendExec(
|
||||
out, err := bankcli.MsgSendExec(
|
||||
val.ClientCtx,
|
||||
val.Address,
|
||||
account2.GetAddress(),
|
||||
@ -259,7 +255,6 @@ func (s *IntegrationTestSuite) TestCLIQueryTxCmd() {
|
||||
s.Require().NoError(err)
|
||||
var txRes sdk.TxResponse
|
||||
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), &txRes))
|
||||
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
testCases := []struct {
|
||||
@ -282,7 +277,7 @@ func (s *IntegrationTestSuite) TestCLIQueryTxCmd() {
|
||||
},
|
||||
{
|
||||
"happy case (legacy Msg)",
|
||||
[]string{legacyMsgTxRes.TxHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
|
||||
[]string{legacyTxRes.TxResponse.TxHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
|
||||
false,
|
||||
"",
|
||||
},
|
||||
|
||||
@ -269,7 +269,7 @@ func (s *IntegrationTestSuite) TestQueryTxWithStdTx() {
|
||||
s.testQueryTx(s.stdTxRes.Height, s.stdTxRes.TxHash, val0.Address.String())
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryTxWithServiceMessage() {
|
||||
func (s *IntegrationTestSuite) TestQueryTxWithServiceMsg() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 10)
|
||||
@ -278,7 +278,7 @@ func (s *IntegrationTestSuite) TestQueryTxWithServiceMessage() {
|
||||
// Might need to wait a block to refresh sequences from previous setups.
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
out, err := bankcli.ServiceMsgSendExec(
|
||||
out, err := bankcli.MsgSendExec(
|
||||
val.ClientCtx,
|
||||
val.Address,
|
||||
addr,
|
||||
|
||||
@ -35,6 +35,9 @@ type StdSignDoc struct {
|
||||
func StdSignBytes(chainID string, accnum, sequence, timeout uint64, fee StdFee, msgs []sdk.Msg, memo string) []byte {
|
||||
msgsBytes := make([]json.RawMessage, 0, len(msgs))
|
||||
for _, msg := range msgs {
|
||||
// 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()))
|
||||
}
|
||||
|
||||
|
||||
@ -175,14 +175,14 @@ func (s IntegrationTestSuite) TestGetTxEvents_GRPC() {
|
||||
{
|
||||
"without pagination",
|
||||
&tx.GetTxsEventRequest{
|
||||
Events: []string{"message.action=send"},
|
||||
Events: []string{"message.action=/cosmos.bank.v1beta1.Msg/Send"},
|
||||
},
|
||||
false, "",
|
||||
},
|
||||
{
|
||||
"with pagination",
|
||||
&tx.GetTxsEventRequest{
|
||||
Events: []string{"message.action=send"},
|
||||
Events: []string{"message.action=/cosmos.bank.v1beta1.Msg/Send"},
|
||||
Pagination: &query.PageRequest{
|
||||
CountTotal: false,
|
||||
Offset: 0,
|
||||
@ -194,7 +194,7 @@ func (s IntegrationTestSuite) TestGetTxEvents_GRPC() {
|
||||
{
|
||||
"with multi events",
|
||||
&tx.GetTxsEventRequest{
|
||||
Events: []string{"message.action=send", "message.module=bank"},
|
||||
Events: []string{"message.action=/cosmos.bank.v1beta1.Msg/Send", "message.module=bank"},
|
||||
},
|
||||
false, "",
|
||||
},
|
||||
@ -231,25 +231,25 @@ func (s IntegrationTestSuite) TestGetTxEvents_GRPCGateway() {
|
||||
},
|
||||
{
|
||||
"without pagination",
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s", val.APIAddress, "message.action=send"),
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s", val.APIAddress, "message.action=/cosmos.bank.v1beta1.Msg/Send"),
|
||||
false,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"with pagination",
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&pagination.offset=%d&pagination.limit=%d", val.APIAddress, "message.action=send", 0, 10),
|
||||
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),
|
||||
false,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"expect pass with multiple-events",
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&events=%s", val.APIAddress, "message.action=send", "message.module=bank"),
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&events=%s", val.APIAddress, "message.action=/cosmos.bank.v1beta1.Msg/Send", "message.module=bank"),
|
||||
false,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"expect pass with escape event",
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s", val.APIAddress, "message.action%3Dsend"),
|
||||
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s", val.APIAddress, "message.action%3D%2Fcosmos.bank.v1beta1.Msg%2FSend"),
|
||||
false,
|
||||
"",
|
||||
},
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
||||
)
|
||||
|
||||
@ -69,11 +70,14 @@ timestamp.`,
|
||||
delayed, _ := cmd.Flags().GetBool(FlagDelayed)
|
||||
|
||||
msg := types.NewMsgCreateVestingAccount(clientCtx.GetFromAddress(), toAddr, amount, endTime, delayed)
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.CreateVestingAccount(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -647,7 +647,7 @@ func (s *IntegrationTestSuite) TestNewExecGrantAuthorized() {
|
||||
tokens := sdk.NewCoins(
|
||||
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), sdk.NewInt(12)),
|
||||
)
|
||||
normalGeneratedTx, err := bankcli.ServiceMsgSendExec(
|
||||
normalGeneratedTx, err := bankcli.MsgSendExec(
|
||||
val.ClientCtx,
|
||||
val.Address,
|
||||
grantee,
|
||||
|
||||
@ -108,8 +108,8 @@ Examples:
|
||||
}
|
||||
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
authzMsgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = authzMsgClient.GrantAuthorization(context.Background(), msg)
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.GrantAuthorization(context.Background(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -153,8 +153,8 @@ Example:
|
||||
msg := types.NewMsgRevokeAuthorization(granter, grantee, msgAuthorized)
|
||||
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
authzMsgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = authzMsgClient.RevokeAuthorization(context.Background(), &msg)
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.RevokeAuthorization(context.Background(), &msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -206,8 +206,8 @@ Example:
|
||||
|
||||
msg := types.NewMsgExecAuthorized(grantee, serviceMsgs)
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
authzMsgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = authzMsgClient.ExecAuthorized(context.Background(), &msg)
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.ExecAuthorized(context.Background(), &msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -372,7 +372,10 @@ func (s *IntegrationTestSuite) TestNewSendTxCmdGenOnly() {
|
||||
s.Require().NoError(err)
|
||||
tx, err := s.cfg.TxConfig.TxJSONDecoder()(bz.Bytes())
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal([]sdk.Msg{types.NewMsgSend(from, to, amount)}, tx.GetMsgs())
|
||||
s.Require().Equal([]sdk.Msg{sdk.ServiceMsg{
|
||||
MethodName: "/cosmos.bank.v1beta1.Msg/Send",
|
||||
Request: types.NewMsgSend(from, to, amount),
|
||||
}}, tx.GetMsgs())
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestNewSendTxCmd() {
|
||||
@ -461,61 +464,6 @@ func (s *IntegrationTestSuite) TestNewSendTxCmd() {
|
||||
}
|
||||
}
|
||||
|
||||
// TestBankMsgService does a basic test of whether or not service Msg's as defined
|
||||
// in ADR 031 work in the most basic end-to-end case.
|
||||
func (s *IntegrationTestSuite) TestBankMsgService() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
from, to sdk.AccAddress
|
||||
amount sdk.Coins
|
||||
args []string
|
||||
expectErr bool
|
||||
respType proto.Message
|
||||
expectedCode uint32
|
||||
rawLogContains string
|
||||
}{
|
||||
{
|
||||
"valid transaction",
|
||||
val.Address,
|
||||
val.Address,
|
||||
sdk.NewCoins(
|
||||
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), sdk.NewInt(10)),
|
||||
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)),
|
||||
),
|
||||
[]string{
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
false,
|
||||
&sdk.TxResponse{},
|
||||
0,
|
||||
"/cosmos.bank.v1beta1.Msg/Send", // indicates we are using ServiceMsg and not a regular Msg
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
clientCtx := val.ClientCtx
|
||||
bz, err := banktestutil.ServiceMsgSendExec(clientCtx, tc.from, tc.to, tc.amount, tc.args...)
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(bz.Bytes(), tc.respType), bz.String())
|
||||
txResp := tc.respType.(*sdk.TxResponse)
|
||||
s.Require().Equal(tc.expectedCode, txResp.Code)
|
||||
s.Require().Contains(txResp.RawLog, tc.rawLogContains)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntegrationTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(IntegrationTestSuite))
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
)
|
||||
|
||||
@ -49,11 +50,14 @@ ignored as it is implied from [from_key_or_address].`,
|
||||
}
|
||||
|
||||
msg := types.NewMsgSend(clientCtx.GetFromAddress(), toAddr, coins)
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.Send(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -1,18 +1,20 @@
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
|
||||
"github.com/cosmos/cosmos-sdk/types/tx/signing"
|
||||
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
|
||||
bankcli "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
)
|
||||
@ -31,54 +33,55 @@ func QueryBalancesExec(clientCtx client.Context, address fmt.Stringer, extraArgs
|
||||
return clitestutil.ExecTestCLICmd(clientCtx, bankcli.GetBalancesCmd(), args)
|
||||
}
|
||||
|
||||
// newSendTxMsgServiceCmd is just for the purpose of testing ServiceMsg's in an end-to-end case. It is effectively
|
||||
// NewSendTxCmd but using MsgClient.
|
||||
func newSendTxMsgServiceCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "send [from_key_or_address] [to_address] [amount]",
|
||||
Short: `Send funds from one account to another. Note, the'--from' flag is
|
||||
ignored as it is implied from [from_key_or_address].`,
|
||||
Args: cobra.ExactArgs(3),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cmd.Flags().Set(flags.FlagFrom, args[0])
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
toAddr, err := sdk.AccAddressFromBech32(args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// LegacyGRPCProtoMsgSend is a legacy method to broadcast a legacy proto MsgSend.
|
||||
//
|
||||
// Deprecated.
|
||||
//nolint:interfacer
|
||||
func LegacyGRPCProtoMsgSend(clientCtx client.Context, keyName string, from, to sdk.Address, fee, amount []sdk.Coin, extraArgs ...string) (*txtypes.BroadcastTxResponse, error) {
|
||||
// prepare txBuilder with msg
|
||||
txBuilder := clientCtx.TxConfig.NewTxBuilder()
|
||||
feeAmount := fee
|
||||
gasLimit := testdata.NewTestGasLimit()
|
||||
|
||||
coins, err := sdk.ParseCoinsNormalized(args[2])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg := types.NewMsgSend(clientCtx.GetFromAddress(), toAddr, coins)
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
bankMsgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = bankMsgClient.Send(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
// This sets a legacy Proto MsgSend.
|
||||
err := txBuilder.SetMsgs(&types.MsgSend{
|
||||
FromAddress: from.String(),
|
||||
ToAddress: to.String(),
|
||||
Amount: amount,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
flags.AddTxFlagsToCmd(cmd)
|
||||
txBuilder.SetFeeAmount(feeAmount)
|
||||
txBuilder.SetGasLimit(gasLimit)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// ServiceMsgSendExec is a temporary method to test Msg services in CLI using
|
||||
// x/bank's Msg/Send service. After https://github.com/cosmos/cosmos-sdk/issues/7541
|
||||
// is merged, this method should be removed, and we should prefer MsgSendExec
|
||||
// instead.
|
||||
func ServiceMsgSendExec(clientCtx client.Context, from, to, amount fmt.Stringer, extraArgs ...string) (testutil.BufferWriter, error) {
|
||||
args := []string{from.String(), to.String(), amount.String()}
|
||||
args = append(args, extraArgs...)
|
||||
|
||||
return clitestutil.ExecTestCLICmd(clientCtx, newSendTxMsgServiceCmd(), args)
|
||||
// setup txFactory
|
||||
txFactory := tx.Factory{}.
|
||||
WithChainID(clientCtx.ChainID).
|
||||
WithKeybase(clientCtx.Keyring).
|
||||
WithTxConfig(clientCtx.TxConfig).
|
||||
WithSignMode(signing.SignMode_SIGN_MODE_DIRECT)
|
||||
|
||||
// Sign Tx.
|
||||
err = authclient.SignTx(txFactory, clientCtx, keyName, txBuilder, false, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
txBytes, err := clientCtx.TxConfig.TxEncoder()(txBuilder.GetTx())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Broadcast the tx via gRPC.
|
||||
queryClient := txtypes.NewServiceClient(clientCtx)
|
||||
|
||||
return queryClient.BroadcastTx(
|
||||
context.Background(),
|
||||
&txtypes.BroadcastTxRequest{
|
||||
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
||||
TxBytes: txBytes,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis/types"
|
||||
)
|
||||
|
||||
@ -49,11 +50,14 @@ func NewMsgVerifyInvariantTxCmd() *cobra.Command {
|
||||
senderAddr := clientCtx.GetFromAddress()
|
||||
|
||||
msg := types.NewMsgVerifyInvariant(senderAddr, moduleName, route)
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.VerifyInvariant(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
@ -214,11 +215,14 @@ $ %s tx distribution set-withdraw-addr %s1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p
|
||||
}
|
||||
|
||||
msg := types.NewMsgSetWithdrawAddress(delAddr, withdrawAddr)
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.SetWithdrawAddress(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
@ -253,11 +257,14 @@ $ %s tx distribution fund-community-pool 100uatom --from mykey
|
||||
}
|
||||
|
||||
msg := types.NewMsgFundCommunityPool(amount, depositorAddr)
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.FundCommunityPool(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
@ -326,11 +333,14 @@ Where proposal.json contains:
|
||||
return err
|
||||
}
|
||||
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := govtypes.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.SubmitProposal(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -149,8 +149,8 @@ Examples:
|
||||
}
|
||||
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
feeGrantMsgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = feeGrantMsgClient.GrantFeeAllowance(cmd.Context(), msg)
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.GrantFeeAllowance(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -196,8 +196,8 @@ Example:
|
||||
|
||||
msg := types.NewMsgRevokeFeeAllowance(clientCtx.GetFromAddress(), grantee)
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
feeGrantMsgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = feeGrantMsgClient.RevokeFeeAllowance(cmd.Context(), &msg)
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.RevokeFeeAllowance(cmd.Context(), &msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
govutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
@ -126,11 +127,14 @@ $ %s tx gov submit-proposal --title="Test Proposal" --description="My awesome pr
|
||||
return fmt.Errorf("invalid message: %w", err)
|
||||
}
|
||||
|
||||
if err = msg.ValidateBasic(); err != nil {
|
||||
return fmt.Errorf("message validation failed: %w", err)
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.SubmitProposal(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
@ -182,12 +186,14 @@ $ %s tx gov deposit 1 10stake --from mykey
|
||||
}
|
||||
|
||||
msg := types.NewMsgDeposit(from, proposalID, amount)
|
||||
err = msg.ValidateBasic()
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.Deposit(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
@ -234,12 +240,14 @@ $ %s tx gov vote 1 yes --from mykey
|
||||
|
||||
// Build vote message and run basic validation
|
||||
msg := types.NewMsgVote(from, proposalID, byteVoteOption)
|
||||
err = msg.ValidateBasic()
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.Vote(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -37,14 +37,19 @@ func (p Proposer) String() string {
|
||||
// NOTE: SearchTxs is used to facilitate the txs query which does not currently
|
||||
// support configurable pagination.
|
||||
func QueryDepositsByTxQuery(clientCtx client.Context, params types.QueryProposalParams) ([]byte, error) {
|
||||
events := []string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgDeposit),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalDeposit, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
|
||||
}
|
||||
|
||||
// NOTE: SearchTxs is used to facilitate the txs query which does not currently
|
||||
// support configurable pagination.
|
||||
searchResult, err := authclient.QueryTxsByEvents(clientCtx, events, defaultPage, defaultLimit, "")
|
||||
searchResult, err := combineEvents(
|
||||
clientCtx, defaultPage,
|
||||
// Query old Msgs
|
||||
[]string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgDeposit),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalDeposit, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
|
||||
},
|
||||
// Query service Msgs
|
||||
[]string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeSvcMsgDeposit),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalDeposit, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -53,9 +58,14 @@ func QueryDepositsByTxQuery(clientCtx client.Context, params types.QueryProposal
|
||||
|
||||
for _, info := range searchResult.Txs {
|
||||
for _, msg := range info.GetTx().GetMsgs() {
|
||||
if msg.Type() == types.TypeMsgDeposit {
|
||||
depMsg := msg.(*types.MsgDeposit)
|
||||
var depMsg *types.MsgDeposit
|
||||
if msg.Type() == types.TypeSvcMsgDeposit {
|
||||
depMsg = msg.(sdk.ServiceMsg).Request.(*types.MsgDeposit)
|
||||
} else if protoDepMsg, ok := msg.(*types.MsgDeposit); ok {
|
||||
depMsg = protoDepMsg
|
||||
}
|
||||
|
||||
if depMsg != nil {
|
||||
deposits = append(deposits, types.Deposit{
|
||||
Depositor: depMsg.Depositor,
|
||||
ProposalId: params.ProposalID,
|
||||
@ -78,39 +88,70 @@ func QueryDepositsByTxQuery(clientCtx client.Context, params types.QueryProposal
|
||||
// marshalled result or any error that occurred.
|
||||
func QueryVotesByTxQuery(clientCtx client.Context, params types.QueryProposalVotesParams) ([]byte, error) {
|
||||
var (
|
||||
events = []string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgVote),
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgVoteWeighted),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalVote, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
|
||||
}
|
||||
votes []types.Vote
|
||||
nextTxPage = defaultPage
|
||||
totalLimit = params.Limit * params.Page
|
||||
)
|
||||
|
||||
// query interrupted either if we collected enough votes or tx indexer run out of relevant txs
|
||||
for len(votes) < totalLimit {
|
||||
searchResult, err := authclient.QueryTxsByEvents(clientCtx, events, nextTxPage, defaultLimit, "")
|
||||
// Search for both (old) votes and weighted votes.
|
||||
searchResult, err := combineEvents(
|
||||
clientCtx, nextTxPage,
|
||||
// Query old Vote Msgs
|
||||
[]string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgVote),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalVote, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
|
||||
},
|
||||
// Query Vote service Msgs
|
||||
[]string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeSvcMsgVote),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalVote, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
|
||||
},
|
||||
// Query old VoteWeighted Msgs
|
||||
[]string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgVoteWeighted),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalVote, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
|
||||
},
|
||||
// Query VoteWeighted service Msgs
|
||||
[]string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeSvcMsgVoteWeighted),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalVote, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nextTxPage++
|
||||
|
||||
for _, info := range searchResult.Txs {
|
||||
for _, msg := range info.GetTx().GetMsgs() {
|
||||
if msg.Type() == types.TypeMsgVote {
|
||||
voteMsg := msg.(*types.MsgVote)
|
||||
var voteMsg *types.MsgVote
|
||||
if msg.Type() == types.TypeSvcMsgVote {
|
||||
voteMsg = msg.(sdk.ServiceMsg).Request.(*types.MsgVote)
|
||||
} else if protoVoteMsg, ok := msg.(*types.MsgVote); ok {
|
||||
voteMsg = protoVoteMsg
|
||||
}
|
||||
|
||||
if voteMsg != nil {
|
||||
votes = append(votes, types.Vote{
|
||||
Voter: voteMsg.Voter,
|
||||
ProposalId: params.ProposalID,
|
||||
Options: types.NewNonSplitVoteOption(voteMsg.Option),
|
||||
})
|
||||
} else if msg.Type() == types.TypeMsgVoteWeighted {
|
||||
voteMsg := msg.(*types.MsgVoteWeighted)
|
||||
}
|
||||
|
||||
var voteWeightedMsg *types.MsgVoteWeighted
|
||||
if msg.Type() == types.TypeSvcMsgVoteWeighted {
|
||||
voteWeightedMsg = msg.(sdk.ServiceMsg).Request.(*types.MsgVoteWeighted)
|
||||
} else if protoVoteWeightedMsg, ok := msg.(*types.MsgVoteWeighted); ok {
|
||||
voteWeightedMsg = protoVoteWeightedMsg
|
||||
}
|
||||
|
||||
if voteWeightedMsg != nil {
|
||||
votes = append(votes, types.Vote{
|
||||
Voter: voteMsg.Voter,
|
||||
Voter: voteWeightedMsg.Voter,
|
||||
ProposalId: params.ProposalID,
|
||||
Options: voteMsg.Options,
|
||||
Options: voteWeightedMsg.Options,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -118,6 +159,8 @@ func QueryVotesByTxQuery(clientCtx client.Context, params types.QueryProposalVot
|
||||
if len(searchResult.Txs) != defaultLimit {
|
||||
break
|
||||
}
|
||||
|
||||
nextTxPage++
|
||||
}
|
||||
start, end := client.Paginate(len(votes), params.Page, params.Limit, 100)
|
||||
if start < 0 || end < 0 {
|
||||
@ -136,24 +179,48 @@ func QueryVotesByTxQuery(clientCtx client.Context, params types.QueryProposalVot
|
||||
|
||||
// QueryVoteByTxQuery will query for a single vote via a direct txs tags query.
|
||||
func QueryVoteByTxQuery(clientCtx client.Context, params types.QueryVoteParams) ([]byte, error) {
|
||||
events := []string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgVote),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalVote, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, []byte(params.Voter.String())),
|
||||
}
|
||||
|
||||
// NOTE: SearchTxs is used to facilitate the txs query which does not currently
|
||||
// support configurable pagination.
|
||||
searchResult, err := authclient.QueryTxsByEvents(clientCtx, events, defaultPage, defaultLimit, "")
|
||||
searchResult, err := combineEvents(
|
||||
clientCtx, defaultPage,
|
||||
// Query old Vote Msgs
|
||||
[]string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgVote),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalVote, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, []byte(params.Voter.String())),
|
||||
},
|
||||
// Query Vote service Msgs
|
||||
[]string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeSvcMsgVote),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalVote, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, []byte(params.Voter.String())),
|
||||
},
|
||||
// Query old VoteWeighted Msgs
|
||||
[]string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgVoteWeighted),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalVote, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, []byte(params.Voter.String())),
|
||||
},
|
||||
// Query VoteWeighted service Msgs
|
||||
[]string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeSvcMsgVoteWeighted),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalVote, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, []byte(params.Voter.String())),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, info := range searchResult.Txs {
|
||||
for _, msg := range info.GetTx().GetMsgs() {
|
||||
var voteMsg *types.MsgVote
|
||||
// there should only be a single vote under the given conditions
|
||||
if msg.Type() == types.TypeMsgVote {
|
||||
voteMsg := msg.(*types.MsgVote)
|
||||
if msg.Type() == types.TypeSvcMsgVote {
|
||||
voteMsg = msg.(sdk.ServiceMsg).Request.(*types.MsgVote)
|
||||
} else if protoVoteMsg, ok := msg.(*types.MsgVote); ok {
|
||||
voteMsg = protoVoteMsg
|
||||
}
|
||||
|
||||
if voteMsg != nil {
|
||||
vote := types.Vote{
|
||||
Voter: voteMsg.Voter,
|
||||
ProposalId: params.ProposalID,
|
||||
@ -191,25 +258,36 @@ func QueryVoteByTxQuery(clientCtx client.Context, params types.QueryVoteParams)
|
||||
// QueryDepositByTxQuery will query for a single deposit via a direct txs tags
|
||||
// query.
|
||||
func QueryDepositByTxQuery(clientCtx client.Context, params types.QueryDepositParams) ([]byte, error) {
|
||||
events := []string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgDeposit),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalDeposit, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, []byte(params.Depositor.String())),
|
||||
}
|
||||
|
||||
// NOTE: SearchTxs is used to facilitate the txs query which does not currently
|
||||
// support configurable pagination.
|
||||
searchResult, err := authclient.QueryTxsByEvents(clientCtx, events, defaultPage, defaultLimit, "")
|
||||
searchResult, err := combineEvents(
|
||||
clientCtx, defaultPage,
|
||||
// Query old Msgs
|
||||
[]string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgDeposit),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalDeposit, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, []byte(params.Depositor.String())),
|
||||
},
|
||||
// Query service Msgs
|
||||
[]string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeSvcMsgDeposit),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalDeposit, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, []byte(params.Depositor.String())),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, info := range searchResult.Txs {
|
||||
for _, msg := range info.GetTx().GetMsgs() {
|
||||
var depMsg *types.MsgDeposit
|
||||
// there should only be a single deposit under the given conditions
|
||||
if msg.Type() == types.TypeMsgDeposit {
|
||||
depMsg := msg.(*types.MsgDeposit)
|
||||
if msg.Type() == types.TypeSvcMsgDeposit {
|
||||
depMsg = msg.(sdk.ServiceMsg).Request.(*types.MsgDeposit)
|
||||
} else if protoDepMsg, ok := msg.(*types.MsgDeposit); ok {
|
||||
depMsg = protoDepMsg
|
||||
}
|
||||
|
||||
if depMsg != nil {
|
||||
deposit := types.Deposit{
|
||||
Depositor: depMsg.Depositor,
|
||||
ProposalId: params.ProposalID,
|
||||
@ -232,14 +310,20 @@ func QueryDepositByTxQuery(clientCtx client.Context, params types.QueryDepositPa
|
||||
// QueryProposerByTxQuery will query for a proposer of a governance proposal by
|
||||
// ID.
|
||||
func QueryProposerByTxQuery(clientCtx client.Context, proposalID uint64) (Proposer, error) {
|
||||
events := []string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgSubmitProposal),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", proposalID))),
|
||||
}
|
||||
|
||||
// NOTE: SearchTxs is used to facilitate the txs query which does not currently
|
||||
// support configurable pagination.
|
||||
searchResult, err := authclient.QueryTxsByEvents(clientCtx, events, defaultPage, defaultLimit, "")
|
||||
searchResult, err := combineEvents(
|
||||
clientCtx,
|
||||
defaultPage,
|
||||
// Query old Msgs
|
||||
[]string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgSubmitProposal),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", proposalID))),
|
||||
},
|
||||
// Query service Msgs
|
||||
[]string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeSvcMsgSubmitProposal),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", proposalID))),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return Proposer{}, err
|
||||
}
|
||||
@ -247,8 +331,13 @@ func QueryProposerByTxQuery(clientCtx client.Context, proposalID uint64) (Propos
|
||||
for _, info := range searchResult.Txs {
|
||||
for _, msg := range info.GetTx().GetMsgs() {
|
||||
// there should only be a single proposal under the given conditions
|
||||
if msg.Type() == types.TypeMsgSubmitProposal {
|
||||
subMsg := msg.(*types.MsgSubmitProposal)
|
||||
if msg.Type() == types.TypeSvcMsgSubmitProposal {
|
||||
subMsg := msg.(sdk.ServiceMsg).Request.(*types.MsgSubmitProposal)
|
||||
|
||||
return NewProposer(proposalID, subMsg.Proposer), nil
|
||||
} else if protoSubMsg, ok := msg.(*types.MsgSubmitProposal); ok {
|
||||
subMsg := protoSubMsg
|
||||
|
||||
return NewProposer(proposalID, subMsg.Proposer), nil
|
||||
}
|
||||
}
|
||||
@ -272,3 +361,25 @@ func QueryProposalByID(proposalID uint64, clientCtx client.Context, queryRoute s
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
// combineEvents queries txs by events with all events from each event group,
|
||||
// and combines all those events together.
|
||||
//
|
||||
// Tx are indexed in tendermint via their Msgs `Type()`, which can be:
|
||||
// - via legacy Msgs (amino or proto), their `Type()` is a custom string,
|
||||
// - via ADR-031 service msgs, their `Type()` is the protobuf FQ method name.
|
||||
// In searching for events, we search for both `Type()`s, and we use the
|
||||
// `combineEvents` function here to merge events.
|
||||
func combineEvents(clientCtx client.Context, page int, eventGroups ...[]string) (*sdk.SearchTxsResult, error) {
|
||||
// Only the Txs field will be populated in the final SearchTxsResult.
|
||||
allTxs := []*sdk.TxResponse{}
|
||||
for _, events := range eventGroups {
|
||||
res, err := authclient.QueryTxsByEvents(clientCtx, events, page, defaultLimit, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
allTxs = append(allTxs, res.Txs...)
|
||||
}
|
||||
|
||||
return &sdk.SearchTxsResult{Txs: allTxs}, nil
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package utils_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -10,15 +11,14 @@ import (
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/client/utils"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
)
|
||||
|
||||
type TxSearchMock struct {
|
||||
txConfig client.TxConfig
|
||||
mock.Client
|
||||
txs []tmtypes.Tx
|
||||
}
|
||||
@ -32,12 +32,35 @@ func (mock TxSearchMock) TxSearch(ctx context.Context, query string, prove bool,
|
||||
*perPage = 0
|
||||
}
|
||||
|
||||
// Get the `message.action` value from the query.
|
||||
messageAction := regexp.MustCompile(`message\.action='(.*)' .*$`)
|
||||
msgType := messageAction.FindStringSubmatch(query)[1]
|
||||
|
||||
// Filter only the txs that match the query
|
||||
matchingTxs := make([]tmtypes.Tx, 0)
|
||||
for _, tx := range mock.txs {
|
||||
sdkTx, err := mock.txConfig.TxDecoder()(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, msg := range sdkTx.GetMsgs() {
|
||||
if msg.Type() == msgType {
|
||||
matchingTxs = append(matchingTxs, tx)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
start, end := client.Paginate(len(mock.txs), *page, *perPage, 100)
|
||||
if start < 0 || end < 0 {
|
||||
// nil result with nil error crashes utils.QueryTxsByEvents
|
||||
return &ctypes.ResultTxSearch{}, nil
|
||||
}
|
||||
txs := mock.txs[start:end]
|
||||
if len(matchingTxs) < end {
|
||||
return &ctypes.ResultTxSearch{}, nil
|
||||
}
|
||||
|
||||
txs := matchingTxs[start:end]
|
||||
rst := &ctypes.ResultTxSearch{Txs: make([]*ctypes.ResultTx, len(txs)), TotalCount: len(txs)}
|
||||
for i := range txs {
|
||||
rst.Txs[i] = &ctypes.ResultTx{Tx: txs[i]}
|
||||
@ -50,15 +73,9 @@ func (mock TxSearchMock) Block(ctx context.Context, height *int64) (*ctypes.Resu
|
||||
return &ctypes.ResultBlock{Block: &tmtypes.Block{}}, nil
|
||||
}
|
||||
|
||||
func newTestCodec() *codec.LegacyAmino {
|
||||
cdc := codec.NewLegacyAmino()
|
||||
sdk.RegisterLegacyAminoCodec(cdc)
|
||||
types.RegisterLegacyAminoCodec(cdc)
|
||||
authtypes.RegisterLegacyAminoCodec(cdc)
|
||||
return cdc
|
||||
}
|
||||
|
||||
func TestGetPaginatedVotes(t *testing.T) {
|
||||
encCfg := simapp.MakeTestEncodingConfig()
|
||||
|
||||
type testCase struct {
|
||||
description string
|
||||
page, limit int
|
||||
@ -144,17 +161,12 @@ func TestGetPaginatedVotes(t *testing.T) {
|
||||
tc := tc
|
||||
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
var (
|
||||
marshalled = make([]tmtypes.Tx, len(tc.msgs))
|
||||
cdc = newTestCodec()
|
||||
)
|
||||
|
||||
encodingConfig := simapp.MakeTestEncodingConfig()
|
||||
cli := TxSearchMock{txs: marshalled}
|
||||
var marshalled = make([]tmtypes.Tx, len(tc.msgs))
|
||||
cli := TxSearchMock{txs: marshalled, txConfig: encCfg.TxConfig}
|
||||
clientCtx := client.Context{}.
|
||||
WithLegacyAmino(cdc).
|
||||
WithLegacyAmino(encCfg.Amino).
|
||||
WithClient(cli).
|
||||
WithTxConfig(encodingConfig.TxConfig)
|
||||
WithTxConfig(encCfg.TxConfig)
|
||||
|
||||
for i := range tc.msgs {
|
||||
txBuilder := clientCtx.TxConfig.NewTxBuilder()
|
||||
|
||||
@ -18,6 +18,12 @@ const (
|
||||
TypeMsgVote = "vote"
|
||||
TypeMsgVoteWeighted = "weighted_vote"
|
||||
TypeMsgSubmitProposal = "submit_proposal"
|
||||
|
||||
// These are used for querying events by action.
|
||||
TypeSvcMsgDeposit = "/cosmos.gov.v1beta1.Msg/Deposit"
|
||||
TypeSvcMsgVote = "/cosmos.gov.v1beta1.Msg/Vote"
|
||||
TypeSvcMsgVoteWeighted = "/cosmos.gov.v1beta1.Msg/VoteWeighted"
|
||||
TypeSvcMsgSubmitProposal = "/cosmos.gov.v1beta1.Msg/SubmitProposal"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types"
|
||||
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
|
||||
@ -96,11 +97,14 @@ to the counterparty channel. Any timeout set to 0 is disabled.`),
|
||||
msg := types.NewMsgTransfer(
|
||||
srcPort, srcChannel, coin, sender, receiver, timeoutHeight, timeoutTimestamp,
|
||||
)
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.Transfer(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
@ -73,11 +74,14 @@ func NewCreateClientCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.CreateClient(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
@ -123,11 +127,14 @@ func NewUpdateClientCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.UpdateClient(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -168,11 +175,14 @@ func NewSubmitMisbehaviourCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.SubmitMisbehaviour(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -235,11 +245,14 @@ func NewUpgradeClientCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.UpgradeClient(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/client/utils"
|
||||
@ -76,11 +77,14 @@ func NewConnectionOpenInitCmd() *cobra.Command {
|
||||
counterpartyPrefix, version, delayPeriod, clientCtx.GetFromAddress(),
|
||||
)
|
||||
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.ConnectionOpenInit(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
@ -189,11 +193,14 @@ func NewConnectionOpenTryCmd() *cobra.Command {
|
||||
consensusHeight, clientCtx.GetFromAddress(),
|
||||
)
|
||||
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.ConnectionOpenTry(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
@ -276,11 +283,14 @@ func NewConnectionOpenAckCmd() *cobra.Command {
|
||||
consensusHeight, version, clientCtx.GetFromAddress(),
|
||||
)
|
||||
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.ConnectionOpenAck(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
@ -321,11 +331,14 @@ func NewConnectionOpenConfirmCmd() *cobra.Command {
|
||||
connectionID, proofAck, proofHeight, clientCtx.GetFromAddress(),
|
||||
)
|
||||
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.ConnectionOpenConfirm(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types"
|
||||
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
|
||||
connectionutils "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/client/utils"
|
||||
@ -42,11 +43,14 @@ func NewChannelOpenInitCmd() *cobra.Command {
|
||||
portID, version, order, hops,
|
||||
counterpartyPortID, clientCtx.GetFromAddress(),
|
||||
)
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.ChannelOpenInit(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
@ -93,11 +97,14 @@ func NewChannelOpenTryCmd() *cobra.Command {
|
||||
counterpartyPortID, counterpartyChannelID, version,
|
||||
proofInit, proofHeight, clientCtx.GetFromAddress(),
|
||||
)
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.ChannelOpenTry(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
@ -139,11 +146,14 @@ func NewChannelOpenAckCmd() *cobra.Command {
|
||||
msg := types.NewMsgChannelOpenAck(
|
||||
portID, channelID, counterpartyChannelID, version, proofTry, proofHeight, clientCtx.GetFromAddress(),
|
||||
)
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.ChannelOpenAck(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
cmd.Flags().String(FlagIBCVersion, ibctransfertypes.Version, "IBC application version")
|
||||
@ -179,11 +189,14 @@ func NewChannelOpenConfirmCmd() *cobra.Command {
|
||||
msg := types.NewMsgChannelOpenConfirm(
|
||||
portID, channelID, proofAck, proofHeight, clientCtx.GetFromAddress(),
|
||||
)
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.ChannelOpenConfirm(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
@ -207,11 +220,14 @@ func NewChannelCloseInitCmd() *cobra.Command {
|
||||
channelID := args[1]
|
||||
|
||||
msg := types.NewMsgChannelCloseInit(portID, channelID, clientCtx.GetFromAddress())
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.ChannelCloseInit(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
@ -247,11 +263,14 @@ func NewChannelCloseConfirmCmd() *cobra.Command {
|
||||
msg := types.NewMsgChannelCloseConfirm(
|
||||
portID, channelID, proofInit, proofHeight, clientCtx.GetFromAddress(),
|
||||
)
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.ChannelCloseConfirm(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
paramscutils "github.com/cosmos/cosmos-sdk/x/params/client/utils"
|
||||
@ -80,11 +81,14 @@ Where proposal.json contains:
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := govtypes.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.SubmitProposal(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing/types"
|
||||
)
|
||||
|
||||
@ -41,11 +42,14 @@ $ <appd> tx slashing unjail --from mykey
|
||||
valAddr := clientCtx.GetFromAddress()
|
||||
|
||||
msg := types.NewMsgUnjail(sdk.ValAddress(valAddr))
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.Unjail(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
@ -59,12 +60,19 @@ func NewCreateValidatorCmd() *cobra.Command {
|
||||
}
|
||||
txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever)
|
||||
|
||||
txf, msg, err := NewBuildCreateValidatorMsg(clientCtx, txf, cmd.Flags())
|
||||
txf, msg, err := newBuildCreateValidatorMsg(clientCtx, txf, cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.CreateValidator(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
@ -128,11 +136,14 @@ func NewEditValidatorCmd() *cobra.Command {
|
||||
}
|
||||
|
||||
msg := types.NewMsgEditValidator(sdk.ValAddress(valAddr), description, newRate, newMinSelfDelegation)
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.EditValidator(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
@ -177,11 +188,14 @@ $ %s tx staking delegate %s1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 1000stake --f
|
||||
}
|
||||
|
||||
msg := types.NewMsgDelegate(delAddr, valAddr, amount)
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.Delegate(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
@ -228,11 +242,14 @@ $ %s tx staking redelegate %s1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj %s1l2rsakp3
|
||||
}
|
||||
|
||||
msg := types.NewMsgBeginRedelegate(delAddr, valSrcAddr, valDstAddr, amount)
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.BeginRedelegate(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
@ -274,11 +291,14 @@ $ %s tx staking unbond %s1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 100stake --from
|
||||
}
|
||||
|
||||
msg := types.NewMsgUndelegate(delAddr, valAddr, amount)
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.Undelegate(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
@ -287,7 +307,7 @@ $ %s tx staking unbond %s1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 100stake --from
|
||||
return cmd
|
||||
}
|
||||
|
||||
func NewBuildCreateValidatorMsg(clientCtx client.Context, txf tx.Factory, fs *flag.FlagSet) (tx.Factory, sdk.Msg, error) {
|
||||
func newBuildCreateValidatorMsg(clientCtx client.Context, txf tx.Factory, fs *flag.FlagSet) (tx.Factory, *types.MsgCreateValidator, error) {
|
||||
fAmount, _ := fs.GetString(FlagAmount)
|
||||
amount, err := sdk.ParseCoinNormalized(fAmount)
|
||||
if err != nil {
|
||||
|
||||
@ -151,20 +151,30 @@ func delegatorTxsHandlerFn(clientCtx client.Context) http.HandlerFunc {
|
||||
actions []string
|
||||
)
|
||||
|
||||
// For each case, we search txs for both:
|
||||
// - legacy messages: their Type() is a custom string, e.g. "delegate"
|
||||
// - service Msgs: their Type() is their FQ method name, e.g. "/cosmos.staking.v1beta1.Msg/Deledate"
|
||||
// and we combine the results.
|
||||
switch {
|
||||
case isBondTx:
|
||||
actions = append(actions, types.MsgDelegate{}.Type())
|
||||
actions = append(actions, types.TypeMsgDelegate)
|
||||
actions = append(actions, types.TypeSvcMsgDelegate)
|
||||
|
||||
case isUnbondTx:
|
||||
actions = append(actions, types.MsgUndelegate{}.Type())
|
||||
actions = append(actions, types.TypeMsgUndelegate)
|
||||
actions = append(actions, types.TypeSvcMsgUndelegate)
|
||||
|
||||
case isRedTx:
|
||||
actions = append(actions, types.MsgBeginRedelegate{}.Type())
|
||||
actions = append(actions, types.TypeMsgBeginRedelegate)
|
||||
actions = append(actions, types.TypeSvcMsgBeginRedelegate)
|
||||
|
||||
case noQuery:
|
||||
actions = append(actions, types.MsgDelegate{}.Type())
|
||||
actions = append(actions, types.MsgUndelegate{}.Type())
|
||||
actions = append(actions, types.MsgBeginRedelegate{}.Type())
|
||||
actions = append(actions, types.TypeMsgDelegate)
|
||||
actions = append(actions, types.TypeSvcMsgDelegate)
|
||||
actions = append(actions, types.TypeMsgUndelegate)
|
||||
actions = append(actions, types.TypeSvcMsgUndelegate)
|
||||
actions = append(actions, types.TypeMsgBeginRedelegate)
|
||||
actions = append(actions, types.TypeSvcMsgBeginRedelegate)
|
||||
|
||||
default:
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
|
||||
@ -24,6 +24,13 @@ const (
|
||||
TypeMsgCreateValidator = "create_validator"
|
||||
TypeMsgDelegate = "delegate"
|
||||
TypeMsgBeginRedelegate = "begin_redelegate"
|
||||
|
||||
// These are used for querying events by action.
|
||||
TypeSvcMsgUndelegate = "/cosmos.staking.v1beta1.Msg/Undelegate"
|
||||
TypeSvcMsgEditValidator = "/cosmos.staking.v1beta1.Msg/EditValidator"
|
||||
TypeSvcMsgCreateValidator = "/cosmos.staking.v1beta1.Msg/CreateValidator"
|
||||
TypeSvcMsgDelegate = "/cosmos.staking.v1beta1.Msg/Deledate"
|
||||
TypeSvcMsgBeginRedelegate = "/cosmos.staking.v1beta1.Msg/BeginRedelegate"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
||||
gov "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
||||
@ -69,11 +70,14 @@ func NewCmdSubmitUpgradeProposal() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := gov.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.SubmitProposal(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
@ -128,11 +132,14 @@ func NewCmdSubmitCancelUpgradeProposal() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = msg.ValidateBasic(); err != nil {
|
||||
svcMsgClientConn := &msgservice.ServiceMsgClientConn{}
|
||||
msgClient := gov.NewMsgClient(svcMsgClientConn)
|
||||
_, err = msgClient.SubmitProposal(cmd.Context(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.GetMsgs()...)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user