-
Notifications
You must be signed in to change notification settings - Fork 6
/
msg_server_update_params.go
92 lines (76 loc) · 3.97 KB
/
msg_server_update_params.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
package keeper
import (
"context"
"cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/telemetry"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/chain4energy/c4e-chain/x/cfedistributor/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func (k msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
defer telemetry.IncrCounter(1, types.ModuleName, "Update all sub distributors")
if k.authority != msg.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, msg.Authority)
}
ctx := sdk.UnwrapSDKContext(goCtx)
if err := k.SetParams(ctx, types.Params{SubDistributors: msg.SubDistributors}); err != nil {
return nil, err
}
return &types.MsgUpdateParamsResponse{}, nil
}
func (k msgServer) UpdateSubDistributorParam(goCtx context.Context, distributor *types.MsgUpdateSubDistributorParam) (*types.MsgUpdateSubDistributorParamResponse, error) {
defer telemetry.IncrCounter(1, types.ModuleName, "Update sub distributor")
if k.authority != distributor.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, distributor.Authority)
}
ctx := sdk.UnwrapSDKContext(goCtx)
subDistributors := k.Keeper.GetParams(ctx).SubDistributors
for i, subDistributor := range subDistributors {
if subDistributor.Name == distributor.SubDistributor.Name {
subDistributors[i] = *distributor.SubDistributor
if err := k.SetParams(ctx, types.Params{SubDistributors: subDistributors}); err != nil {
return nil, errors.Wrapf(govtypes.ErrInvalidProposalMsg, "validation error: %s", err)
}
return &types.MsgUpdateSubDistributorParamResponse{}, nil
}
}
return nil, errors.Wrapf(govtypes.ErrInvalidProposalMsg, "distributor not found")
}
func (k msgServer) UpdateSubDistributorDestinationShareParam(goCtx context.Context, msg *types.MsgUpdateSubDistributorDestinationShareParam) (*types.MsgUpdateSubDistributorDestinationShareParamResponse, error) {
defer telemetry.IncrCounter(1, types.ModuleName, "Update sub distributor destination share")
if k.authority != msg.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, msg.Authority)
}
ctx := sdk.UnwrapSDKContext(goCtx)
subDistributors := k.Keeper.GetParams(ctx).SubDistributors
for i, subDistributor := range subDistributors {
for y, share := range subDistributor.Destinations.Shares {
if share.Name == msg.DestinationName {
subDistributors[i].Destinations.Shares[y].Share = msg.Share
if err := k.SetParams(ctx, types.Params{SubDistributors: subDistributors}); err != nil {
return nil, errors.Wrapf(govtypes.ErrInvalidProposalMsg, "validation error: %s", err)
}
return &types.MsgUpdateSubDistributorDestinationShareParamResponse{}, nil
}
}
}
return nil, errors.Wrapf(govtypes.ErrInvalidProposalMsg, "distributor not found")
}
func (k msgServer) UpdateSubDistributorBurnShareParam(goCtx context.Context, msg *types.MsgUpdateSubDistributorBurnShareParam) (*types.MsgUpdateSubDistributorBurnShareParamResponse, error) {
defer telemetry.IncrCounter(1, types.ModuleName, "Update sub distributor burn share")
if k.authority != msg.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, msg.Authority)
}
ctx := sdk.UnwrapSDKContext(goCtx)
subDistributors := k.Keeper.GetParams(ctx).SubDistributors
for i, subDistributor := range subDistributors {
if subDistributor.Name == msg.SubDistributorName {
subDistributors[i].Destinations.BurnShare = msg.BurnShare
if err := k.SetParams(ctx, types.Params{SubDistributors: subDistributors}); err != nil {
return nil, errors.Wrapf(govtypes.ErrInvalidProposalMsg, "validation error: %s", err)
}
return &types.MsgUpdateSubDistributorBurnShareParamResponse{}, nil
}
}
return nil, errors.Wrapf(govtypes.ErrInvalidProposalMsg, "distributor not found")
}