forked from terra-money/classic-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
query.go
191 lines (156 loc) · 5.3 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package cli
import (
"fmt"
"strings"
"terra/x/treasury"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
flagDenom = "denom"
)
// GetCmdQueryTaxRate implements the query taxrate command.
func GetCmdQueryTaxRate(queryRoute string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "taxrate",
Short: "Query the current stability tax rate",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, treasury.QueryTaxRate), nil)
if err != nil {
return err
}
var taxRate sdk.Dec
cdc.MustUnmarshalBinaryLengthPrefixed(res, &taxRate)
return cliCtx.PrintOutput(taxRate)
},
}
return cmd
}
// GetCmdQueryTaxCap implements the query taxcap command.
func GetCmdQueryTaxCap(queryRoute string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "taxcap [denom]",
Short: "Query the current stability tax cap of the [denom] asset",
Long: strings.TrimSpace(`
Query the current stability tax cap of the [denom] asset.
The stability tax levied on a tx is at most tax cap, regardless of the size of the transaction.
$ terracli query treasury taxcap krw
`),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
denom := viper.GetString(flagDenom)
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", queryRoute, treasury.QueryTaxCap, denom), nil)
if err != nil {
return err
}
var price sdk.Dec
cdc.MustUnmarshalBinaryLengthPrefixed(res, &price)
return cliCtx.PrintOutput(price)
},
}
return cmd
}
// GetCmdQueryIssuance implements the query issuance command.
func GetCmdQueryIssuance(queryRoute string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "issuance [denom]",
Short: "Query the current issuance of the [denom] asset",
Long: strings.TrimSpace(`
Query the current issuance of the [denom] asset.
$ terracli query treasury issuance krw
`),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
denom := viper.GetString(flagDenom)
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", queryRoute, treasury.QueryIssuance, denom), nil)
if err != nil {
return err
}
var issuance sdk.Int
cdc.MustUnmarshalBinaryLengthPrefixed(res, &issuance)
return cliCtx.PrintOutput(issuance)
},
}
return cmd
}
// GetCmdQueryActiveClaims implements the query activeclaims command.
func GetCmdQueryActiveClaims(queryRoute string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "activeclaims",
Short: "Query claims that have yet to be redeemed by the treasury",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, treasury.QueryActiveClaims), nil)
if err != nil {
return err
}
var claims treasury.Claims
cdc.MustUnmarshalBinaryLengthPrefixed(res, &claims)
return cliCtx.PrintOutput(claims)
},
}
return cmd
}
// GetCmdQueryMiningWeight implements the query miningweight command.
func GetCmdQueryMiningWeight(queryRoute string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "miningweight",
Short: "Query the current mining weight",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, treasury.QueryMiningRewardWeight), nil)
if err != nil {
return err
}
var miningWeight sdk.Dec
cdc.MustUnmarshalBinaryLengthPrefixed(res, &miningWeight)
return cliCtx.PrintOutput(miningWeight)
},
}
return cmd
}
// GetCmdQueryBalance implements the query balance command.
func GetCmdQueryBalance(queryRoute string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "balance",
Short: "Query the current Treasury balance",
Long: strings.TrimSpace(`
Query the current Treasury balance, denominated in TerraSDR.
Balance clears periodically to satisfy claims registered with the Treasury.
$ terracli query treasury balance
`),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, treasury.QueryBalance), nil)
if err != nil {
return err
}
var balance sdk.Int
cdc.MustUnmarshalBinaryLengthPrefixed(res, &balance)
return cliCtx.PrintOutput(balance)
},
}
return cmd
}
// GetCmdQueryParams implements the query params command.
func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Query the current Treasury params",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, treasury.QueryParams), nil)
if err != nil {
return err
}
var params treasury.Params
cdc.MustUnmarshalJSON(res, ¶ms)
return cliCtx.PrintOutput(params)
},
}
return cmd
}