-
Notifications
You must be signed in to change notification settings - Fork 568
/
keeper.go
63 lines (52 loc) · 1.46 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
package keeper
import (
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/osmosis-labs/osmosis/x/gamm/types"
)
func permContains(perms []string, perm string) bool {
for _, v := range perms {
if v == perm {
return true
}
}
return false
}
type Keeper struct {
storeKey sdk.StoreKey
cdc codec.BinaryMarshaler
hooks types.GammHooks
// keepers
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
}
func NewKeeper(cdc codec.BinaryMarshaler, storeKey sdk.StoreKey, accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper) Keeper {
// Ensure that the module account are set.
moduleAddr, perms := accountKeeper.GetModuleAddressAndPermissions(types.ModuleName)
if moduleAddr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}
if !permContains(perms, authtypes.Minter) {
panic(fmt.Sprintf("%s module account should have the minter permission", types.ModuleName))
}
if !permContains(perms, authtypes.Burner) {
panic(fmt.Sprintf("%s module account should have the burner permission", types.ModuleName))
}
return Keeper{
storeKey: storeKey,
cdc: cdc,
// keepers
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
}
}
// Set the gamm hooks
func (k *Keeper) SetHooks(gh types.GammHooks) *Keeper {
if k.hooks != nil {
panic("cannot set gamm hooks twice")
}
k.hooks = gh
return k
}