diff --git a/app/app.go b/app/app.go index f1d4362e..de5eb671 100644 --- a/app/app.go +++ b/app/app.go @@ -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) @@ -592,6 +592,8 @@ func New( wasmOpts..., ) + app.LogicKeeper.WasmKeeper = app.WasmKeeper + govRouter := govv1beta1.NewRouter() govRouter. AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler). @@ -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 @@ -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() diff --git a/x/logic/interpreter/fs/fs.go b/x/logic/interpreter/fs/fs.go new file mode 100644 index 00000000..1a0d1427 --- /dev/null +++ b/x/logic/interpreter/fs/fs.go @@ -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") +} diff --git a/x/logic/interpreter/interpreter.go b/x/logic/interpreter/interpreter.go index 75a66c27..920509e6 100644 --- a/x/logic/interpreter/interpreter.go +++ b/x/logic/interpreter/interpreter.go @@ -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: @@ -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 { diff --git a/x/logic/keeper/interpreter.go b/x/logic/keeper/interpreter.go index 88c25962..003e31d9 100644 --- a/x/logic/keeper/interpreter.go +++ b/x/logic/keeper/interpreter.go @@ -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 diff --git a/x/logic/keeper/keeper.go b/x/logic/keeper/keeper.go index dfc90e6c..f432a61d 100644 --- a/x/logic/keeper/keeper.go +++ b/x/logic/keeper/keeper.go @@ -20,6 +20,7 @@ type ( authKeeper types.AccountKeeper bankKeeper types.BankKeeper + WasmKeeper types.WasmKeeper } ) @@ -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() { @@ -43,6 +45,7 @@ func NewKeeper( paramstore: ps, authKeeper: authKeeper, bankKeeper: bankKeeper, + WasmKeeper: wasmKeeper, } } diff --git a/x/logic/module.go b/x/logic/module.go index cd2f8188..bd1093df 100644 --- a/x/logic/module.go +++ b/x/logic/module.go @@ -94,10 +94,9 @@ 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( @@ -105,14 +104,12 @@ func NewAppModule( 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, } }