-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconversions.go
87 lines (81 loc) · 2.69 KB
/
conversions.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
package poa
import (
"github.com/cosmos/cosmos-sdk/x/staking/types"
"cosmossdk.io/math"
)
// NewDescription creates a new POA Description instance.
func NewDescription(moniker, identity, website, securityContact, details string) Description {
return Description{
Moniker: moniker,
Identity: identity,
Website: website,
SecurityContact: securityContact,
Details: details,
}
}
// NewCommissionRates creates a new POA CommissionRates instance.
func NewCommissionRates(rate, maxRate, maxChangeRate math.LegacyDec) CommissionRates {
return CommissionRates{
Rate: rate,
MaxRate: maxRate,
MaxChangeRate: maxChangeRate,
}
}
// ConvertPOAToStaking converts a POA Validator to a Staking Validator.
func ConvertPOAToStaking(poa Validator) types.Validator {
return types.Validator{
OperatorAddress: poa.OperatorAddress,
ConsensusPubkey: poa.ConsensusPubkey,
Jailed: poa.Jailed,
Status: types.BondStatus(poa.Status),
Tokens: poa.Tokens,
DelegatorShares: poa.DelegatorShares,
Description: types.NewDescription(
poa.Description.Moniker,
poa.Description.Identity,
poa.Description.Website,
poa.Description.SecurityContact,
poa.Description.Details,
),
UnbondingHeight: poa.UnbondingHeight,
UnbondingTime: poa.UnbondingTime,
Commission: types.NewCommission(
poa.Commission.CommissionRates.Rate,
poa.Commission.CommissionRates.MaxRate,
poa.Commission.CommissionRates.MaxChangeRate,
),
MinSelfDelegation: poa.MinSelfDelegation,
UnbondingOnHoldRefCount: poa.UnbondingOnHoldRefCount,
UnbondingIds: poa.UnbondingIds,
}
}
// ConvertStakingToPOA converts a Staking Validator to a POA Validator.
func ConvertStakingToPOA(val types.Validator) Validator {
return Validator{
OperatorAddress: val.OperatorAddress,
ConsensusPubkey: val.ConsensusPubkey,
Jailed: val.Jailed,
Status: BondStatus(val.Status),
Tokens: val.Tokens,
DelegatorShares: val.DelegatorShares,
Description: Description{
Moniker: val.Description.Moniker,
Identity: val.Description.Identity,
Website: val.Description.Website,
SecurityContact: val.Description.SecurityContact,
Details: val.Description.Details,
},
UnbondingHeight: val.UnbondingHeight,
UnbondingTime: val.UnbondingTime,
Commission: Commission{
CommissionRates: CommissionRates{
Rate: val.Commission.Rate,
MaxRate: val.Commission.MaxRate,
MaxChangeRate: val.Commission.MaxChangeRate,
},
},
MinSelfDelegation: val.MinSelfDelegation,
UnbondingOnHoldRefCount: val.UnbondingOnHoldRefCount,
UnbondingIds: val.UnbondingIds,
}
}