/
params.go
72 lines (65 loc) · 2.34 KB
/
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
package v2
import (
"fmt"
"github.com/chain4energy/c4e-chain/types/subspace"
"github.com/chain4energy/c4e-chain/x/cfeminter/migrations/v1"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"time"
)
// MigrateParams performs in-place store migrations from v1.0.1 to v1.1.0
// The migration includes:
// - Cfeminter params structure changed
// - Remove ReductionPeriodLength from PeriodicReducstionMinter
func MigrateParams(ctx sdk.Context, paramStore subspace.Subspace) error {
var oldMinterConfig v1.Minter
if !paramStore.HasKeyTable() {
paramStore.WithKeyTable(ParamKeyTable())
}
oldMinterConfigRaw := paramStore.GetRaw(ctx, v1.KeyMinter)
if err := codec.NewLegacyAmino().UnmarshalJSON(oldMinterConfigRaw, &oldMinterConfig); err != nil {
panic(err)
}
var newMinterConfig MinterConfig
newMinterConfig.StartTime = oldMinterConfig.Start
var newMinters []*Minter
for _, oldMinter := range oldMinterConfig.Periods {
var linearMinting *LinearMinting
var exponentialStepMinting *ExponentialStepMinting
if oldMinter.TimeLinearMinter != nil {
linearMinting = &LinearMinting{
Amount: oldMinter.TimeLinearMinter.Amount,
}
}
periodicReductionMinter := oldMinter.PeriodicReductionMinter
if periodicReductionMinter != nil {
exponentialStepMinting = &ExponentialStepMinting{
Amount: periodicReductionMinter.MintAmount.MulRaw(int64(periodicReductionMinter.ReductionPeriodLength)),
StepDuration: time.Duration(oldMinter.PeriodicReductionMinter.MintPeriod*periodicReductionMinter.ReductionPeriodLength) * time.Second,
AmountMultiplier: oldMinter.PeriodicReductionMinter.ReductionFactor,
}
}
var newType string
switch oldMinter.Type {
case "TIME_LINEAR_MINTER":
newType = "LINEAR_MINTING"
case "PERIODIC_REDUCTION_MINTER":
newType = "EXPONENTIAL_STEP_MINTING"
case "NO_MINTING":
newType = "NO_MINTING"
default:
return fmt.Errorf("wrong minting period type")
}
newMinter := Minter{
SequenceId: uint32(oldMinter.Position),
EndTime: oldMinter.PeriodEnd,
Type: newType,
LinearMinting: linearMinting,
ExponentialStepMinting: exponentialStepMinting,
}
newMinters = append(newMinters, &newMinter)
}
newMinterConfig.Minters = newMinters
paramStore.Set(ctx, KeyMinterConfig, newMinterConfig)
return nil
}