Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate {x/auth, x/gov, x/staking} missing CLI queries to proto #6994

Merged
merged 51 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
e353cd0
Fix error code
sahith-narahari Aug 9, 2020
93fab54
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/upd…
sahith-narahari Aug 13, 2020
237c08f
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/upd…
sahith-narahari Aug 14, 2020
a8e1550
Merge branch 'master' into sahith/update-query-cli
anilcse Aug 17, 2020
ce925c3
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/upd…
anilcse Aug 18, 2020
97e1d87
Merge branch 'master' into sahith/update-query-cli
anilcse Aug 18, 2020
647d146
Merge branch 'sahith/update-query-cli' of github.com:cosmos/cosmos-sd…
anilcse Aug 18, 2020
bc70575
Fix decoder
anilcse Aug 22, 2020
e564ed1
Fix typo
anilcse Aug 22, 2020
f34a03b
Fix decode
anilcse Aug 24, 2020
810fcac
refactor
anilcse Aug 24, 2020
176592c
Merge branch 'master' into sahith/update-query-cli
anilcse Aug 24, 2020
d8d3264
Migrate SearchTxsResult to proto
anilcse Aug 25, 2020
d899405
Merge branch 'master' into sahith/update-query-cli
alexanderbez Aug 25, 2020
706bacc
fix MarkEventsToIndex
alexanderbez Aug 25, 2020
e228a57
lint++
alexanderbez Aug 25, 2020
95fccdd
Merge branch 'bez/fix-MarkEventsToIndex' of github.com:cosmos/cosmos-…
anilcse Aug 25, 2020
1991204
Merge branch 'sahith/update-query-cli' of github.com:cosmos/cosmos-sd…
anilcse Aug 25, 2020
a541306
Fix output
anilcse Aug 25, 2020
0ef79e6
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into sahi…
amaury1093 Aug 26, 2020
bc4498e
Add QueryTxCmd cli test
anilcse Aug 26, 2020
3c8bc53
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/upd…
anilcse Aug 26, 2020
66000da
Merge branch 'sahith/update-query-cli' of ssh://github.com/cosmos/cos…
amaury1093 Aug 26, 2020
d5dc3a4
Add fmt
amaury1093 Aug 27, 2020
b4a41c2
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into sahi…
amaury1093 Sep 1, 2020
2a02efc
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into sahi…
amaury1093 Sep 3, 2020
db5d236
Put txBuilder in types/tx
amaury1093 Sep 3, 2020
abcdee3
Add GetAnyTx in TxBuilder
amaury1093 Sep 3, 2020
aaa930a
Add new IsAnyTx
amaury1093 Sep 3, 2020
b187831
Rename to IntoAny
amaury1093 Sep 3, 2020
61e257e
Fix bug
amaury1093 Sep 3, 2020
6e10445
Merge branch 'master' into sahith/update-query-cli
amaury1093 Sep 3, 2020
0be2e5b
Merge branch 'sahith/update-query-cli' of ssh://github.com/cosmos/cos…
amaury1093 Sep 3, 2020
2dac31c
fmt
anilcse Sep 3, 2020
c8815e7
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/upd…
anilcse Sep 5, 2020
e08c852
Fix ibc CLI to use proto
anilcse Sep 5, 2020
1aa75c4
Merge branch 'sahith/update-query-cli' of github.com:cosmos/cosmos-sd…
anilcse Sep 5, 2020
bed75a8
Merge branch 'sahith/update-query-cli' of ssh://github.com/cosmos/cos…
amaury1093 Sep 7, 2020
aa9b78f
Fix any MarshalJSON
amaury1093 Sep 7, 2020
1ea476f
Fix test
amaury1093 Sep 7, 2020
cf17bcd
Make tx.Tx implement sdk.Tx
amaury1093 Sep 7, 2020
8fb572d
Register sdk.Tx
amaury1093 Sep 7, 2020
85a92e9
Fix lint
amaury1093 Sep 7, 2020
8b96e49
Allow DefaultJSONTxEncoder to take tx.Tx
amaury1093 Sep 7, 2020
c2e6f7f
refactor
anilcse Sep 7, 2020
97269db
Merge branch 'master' into sahith/update-query-cli
anilcse Sep 7, 2020
afca789
Rename variable
amaury1093 Sep 8, 2020
598be43
Merge branch 'master' into sahith/update-query-cli
alexanderbez Sep 8, 2020
1a406c9
Merge branch 'master' into sahith/update-query-cli
anilcse Sep 8, 2020
3ec3d52
Merge branch 'master' into sahith/update-query-cli
anilcse Sep 10, 2020
ff49992
remove fmt
anilcse Sep 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions proto/cosmos/base/abci/v1beta1/abci.proto
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,30 @@ message TxMsgData {

repeated MsgData data = 1;
}

