Browse Source

Improve go-data json support in rpc

pull/455/head
Ethan Frey 8 years ago
committed by Ethan Buchman
parent
commit
90abc61c56
13 changed files with 41 additions and 29 deletions
  1. +2
    -1
      rpc/client/httpclient.go
  2. +2
    -1
      rpc/client/interface.go
  3. +2
    -1
      rpc/client/localclient.go
  4. +5
    -4
      rpc/client/mock/abci.go
  5. +5
    -4
      rpc/client/mock/abci_test.go
  6. +2
    -1
      rpc/client/mock/client.go
  7. +3
    -2
      rpc/client/mock/status_test.go
  8. +2
    -1
      rpc/core/abci.go
  9. +2
    -1
      rpc/core/mempool.go
  10. +6
    -4
      rpc/core/routes.go
  11. +3
    -2
      rpc/core/status.go
  12. +4
    -3
      rpc/core/types/responses.go
  13. +3
    -4
      rpc/test/client_test.go

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

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/pkg/errors"
data "github.com/tendermint/go-data"
events "github.com/tendermint/go-events"
"github.com/tendermint/go-rpc/client"
wire "github.com/tendermint/go-wire"
@ -67,7 +68,7 @@ func (c *HTTP) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
return (*tmResult).(*ctypes.ResultABCIInfo), nil
}
func (c *HTTP) ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultABCIQuery, error) {
func (c *HTTP) ABCIQuery(path string, data data.Bytes, prove bool) (*ctypes.ResultABCIQuery, error) {
tmResult := new(ctypes.TMResult)
_, err := c.rpc.Call("abci_query",
map[string]interface{}{"path": path, "data": data, "prove": prove},


+ 2
- 1
rpc/client/interface.go View File

@ -20,6 +20,7 @@ implementation.
package client
import (
data "github.com/tendermint/go-data"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
)
@ -30,7 +31,7 @@ import (
type ABCIClient interface {
// reading from abci app
ABCIInfo() (*ctypes.ResultABCIInfo, error)
ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultABCIQuery, error)
ABCIQuery(path string, data data.Bytes, prove bool) (*ctypes.ResultABCIQuery, error)
// writing to abci app
BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)


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

@ -1,6 +1,7 @@
package client
import (
data "github.com/tendermint/go-data"
nm "github.com/tendermint/tendermint/node"
"github.com/tendermint/tendermint/rpc/core"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
@ -56,7 +57,7 @@ func (c Local) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
return core.ABCIInfo()
}
func (c Local) ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultABCIQuery, error) {
func (c Local) ABCIQuery(path string, data data.Bytes, prove bool) (*ctypes.ResultABCIQuery, error) {
return core.ABCIQuery(path, data, prove)
}


+ 5
- 4
rpc/client/mock/abci.go View File

@ -2,6 +2,7 @@ package mock
import (
abci "github.com/tendermint/abci/types"
data "github.com/tendermint/go-data"
"github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
@ -22,7 +23,7 @@ func (a ABCIApp) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
return &ctypes.ResultABCIInfo{a.App.Info()}, nil
}
func (a ABCIApp) ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultABCIQuery, error) {
func (a ABCIApp) ABCIQuery(path string, data data.Bytes, prove bool) (*ctypes.ResultABCIQuery, error) {
q := a.App.Query(abci.RequestQuery{data, path, 0, prove})
return &ctypes.ResultABCIQuery{q}, nil
}
@ -79,7 +80,7 @@ func (m ABCIMock) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
return &ctypes.ResultABCIInfo{res.(abci.ResponseInfo)}, nil
}
func (m ABCIMock) ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultABCIQuery, error) {
func (m ABCIMock) ABCIQuery(path string, data data.Bytes, prove bool) (*ctypes.ResultABCIQuery, error) {
res, err := m.Query.GetResponse(QueryArgs{path, data, prove})
if err != nil {
return nil, err
@ -131,7 +132,7 @@ func (r *ABCIRecorder) _assertABCIClient() client.ABCIClient {
type QueryArgs struct {
Path string
Data []byte
Data data.Bytes
Prove bool
}
@ -149,7 +150,7 @@ func (r *ABCIRecorder) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
return res, err
}
func (r *ABCIRecorder) ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultABCIQuery, error) {
func (r *ABCIRecorder) ABCIQuery(path string, data data.Bytes, prove bool) (*ctypes.ResultABCIQuery, error) {
res, err := r.Client.ABCIQuery(path, data, prove)
r.addCall(Call{
Name: "abci_query",


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

@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/abci/example/dummy"
abci "github.com/tendermint/abci/types"
data "github.com/tendermint/go-data"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
@ -35,8 +36,8 @@ func TestABCIMock(t *testing.T) {
BroadcastCommit: mock.Call{
Args: goodTx,
Response: &ctypes.ResultBroadcastTxCommit{
CheckTx: &abci.ResponseCheckTx{Data: []byte("stand")},
DeliverTx: &abci.ResponseDeliverTx{Data: []byte("deliver")},
CheckTx: &abci.ResponseCheckTx{Data: data.Bytes("stand")},
DeliverTx: &abci.ResponseDeliverTx{Data: data.Bytes("deliver")},
},
Error: errors.New("bad tx"),
},
@ -91,7 +92,7 @@ func TestABCIRecorder(t *testing.T) {
require.Equal(0, len(r.Calls))
r.ABCIInfo()
r.ABCIQuery("path", []byte("data"), true)
r.ABCIQuery("path", data.Bytes("data"), true)
require.Equal(2, len(r.Calls))
info := r.Calls[0]
@ -163,7 +164,7 @@ func TestABCIApp(t *testing.T) {
assert.True(res.DeliverTx.Code.IsOK())
// check the key
qres, err := m.ABCIQuery("/key", []byte(key), false)
qres, err := m.ABCIQuery("/key", data.Bytes(key), false)
require.Nil(err)
assert.EqualValues(value, qres.Response.Value)
}

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

@ -16,6 +16,7 @@ package mock
import (
"reflect"
data "github.com/tendermint/go-data"
"github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tendermint/rpc/core"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
@ -83,7 +84,7 @@ func (c Client) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
return core.ABCIInfo()
}
func (c Client) ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultABCIQuery, error) {
func (c Client) ABCIQuery(path string, data data.Bytes, prove bool) (*ctypes.ResultABCIQuery, error) {
return core.ABCIQuery(path, data, prove)
}


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

@ -5,6 +5,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
data "github.com/tendermint/go-data"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/rpc/client/mock"
@ -16,8 +17,8 @@ func TestStatus(t *testing.T) {
m := &mock.StatusMock{
Call: mock.Call{
Response: &ctypes.ResultStatus{
LatestBlockHash: []byte("block"),
LatestAppHash: []byte("app"),
LatestBlockHash: data.Bytes("block"),
LatestAppHash: data.Bytes("app"),
LatestBlockHeight: 10,
}},
}


+ 2
- 1
rpc/core/abci.go View File

@ -2,12 +2,13 @@ package core
import (
abci "github.com/tendermint/abci/types"
data "github.com/tendermint/go-data"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
)
//-----------------------------------------------------------------------------
func ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultABCIQuery, error) {
func ABCIQuery(path string, data data.Bytes, prove bool) (*ctypes.ResultABCIQuery, error) {
resQuery, err := proxyAppQuery.QuerySync(abci.RequestQuery{
Path: path,
Data: data,


+ 2
- 1
rpc/core/mempool.go View File

@ -5,6 +5,7 @@ import (
"time"
abci "github.com/tendermint/abci/types"
data "github.com/tendermint/go-data"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
)
@ -84,7 +85,7 @@ func BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
Data: deliverTxRes.Data,
Log: deliverTxRes.Log,
}
log.Notice("DeliverTx passed ", "tx", []byte(tx), "response", deliverTxR)
log.Notice("DeliverTx passed ", "tx", data.Bytes(tx), "response", deliverTxR)
return &ctypes.ResultBroadcastTxCommit{
CheckTx: checkTxR,
DeliverTx: deliverTxR,


+ 6
- 4
rpc/core/routes.go View File

@ -1,9 +1,11 @@
package core
import (
data "github.com/tendermint/go-data"
rpc "github.com/tendermint/go-rpc/server"
"github.com/tendermint/go-rpc/types"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
)
// TODO: better system than "unsafe" prefix
@ -104,19 +106,19 @@ func TxResult(hash []byte, prove bool) (ctypes.TMResult, error) {
return Tx(hash, prove)
}
func BroadcastTxCommitResult(tx []byte) (ctypes.TMResult, error) {
func BroadcastTxCommitResult(tx types.Tx) (ctypes.TMResult, error) {
return BroadcastTxCommit(tx)
}
func BroadcastTxSyncResult(tx []byte) (ctypes.TMResult, error) {
func BroadcastTxSyncResult(tx types.Tx) (ctypes.TMResult, error) {
return BroadcastTxSync(tx)
}
func BroadcastTxAsyncResult(tx []byte) (ctypes.TMResult, error) {
func BroadcastTxAsyncResult(tx types.Tx) (ctypes.TMResult, error) {
return BroadcastTxAsync(tx)
}
func ABCIQueryResult(path string, data []byte, prove bool) (ctypes.TMResult, error) {
func ABCIQueryResult(path string, data data.Bytes, prove bool) (ctypes.TMResult, error) {
return ABCIQuery(path, data, prove)
}


+ 3
- 2
rpc/core/status.go View File

@ -1,6 +1,7 @@
package core
import (
data "github.com/tendermint/go-data"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
)
@ -9,8 +10,8 @@ func Status() (*ctypes.ResultStatus, error) {
latestHeight := blockStore.Height()
var (
latestBlockMeta *types.BlockMeta
latestBlockHash []byte
latestAppHash []byte
latestBlockHash data.Bytes
latestAppHash data.Bytes
latestBlockTime int64
)
if latestHeight != 0 {


+ 4
- 3
rpc/core/types/responses.go View File

@ -5,6 +5,7 @@ import (
abci "github.com/tendermint/abci/types"
"github.com/tendermint/go-crypto"
data "github.com/tendermint/go-data"
"github.com/tendermint/go-p2p"
"github.com/tendermint/go-rpc/types"
"github.com/tendermint/go-wire"
@ -34,8 +35,8 @@ type ResultCommit struct {
type ResultStatus struct {
NodeInfo *p2p.NodeInfo `json:"node_info"`
PubKey crypto.PubKey `json:"pub_key"`
LatestBlockHash []byte `json:"latest_block_hash"`
LatestAppHash []byte `json:"latest_app_hash"`
LatestBlockHash data.Bytes `json:"latest_block_hash"`
LatestAppHash data.Bytes `json:"latest_app_hash"`
LatestBlockHeight int `json:"latest_block_height"`
LatestBlockTime int64 `json:"latest_block_time"` // nano
}
@ -81,7 +82,7 @@ type ResultDumpConsensusState struct {
type ResultBroadcastTx struct {
Code abci.CodeType `json:"code"`
Data []byte `json:"data"`
Data data.Bytes `json:"data"`
Log string `json:"log"`
Hash []byte `json:"hash"`


+ 3
- 4
rpc/test/client_test.go View File

@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/require"
abci "github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
data "github.com/tendermint/go-data"
rpc "github.com/tendermint/go-rpc/client"
"github.com/tendermint/tendermint/rpc/core"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
@ -85,10 +86,10 @@ func testBroadcastTxSync(t *testing.T, client rpc.HTTPClient) {
//--------------------------------------------------------------------------------
// query
func testTxKV(t *testing.T) ([]byte, []byte, []byte) {
func testTxKV(t *testing.T) ([]byte, []byte, types.Tx) {
k := randBytes(t)
v := randBytes(t)
return k, v, []byte(Fmt("%s=%s", k, v))
return k, v, types.Tx(Fmt("%s=%s", k, v))
}
func sendTx(t *testing.T, client rpc.HTTPClient) ([]byte, []byte) {
@ -114,8 +115,6 @@ func testABCIQuery(t *testing.T, client rpc.HTTPClient) {
_, err := client.Call("abci_query",
map[string]interface{}{"path": "", "data": k, "prove": false}, tmResult)
require.Nil(t, err)
resQuery := (*tmResult).(*ctypes.ResultABCIQuery)
require.EqualValues(t, 0, resQuery.Response.Code)
// XXX: specific to value returned by the dummy


Loading…
Cancel
Save