mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-11 20:31:20 +00:00
Improve go-data json support in rpc
This commit is contained in:
committed by
Ethan Buchman
parent
6a0217688f
commit
90abc61c56
@ -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},
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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,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,
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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"`
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user