mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-19 14:34:17 +00:00
Support new Query message for proofs
This commit is contained in:
+16
-13
@@ -1,25 +1,28 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
abci "github.com/tendermint/abci/types"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
func ABCIQuery(query []byte) (*ctypes.ResultABCIQuery, error) {
|
||||
res := proxyAppQuery.QuerySync(query)
|
||||
return &ctypes.ResultABCIQuery{res}, nil
|
||||
}
|
||||
|
||||
func ABCIInfo() (*ctypes.ResultABCIInfo, error) {
|
||||
res, err := proxyAppQuery.InfoSync()
|
||||
func ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultABCIQuery, error) {
|
||||
resQuery, err := proxyAppQuery.QuerySync(abci.RequestQuery{
|
||||
Path: path,
|
||||
Data: data,
|
||||
Prove: prove,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ctypes.ResultABCIInfo{
|
||||
Data: res.Data,
|
||||
Version: res.Version,
|
||||
LastBlockHeight: res.LastBlockHeight,
|
||||
LastBlockAppHash: res.LastBlockAppHash,
|
||||
}, nil
|
||||
return &ctypes.ResultABCIQuery{resQuery}, nil
|
||||
}
|
||||
|
||||
func ABCIInfo() (*ctypes.ResultABCIInfo, error) {
|
||||
resInfo, err := proxyAppQuery.InfoSync()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ctypes.ResultABCIInfo{resInfo}, nil
|
||||
}
|
||||
|
||||
+3
-3
@@ -29,7 +29,7 @@ var Routes = map[string]*rpc.RPCFunc{
|
||||
"broadcast_tx_async": rpc.NewRPCFunc(BroadcastTxAsyncResult, "tx"),
|
||||
|
||||
// abci API
|
||||
"abci_query": rpc.NewRPCFunc(ABCIQueryResult, "query"),
|
||||
"abci_query": rpc.NewRPCFunc(ABCIQueryResult, "path,data,prove"),
|
||||
"abci_info": rpc.NewRPCFunc(ABCIInfoResult, ""),
|
||||
|
||||
// control API
|
||||
@@ -163,8 +163,8 @@ func BroadcastTxAsyncResult(tx []byte) (ctypes.TMResult, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func ABCIQueryResult(query []byte) (ctypes.TMResult, error) {
|
||||
if r, err := ABCIQuery(query); err != nil {
|
||||
func ABCIQueryResult(path string, data []byte, prove bool) (ctypes.TMResult, error) {
|
||||
if r, err := ABCIQuery(path, data, prove); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return r, nil
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package core_types
|
||||
|
||||
import (
|
||||
abci "github.com/tendermint/abci/types"
|
||||
"github.com/tendermint/go-crypto"
|
||||
"github.com/tendermint/go-p2p"
|
||||
"github.com/tendermint/go-rpc/types"
|
||||
"github.com/tendermint/go-wire"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
abci "github.com/tendermint/abci/types"
|
||||
)
|
||||
|
||||
type ResultBlockchainInfo struct {
|
||||
@@ -64,7 +64,7 @@ type ResultBroadcastTx struct {
|
||||
}
|
||||
|
||||
type ResultBroadcastTxCommit struct {
|
||||
CheckTx *abci.ResponseCheckTx `json:"check_tx"`
|
||||
CheckTx *abci.ResponseCheckTx `json:"check_tx"`
|
||||
DeliverTx *abci.ResponseDeliverTx `json:"deliver_tx"`
|
||||
}
|
||||
|
||||
@@ -74,14 +74,11 @@ type ResultUnconfirmedTxs struct {
|
||||
}
|
||||
|
||||
type ResultABCIInfo struct {
|
||||
Data string `json:"data"`
|
||||
Version string `json:"version"`
|
||||
LastBlockHeight uint64 `json:"last_block_height"`
|
||||
LastBlockAppHash []byte `json:"last_block_app_hash"`
|
||||
Response abci.ResponseInfo `json:"response"`
|
||||
}
|
||||
|
||||
type ResultABCIQuery struct {
|
||||
Result abci.Result `json:"result"`
|
||||
Response abci.ResponseQuery `json:"response"`
|
||||
}
|
||||
|
||||
type ResultUnsafeFlushMempool struct{}
|
||||
|
||||
+8
-14
@@ -8,12 +8,10 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
abci "github.com/tendermint/abci/types"
|
||||
. "github.com/tendermint/go-common"
|
||||
"github.com/tendermint/go-wire"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
"github.com/tendermint/abci/example/dummy"
|
||||
abci "github.com/tendermint/abci/types"
|
||||
)
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
@@ -134,7 +132,7 @@ func TestURIABCIQuery(t *testing.T) {
|
||||
k, v := sendTx()
|
||||
time.Sleep(time.Second)
|
||||
tmResult := new(ctypes.TMResult)
|
||||
_, err := clientURI.Call("abci_query", map[string]interface{}{"query": k}, tmResult)
|
||||
_, err := clientURI.Call("abci_query", map[string]interface{}{"path": "", "data": k, "prove": false}, tmResult)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -144,7 +142,7 @@ func TestURIABCIQuery(t *testing.T) {
|
||||
func TestJSONABCIQuery(t *testing.T) {
|
||||
k, v := sendTx()
|
||||
tmResult := new(ctypes.TMResult)
|
||||
_, err := clientJSON.Call("abci_query", []interface{}{k}, tmResult)
|
||||
_, err := clientJSON.Call("abci_query", []interface{}{"", k, false}, tmResult)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -153,18 +151,14 @@ func TestJSONABCIQuery(t *testing.T) {
|
||||
|
||||
func testABCIQuery(t *testing.T, statusI interface{}, value []byte) {
|
||||
tmRes := statusI.(*ctypes.TMResult)
|
||||
query := (*tmRes).(*ctypes.ResultABCIQuery)
|
||||
if query.Result.IsErr() {
|
||||
panic(Fmt("Query returned an err: %v", query))
|
||||
resQuery := (*tmRes).(*ctypes.ResultABCIQuery)
|
||||
if !resQuery.Response.Code.IsOK() {
|
||||
panic(Fmt("Query returned an err: %v", resQuery))
|
||||
}
|
||||
|
||||
qResult := new(dummy.QueryResult)
|
||||
if err := wire.ReadJSONBytes(query.Result.Data, qResult); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// XXX: specific to value returned by the dummy
|
||||
if qResult.Exists != true {
|
||||
panic(Fmt("Query error. Expected to find 'exists=true'. Got: %v", qResult))
|
||||
if len(resQuery.Response.Value) == 0 {
|
||||
panic(Fmt("Query error. Found no value"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user