Skip to content

Commit

Permalink
Added q_sets args
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed Oct 15, 2023
1 parent d6bf203 commit 74c164e
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions x/cardchain/client/cli/query_q_sets.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cli

import (
"encoding/json"
"slices"
"strconv"

"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
Expand All @@ -13,21 +15,33 @@ var _ = strconv.Itoa(0)

func CmdQSets() *cobra.Command {
cmd := &cobra.Command{
Use: "q-sets [status]",
Use: "q-sets [status] [contributors] [contains-cards] [owner]",
Short: "Query q_sets",
Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) (err error) {
var (
reqStatus types.CStatus
ignoreStatus bool = false
)

if args[0] != "" {
if slices.Contains([]string{"\"\"", "''"}, args[0]) {
reqStatus = types.CStatus(types.CStatus_value[args[0]])
} else {
ignoreStatus = true
}

var argContributors []string
err = json.Unmarshal([]byte(args[1]), &argContributors)
if err != nil {
return err
}

var argContainsCards []uint64
err = json.Unmarshal([]byte(args[2]), &argContainsCards)
if err != nil {
return err
}

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
Expand All @@ -39,6 +53,9 @@ func CmdQSets() *cobra.Command {

Status: reqStatus,
IgnoreStatus: ignoreStatus,
Contributors: argContributors,
ContainsCards: argContainsCards,
Owner: args[3],
}

res, err := queryClient.QSets(cmd.Context(), params)
Expand Down

0 comments on commit 74c164e

Please sign in to comment.