Skip to content

Commit

Permalink
Added files
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed Jan 15, 2024
1 parent bcc523f commit 1e19553
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
54 changes: 54 additions & 0 deletions x/cardchain/client/cli/query_q_card_contents.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package cli

import (
"strconv"

"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cast"
"github.com/spf13/cobra"
)

var _ = strconv.Itoa(0)

func CmdQCardContents() *cobra.Command {
cmd := &cobra.Command{
Use: "q-card-contents [card-ids]",
Short: "Query q_card_contents",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
var reqCardIds []uint64
for _, id := range args[0:] {
convId, err := cast.ToUint64E(id)
if err != nil {
return err
}
reqCardIds = append(reqCardIds, convId)
}

clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryQCardContentsRequest{

CardIds: reqCardIds,
}

res, err := queryClient.QCardContents(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
32 changes: 32 additions & 0 deletions x/cardchain/keeper/query_q_card_contents.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package keeper

import (
"context"

"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func (k Keeper) QCardContents(goCtx context.Context, req *types.QueryQCardContentsRequest) (*types.QueryQCardContentsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

var resps []*types.QueryQCardContentResponse

for _, cardId := range req.CardIds {
resp, err := k.GetContentResponseFromId(ctx, cardId)
if err != nil {
return nil, err
}
resps = append(resps, resp)
}

return &types.QueryQCardContentsResponse{
Cards: resps,
}, nil
}

0 comments on commit 1e19553

Please sign in to comment.