-
Notifications
You must be signed in to change notification settings - Fork 340
/
keeper.go
118 lines (100 loc) · 3.51 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
108
109
110
111
112
113
114
115
116
117
118
package keeper
import (
"fmt"
"cosmossdk.io/collections"
"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"
"github.com/dymensionxyz/dymension/v3/internal/collcompat"
"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)
type Keeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
hooks types.MultiRollappHooks
paramstore paramtypes.Subspace
authority string // authority is the x/gov module account
accKeeper AccountKeeper
ibcClientKeeper IBCClientKeeper
canonicalClientKeeper CanonicalLightClientKeeper
channelKeeper ChannelKeeper
sequencerKeeper SequencerKeeper
bankKeeper BankKeeper
vulnerableDRSVersions collections.KeySet[uint32]
registeredRollappDenoms collections.KeySet[collections.Pair[string, string]]
finalizePending func(ctx sdk.Context, stateInfoIndex types.StateInfoIndex) error
}
func NewKeeper(
cdc codec.BinaryCodec,
storeKey storetypes.StoreKey,
ps paramtypes.Subspace,
ak AccountKeeper,
channelKeeper ChannelKeeper,
ibcclientKeeper IBCClientKeeper,
sequencerKeeper SequencerKeeper,
bankKeeper BankKeeper,
authority string,
canonicalClientKeeper CanonicalLightClientKeeper,
) *Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
ps = ps.WithKeyTable(types.ParamKeyTable())
}
if _, err := sdk.AccAddressFromBech32(authority); err != nil {
panic(fmt.Errorf("invalid x/rollapp authority address: %w", err))
}
k := &Keeper{
cdc: cdc,
storeKey: storeKey,
paramstore: ps,
hooks: nil,
channelKeeper: channelKeeper,
authority: authority,
accKeeper: ak,
ibcClientKeeper: ibcclientKeeper,
sequencerKeeper: sequencerKeeper,
bankKeeper: bankKeeper,
vulnerableDRSVersions: collections.NewKeySet(
collections.NewSchemaBuilder(collcompat.NewKVStoreService(storeKey)),
collections.NewPrefix(types.VulnerableDRSVersionsKeyPrefix),
"vulnerable_drs_versions",
collections.Uint32Key,
),
registeredRollappDenoms: collections.NewKeySet[collections.Pair[string, string]](
collections.NewSchemaBuilder(collcompat.NewKVStoreService(storeKey)),
collections.NewPrefix(types.KeyRegisteredDenomPrefix),
"registered_rollapp_denoms",
collections.PairKeyCodec(collections.StringKey, collections.StringKey),
),
finalizePending: nil,
canonicalClientKeeper: canonicalClientKeeper,
}
k.SetFinalizePendingFn(k.finalizePendingState)
return k
}
func (k *Keeper) SetFinalizePendingFn(fn func(ctx sdk.Context, stateInfoIndex types.StateInfoIndex) error) {
k.finalizePending = fn
}
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
func (k *Keeper) SetSequencerKeeper(sk SequencerKeeper) {
k.sequencerKeeper = sk
}
func (k *Keeper) SetCanonicalClientKeeper(kk CanonicalLightClientKeeper) {
k.canonicalClientKeeper = kk
}
/* -------------------------------------------------------------------------- */
/* Hooks */
/* -------------------------------------------------------------------------- */
func (k *Keeper) SetHooks(sh types.MultiRollappHooks) {
if k.hooks != nil {
panic("cannot set rollapp hooks twice")
}
k.hooks = sh
}
func (k *Keeper) GetHooks() types.MultiRollappHooks {
return k.hooks
}