// SearchTxsResult defines a structure for querying txs pageable
message SearchTxsResult {
option (gogoproto.stringer) = true;

// Count of all txs
uint64 total_count = 1 [
(gogoproto.moretags) = "yaml:\"total_count\"",
(gogoproto.jsontag) = "total_count"
];
// Count of txs in current page
uint64 count = 2;
// Index of current page, start from 1
uint64 page_number = 3 [
(gogoproto.moretags) = "yaml:\"page_number\"",
(gogoproto.jsontag) = "page_number"
];
// Count of total pages
uint64 page_total = 4 [
(gogoproto.moretags) = "yaml:\"page_total\"",
(gogoproto.jsontag) = "page_total"
];
// Max count txs per page
uint64 limit = 5;
// List of txs in current page
repeated TxResponse txs = 6;
}
496 changes: 445 additions & 51 deletions types/abci.pb.go

Large diffs are not rendered by default.

16 changes: 3 additions & 13 deletions types/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,22 +213,12 @@ func (r TxResponse) Empty() bool {
return r.TxHash == "" && r.Logs == nil
}

// SearchTxsResult defines a structure for querying txs pageable
type SearchTxsResult struct {
TotalCount int `json:"total_count"` // Count of all txs
Count int `json:"count"` // Count of txs in current page
PageNumber int `json:"page_number"` // Index of current page, start from 1
PageTotal int `json:"page_total"` // Count of total pages
Limit int `json:"limit"` // Max count txs per page
Txs []*TxResponse `json:"txs"` // List of txs in current page
}

func NewSearchTxsResult(totalCount, count, page, limit int, txs []*TxResponse) SearchTxsResult {
return SearchTxsResult{
func NewSearchTxsResult(totalCount, count, page, limit uint64, txs []*TxResponse) *SearchTxsResult {
return &SearchTxsResult{
TotalCount: totalCount,
Count: count,
PageNumber: page,
PageTotal: int(math.Ceil(float64(totalCount) / float64(limit))),
PageTotal: uint64(math.Ceil(float64(totalCount) / float64(limit))),
Limit: limit,
Txs: txs,
}
Expand Down
2 changes: 1 addition & 1 deletion types/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestABCIMessageLog(t *testing.T) {
func TestNewSearchTxsResult(t *testing.T) {
t.Parallel()
got := sdk.NewSearchTxsResult(150, 20, 2, 20, []*sdk.TxResponse{})
require.Equal(t, sdk.SearchTxsResult{
require.Equal(t, &sdk.SearchTxsResult{
TotalCount: 150,
Count: 20,
PageNumber: 2,
Expand Down
44 changes: 42 additions & 2 deletions x/auth/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"strings"
"testing"

"github.com/cosmos/cosmos-sdk/codec/types"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
tmcrypto "github.com/tendermint/tendermint/crypto"
Expand All @@ -18,6 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
codec2 "github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
Expand Down Expand Up @@ -165,6 +164,47 @@ func (s *IntegrationTestSuite) TestCLISignBatch() {
s.Require().Error(err)
}

func (s *IntegrationTestSuite) TestCLITxQueryCmd() {
val := s.network.Validators[0]
var txHash string

s.Run("bank send tx", func() {
clientCtx := val.ClientCtx

bz, err := bankcli.MsgSendExec(clientCtx, 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()),
}...)

var txRes sdk.TxResponse
s.Require().NoError(err)
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(bz.Bytes(), &txRes), bz.String())

txHash = txRes.TxHash
s.Require().Equal(uint32(0), txRes.Code)
})

s.network.WaitForNextBlock()

s.Run("", func() {
anilcse marked this conversation as resolved.
Show resolved Hide resolved
cmd := authcli.QueryTxCmd()
args := []string{
txHash,
}

out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
s.Require().NoError(err)

var tx sdk.TxResponse
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), &tx))
fmt.Println(tx)
})
}

func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
val1 := s.network.Validators[0]

Expand Down
8 changes: 1 addition & 7 deletions x/auth/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,7 @@ $ %s query txs --%s 'message.sender=cosmos1...&message.action=withdraw_delegator
return err
}

output, err := clientCtx.LegacyAmino.MarshalJSON(txs)
if err != nil {
return err
}

fmt.Println(string(output))
return nil
return clientCtx.PrintOutput(txs)
},
}

