Browse Source

fixes from @cloudhead review

pull/734/head
Anton Kaliaev 7 years ago
parent
commit
db413aadfd
No known key found for this signature in database GPG Key ID: 7B6881D965918214
8 changed files with 33 additions and 35 deletions
  1. +2
    -2
      rpc/client/httpclient.go
  2. +2
    -2
      rpc/client/localclient.go
  3. +10
    -10
      rpc/client/mock/abci.go
  4. +4
    -4
      rpc/client/mock/abci_test.go
  5. +2
    -2
      rpc/client/mock/client.go
  6. +2
    -2
      rpc/client/rpc_test.go
  7. +3
    -5
      rpc/client/types.go
  8. +8
    -8
      rpc/core/abci.go

+ 2
- 2
rpc/client/httpclient.go View File

@ -70,13 +70,13 @@ func (c *HTTP) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
} }
func (c *HTTP) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) { func (c *HTTP) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) {
return c.ABCIQueryWithOptions(path, data, DefaultABCIQueryOptions())
return c.ABCIQueryWithOptions(path, data, DefaultABCIQueryOptions)
} }
func (c *HTTP) ABCIQueryWithOptions(path string, data data.Bytes, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) { func (c *HTTP) ABCIQueryWithOptions(path string, data data.Bytes, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
result := new(ctypes.ResultABCIQuery) result := new(ctypes.ResultABCIQuery)
_, err := c.rpc.Call("abci_query", _, err := c.rpc.Call("abci_query",
map[string]interface{}{"path": path, "data": data, "height": opts.Height, "prove": opts.Prove},
map[string]interface{}{"path": path, "data": data, "height": opts.Height, "trusted": opts.Trusted},
result) result)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "ABCIQuery") return nil, errors.Wrap(err, "ABCIQuery")


+ 2
- 2
rpc/client/localclient.go View File

@ -58,11 +58,11 @@ func (c Local) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
} }
func (c Local) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) { func (c Local) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) {
return c.ABCIQueryWithOptions(path, data, DefaultABCIQueryOptions())
return c.ABCIQueryWithOptions(path, data, DefaultABCIQueryOptions)
} }
func (c Local) ABCIQueryWithOptions(path string, data data.Bytes, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) { func (c Local) ABCIQueryWithOptions(path string, data data.Bytes, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
return core.ABCIQuery(path, data, opts.Height, opts.Prove)
return core.ABCIQuery(path, data, opts.Height, opts.Trusted)
} }
func (c Local) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) { func (c Local) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {


+ 10
- 10
rpc/client/mock/abci.go View File

@ -25,11 +25,11 @@ func (a ABCIApp) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
} }
func (a ABCIApp) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) { func (a ABCIApp) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) {
return a.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions())
return a.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions)
} }
func (a ABCIApp) ABCIQueryWithOptions(path string, data data.Bytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) { func (a ABCIApp) ABCIQueryWithOptions(path string, data data.Bytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
q := a.App.Query(abci.RequestQuery{data, path, opts.Height, opts.Prove})
q := a.App.Query(abci.RequestQuery{data, path, opts.Height, opts.Trusted})
return &ctypes.ResultABCIQuery{q.Result()}, nil return &ctypes.ResultABCIQuery{q.Result()}, nil
} }
@ -84,11 +84,11 @@ func (m ABCIMock) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
} }
func (m ABCIMock) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) { func (m ABCIMock) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) {
return m.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions())
return m.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions)
} }
func (m ABCIMock) ABCIQueryWithOptions(path string, data data.Bytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) { func (m ABCIMock) ABCIQueryWithOptions(path string, data data.Bytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
res, err := m.Query.GetResponse(QueryArgs{path, data, opts.Height, opts.Prove})
res, err := m.Query.GetResponse(QueryArgs{path, data, opts.Height, opts.Trusted})
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -139,10 +139,10 @@ func (r *ABCIRecorder) _assertABCIClient() client.ABCIClient {
} }
type QueryArgs struct { type QueryArgs struct {
Path string
Data data.Bytes
Height uint64
Prove bool
Path string
Data data.Bytes
Height uint64
Trusted bool
} }
func (r *ABCIRecorder) addCall(call Call) { func (r *ABCIRecorder) addCall(call Call) {
@ -160,14 +160,14 @@ func (r *ABCIRecorder) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
} }
func (r *ABCIRecorder) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) { func (r *ABCIRecorder) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) {
return r.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions())
return r.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions)
} }
func (r *ABCIRecorder) ABCIQueryWithOptions(path string, data data.Bytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) { func (r *ABCIRecorder) ABCIQueryWithOptions(path string, data data.Bytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
res, err := r.Client.ABCIQueryWithOptions(path, data, opts) res, err := r.Client.ABCIQueryWithOptions(path, data, opts)
r.addCall(Call{ r.addCall(Call{
Name: "abci_query", Name: "abci_query",
Args: QueryArgs{path, data, opts.Height, opts.Prove},
Args: QueryArgs{path, data, opts.Height, opts.Trusted},
Response: res, Response: res,
Error: err, Error: err,
}) })


+ 4
- 4
rpc/client/mock/abci_test.go View File

@ -51,7 +51,7 @@ func TestABCIMock(t *testing.T) {
assert.Equal("foobar", err.Error()) assert.Equal("foobar", err.Error())
// query always returns the response // query always returns the response
query, err := m.ABCIQueryWithOptions("/", nil, client.ABCIQueryOptions{Prove: false})
query, err := m.ABCIQueryWithOptions("/", nil, client.ABCIQueryOptions{Trusted: true})
require.Nil(err) require.Nil(err)
require.NotNil(query) require.NotNil(query)
assert.EqualValues(key, query.Key) assert.EqualValues(key, query.Key)
@ -93,7 +93,7 @@ func TestABCIRecorder(t *testing.T) {
require.Equal(0, len(r.Calls)) require.Equal(0, len(r.Calls))
r.ABCIInfo() r.ABCIInfo()
r.ABCIQueryWithOptions("path", data.Bytes("data"), client.ABCIQueryOptions{Prove: true})
r.ABCIQueryWithOptions("path", data.Bytes("data"), client.ABCIQueryOptions{Trusted: false})
require.Equal(2, len(r.Calls)) require.Equal(2, len(r.Calls))
info := r.Calls[0] info := r.Calls[0]
@ -116,7 +116,7 @@ func TestABCIRecorder(t *testing.T) {
require.True(ok) require.True(ok)
assert.Equal("path", qa.Path) assert.Equal("path", qa.Path)
assert.EqualValues("data", qa.Data) assert.EqualValues("data", qa.Data)
assert.True(qa.Prove)
assert.False(qa.Trusted)
// now add some broadcasts // now add some broadcasts
txs := []types.Tx{{1}, {2}, {3}} txs := []types.Tx{{1}, {2}, {3}}
@ -165,7 +165,7 @@ func TestABCIApp(t *testing.T) {
assert.True(res.DeliverTx.Code.IsOK()) assert.True(res.DeliverTx.Code.IsOK())
// check the key // check the key
qres, err := m.ABCIQueryWithOptions("/key", data.Bytes(key), client.ABCIQueryOptions{Prove: false})
qres, err := m.ABCIQueryWithOptions("/key", data.Bytes(key), client.ABCIQueryOptions{Trusted: true})
require.Nil(err) require.Nil(err)
assert.EqualValues(value, qres.Value) assert.EqualValues(value, qres.Value)
} }

+ 2
- 2
rpc/client/mock/client.go View File

@ -85,11 +85,11 @@ func (c Client) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
} }
func (c Client) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) { func (c Client) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) {
return c.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions())
return c.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions)
} }
func (c Client) ABCIQueryWithOptions(path string, data data.Bytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) { func (c Client) ABCIQueryWithOptions(path string, data data.Bytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
return core.ABCIQuery(path, data, opts.Height, opts.Prove)
return core.ABCIQuery(path, data, opts.Height, opts.Trusted)
} }
func (c Client) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) { func (c Client) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {


+ 2
- 2
rpc/client/rpc_test.go View File

@ -141,7 +141,7 @@ func TestAppCalls(t *testing.T) {
// wait before querying // wait before querying
client.WaitForHeight(c, apph, nil) client.WaitForHeight(c, apph, nil)
qres, err := c.ABCIQueryWithOptions("/key", k, client.ABCIQueryOptions{Prove: false})
qres, err := c.ABCIQueryWithOptions("/key", k, client.ABCIQueryOptions{Trusted: true})
if assert.Nil(err) && assert.True(qres.Code.IsOK()) { if assert.Nil(err) && assert.True(qres.Code.IsOK()) {
// assert.Equal(k, data.GetKey()) // only returned for proofs // assert.Equal(k, data.GetKey()) // only returned for proofs
assert.EqualValues(v, qres.Value) assert.EqualValues(v, qres.Value)
@ -189,7 +189,7 @@ func TestAppCalls(t *testing.T) {
assert.Equal(block.Block.LastCommit, commit2.Commit) assert.Equal(block.Block.LastCommit, commit2.Commit)
// and we got a proof that works! // and we got a proof that works!
pres, err := c.ABCIQueryWithOptions("/key", k, client.ABCIQueryOptions{Prove: true})
pres, err := c.ABCIQueryWithOptions("/key", k, client.ABCIQueryOptions{Trusted: false})
if assert.Nil(err) && assert.True(pres.Code.IsOK()) { if assert.Nil(err) && assert.True(pres.Code.IsOK()) {
proof, err := iavl.ReadProof(pres.Proof) proof, err := iavl.ReadProof(pres.Proof)
if assert.Nil(err) { if assert.Nil(err) {


+ 3
- 5
rpc/client/types.go View File

@ -3,11 +3,9 @@ package client
// ABCIQueryOptions can be used to provide options for ABCIQuery call other // ABCIQueryOptions can be used to provide options for ABCIQuery call other
// than the DefaultABCIQueryOptions. // than the DefaultABCIQueryOptions.
type ABCIQueryOptions struct { type ABCIQueryOptions struct {
Height uint64
Prove bool
Height uint64
Trusted bool
} }
// DefaultABCIQueryOptions are latest height (0) and prove equal to true. // DefaultABCIQueryOptions are latest height (0) and prove equal to true.
func DefaultABCIQueryOptions() ABCIQueryOptions {
return ABCIQueryOptions{Height: 0, Prove: true}
}
var DefaultABCIQueryOptions = ABCIQueryOptions{Height: 0, Trusted: false}

+ 8
- 8
rpc/core/abci.go View File

@ -41,18 +41,18 @@ import (
// //
// ### Query Parameters // ### Query Parameters
// //
// | Parameter | Type | Default | Required | Description |
// |-----------+--------+---------+----------+---------------------------------------|
// | path | string | false | false | Path to the data ("/a/b/c") |
// | data | []byte | false | true | Data |
// | height | uint64 | 0 | false | Height (0 means latest) |
// | prove | bool | false | false | Include a proof of the data inclusion |
func ABCIQuery(path string, data data.Bytes, height uint64, prove bool) (*ctypes.ResultABCIQuery, error) {
// | Parameter | Type | Default | Required | Description |
// |-----------+--------+---------+----------+------------------------------------------------|
// | path | string | false | false | Path to the data ("/a/b/c") |
// | data | []byte | false | true | Data |
// | height | uint64 | 0 | false | Height (0 means latest) |
// | trusted | bool | false | false | Does not include a proof of the data inclusion |
func ABCIQuery(path string, data data.Bytes, height uint64, trusted bool) (*ctypes.ResultABCIQuery, error) {
resQuery, err := proxyAppQuery.QuerySync(abci.RequestQuery{ resQuery, err := proxyAppQuery.QuerySync(abci.RequestQuery{
Path: path, Path: path,
Data: data, Data: data,
Height: height, Height: height,
Prove: prove,
Prove: !trusted,
}) })
if err != nil { if err != nil {
return nil, err return nil, err


Loading…
Cancel
Save