-
Notifications
You must be signed in to change notification settings - Fork 1
/
keeper_delegate_key.go
197 lines (185 loc) · 5.72 KB
/
keeper_delegate_key.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package keeper
import (
"time"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/onomyprotocol/near-aurora-bridge/module/x/nab/types"
)
/////////////////////////////
// ADDRESS DELEGATION //
/////////////////////////////
// SetOrchestratorValidator sets the Orchestrator key for a given validator
func (k Keeper) SetOrchestratorValidator(ctx sdk.Context, val sdk.ValAddress, orch sdk.AccAddress) {
store := ctx.KVStore(k.storeKey)
store.Set(types.GetOrchestratorAddressKey(orch), val.Bytes())
}
// GetOrchestratorValidator returns the validator key associated with an orchestrator key
func (k Keeper) GetOrchestratorValidator(ctx sdk.Context, orch sdk.AccAddress) (validator stakingtypes.Validator, found bool) {
store := ctx.KVStore(k.storeKey)
valAddr := store.Get(types.GetOrchestratorAddressKey(orch))
if valAddr == nil {
return stakingtypes.Validator{
OperatorAddress: "",
ConsensusPubkey: &codectypes.Any{
TypeUrl: "",
Value: []byte{},
XXX_NoUnkeyedLiteral: struct{}{},
XXX_unrecognized: []byte{},
XXX_sizecache: 0,
},
Jailed: false,
Status: 0,
Tokens: sdk.Int{},
DelegatorShares: sdk.Dec{},
Description: stakingtypes.Description{
Moniker: "",
Identity: "",
Website: "",
SecurityContact: "",
Details: "",
},
UnbondingHeight: 0,
UnbondingTime: time.Time{},
Commission: stakingtypes.Commission{
CommissionRates: stakingtypes.CommissionRates{
Rate: sdk.Dec{},
MaxRate: sdk.Dec{},
MaxChangeRate: sdk.Dec{},
},
UpdateTime: time.Time{},
},
MinSelfDelegation: sdk.Int{},
}, false
}
validator, found = k.StakingKeeper.GetValidator(ctx, valAddr)
if !found {
return stakingtypes.Validator{
OperatorAddress: "",
ConsensusPubkey: &codectypes.Any{
TypeUrl: "",
Value: []byte{},
XXX_NoUnkeyedLiteral: struct{}{},
XXX_unrecognized: []byte{},
XXX_sizecache: 0,
},
Jailed: false,
Status: 0,
Tokens: sdk.Int{},
DelegatorShares: sdk.Dec{},
Description: stakingtypes.Description{
Moniker: "",
Identity: "",
Website: "",
SecurityContact: "",
Details: "",
},
UnbondingHeight: 0,
UnbondingTime: time.Time{},
Commission: stakingtypes.Commission{
CommissionRates: stakingtypes.CommissionRates{
Rate: sdk.Dec{},
MaxRate: sdk.Dec{},
MaxChangeRate: sdk.Dec{},
},
UpdateTime: time.Time{},
},
MinSelfDelegation: sdk.Int{},
}, false
}
return validator, true
}
/////////////////////////////
// ETH ADDRESS //
/////////////////////////////
// SetEthAddress sets the ethereum address for a given validator
func (k Keeper) SetEthAddressForValidator(ctx sdk.Context, validator sdk.ValAddress, ethAddr string) {
store := ctx.KVStore(k.storeKey)
store.Set(types.GetEthAddressByValidatorKey(validator), []byte(ethAddr))
store.Set(types.GetValidatorByEthAddressKey(ethAddr), []byte(validator))
}
// GetEthAddressByValidator returns the eth address for a given gravity validator
func (k Keeper) GetEthAddressByValidator(ctx sdk.Context, validator sdk.ValAddress) (ethAddress string, found bool) {
store := ctx.KVStore(k.storeKey)
ethAddr := store.Get(types.GetEthAddressByValidatorKey(validator))
if ethAddr == nil {
return "", false
} else {
return string(ethAddr), true
}
}
// GetValidatorByEthAddress returns the validator for a given eth address
func (k Keeper) GetValidatorByEthAddress(ctx sdk.Context, ethAddr string) (validator stakingtypes.Validator, found bool) {
store := ctx.KVStore(k.storeKey)
valAddr := store.Get(types.GetValidatorByEthAddressKey(ethAddr))
if valAddr == nil {
return stakingtypes.Validator{
OperatorAddress: "",
ConsensusPubkey: &codectypes.Any{
TypeUrl: "",
Value: []byte{},
XXX_NoUnkeyedLiteral: struct{}{},
XXX_unrecognized: []byte{},
XXX_sizecache: 0,
},
Jailed: false,
Status: 0,
Tokens: sdk.Int{},
DelegatorShares: sdk.Dec{},
Description: stakingtypes.Description{
Moniker: "",
Identity: "",
Website: "",
SecurityContact: "",
Details: "",
},
UnbondingHeight: 0,
UnbondingTime: time.Time{},
Commission: stakingtypes.Commission{
CommissionRates: stakingtypes.CommissionRates{
Rate: sdk.Dec{},
MaxRate: sdk.Dec{},
MaxChangeRate: sdk.Dec{},
},
UpdateTime: time.Time{},
},
MinSelfDelegation: sdk.Int{},
}, false
}
validator, found = k.StakingKeeper.GetValidator(ctx, valAddr)
if !found {
return stakingtypes.Validator{
OperatorAddress: "",
ConsensusPubkey: &codectypes.Any{
TypeUrl: "",
Value: []byte{},
XXX_NoUnkeyedLiteral: struct{}{},
XXX_unrecognized: []byte{},
XXX_sizecache: 0,
},
Jailed: false,
Status: 0,
Tokens: sdk.Int{},
DelegatorShares: sdk.Dec{},
Description: stakingtypes.Description{
Moniker: "",
Identity: "",
Website: "",
SecurityContact: "",
Details: "",
},
UnbondingHeight: 0,
UnbondingTime: time.Time{},
Commission: stakingtypes.Commission{
CommissionRates: stakingtypes.CommissionRates{
Rate: sdk.Dec{},
MaxRate: sdk.Dec{},
MaxChangeRate: sdk.Dec{},
},
UpdateTime: time.Time{},
},
MinSelfDelegation: sdk.Int{},
}, false
}
return validator, true
}