diff --git a/x/wasm/internal/keeper/genesis.go b/x/wasm/internal/keeper/genesis.go index ad72c7d..2666e36 100644 --- a/x/wasm/internal/keeper/genesis.go +++ b/x/wasm/internal/keeper/genesis.go @@ -52,8 +52,8 @@ func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState { var state []types.Model for ; contractStateIterator.Valid(); contractStateIterator.Next() { m := types.Model{ - Key: string(contractStateIterator.Key()), - Value: string(contractStateIterator.Value()), + Key: contractStateIterator.Key(), + Value: contractStateIterator.Value(), } state = append(state, m) } diff --git a/x/wasm/internal/keeper/keeper.go b/x/wasm/internal/keeper/keeper.go index 2ed25db..0758be4 100644 --- a/x/wasm/internal/keeper/keeper.go +++ b/x/wasm/internal/keeper/keeper.go @@ -193,8 +193,8 @@ func (k Keeper) QueryRaw(ctx sdk.Context, contractAddress sdk.AccAddress, key [] if val := prefixStore.Get(key); val != nil { return append(result, types.Model{ - Key: string(key), - Value: string(val), + Key: key, + Value: val, }) } return result diff --git a/x/wasm/internal/keeper/querier.go b/x/wasm/internal/keeper/querier.go index d4099d4..4585594 100644 --- a/x/wasm/internal/keeper/querier.go +++ b/x/wasm/internal/keeper/querier.go @@ -90,9 +90,8 @@ func queryContractState(ctx sdk.Context, bech, queryMethod string, req abci.Requ case QueryMethodContractStateAll: for iter := keeper.GetContractState(ctx, contractAddr); iter.Valid(); iter.Next() { resultData = append(resultData, types.Model{ - // TODO: binary and raw json - Key: string(iter.Key()), - Value: string(iter.Value()), + Key: iter.Key(), + Value: iter.Value(), }) } if resultData == nil { diff --git a/x/wasm/internal/keeper/querier_test.go b/x/wasm/internal/keeper/querier_test.go index c3f1677..f26ccd6 100644 --- a/x/wasm/internal/keeper/querier_test.go +++ b/x/wasm/internal/keeper/querier_test.go @@ -15,10 +15,7 @@ import ( ) func TestQueryContractState(t *testing.T) { - type model struct { - Key string `json:"key"` - Value string `json:"val"` - } + type model = types.Model tempDir, err := ioutil.TempDir("", "wasm") require.NoError(t, err) @@ -48,8 +45,8 @@ func TestQueryContractState(t *testing.T) { require.NoError(t, err) contractModel := []types.Model{ - {Key: "foo", Value: "bar"}, - {Key: string([]byte{0x0, 0x1}), Value: string([]byte{0x2, 0x3})}, + {Key: []byte("foo"), Value: []byte("\"bar\"")}, + {Key: []byte{0x0, 0x1}, Value: []byte("{}")}, } keeper.setContractState(ctx, addr, contractModel) @@ -70,21 +67,21 @@ func TestQueryContractState(t *testing.T) { srcPath: []string{QueryGetContractState, addr.String(), QueryMethodContractStateAll}, expModelLen: 3, expModelContains: []model{ - {Key: "foo", Value: "bar"}, - {Key: string([]byte{0x0, 0x1}), Value: string([]byte{0x2, 0x3})}, + {Key: []byte("foo"), Value: []byte(`"bar"`)}, + {Key: []byte{0x0, 0x1}, Value: []byte(`{"count":8}`)}, }, }, "query raw key": { srcPath: []string{QueryGetContractState, addr.String(), QueryMethodContractStateRaw}, srcReq: abci.RequestQuery{Data: []byte("foo")}, expModelLen: 1, - expModelContains: []model{{Key: "foo", Value: "bar"}}, + expModelContains: []model{{Key: []byte("foo"), Value: []byte(`["bar"]`)}}, }, "query raw binary key": { srcPath: []string{QueryGetContractState, addr.String(), QueryMethodContractStateRaw}, srcReq: abci.RequestQuery{Data: []byte{0x0, 0x1}}, expModelLen: 1, - expModelContains: []model{{Key: string([]byte{0x0, 0x1}), Value: string([]byte{0x2, 0x3})}}, + expModelContains: []model{{Key: []byte{0x0, 0x1}, Value: []byte("798")}, }, "query smart": { srcPath: []string{QueryGetContractState, addr.String(), QueryMethodContractStateSmart}, diff --git a/x/wasm/internal/types/types.go b/x/wasm/internal/types/types.go index 047f329..2b182ba 100644 --- a/x/wasm/internal/types/types.go +++ b/x/wasm/internal/types/types.go @@ -20,10 +20,10 @@ type Model struct { // CodeInfo is data for the uploaded contract WASM code type CodeInfo struct { - CodeHash tmBytes.HexBytes `json:"code_hash"` - Creator sdk.AccAddress `json:"creator"` - Source string `json:"source"` - Builder string `json:"builder"` + CodeHash []byte `json:"code_hash"` + Creator sdk.AccAddress `json:"creator"` + Source string `json:"source"` + Builder string `json:"builder"` } // NewCodeInfo fills a new Contract struct