-
Notifications
You must be signed in to change notification settings - Fork 7
/
query.go
49 lines (42 loc) · 1.33 KB
/
query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package cli
import (
"fmt"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/sharering/shareledger/x/booking/types"
"github.com/spf13/cobra"
)
func QueryCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
bookingQueryCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the booking module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
bookingQueryCmd.AddCommand(flags.GetCommands(
CmdGetBooking(storeKey, cdc),
)...)
return bookingQueryCmd
}
func CmdGetBooking(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "get [bookID]",
Short: "get booking info from bookID",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
bookID := args[0]
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/booking/%s", queryRoute, bookID), nil)
if err != nil {
fmt.Printf("could not get asset - %s \n", bookID)
return nil
}
var out types.Booking
cdc.MustUnmarshalJSON(res, &out)
return cliCtx.PrintOutput(out)
},
}
}