From a2189bc67258d29dfcc15f8879a848fb3e11198c Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Tue, 27 Nov 2018 14:37:03 +0100 Subject: [PATCH] fix tx search CLI --- client/tx/search.go | 31 +++++++++++++++---------------- cmd/gaia/cli_test/cli_test.go | 2 +- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/client/tx/search.go b/client/tx/search.go index 821d12cb0..2f3bd9070 100644 --- a/client/tx/search.go +++ b/client/tx/search.go @@ -20,7 +20,7 @@ import ( ) const ( - flagTags = "tag" + flagTags = "tags" flagAny = "any" ) @@ -31,38 +31,37 @@ func SearchTxCmd(cdc *codec.Codec) *cobra.Command { Short: "Search for all transactions that match the given tags.", Long: strings.TrimSpace(` Search for transactions that match the given tags. By default, transactions must match ALL tags -passed to the --tags option. To match any transaction, use the --any option. +passed to the --tag option. To match any transaction, use the --any option. For example: -$ gaiacli query txs --tag test1,test2 +$ gaiacli query txs --tags :&: -will match any transaction tagged with both test1,test2. To match a transaction tagged with either -test1 or test2, use: +will match any transaction tagged with both = and =. +To match a transaction tagged with either value1 or value2, use: -$ gaiacli query txs --tag =&= --any +$ gaiacli query txs --tags :&: --any `), RunE: func(cmd *cobra.Command, args []string) error { tagsStr := viper.GetString(flagTags) tagsStr = strings.Trim(tagsStr, "'") - var tags []string switch strings.Contains(tagsStr, "&") { case true: tags = strings.Split(tagsStr, "&") case false: - tags = []string{tagsStr} + tags = append(tags, tagsStr) } var tmTags []string for _, tag := range tags { - if !strings.Contains(tag, "=") { - return fmt.Errorf("%s should be of the format =", tagsStr) + if !strings.Contains(tag, ":") { + return fmt.Errorf("%s should be of the format :", tagsStr) } - keyValue := strings.Split(tag, "=") + keyValue := strings.Split(tag, ":") key, value, errMsg := getKeyFromBechPrefix(keyValue[0], keyValue[1]) - if errMsg == "" { - return fmt.Errorf(errMsg) + if errMsg != "" { + return errors.New(errMsg) } tag = fmt.Sprintf("%s='%s'", key, value) @@ -98,7 +97,7 @@ $ gaiacli query txs --tag =&= --any viper.BindPFlag(client.FlagChainID, cmd.Flags().Lookup(client.FlagChainID)) cmd.Flags().Bool(client.FlagTrustNode, false, "Trust connected full node (don't verify proofs for responses)") viper.BindPFlag(client.FlagTrustNode, cmd.Flags().Lookup(client.FlagTrustNode)) - cmd.Flags().StringSlice(flagTags, nil, "Comma-separated list of tags that must match") + cmd.Flags().String(flagTags, "", "key:value list of tags that must match") cmd.Flags().Bool(flagAny, false, "Return transactions that match ANY tag, rather than ALL") return cmd } @@ -205,11 +204,11 @@ func SearchTxRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http. } key, value, errMsg := getKeyFromBechPrefix(key, value) - if errMsg == "" { + if errMsg != "" { utils.WriteErrorResponse(w, http.StatusBadRequest, errMsg) return } - + fmt.Println(fmt.Sprintf("%s='%s'", key, value)) tag := fmt.Sprintf("%s='%s'", key, value) tags = append(tags, tag) } diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index 4b0727ab5..ee773da62 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -383,7 +383,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) { executeWrite(t, spStr, app.DefaultKeyPass) tests.WaitForNextNBlocksTM(2, port) - txs := executeGetTxs(t, fmt.Sprintf("gaiacli query txs --tag='action=submit-proposal&proposer=%s' %v", fooAddr, flags)) + txs := executeGetTxs(t, fmt.Sprintf("gaiacli query txs --tags='action:submit-proposal&proposer:%s' %v", fooAddr, flags)) require.Len(t, txs, 1) fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))