/
proposal_handler.go
55 lines (45 loc) · 1.46 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
43
44
45
46
47
48
49
50
51
52
53
54
55
package keeper
import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/kogisin/cosmos-sdk-modules/x/farming/types"
)
// HandlePublicPlanProposal is a handler for executing a fixed amount plan creation proposal.
func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, plansAny []*codectypes.Any) error {
plans, err := types.UnpackPlans(plansAny)
if err != nil {
return err
}
for _, plan := range plans {
switch p := plan.(type) {
case *types.FixedAmountPlan:
msg := types.NewMsgCreateFixedAmountPlan(
p.GetFarmingPoolAddress(),
p.GetStakingCoinWeights(),
p.GetStartTime(),
p.GetEndTime(),
p.GetEpochDays(),
p.EpochAmount,
)
fixedPlan := k.CreateFixedAmountPlan(ctx, msg, types.PlanTypePublic)
logger := k.Logger(ctx)
logger.Info("created public fixed amount plan", "fixed_amount_plan", fixedPlan)
case *types.RatioPlan:
msg := types.NewMsgCreateRatioPlan(
p.GetFarmingPoolAddress(),
p.GetStakingCoinWeights(),
p.GetStartTime(),
p.GetEndTime(),
p.GetEpochDays(),
p.EpochRatio,
)
ratioPlan := k.CreateRatioPlan(ctx, msg, types.PlanTypePublic)
logger := k.Logger(ctx)
logger.Info("created public fixed amount plan", "ratio_plan", ratioPlan)
default:
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized farming proposal plan type: %T", p)
}
}
return nil
}