Skip to content

Commit

Permalink
feat(logic): create custom file system handler
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Mar 3, 2023
1 parent 4ccc32b commit b9cd4fb
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 13 deletions.
8 changes: 5 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,8 @@ func New(
app.GetSubspace(logicmoduletypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.WasmKeeper,
)
logicModule := logicmodule.NewAppModule(appCodec, app.LogicKeeper, app.AccountKeeper, app.BankKeeper, app.WasmKeeper)

wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
Expand Down Expand Up @@ -592,6 +592,8 @@ func New(
wasmOpts...,
)

app.LogicKeeper.WasmKeeper = app.WasmKeeper

govRouter := govv1beta1.NewRouter()
govRouter.
AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
Expand Down Expand Up @@ -663,7 +665,7 @@ func New(
transferModule,
icaModule,
interTxModule,
logicModule,
logicmodule.NewAppModule(appCodec, app.LogicKeeper, app.AccountKeeper, app.BankKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -782,7 +784,7 @@ func New(
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
ibc.NewAppModule(app.IBCKeeper),
transferModule,
logicModule,
logicmodule.NewAppModule(appCodec, app.LogicKeeper, app.AccountKeeper, app.BankKeeper),
)
app.sm.RegisterStoreDecoders()

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

import (
"fmt"
"io/fs"

"github.com/okp4/okp4d/x/logic/types"
)

type FileSystem struct {
wasmKeeper types.WasmKeeper
}

// New return a new FileSystem object that will handle all virtual file on the interpreter.
// File can be provided from different sources like CosmWasm cw-storage smart contract.
func New(keeper types.WasmKeeper) FileSystem {
return FileSystem{
wasmKeeper: keeper,
}
}

func (f FileSystem) Open(name string) (fs.File, error) {
return nil, fmt.Errorf("not implemented")
}
4 changes: 4 additions & 0 deletions x/logic/interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ichiban/prolog"
"github.com/okp4/okp4d/x/logic/interpreter/fs"
"github.com/okp4/okp4d/x/logic/types"
)

// New creates a new prolog.Interpreter with:
Expand All @@ -20,8 +22,10 @@ func New(
predicates []string,
bootstrap string,
meter sdk.GasMeter,
wasmKeeper types.WasmKeeper,
) (*prolog.Interpreter, error) {
var i prolog.Interpreter
i.FS = fs.New(wasmKeeper)

for _, o := range predicates {
if err := Register(&i, o, meter); err != nil {
Expand Down
1 change: 1 addition & 0 deletions x/logic/keeper/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (k Keeper) newInterpreter(ctx goctx.Context) (*prolog.Interpreter, error) {
util.NonZeroOrDefault(interpreterParams.GetRegisteredPredicates(), interpreter.RegistryNames),
util.NonZeroOrDefault(interpreterParams.GetBootstrap(), interpreter.Bootstrap()),
sdkctx.GasMeter(),
k.WasmKeeper,
)

return interpreted, err
Expand Down
3 changes: 3 additions & 0 deletions x/logic/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type (

authKeeper types.AccountKeeper
bankKeeper types.BankKeeper
WasmKeeper types.WasmKeeper
}
)

Expand All @@ -30,6 +31,7 @@ func NewKeeper(
ps paramtypes.Subspace,
authKeeper types.AccountKeeper,
bankKeeper types.BankKeeper,
wasmKeeper types.WasmKeeper,
) *Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
Expand All @@ -43,6 +45,7 @@ func NewKeeper(
paramstore: ps,
authKeeper: authKeeper,
bankKeeper: bankKeeper,
WasmKeeper: wasmKeeper,
}
}

Expand Down
17 changes: 7 additions & 10 deletions x/logic/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,22 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command {
type AppModule struct {
AppModuleBasic

keeper keeper.Keeper
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
wasmVMQueryHandler types.WasmKeeper
keeper keeper.Keeper
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
}

func NewAppModule(
cdc codec.Codec,
keeper keeper.Keeper,
accountKeeper types.AccountKeeper,
bankKeeper types.BankKeeper,
wasmVMQueryHandler types.WasmKeeper,
) AppModule {
return AppModule{
AppModuleBasic: NewAppModuleBasic(cdc),
keeper: keeper,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
wasmVMQueryHandler: wasmVMQueryHandler,
AppModuleBasic: NewAppModuleBasic(cdc),
keeper: keeper,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
}
}

Expand Down

0 comments on commit b9cd4fb

Please sign in to comment.