-
Notifications
You must be signed in to change notification settings - Fork 117
/
genesis.go
77 lines (66 loc) · 2.78 KB
/
genesis.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
package v42
import (
gogotypes "github.com/gogo/protobuf/types"
v039dispensation "github.com/Sifchain/sifnode/x/dispensation/legacy/v39"
"github.com/Sifchain/sifnode/x/dispensation/types"
)
func Migrate(state v039dispensation.GenesisState) *types.GenesisState {
records := make([]*types.DistributionRecord, 0)
for _, d := range state.DistributionRecords {
records = append(records, &types.DistributionRecord{
DistributionStatus: migrateDistributionRecordStatus(d.DistributionStatus),
DistributionType: migrateDistributionType(d.DistributionType),
DistributionName: d.DistributionName,
RecipientAddress: d.RecipientAddress.String(),
Coins: d.Coins,
DistributionStartHeight: d.DistributionStartHeight,
DistributionCompletedHeight: d.DistributionCompletedHeight,
AuthorizedRunner: d.AuthorizedRunner.String(),
})
}
distributions := make([]*types.Distribution, 0)
for _, d := range state.Distributions {
distributions = append(distributions, &types.Distribution{
DistributionType: migrateDistributionType(d.DistributionType),
DistributionName: d.DistributionName,
// Note: Distribution.Runner is only defined and stored in 39, it was not defined in 42
Runner: d.Runner.String(),
})
}
claims := make([]*types.UserClaim, 0)
for _, c := range state.Claims {
t, err := gogotypes.TimestampProto(c.UserClaimTime)
if err != nil {
panic(err)
}
claims = append(claims, &types.UserClaim{
UserAddress: c.UserAddress.String(),
UserClaimType: migrateDistributionType(c.UserClaimType),
UserClaimTime: t,
})
}
return &types.GenesisState{
DistributionRecords: &types.DistributionRecords{DistributionRecords: records},
Distributions: &types.Distributions{Distributions: distributions},
Claims: &types.UserClaims{UserClaims: claims},
}
}
func migrateDistributionRecordStatus(status v039dispensation.DistributionStatus) types.DistributionStatus {
// Note: Failed status does not exist on 39
if status == v039dispensation.Pending {
return types.DistributionStatus_DISTRIBUTION_STATUS_PENDING
} else if status == v039dispensation.Completed {
return types.DistributionStatus_DISTRIBUTION_STATUS_COMPLETED
}
return types.DistributionStatus_DISTRIBUTION_STATUS_UNSPECIFIED
}
func migrateDistributionType(t v039dispensation.DistributionType) types.DistributionType {
if t == v039dispensation.Airdrop {
return types.DistributionType_DISTRIBUTION_TYPE_AIRDROP
} else if t == v039dispensation.LiquidityMining {
return types.DistributionType_DISTRIBUTION_TYPE_LIQUIDITY_MINING
} else if t == v039dispensation.ValidatorSubsidy {
return types.DistributionType_DISTRIBUTION_TYPE_VALIDATOR_SUBSIDY
}
return types.DistributionType_DISTRIBUTION_TYPE_UNSPECIFIED
}