diff --git a/app/rest_test.go b/app/rest_test.go index 8c593427..37514d6d 100644 --- a/app/rest_test.go +++ b/app/rest_test.go @@ -3,7 +3,6 @@ package app import ( - "encoding/hex" "fmt" "io/ioutil" "net/http" @@ -449,20 +448,6 @@ func Test_VMRest(t *testing.T) { req, _ := ct.RestQueryVMGetData(writeSet.Address, "non-valid-path") req.CheckFailed(http.StatusUnprocessableEntity, nil) } - - // restricted path - { - path := writeSet.Path - - pathBytes, err := hex.DecodeString(path) - require.NoError(t, err, "decoding path HEX string") - - pathBytes[0] = 0x1 - path = hex.EncodeToString(pathBytes) - - req, _ := ct.RestQueryVMGetData(writeSet.Address, path) - req.CheckFailed(http.StatusUnprocessableEntity, nil) - } } } } diff --git a/x/vm/abci.go b/x/vm/abci.go index b952cdbe..882fea2c 100644 --- a/x/vm/abci.go +++ b/x/vm/abci.go @@ -11,6 +11,8 @@ import ( func BeginBlocker(ctx sdk.Context, keeper Keeper, _ abci.RequestBeginBlock) { logger := keeper.Logger(ctx) + keeper.SetDSContext(ctx) + keeper.IterateProposalsQueue(ctx, func(id uint64, pProposal PlannedProposal) { if !pProposal.GetPlan().ShouldExecute(ctx) { return diff --git a/x/vm/client/cli/queries.go b/x/vm/client/cli/queries.go index 00ec1838..24de6276 100644 --- a/x/vm/client/cli/queries.go +++ b/x/vm/client/cli/queries.go @@ -105,8 +105,6 @@ func GetData(queryRoute string, cdc *codec.Codec) *cobra.Command { if err != nil { return fmt.Errorf("can't parse address: %s\n, check address format, it could be libra hex or bech32", rawAddress) } - - address = common_vm.Bech32ToLibra(address) } path, err := hex.DecodeString(args[1]) @@ -115,7 +113,7 @@ func GetData(queryRoute string, cdc *codec.Codec) *cobra.Command { } bz, err := cdc.MarshalJSON(types.QueryAccessPath{ - Address: address, + Address: common_vm.Bech32ToLibra(address), Path: path, }) if err != nil { diff --git a/x/vm/client/rest/rest.go b/x/vm/client/rest/rest.go index da2818df..c5a66c71 100644 --- a/x/vm/client/rest/rest.go +++ b/x/vm/client/rest/rest.go @@ -106,8 +106,6 @@ func getData(cliCtx context.CLIContext) http.HandlerFunc { ) return } - - address = common_vm.Bech32ToLibra(address) } path, err := hex.DecodeString(rawPath) @@ -119,17 +117,9 @@ func getData(cliCtx context.CLIContext) http.HandlerFunc { ) return } - if len(path) > 0 && path[0] != 0x0 { - rest.WriteErrorResponse( - w, - http.StatusUnprocessableEntity, - fmt.Sprintf("path %q: first byte must be 0x0", rawPath), - ) - return - } bz, err := cliCtx.Codec.MarshalJSON(types.QueryAccessPath{ - Address: address, + Address: common_vm.Bech32ToLibra(address), Path: path, }) if err != nil { diff --git a/x/vm/internal/keeper/keeper_vm.go b/x/vm/internal/keeper/keeper_vm.go index d7b7a2cc..0bc73d0f 100644 --- a/x/vm/internal/keeper/keeper_vm.go +++ b/x/vm/internal/keeper/keeper_vm.go @@ -36,6 +36,21 @@ func (keeper Keeper) GetValue(ctx sdk.Context, accessPath *vm_grpc.VMAccessPath) return keeper.getValue(ctx, accessPath) } +// GetValue with middleware context-dependant processing. +func (keeper Keeper) GetValueWithMiddlewares(ctx sdk.Context, accessPath *vm_grpc.VMAccessPath) []byte { + for _, f := range keeper.dsServer.dataMiddlewares { + data, err := f(ctx, accessPath) + if err != nil { + return nil + } + if data != nil { + return data + } + } + + return keeper.GetValue(ctx, accessPath) +} + // Public set value. func (keeper Keeper) SetValue(ctx sdk.Context, accessPath *vm_grpc.VMAccessPath, value []byte) { keeper.setValue(ctx, accessPath, value) diff --git a/x/vm/querier.go b/x/vm/querier.go index 785579d7..4f0733f5 100644 --- a/x/vm/querier.go +++ b/x/vm/querier.go @@ -29,12 +29,11 @@ func NewQuerier(vmKeeper Keeper) sdk.Querier { // Processing query to get value from DS. func queryGetValue(ctx sdk.Context, vmKeeper Keeper, req abci.RequestQuery) ([]byte, error) { var queryAccessPath QueryAccessPath - if err := ModuleCdc.UnmarshalJSON(req.Data, &queryAccessPath); err != nil { return nil, sdkErrors.Wrap(ErrInternal, "unknown query") } - return vmKeeper.GetValue(ctx, &vm_grpc.VMAccessPath{ + return vmKeeper.GetValueWithMiddlewares(ctx, &vm_grpc.VMAccessPath{ Address: queryAccessPath.Address, Path: queryAccessPath.Path, }), nil