/
keeper.go
77 lines (66 loc) · 2.29 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
package keeper
import (
"fmt"
"github.com/tendermint/tendermint/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/furynet/furymod/modules/htlc/types"
)
// Keeper defines the HTLC keeper
type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.Codec
paramSpace paramstypes.Subspace
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
blockedAddrs map[string]bool
}
// NewKeeper creates a new HTLC Keeper instance
func NewKeeper(
cdc codec.Codec,
key storetypes.StoreKey,
paramSpace paramstypes.Subspace,
accountKeeper types.AccountKeeper,
bankKeeper types.BankKeeper,
blockedAddrs map[string]bool,
) Keeper {
// ensure the HTLC module account is set
if addr := accountKeeper.GetModuleAddress(types.ModuleName); addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}
// set KeyTable if it has not already been set
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(ParamKeyTable())
}
return Keeper{
storeKey: key,
cdc: cdc,
paramSpace: paramSpace,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
blockedAddrs: blockedAddrs,
}
}
// Logger returns a module-specific logger
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("furymod/%s", types.ModuleName))
}
// GetHTLCAccount returns the HTLC module account
func (k Keeper) GetHTLCAccount(ctx sdk.Context) authtypes.ModuleAccountI {
return k.accountKeeper.GetModuleAccount(ctx, types.ModuleName)
}
// EnsureModuleAccountPermissions syncs the bep3 module account's permissions with those in the supply keeper.
func (k Keeper) EnsureModuleAccountPermissions(ctx sdk.Context) error {
maccI := k.accountKeeper.GetModuleAccount(ctx, types.ModuleName)
macc, ok := maccI.(*authtypes.ModuleAccount)
if !ok {
return fmt.Errorf("expected %s account to be a module account type", types.ModuleName)
}
_, perms := k.accountKeeper.GetModuleAddressAndPermissions(types.ModuleName)
macc.Permissions = perms
k.accountKeeper.SetModuleAccount(ctx, macc)
return nil
}