Expand Down
24 changes: 11 additions & 13 deletions x/auth/client/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import (
ctypes "github.com/tendermint/tendermint/rpc/core/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/types"
)

// QueryTxsByEvents performs a search for transactions for a given set of events
Expand Down Expand Up @@ -53,14 +51,14 @@ func QueryTxsByEvents(clientCtx client.Context, events []string, page, limit int
return nil, err
}

txs, err := formatTxResults(clientCtx.LegacyAmino, resTxs.Txs, resBlocks)
txs, err := formatTxResults(clientCtx.TxConfig, resTxs.Txs, resBlocks)
if err != nil {
return nil, err
}

result := sdk.NewSearchTxsResult(resTxs.TotalCount, len(txs), page, limit, txs)
result := sdk.NewSearchTxsResult(uint64(resTxs.TotalCount), uint64(len(txs)), uint64(page), uint64(limit), txs)

return &result, nil
return result, nil
}

// QueryTx queries for a single transaction by a hash string in hex format. An
Expand Down Expand Up @@ -88,7 +86,7 @@ func QueryTx(clientCtx client.Context, hashHexStr string) (*sdk.TxResponse, erro
return nil, err
}

out, err := formatTxResult(clientCtx.LegacyAmino, resTx, resBlocks[resTx.Height])
out, err := formatTxResult(clientCtx.TxConfig, resTx, resBlocks[resTx.Height])
if err != nil {
return out, err
}
Expand All @@ -97,11 +95,11 @@ func QueryTx(clientCtx client.Context, hashHexStr string) (*sdk.TxResponse, erro
}

