-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
52 lines (43 loc) · 1.73 KB
/
common.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
package common
import (
"fmt"
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/fastock/fastock-chain/x/distribution/types"
)
// QueryParams actually queries distribution params
func QueryParams(cliCtx context.CLIContext, queryRoute string) (params types.Params, err error) {
route := fmt.Sprintf("custom/%s/params/%s", queryRoute, types.ParamCommunityTax)
var communityTax sdk.Dec
var withdrawAddrEnabled bool
bytes, _, err := cliCtx.QueryWithData(route, []byte{})
if err != nil {
return
}
cliCtx.Codec.MustUnmarshalJSON(bytes, &communityTax)
route = fmt.Sprintf("custom/%s/params/%s", queryRoute, types.ParamWithdrawAddrEnabled)
bytes, _, err = cliCtx.QueryWithData(route, []byte{})
if err != nil {
return
}
cliCtx.Codec.MustUnmarshalJSON(bytes, &withdrawAddrEnabled)
return types.NewParams(communityTax, withdrawAddrEnabled), err
}
// QueryValidatorCommission returns a validator's commission.
func QueryValidatorCommission(cliCtx context.CLIContext, queryRoute string, validatorAddr sdk.ValAddress) (
[]byte, error) {
res, _, err := cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryValidatorCommission),
cliCtx.Codec.MustMarshalJSON(types.NewQueryValidatorCommissionParams(validatorAddr)),
)
return res, err
}
// WithdrawValidatorRewardsAndCommission builds a two-message message slice to be
// used to withdraw both validation's commission and self-delegation reward.
func WithdrawValidatorRewardsAndCommission(validatorAddr sdk.ValAddress) ([]sdk.Msg, error) {
commissionMsg := types.NewMsgWithdrawValidatorCommission(validatorAddr)
if err := commissionMsg.ValidateBasic(); err != nil {
return nil, err
}
return []sdk.Msg{commissionMsg}, nil
}