-
Notifications
You must be signed in to change notification settings - Fork 30
/
keeper.go
57 lines (48 loc) · 1.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
package keeper
import (
"fmt"
"github.com/line/lbm-sdk/codec"
sdk "github.com/line/lbm-sdk/types"
"github.com/line/lbm-sdk/x/contract"
"github.com/line/lbm-sdk/x/token/internal/types"
"github.com/tendermint/tendermint/libs/log"
)
type Keeper struct {
accountKeeper types.AccountKeeper
storeKey sdk.StoreKey
contractKeeper contract.Keeper
cdc *codec.Codec
}
func NewKeeper(cdc *codec.Codec, accountKeeper types.AccountKeeper, contractKeeper contract.Keeper, storeKey sdk.StoreKey) Keeper {
return Keeper{
accountKeeper: accountKeeper,
storeKey: storeKey,
contractKeeper: contractKeeper,
cdc: cdc,
}
}
func (k Keeper) NewContractID(ctx sdk.Context) string {
return k.contractKeeper.NewContractID(ctx)
}
func (k Keeper) HasContractID(ctx sdk.Context) bool {
return k.contractKeeper.HasContractID(ctx, k.getContractID(ctx))
}
func (k Keeper) getContractID(ctx sdk.Context) string {
contractI := ctx.Context().Value(contract.CtxKey{})
if contractI == nil {
panic("contract id does not set on the context")
}
return contractI.(string)
}
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
func (k Keeper) UnmarshalJSON(bz []byte, ptr interface{}) error {
return k.cdc.UnmarshalJSON(bz, ptr)
}
func (k Keeper) MarshalJSON(o interface{}) ([]byte, error) {
return k.cdc.MarshalJSON(o)
}
func (k Keeper) MarshalJSONIndent(o interface{}) ([]byte, error) {
return k.cdc.MarshalJSONIndent(o, "", " ")
}