// formatTxResults parses the indexed txs into a slice of TxResponse objects.
func formatTxResults(cdc *codec.LegacyAmino, resTxs []*ctypes.ResultTx, resBlocks map[int64]*ctypes.ResultBlock) ([]*sdk.TxResponse, error) {
func formatTxResults(txConfig client.TxConfig, resTxs []*ctypes.ResultTx, resBlocks map[int64]*ctypes.ResultBlock) ([]*sdk.TxResponse, error) {
var err error
out := make([]*sdk.TxResponse, len(resTxs))
for i := range resTxs {
out[i], err = formatTxResult(cdc, resTxs[i], resBlocks[resTxs[i].Height])
out[i], err = formatTxResult(txConfig, resTxs[i], resBlocks[resTxs[i].Height])
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -132,19 +130,19 @@ func getBlocksForTxResults(clientCtx client.Context, resTxs []*ctypes.ResultTx)
return resBlocks, nil
}

func formatTxResult(cdc *codec.LegacyAmino, resTx *ctypes.ResultTx, resBlock *ctypes.ResultBlock) (*sdk.TxResponse, error) {
tx, err := parseTx(cdc, resTx.Tx)
func formatTxResult(txConfig client.TxConfig, resTx *ctypes.ResultTx, resBlock *ctypes.ResultBlock) (*sdk.TxResponse, error) {
tx, err := parseTx(txConfig, resTx.Tx)
if err != nil {
return nil, err
}

return sdk.NewResponseResultTx(resTx, tx, resBlock.Block.Time.Format(time.RFC3339)), nil
}

func parseTx(cdc *codec.LegacyAmino, txBytes []byte) (sdk.Tx, error) {
var tx types.StdTx
func parseTx(txConfig client.TxConfig, txBytes []byte) (sdk.Tx, error) {
var tx sdk.Tx

err := cdc.UnmarshalBinaryBare(txBytes, &tx)
tx, err := txConfig.TxDecoder()(txBytes)
if err != nil {
return nil, err
}
Expand Down
62 changes: 34 additions & 28 deletions x/gov/client/utils/query_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package utils
package utils_test

import (
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/x/gov/client/utils"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -59,7 +61,7 @@ func TestGetPaginatedVotes(t *testing.T) {
type testCase struct {
description string
page, limit int
txs []authtypes.StdTx
msgs [][]sdk.Msg
votes []types.Vote
}
acc1 := make(sdk.AccAddress, 20)
Expand All @@ -79,22 +81,21 @@ func TestGetPaginatedVotes(t *testing.T) {
description: "1MsgPerTxAll",
page: 1,
limit: 2,
txs: []authtypes.StdTx{
{Msgs: acc1Msgs[:1]},
{Msgs: acc2Msgs[:1]},
msgs: [][]sdk.Msg{
acc1Msgs[:1],
acc2Msgs[:1],
},
votes: []types.Vote{
types.NewVote(0, acc1, types.OptionYes),
types.NewVote(0, acc2, types.OptionYes)},
},

{
description: "2MsgPerTx1Chunk",
page: 1,
limit: 2,
txs: []authtypes.StdTx{
{Msgs: acc1Msgs},
{Msgs: acc2Msgs},
msgs: [][]sdk.Msg{
acc1Msgs,
acc2Msgs,
},
votes: []types.Vote{
types.NewVote(0, acc1, types.OptionYes),
Expand All @@ -104,9 +105,9 @@ func TestGetPaginatedVotes(t *testing.T) {
description: "2MsgPerTx2Chunk",
page: 2,
limit: 2,
txs: []authtypes.StdTx{
{Msgs: acc1Msgs},
{Msgs: acc2Msgs},
msgs: [][]sdk.Msg{
acc1Msgs,
acc2Msgs,
},
votes: []types.Vote{
types.NewVote(0, acc2, types.OptionYes),
Expand All @@ -116,49 +117,54 @@ func TestGetPaginatedVotes(t *testing.T) {
description: "IncompleteSearchTx",
page: 1,
limit: 2,
txs: []authtypes.StdTx{
{Msgs: acc1Msgs[:1]},
msgs: [][]sdk.Msg{
acc1Msgs[:1],
},
votes: []types.Vote{types.NewVote(0, acc1, types.OptionYes)},
},
{
description: "InvalidPage",
page: -1,
txs: []authtypes.StdTx{
{Msgs: acc1Msgs[:1]},
msgs: [][]sdk.Msg{
acc1Msgs[:1],
},
},
{
description: "OutOfBounds",
page: 2,
limit: 10,
txs: []authtypes.StdTx{
{Msgs: acc1Msgs[:1]},
msgs: [][]sdk.Msg{
acc1Msgs[:1],
},
},
} {

tc := tc

t.Run(tc.description, func(t *testing.T) {
var (
marshalled = make([]tmtypes.Tx, len(tc.txs))
marshalled = make([]tmtypes.Tx, len(tc.msgs))
cdc = newTestCodec()
)

for i := range tc.txs {
tx, err := cdc.MarshalBinaryBare(&tc.txs[i])
require.NoError(t, err)
marshalled[i] = tx
}

encodingConfig := simapp.MakeEncodingConfig()
cli := TxSearchMock{txs: marshalled}
clientCtx := client.Context{}.
WithLegacyAmino(cdc).
WithClient(cli)
WithClient(cli).
WithTxConfig(encodingConfig.TxConfig)

for i := range tc.msgs {
txBuilder := clientCtx.TxConfig.NewTxBuilder()
err := txBuilder.SetMsgs(tc.msgs[i]...)
require.NoError(t, err)

tx, err := clientCtx.TxConfig.TxEncoder()(txBuilder.GetTx())
require.NoError(t, err)
marshalled[i] = tx
}

params := types.NewQueryProposalVotesParams(0, tc.page, tc.limit)
votesData, err := QueryVotesByTxQuery(clientCtx, params)
votesData, err := utils.QueryVotesByTxQuery(clientCtx, params)
require.NoError(t, err)
votes := []types.Vote{}
require.NoError(t, clientCtx.LegacyAmino.UnmarshalJSON(votesData, &votes))
Expand Down
2 changes: 1 addition & 1 deletion x/ibc/02-client/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func GetCmdQueryHeader() *cobra.Command {
}

clientCtx = clientCtx.WithHeight(height)
return clientCtx.PrintOutputLegacy(header)
return clientCtx.PrintOutput(&header)
},
}

Expand Down
2 changes: 1 addition & 1 deletion x/ibc/04-channel/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func GetCmdQueryChannelClientState() *cobra.Command {
return err
}

return clientCtx.PrintOutputLegacy(res.IdentifiedClientState)
return clientCtx.PrintOutput(res.IdentifiedClientState)
anilcse marked this conversation as resolved.
Show resolved Hide resolved
},
}

Expand Down