forked from bnb-chain/bnc-cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keeper.go
91 lines (76 loc) · 2.18 KB
/
keeper.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
package stake
//// keeper of the staking store
//type Keeper struct {
//storeKey sdk.StoreKey
//cdc *wire.Codec
//coinKeeper bank.Keeper
//// codespace
//codespace sdk.CodespaceType
//}
//func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, ck bank.Keeper, codespace sdk.CodespaceType) Keeper {
//keeper := Keeper{
//storeKey: key,
//cdc: cdc,
//coinKeeper: ck,
//codespace: codespace,
//}
//return keeper
//}
////_________________________________________________________________________
//// cummulative power of the non-absent prevotes
//func (k Keeper) GetTotalPrecommitVotingPower(ctx sdk.Context) sdk.Rat {
//store := ctx.KVStore(k.storeKey)
//// get absent prevote indexes
//absents := ctx.AbsentValidators()
//TotalPower := sdk.ZeroRat()
//i := int32(0)
//iterator := store.SubspaceIterator(ValidatorsBondedKey)
//for ; iterator.Valid(); iterator.Next() {
//skip := false
//for j, absentIndex := range absents {
//if absentIndex > i {
//break
//}
//// if non-voting validator found, skip adding its power
//if absentIndex == i {
//absents = append(absents[:j], absents[j+1:]...) // won't need again
//skip = true
//break
//}
//}
//if skip {
//continue
//}
//bz := iterator.Value()
//var validator Validator
//k.cdc.MustUnmarshalBinary(bz, &validator)
//TotalPower = TotalPower.Add(validator.Power)
//i++
//}
//iterator.Close()
//return TotalPower
//}
////_______________________________________________________________________
//// XXX TODO trim functionality
//// retrieve all the power changes which occur after a height
//func (k Keeper) GetPowerChangesAfterHeight(ctx sdk.Context, earliestHeight int64) (pcs []PowerChange) {
//store := ctx.KVStore(k.storeKey)
//iterator := store.SubspaceIterator(PowerChangeKey) //smallest to largest
//for ; iterator.Valid(); iterator.Next() {
//pcBytes := iterator.Value()
//var pc PowerChange
//k.cdc.MustUnmarshalBinary(pcBytes, &pc)
//if pc.Height < earliestHeight {
//break
//}
//pcs = append(pcs, pc)
//}
//iterator.Close()
//return
//}
//// set a power change
//func (k Keeper) setPowerChange(ctx sdk.Context, pc PowerChange) {
//store := ctx.KVStore(k.storeKey)
//b := k.cdc.MustMarshalBinary(pc)
//store.Set(GetPowerChangeKey(pc.Height), b)
//}