diff --git a/x/logic/interpreter/fs/fs.go b/x/logic/interpreter/fs/fs.go index e451af28..be03e74e 100644 --- a/x/logic/interpreter/fs/fs.go +++ b/x/logic/interpreter/fs/fs.go @@ -5,21 +5,23 @@ import ( "io/fs" ) -// FileSystem is the custom virtual file system used into the blockchain. +// VirtualFS is the custom virtual file system used into the blockchain. // It will hold a list of handler that can resolve file URI and return the corresponding binary file. -type FileSystem struct { +type VirtualFS struct { ctx goctx.Context router Router } -// New return a new FileSystem object that will handle all virtual file on the interpreter. +var _ fs.FS = (*VirtualFS)(nil) + +// New return a new VirtualFS 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(ctx goctx.Context, handlers []URIHandler) FileSystem { +func New(ctx goctx.Context, handlers []URIHandler) VirtualFS { router := NewRouter() for _, handler := range handlers { router.RegisterHandler(handler) } - return FileSystem{ + return VirtualFS{ ctx: ctx, router: router, } @@ -34,7 +36,7 @@ func New(ctx goctx.Context, handlers []URIHandler) FileSystem { // Open should reject attempts to open names that do not satisfy // ValidPath(name), returning a *PathError with Err set to // ErrInvalid or ErrNotExist. -func (f FileSystem) Open(name string) (fs.File, error) { +func (f VirtualFS) Open(name string) (fs.File, error) { data, err := f.router.Open(f.ctx, name) if err != nil { return nil, &fs.PathError{ diff --git a/x/logic/interpreter/fs/wasm.go b/x/logic/interpreter/fs/wasm.go index 59ae4807..eec213ae 100644 --- a/x/logic/interpreter/fs/wasm.go +++ b/x/logic/interpreter/fs/wasm.go @@ -18,19 +18,21 @@ const ( scheme = "cosmwasm" ) -type WasmFS struct { +type WasmHandler struct { wasmKeeper types.WasmKeeper } -func NewWasmFS(keeper types.WasmKeeper) WasmFS { - return WasmFS{wasmKeeper: keeper} +var _ URIHandler = (*WasmHandler)(nil) + +func NewWasmHandler(keeper types.WasmKeeper) WasmHandler { + return WasmHandler{wasmKeeper: keeper} } -func (w WasmFS) Scheme() string { +func (w WasmHandler) Scheme() string { return scheme } -func (w WasmFS) Open(ctx context.Context, uri *url.URL) (fs.File, error) { +func (w WasmHandler) Open(ctx context.Context, uri *url.URL) (fs.File, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) if uri.Scheme != scheme { diff --git a/x/logic/interpreter/fs/wasm_test.go b/x/logic/interpreter/fs/wasm_test.go index 6833ddaf..5111ac40 100644 --- a/x/logic/interpreter/fs/wasm_test.go +++ b/x/logic/interpreter/fs/wasm_test.go @@ -107,7 +107,7 @@ func TestWasmHandler(t *testing.T) { Return(tc.data, nil) Convey("and wasm handler", func() { - handler := NewWasmFS(wasmKeeper) + handler := NewWasmHandler(wasmKeeper) Convey("When ask handler if it can open uri", func() { uri, err := url.Parse(tc.uri) diff --git a/x/logic/keeper/interpreter.go b/x/logic/keeper/interpreter.go index d61c043c..ee86187c 100644 --- a/x/logic/keeper/interpreter.go +++ b/x/logic/keeper/interpreter.go @@ -98,7 +98,7 @@ func (k Keeper) newInterpreter(ctx goctx.Context) (*prolog.Interpreter, error) { interpreterParams := params.GetInterpreter() - wasmHandler := fs.NewWasmFS(k.WasmKeeper) + wasmHandler := fs.NewWasmHandler(k.WasmKeeper) interpreted, err := interpreter.New( ctx,