From 71e0b9518f93ae49e9e93c7a191a6925f6207728 Mon Sep 17 00:00:00 2001 From: aleem1314 Date: Fri, 4 Jun 2021 13:27:37 +0530 Subject: [PATCH] resolve conflicts --- CHANGELOG.md | 14 +--- x/gov/client/cli/query.go | 22 ------ x/gov/client/testutil/cli_test.go | 2 - x/gov/client/utils/query.go | 123 +++++++----------------------- 4 files changed, 30 insertions(+), 131 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a40d5bfa97bf..cef5df2ef6f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,15 +38,17 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features - * [\#9383](https://github.com/cosmos/cosmos-sdk/pull/9383) New CLI command `query ibc-transfer escrow-address ` to get the escrow address for a channel; can be used to then query balance of escrowed tokens +### Bug Fixes + +* (x/gov) [\#8813](https://github.com/cosmos/cosmos-sdk/pull/8813) fix `GET /cosmos/gov/v1beta1/proposals/{proposal_id}/deposits` to include initial deposit + ## [v0.42.5](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.42.5) - 2021-05-18 ### Bug Fixes -<<<<<<< HEAD * [\#9235](https://github.com/cosmos/cosmos-sdk/pull/9235) CreateMembershipProof/CreateNonMembershipProof now returns an error if input key is empty, or input data contains empty key. * [\#9108](https://github.com/cosmos/cosmos-sdk/pull/9108) Fixed the bug with querying multisig account, which is not showing threshold and public_keys. @@ -54,14 +56,6 @@ if input key is empty, or input data contains empty key. * [\#9040](https://github.com/cosmos/cosmos-sdk/pull/9040) Fix ENV variables binding to CLI flags for client config. ### Features -======= -* (x/gov) [\#8813](https://github.com/cosmos/cosmos-sdk/pull/8813) fix `GET /cosmos/gov/v1beta1/proposals/{proposal_id}/deposits` to include initial deposit -* (gRPC) [\#8945](https://github.com/cosmos/cosmos-sdk/pull/8945) gRPC reflection now works correctly. -* (keyring) [#\8635](https://github.com/cosmos/cosmos-sdk/issues/8635) Remove hardcoded default passphrase value on `NewMnemonic` -* (x/bank) [\#8434](https://github.com/cosmos/cosmos-sdk/pull/8434) Fix legacy REST API `GET /bank/total` and `GET /bank/total/{denom}` in swagger -* (x/slashing) [\#8427](https://github.com/cosmos/cosmos-sdk/pull/8427) Fix query signing infos command -* (x/bank) [\#9229](https://github.com/cosmos/cosmos-sdk/pull/9229) Now zero coin balances cannot be added to balances & supply stores. If any denom becomes zero corresponding key gets deleted from store. ->>>>>>> 66ee994ce (fix: x/gov deposits querier (Initial Deposit) (#9288)) * [\#8953](https://github.com/cosmos/cosmos-sdk/pull/8953) Add the `config` CLI subcommand back to the SDK, which saves client-side configuration in a `client.toml` file. diff --git a/x/gov/client/cli/query.go b/x/gov/client/cli/query.go index 1a20b5745965..1b7f7995f42e 100644 --- a/x/gov/client/cli/query.go +++ b/x/gov/client/cli/query.go @@ -364,14 +364,9 @@ $ %s query gov deposit 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk } // check to see if the proposal is in the store -<<<<<<< HEAD - _, err = queryClient.Proposal( - context.Background(), -======= ctx := cmd.Context() proposalRes, err := queryClient.Proposal( ctx, ->>>>>>> 66ee994ce (fix: x/gov deposits querier (Initial Deposit) (#9288)) &types.QueryProposalRequest{ProposalId: proposalID}, ) if err != nil { @@ -383,31 +378,15 @@ $ %s query gov deposit 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk return err } -<<<<<<< HEAD - res, err := queryClient.Deposit( - context.Background(), - &types.QueryDepositRequest{ProposalId: proposalID, Depositor: args[1]}, - ) - if err != nil { - return err - } - - deposit := res.GetDeposit() - if deposit.Empty() { -======= var deposit types.Deposit propStatus := proposalRes.Proposal.Status if !(propStatus == types.StatusVotingPeriod || propStatus == types.StatusDepositPeriod) { ->>>>>>> 66ee994ce (fix: x/gov deposits querier (Initial Deposit) (#9288)) params := types.NewQueryDepositParams(proposalID, depositorAddr) resByTxQuery, err := gcutils.QueryDepositByTxQuery(clientCtx, params) if err != nil { return err } -<<<<<<< HEAD clientCtx.JSONMarshaler.MustUnmarshalJSON(resByTxQuery, &deposit) -======= - clientCtx.JSONCodec.MustUnmarshalJSON(resByTxQuery, &deposit) return clientCtx.PrintProto(&deposit) } @@ -417,7 +396,6 @@ $ %s query gov deposit 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk ) if err != nil { return err ->>>>>>> 66ee994ce (fix: x/gov deposits querier (Initial Deposit) (#9288)) } return clientCtx.PrintProto(&res.Deposit) diff --git a/x/gov/client/testutil/cli_test.go b/x/gov/client/testutil/cli_test.go index 713c33f12182..e28ba13dcd2d 100644 --- a/x/gov/client/testutil/cli_test.go +++ b/x/gov/client/testutil/cli_test.go @@ -17,8 +17,6 @@ import ( func TestIntegrationTestSuite(t *testing.T) { cfg := network.DefaultConfig() cfg.NumValidators = 1 - suite.Run(t, NewIntegrationTestSuite(cfg)) - genesisState := types.DefaultGenesisState() genesisState.DepositParams = types.NewDepositParams(sdk.NewCoins(sdk.NewCoin(cfg.BondDenom, types.DefaultMinDepositTokens)), time.Duration(15)*time.Second) genesisState.VotingParams = types.NewVotingParams(time.Duration(5) * time.Second) diff --git a/x/gov/client/utils/query.go b/x/gov/client/utils/query.go index 4f43ec55dfd8..c3c590da30fe 100644 --- a/x/gov/client/utils/query.go +++ b/x/gov/client/utils/query.go @@ -5,12 +5,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" sdk "github.com/cosmos/cosmos-sdk/types" -<<<<<<< HEAD - authclient "github.com/cosmos/cosmos-sdk/x/auth/client" -======= sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" ->>>>>>> 66ee994ce (fix: x/gov deposits querier (Initial Deposit) (#9288)) + authclient "github.com/cosmos/cosmos-sdk/x/auth/client" "github.com/cosmos/cosmos-sdk/x/gov/types" ) @@ -42,16 +38,6 @@ 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) { -<<<<<<< HEAD - 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, "") -======= var deposits []types.Deposit // initial deposit was submitted with proposal, so must be queried separately @@ -64,20 +50,14 @@ func QueryDepositsByTxQuery(clientCtx client.Context, params types.QueryProposal deposits = append(deposits, initialDeposit) } - searchResult, err := combineEvents( - clientCtx, defaultPage, - // Query legacy Msgs event action - []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 proto Msgs event action - []string{ - fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgDeposit{})), - fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalDeposit, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))), - }, - ) ->>>>>>> 66ee994ce (fix: x/gov deposits querier (Initial Deposit) (#9288)) + 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, "") if err != nil { return nil, err } @@ -198,18 +178,6 @@ 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) { -<<<<<<< HEAD - 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, "") -======= - // initial deposit was submitted with proposal, so must be queried separately initialDeposit, err := queryInitialDepositByTxQuery(clientCtx, params.ProposalID) if err != nil { @@ -217,7 +185,7 @@ func QueryDepositByTxQuery(clientCtx client.Context, params types.QueryDepositPa } if !initialDeposit.Amount.IsZero() { - bz, err := clientCtx.JSONCodec.MarshalJSON(&initialDeposit) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(&initialDeposit) if err != nil { return nil, err } @@ -225,22 +193,15 @@ func QueryDepositByTxQuery(clientCtx client.Context, params types.QueryDepositPa return bz, nil } - searchResult, err := combineEvents( - clientCtx, defaultPage, - // Query legacy Msgs event action - []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 proto Msgs event action - []string{ - fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgDeposit{})), - 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())), - }, - ) ->>>>>>> 66ee994ce (fix: x/gov deposits querier (Initial Deposit) (#9288)) + 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, "") if err != nil { return nil, err } @@ -313,47 +274,16 @@ func QueryProposalByID(proposalID uint64, clientCtx client.Context, queryRoute s return res, err } -<<<<<<< HEAD -======= - -// 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 proto 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 := authtx.QueryTxsByEvents(clientCtx, events, page, defaultLimit, "") - if err != nil { - return nil, err - } - allTxs = append(allTxs, res.Txs...) - } - - return &sdk.SearchTxsResult{Txs: allTxs}, nil -} // queryInitialDepositByTxQuery will query for a initial deposit of a governance proposal by // ID. func queryInitialDepositByTxQuery(clientCtx client.Context, proposalID uint64) (types.Deposit, error) { - searchResult, err := combineEvents( - clientCtx, defaultPage, - // Query legacy Msgs event action - []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 proto Msgs event action - []string{ - fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&types.MsgSubmitProposal{})), - fmt.Sprintf("%s.%s='%s'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", proposalID))), - }, - ) + // Query legacy Msgs event action + 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))), + } + searchResult, err := authclient.QueryTxsByEvents(clientCtx, events, defaultPage, defaultLimit, "") if err != nil { return types.Deposit{}, err @@ -372,6 +302,5 @@ func queryInitialDepositByTxQuery(clientCtx client.Context, proposalID uint64) ( } } - return types.Deposit{}, sdkerrors.ErrNotFound.Wrapf("failed to find the initial deposit for proposalID %d", proposalID) + return types.Deposit{}, sdkerrors.Wrapf(sdkerrors.ErrKeyNotFound, "failed to find the initial deposit for proposalID %d", proposalID) } ->>>>>>> 66ee994ce (fix: x/gov deposits querier (Initial Deposit) (#9288))