-
Notifications
You must be signed in to change notification settings - Fork 119
/
records.go
134 lines (119 loc) · 4.11 KB
/
records.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package types
import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
gogotypes "github.com/gogo/protobuf/types"
)
//This package is used to keep historical data. This will later be used to distribute rewards over different blocks through a gov proposal
func NewDistributionRecord(status DistributionStatus, distributionType DistributionType, distributionName string, recipientAddress string, coins sdk.Coins, start int64, end int64, runner string) DistributionRecord {
return DistributionRecord{
DistributionStatus: status,
AuthorizedRunner: runner,
DistributionType: distributionType,
DistributionName: distributionName,
RecipientAddress: recipientAddress,
Coins: coins,
DistributionStartHeight: start,
DistributionCompletedHeight: end,
}
}
func (dr DistributionRecord) Validate() bool {
if len(dr.RecipientAddress) == 0 {
return false
}
if !dr.Coins.IsValid() {
return false
}
if !dr.Coins.IsAllPositive() {
return false
}
return true
}
func (dr DistributionRecord) Add(dr2 DistributionRecord) DistributionRecord {
dr.Coins = dr.Coins.Add(dr2.Coins...)
return dr
}
func (dr DistributionRecord) DoesTypeSupportClaim() bool {
if dr.DistributionType == DistributionType_DISTRIBUTION_TYPE_LIQUIDITY_MINING || dr.DistributionType == DistributionType_DISTRIBUTION_TYPE_VALIDATOR_SUBSIDY {
return true
}
return false
}
func NewUserClaim(userAddress string, userClaimType DistributionType, t time.Time) (UserClaim, error) {
tProto, err := gogotypes.TimestampProto(t)
if err != nil {
return UserClaim{}, err
}
return UserClaim{UserAddress: userAddress, UserClaimType: userClaimType, UserClaimTime: tProto}, nil
}
func (uc UserClaim) Validate() bool {
if len(uc.UserAddress) == 0 {
return false
}
return true
}
func NewDistribution(t DistributionType, name string, authorizedRunner string) Distribution {
return Distribution{DistributionType: t, DistributionName: name, Runner: authorizedRunner}
}
func (ar Distribution) Validate() bool {
if ar.DistributionName == "" {
return false
}
return true
}
func GetDistributionStatus(status string) (DistributionStatus, bool) {
switch status {
case "Completed":
return DistributionStatus_DISTRIBUTION_STATUS_COMPLETED, true
case "Pending":
return DistributionStatus_DISTRIBUTION_STATUS_PENDING, true
case "Failed":
return DistributionStatus_DISTRIBUTION_STATUS_FAILED, true
default:
return DistributionStatus_DISTRIBUTION_STATUS_UNSPECIFIED, false
}
}
func GetClaimType(claimType string) (DistributionType, bool) {
switch claimType {
case "LiquidityMining":
return DistributionType_DISTRIBUTION_TYPE_LIQUIDITY_MINING, true
case "ValidatorSubsidy":
return DistributionType_DISTRIBUTION_TYPE_VALIDATOR_SUBSIDY, true
default:
return DistributionType_DISTRIBUTION_TYPE_UNSPECIFIED, false
}
}
func GetDistributionTypeFromShortString(distributionType string) (DistributionType, bool) {
switch distributionType {
case "Airdrop":
return DistributionType_DISTRIBUTION_TYPE_AIRDROP, true
case "LiquidityMining":
return DistributionType_DISTRIBUTION_TYPE_LIQUIDITY_MINING, true
case "ValidatorSubsidy":
return DistributionType_DISTRIBUTION_TYPE_VALIDATOR_SUBSIDY, true
default:
return DistributionType_DISTRIBUTION_TYPE_UNSPECIFIED, false
}
}
func IsValidDistributionType(distributionType string) (DistributionType, bool) {
switch distributionType {
case "DISTRIBUTION_TYPE_AIRDROP":
return DistributionType_DISTRIBUTION_TYPE_AIRDROP, true
case "DISTRIBUTION_TYPE_LIQUIDITY_MINING":
return DistributionType_DISTRIBUTION_TYPE_LIQUIDITY_MINING, true
case "DISTRIBUTION_TYPE_VALIDATOR_SUBSIDY":
return DistributionType_DISTRIBUTION_TYPE_VALIDATOR_SUBSIDY, true
default:
return DistributionType_DISTRIBUTION_TYPE_UNSPECIFIED, false
}
}
func IsValidClaimType(claimType string) (DistributionType, bool) {
switch claimType {
case "DISTRIBUTION_TYPE_LIQUIDITY_MINING":
return DistributionType_DISTRIBUTION_TYPE_LIQUIDITY_MINING, true
case "DISTRIBUTION_TYPE_VALIDATOR_SUBSIDY":
return DistributionType_DISTRIBUTION_TYPE_VALIDATOR_SUBSIDY, true
default:
return 0, false
}
}