-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.go
103 lines (89 loc) · 3.05 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package cli
import (
"fmt"
"strings"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/client"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/client/context"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/client/flags"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/codec"
"github.com/furyaxyz/fuxchain/x/erc20/types"
"github.com/spf13/cobra"
)
// GetQueryCmd defines erc20 module queries through the cli
func GetQueryCmd(moduleName string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the erc20 module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
cmd.AddCommand(flags.GetCommands(
GetCmdQueryParams(moduleName, cdc),
GetCmdQueryTokenMapping(moduleName, cdc),
GetCmdTemplateContract(moduleName, cdc),
)...)
return cmd
}
// GetCmdQueryParams implements the query params command.
func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "params",
Short: "Query all the modifiable parameters of gov proposal",
Long: strings.TrimSpace(`Query the all the parameters for the governance process:
$ fuxchaincli query erc20 params
`),
Args: cobra.NoArgs,
RunE: func(_ *cobra.Command, _ []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryParameters)
bz, _, err := cliCtx.QueryWithData(route, nil)
if err != nil {
return err
}
var params types.Params
cdc.MustUnmarshalJSON(bz, ¶ms)
return cliCtx.PrintOutput(params)
},
}
}
func GetCmdQueryTokenMapping(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "token-mapping",
Short: "Query all token mapping of denom and contract",
Long: strings.TrimSpace(`Query all mapping of denom and contract:
$ fuxchaincli query erc20 token-mapping
`),
Args: cobra.NoArgs,
RunE: func(_ *cobra.Command, _ []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryTokenMapping)
bz, _, err := cliCtx.QueryWithData(route, nil)
if err != nil {
return err
}
var mapping []types.QueryTokenMappingResponse
cdc.MustUnmarshalJSON(bz, &mapping)
return cliCtx.PrintOutput(mapping)
},
}
}
func GetCmdTemplateContract(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "contract-template",
Short: "Query contract-template and note the return value is not available to post as proposal",
Long: strings.TrimSpace(`Query all mapping of denom and contract:
$ fuxchaincli query erc20 contract-template
`),
Args: cobra.NoArgs,
RunE: func(_ *cobra.Command, _ []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryContractTem)
bz, _, err := cliCtx.QueryWithData(route, nil)
if err != nil {
return err
}
return cliCtx.PrintOutput(string(bz))
},
}
}