-
Notifications
You must be signed in to change notification settings - Fork 203
/
keeper.go
107 lines (89 loc) · 3.22 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package keeper
import (
"fmt"
"strconv"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
fixationtypes "github.com/lavanet/lava/x/fixationstore/types"
"github.com/lavanet/lava/x/dualstaking/types"
)
type (
Keeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
memKey storetypes.StoreKey
paramstore paramtypes.Subspace
bankKeeper types.BankKeeper
stakingKeeper types.StakingKeeper
accountKeeper types.AccountKeeper
epochstorageKeeper types.EpochstorageKeeper
specKeeper types.SpecKeeper
delegationFS fixationtypes.FixationStore // map proviers/chainID -> delegations
delegatorFS fixationtypes.FixationStore // map delegators -> providers
}
)
func NewKeeper(
cdc codec.BinaryCodec,
storeKey,
memKey storetypes.StoreKey,
ps paramtypes.Subspace,
bankKeeper types.BankKeeper,
stakingKeeper types.StakingKeeper,
accountKeeper types.AccountKeeper,
epochstorageKeeper types.EpochstorageKeeper,
specKeeper types.SpecKeeper,
fixationStoreKeeper types.FixationStoreKeeper,
) *Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
ps = ps.WithKeyTable(types.ParamKeyTable())
}
keeper := &Keeper{
cdc: cdc,
storeKey: storeKey,
memKey: memKey,
paramstore: ps,
bankKeeper: bankKeeper,
stakingKeeper: stakingKeeper,
accountKeeper: accountKeeper,
epochstorageKeeper: epochstorageKeeper,
specKeeper: specKeeper,
}
delegationFS := *fixationStoreKeeper.NewFixationStore(storeKey, types.DelegationPrefix)
delegatorFS := *fixationStoreKeeper.NewFixationStore(storeKey, types.DelegatorPrefix)
keeper.delegationFS = delegationFS
keeper.delegatorFS = delegatorFS
return keeper
}
// ExportDelegations exports dualstaking delegations data (for genesis)
func (k Keeper) ExportDelegations(ctx sdk.Context) fixationtypes.GenesisState {
return k.delegationFS.Export(ctx)
}
// ExportDelegators exports dualstaking delegators data (for genesis)
func (k Keeper) ExportDelegators(ctx sdk.Context) fixationtypes.GenesisState {
return k.delegatorFS.Export(ctx)
}
// InitDelegations imports dualstaking delegations data (from genesis)
func (k Keeper) InitDelegations(ctx sdk.Context, data fixationtypes.GenesisState) {
k.delegationFS.Init(ctx, data)
}
// InitDelegators imports dualstaking delegators data (from genesis)
func (k Keeper) InitDelegators(ctx sdk.Context, data fixationtypes.GenesisState) {
k.delegatorFS.Init(ctx, data)
}
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
func (k Keeper) ChangeDelegationTimestampForTesting(ctx sdk.Context, index string, block uint64, timestamp int64) error {
var d types.Delegation
entryBlock, _, _, found := k.delegationFS.FindEntryDetailed(ctx, index, block, &d)
if !found {
return fmt.Errorf("cannot change delegation timestamp: delegation not found. index: %s, block: %s", index, strconv.FormatUint(block, 10))
}
d.Timestamp = timestamp
k.delegationFS.ModifyEntry(ctx, index, entryBlock, &d)
return nil
}