diff --git a/x/cardchain/client/cli/query_q_cards.go b/x/cardchain/client/cli/query_q_cards.go index 143b3f14..69a1fba1 100644 --- a/x/cardchain/client/cli/query_q_cards.go +++ b/x/cardchain/client/cli/query_q_cards.go @@ -1,6 +1,7 @@ package cli import ( + "fmt" "strconv" "github.com/DecentralCardGame/Cardchain/x/cardchain/types" @@ -13,11 +14,12 @@ var _ = strconv.Itoa(0) func CmdQCards() *cobra.Command { cmd := &cobra.Command{ - Use: "q-cards [owner] [status] [card-type] [classes] [sort-by] [name-contains] [keywords-contains] [notes-contains]", + Use: "q-cards [owner] [status] [card-type] [classes] [sort-by] [name-contains] [keywords-contains] [notes-contains] [startercards-only]", Short: "Query qCards", - Args: cobra.ExactArgs(8), + Args: cobra.ExactArgs(9), RunE: func(cmd *cobra.Command, args []string) (err error) { reqOwner := args[0] + var reqOnlyStarterCard bool var reqStatus types.QueryQCardsRequest_Status if args[1] == "" { reqStatus = types.QueryQCardsRequest_none @@ -31,6 +33,15 @@ func CmdQCards() *cobra.Command { reqKeywordsContains := args[6] reqNotesContains := args[7] + switch args[8]{ + case "yes": + reqOnlyStarterCard = true + case "no": + reqOnlyStarterCard = false + default: + return fmt.Errorf("arg 'only-startercard' has to be either yes or no but not %s", args[8]) + } + clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err @@ -48,6 +59,7 @@ func CmdQCards() *cobra.Command { NameContains: reqNameContains, KeywordsContains: reqKeywordsContains, NotesContains: reqNotesContains, + OnlyStarterCard: reqOnlyStarterCard, } res, err := queryClient.QCards(cmd.Context(), params) diff --git a/x/cardchain/client/cli/query_q_sets.go b/x/cardchain/client/cli/query_q_sets.go index 8ff328d4..38427381 100644 --- a/x/cardchain/client/cli/query_q_sets.go +++ b/x/cardchain/client/cli/query_q_sets.go @@ -1,6 +1,8 @@ package cli import ( + "encoding/json" + "slices" "strconv" "github.com/DecentralCardGame/Cardchain/x/cardchain/types" @@ -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 @@ -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) diff --git a/x/cardchain/client/cli/tx_msg_open_match.go b/x/cardchain/client/cli/tx_msg_open_match.go index 41ca91c3..c14747d6 100644 --- a/x/cardchain/client/cli/tx_msg_open_match.go +++ b/x/cardchain/client/cli/tx_msg_open_match.go @@ -1,6 +1,7 @@ package cli import ( + "encoding/json" "strconv" "github.com/DecentralCardGame/Cardchain/x/cardchain/types" @@ -14,9 +15,9 @@ var _ = strconv.Itoa(0) func CmdMsgOpenMatch() *cobra.Command { cmd := &cobra.Command{ - Use: "open-match", + Use: "open-match [player-a] [player-b] [player-a-deck] [player-b-deck]", Short: "Broadcast message OpenMatch", - Args: cobra.ExactArgs(0), + Args: cobra.ExactArgs(4), RunE: func(cmd *cobra.Command, args []string) (err error) { clientCtx, err := client.GetClientTxContext(cmd) @@ -24,8 +25,23 @@ func CmdMsgOpenMatch() *cobra.Command { return err } + var argPlayerADeck []uint64 + var argPlayerBDeck []uint64 + err = json.Unmarshal([]byte(args[2]), &argPlayerADeck) + if err != nil { + return err + } + err = json.Unmarshal([]byte(args[3]), &argPlayerBDeck) + if err != nil { + return err + } + msg := types.NewMsgOpenMatch( clientCtx.GetFromAddress().String(), + args[0], + args[1], + argPlayerADeck, + argPlayerBDeck, ) if err := msg.ValidateBasic(); err != nil { return err diff --git a/x/cardchain/types/message_msg_open_match.go b/x/cardchain/types/message_msg_open_match.go index 27ab621d..917a5bc8 100644 --- a/x/cardchain/types/message_msg_open_match.go +++ b/x/cardchain/types/message_msg_open_match.go @@ -9,9 +9,13 @@ const TypeMsgOpenMatch = "msg_open_match" var _ sdk.Msg = &MsgOpenMatch{} -func NewMsgOpenMatch(creator string) *MsgOpenMatch { +func NewMsgOpenMatch(creator string, playerA string, playerB string, playerADeck []uint64, playerBDeck []uint64) *MsgOpenMatch { return &MsgOpenMatch{ Creator: creator, + PlayerA: playerA, + PlayerB: playerB, + PlayerADeck: playerADeck, + PlayerBDeck: playerBDeck, } }