-
Notifications
You must be signed in to change notification settings - Fork 28
/
keeper.go
78 lines (65 loc) · 2.61 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
package keeper
import (
"fmt"
"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"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/irisnet/irismod/modules/service/types"
)
// Keeper defines the service keeper
type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.Codec
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
blockedAddrs map[string]bool
feeCollectorName string
authority string // name of the fee collector
respCallbacks map[string]types.ResponseCallback // used to map the module name to response callback
stateCallbacks map[string]types.StateCallback // used to map the module name to state callback
moduleServices map[string]*types.ModuleService // used to map the module name to module service
}
// NewKeeper creates a new service Keeper instance
func NewKeeper(
cdc codec.Codec,
key storetypes.StoreKey,
accountKeeper types.AccountKeeper,
bankKeeper types.BankKeeper,
feeCollectorName string,
authority string,
) Keeper {
// ensure service module accounts are set
if addr := accountKeeper.GetModuleAddress(types.DepositAccName); addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.DepositAccName))
}
if addr := accountKeeper.GetModuleAddress(types.RequestAccName); addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.RequestAccName))
}
keeper := Keeper{
storeKey: key,
cdc: cdc,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
blockedAddrs: bankKeeper.GetBlockedAddresses(),
feeCollectorName: feeCollectorName,
authority: authority,
}
keeper.respCallbacks = make(map[string]types.ResponseCallback)
keeper.stateCallbacks = make(map[string]types.StateCallback)
keeper.moduleServices = make(map[string]*types.ModuleService)
return keeper
}
// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("irismod/%s", types.ModuleName))
}
// GetServiceDepositAccount returns the service depost ModuleAccount
func (k Keeper) GetServiceDepositAccount(ctx sdk.Context) authtypes.ModuleAccountI {
return k.accountKeeper.GetModuleAccount(ctx, types.DepositAccName)
}
// GetServiceRequestAccount returns the service request ModuleAccount
func (k Keeper) GetServiceRequestAccount(ctx sdk.Context) authtypes.ModuleAccountI {
return k.accountKeeper.GetModuleAccount(ctx, types.RequestAccName)
}