Skip to content

Commit

Permalink
feat(logic): inject auth and bank keeper
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Jan 17, 2023
1 parent 0c3da6b commit 578fd39
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@ func New(
keys[logicmoduletypes.StoreKey],
keys[logicmoduletypes.MemStoreKey],
app.GetSubspace(logicmoduletypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
)
logicModule := logicmodule.NewAppModule(appCodec, app.LogicKeeper, app.AccountKeeper, app.BankKeeper)

Expand Down
2 changes: 2 additions & 0 deletions testutil/keeper/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func LogicKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
storeKey,
memStoreKey,
paramsSubspace,
nil,
nil,
)

ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
Expand Down
3 changes: 3 additions & 0 deletions x/logic/keeper/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ func (k Keeper) newInterpreter(ctx goctx.Context) (*prolog.Interpreter, goctx.Co
interpreterParams := params.GetInterpreter()
limitContext, inc := k.withLimitContext(ctx)

limitContext = goctx.WithValue(limitContext, types.AuthKeeperContextKey, k.authKeeper)
limitContext = goctx.WithValue(limitContext, types.BankKeeperContextKey, k.bankKeeper)

interpreted, err := interpreter.New(
limitContext,
util.NonZeroOrDefault(interpreterParams.GetRegisteredPredicates(), interpreter.RegistryNames),
Expand Down
7 changes: 7 additions & 0 deletions x/logic/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ type (
storeKey storetypes.StoreKey
memKey storetypes.StoreKey
paramstore paramtypes.Subspace

authKeeper types.AccountKeeper
bankKeeper types.BankKeeper
}
)

Expand All @@ -25,6 +28,8 @@ func NewKeeper(
storeKey,
memKey storetypes.StoreKey,
ps paramtypes.Subspace,
authKeeper types.AccountKeeper,
bankKeeper types.BankKeeper,
) *Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
Expand All @@ -36,6 +41,8 @@ func NewKeeper(
storeKey: storeKey,
memKey: memKey,
paramstore: ps,
authKeeper: authKeeper,
bankKeeper: bankKeeper,
}
}

Expand Down
11 changes: 11 additions & 0 deletions x/logic/types/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package types

// ContextKey is a type for context keys.
type ContextKey string

const (
// AuthKeeperContextKey is the context key for the auth keeper.
AuthKeeperContextKey = ContextKey("authKeeper")
// BankKeeperContextKey is the context key for the bank keeper.
BankKeeperContextKey = ContextKey("bankKeeper")
)

0 comments on commit 578fd39

Please sign in to comment.