forked from maticnetwork/heimdall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproposal_handler.go
42 lines (34 loc) · 1.14 KB
/
proposal_handler.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
package params
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/maticnetwork/heimdall/gov/types"
"github.com/maticnetwork/heimdall/params/types"
)
// NewParamChangeProposalHandler new param changes proposal handler
func NewParamChangeProposalHandler(k Keeper) govtypes.Handler {
return func(ctx sdk.Context, content govtypes.Content) sdk.Error {
switch c := content.(type) {
case types.ParameterChangeProposal:
return handleParameterChangeProposal(ctx, k, c)
default:
errMsg := fmt.Sprintf("unrecognized param proposal content type: %T", c)
return sdk.ErrUnknownRequest(errMsg)
}
}
}
func handleParameterChangeProposal(ctx sdk.Context, k Keeper, p types.ParameterChangeProposal) sdk.Error {
for _, c := range p.Changes {
ss, ok := k.GetSubspace(c.Subspace)
if !ok {
return types.ErrUnknownSubspace(k.codespace, c.Subspace)
}
k.Logger(ctx).Info(
fmt.Sprintf("setting new parameter; key: %s, value: %s", c.Key, c.Value),
)
if err := ss.Update(ctx, []byte(c.Key), []byte(c.Value)); err != nil {
return types.ErrSettingParameter(k.codespace, c.Key, c.Value, err.Error())
}
}
return nil
}