Skip to content

Commit

Permalink
Showing 3 changed files with 11 additions and 5 deletions.
12 changes: 7 additions & 5 deletions x/wasm/internal/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -183,20 +183,22 @@ func (k Keeper) QuerySmart(ctx sdk.Context, contractAddr sdk.AccAddress, req []b
return models, nil
}

// QueryRaw returns the contract's state for give key. For a `nil` key a `nil` result is returned.
// QueryRaw returns the contract's state for give key. For a `nil` key a empty slice` result is returned.
func (k Keeper) QueryRaw(ctx sdk.Context, contractAddress sdk.AccAddress, key []byte) []types.Model {
result := make([]types.Model, 0)
if key == nil {
return nil
return result
}
prefixStoreKey := types.GetContractStorePrefixKey(contractAddress)
prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), prefixStoreKey)

if val := prefixStore.Get(key); val != nil {
return []types.Model{{
return append(result, types.Model{
Key: string(key),
Value: string(val),
}}
})
}
return []types.Model{}
return result
}

func (k Keeper) contractInstance(ctx sdk.Context, contractAddress sdk.AccAddress) (types.CodeInfo, prefix.Store, sdk.Error) {
3 changes: 3 additions & 0 deletions x/wasm/internal/keeper/querier.go
Original file line number Diff line number Diff line change
@@ -91,6 +91,9 @@ func queryContractState(ctx sdk.Context, bech, queryMethod string, req abci.Requ
Value: string(iter.Value()),
})
}
if resultData == nil {
resultData = make([]types.Model, 0)
}
case QueryMethodContractStateRaw:
resultData = keeper.QueryRaw(ctx, contractAddr, req.Data)
case QueryMethodContractStateSmart:
1 change: 1 addition & 0 deletions x/wasm/internal/keeper/querier_test.go
Original file line number Diff line number Diff line change
@@ -119,6 +119,7 @@ func TestQueryContractState(t *testing.T) {
var r []model
if spec.expErr == nil {
require.NoError(t, json.Unmarshal(binResult, &r))
require.NotNil(t, r)
}
require.Len(t, r, spec.expModelLen)
// and in result set

0 comments on commit a1e01e5

Please sign in to comment.