-
Notifications
You must be signed in to change notification settings - Fork 168
/
migrate.go
38 lines (30 loc) · 847 Bytes
/
migrate.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
package v2
import (
"github.com/CosmosContracts/juno/v10/x/mint/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
ModuleName = "mint"
)
// Migrate migrates the x/mint module state from the consensus version 1 to
// version 2. Specifically, it take calculate target supply for the current phase
func Migrate(
ctx sdk.Context,
store sdk.KVStore,
cdc codec.BinaryCodec,
) error {
// Get minter
var minter types.Minter
b := store.Get(types.MinterKey)
if b == nil {
panic("stored minter should not have been nil")
}
cdc.MustUnmarshal(b, &minter)
// Calculate target supply
minter.TargetSupply = minter.AnnualProvisions.Add(minter.AnnualProvisions.Quo(minter.Inflation)).TruncateInt()
// Save new minter
bz := cdc.MustMarshal(&minter)
store.Set(types.MinterKey, bz)
return nil
}