mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-13 21:31:23 +00:00
remove TMResult. ::drinks champagne::
This commit is contained in:
@ -50,42 +50,41 @@ func (c *HTTP) _assertIsEventSwitch() types.EventSwitch {
|
||||
}
|
||||
|
||||
func (c *HTTP) Status() (*ctypes.ResultStatus, error) {
|
||||
tmResult := new(ctypes.TMResult)
|
||||
_, err := c.rpc.Call("status", map[string]interface{}{}, tmResult)
|
||||
result := new(ctypes.ResultStatus)
|
||||
_, err := c.rpc.Call("status", map[string]interface{}{}, result)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Status")
|
||||
}
|
||||
// note: panics if rpc doesn't match. okay???
|
||||
return tmResult.Unwrap().(*ctypes.ResultStatus), nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *HTTP) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
|
||||
tmResult := new(ctypes.TMResult)
|
||||
_, err := c.rpc.Call("abci_info", map[string]interface{}{}, tmResult)
|
||||
result := new(ctypes.ResultABCIInfo)
|
||||
_, err := c.rpc.Call("abci_info", map[string]interface{}{}, result)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "ABCIInfo")
|
||||
}
|
||||
return tmResult.Unwrap().(*ctypes.ResultABCIInfo), nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *HTTP) ABCIQuery(path string, data data.Bytes, prove bool) (*ctypes.ResultABCIQuery, error) {
|
||||
tmResult := new(ctypes.TMResult)
|
||||
result := new(ctypes.ResultABCIQuery)
|
||||
_, err := c.rpc.Call("abci_query",
|
||||
map[string]interface{}{"path": path, "data": data, "prove": prove},
|
||||
tmResult)
|
||||
result)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "ABCIQuery")
|
||||
}
|
||||
return tmResult.Unwrap().(*ctypes.ResultABCIQuery), nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *HTTP) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
||||
tmResult := new(ctypes.TMResult)
|
||||
_, err := c.rpc.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult)
|
||||
result := new(ctypes.ResultBroadcastTxCommit)
|
||||
_, err := c.rpc.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, result)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "broadcast_tx_commit")
|
||||
}
|
||||
return tmResult.Unwrap().(*ctypes.ResultBroadcastTxCommit), nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *HTTP) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
||||
@ -97,90 +96,90 @@ func (c *HTTP) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
||||
}
|
||||
|
||||
func (c *HTTP) broadcastTX(route string, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
||||
tmResult := new(ctypes.TMResult)
|
||||
_, err := c.rpc.Call(route, map[string]interface{}{"tx": tx}, tmResult)
|
||||
result := new(ctypes.ResultBroadcastTx)
|
||||
_, err := c.rpc.Call(route, map[string]interface{}{"tx": tx}, result)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, route)
|
||||
}
|
||||
return tmResult.Unwrap().(*ctypes.ResultBroadcastTx), nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *HTTP) NetInfo() (*ctypes.ResultNetInfo, error) {
|
||||
tmResult := new(ctypes.TMResult)
|
||||
_, err := c.rpc.Call("net_info", map[string]interface{}{}, tmResult)
|
||||
result := new(ctypes.ResultNetInfo)
|
||||
_, err := c.rpc.Call("net_info", map[string]interface{}{}, result)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "NetInfo")
|
||||
}
|
||||
return tmResult.Unwrap().(*ctypes.ResultNetInfo), nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *HTTP) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
|
||||
tmResult := new(ctypes.TMResult)
|
||||
_, err := c.rpc.Call("dump_consensus_state", map[string]interface{}{}, tmResult)
|
||||
result := new(ctypes.ResultDumpConsensusState)
|
||||
_, err := c.rpc.Call("dump_consensus_state", map[string]interface{}{}, result)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "DumpConsensusState")
|
||||
}
|
||||
return tmResult.Unwrap().(*ctypes.ResultDumpConsensusState), nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *HTTP) BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error) {
|
||||
tmResult := new(ctypes.TMResult)
|
||||
result := new(ctypes.ResultBlockchainInfo)
|
||||
_, err := c.rpc.Call("blockchain",
|
||||
map[string]interface{}{"minHeight": minHeight, "maxHeight": maxHeight},
|
||||
tmResult)
|
||||
result)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "BlockchainInfo")
|
||||
}
|
||||
return tmResult.Unwrap().(*ctypes.ResultBlockchainInfo), nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *HTTP) Genesis() (*ctypes.ResultGenesis, error) {
|
||||
tmResult := new(ctypes.TMResult)
|
||||
_, err := c.rpc.Call("genesis", map[string]interface{}{}, tmResult)
|
||||
result := new(ctypes.ResultGenesis)
|
||||
_, err := c.rpc.Call("genesis", map[string]interface{}{}, result)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Genesis")
|
||||
}
|
||||
return tmResult.Unwrap().(*ctypes.ResultGenesis), nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *HTTP) Block(height int) (*ctypes.ResultBlock, error) {
|
||||
tmResult := new(ctypes.TMResult)
|
||||
_, err := c.rpc.Call("block", map[string]interface{}{"height": height}, tmResult)
|
||||
result := new(ctypes.ResultBlock)
|
||||
_, err := c.rpc.Call("block", map[string]interface{}{"height": height}, result)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Block")
|
||||
}
|
||||
return tmResult.Unwrap().(*ctypes.ResultBlock), nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *HTTP) Commit(height int) (*ctypes.ResultCommit, error) {
|
||||
tmResult := new(ctypes.TMResult)
|
||||
_, err := c.rpc.Call("commit", map[string]interface{}{"height": height}, tmResult)
|
||||
result := new(ctypes.ResultCommit)
|
||||
_, err := c.rpc.Call("commit", map[string]interface{}{"height": height}, result)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Commit")
|
||||
}
|
||||
return tmResult.Unwrap().(*ctypes.ResultCommit), nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *HTTP) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
||||
tmResult := new(ctypes.TMResult)
|
||||
result := new(ctypes.ResultTx)
|
||||
query := map[string]interface{}{
|
||||
"hash": hash,
|
||||
"prove": prove,
|
||||
}
|
||||
_, err := c.rpc.Call("tx", query, tmResult)
|
||||
_, err := c.rpc.Call("tx", query, result)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Tx")
|
||||
}
|
||||
return tmResult.Unwrap().(*ctypes.ResultTx), nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *HTTP) Validators() (*ctypes.ResultValidators, error) {
|
||||
tmResult := new(ctypes.TMResult)
|
||||
_, err := c.rpc.Call("validators", map[string]interface{}{}, tmResult)
|
||||
result := new(ctypes.ResultValidators)
|
||||
_, err := c.rpc.Call("validators", map[string]interface{}{}, result)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Validators")
|
||||
}
|
||||
return tmResult.Unwrap().(*ctypes.ResultValidators), nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
/** websocket event stuff here... **/
|
||||
@ -335,18 +334,15 @@ func (w *WSEvents) eventListener() {
|
||||
// some implementation of types.TMEventData, and sends it off
|
||||
// on the merry way to the EventSwitch
|
||||
func (w *WSEvents) parseEvent(data []byte) (err error) {
|
||||
result := new(ctypes.TMResult)
|
||||
result := new(ctypes.ResultEvent)
|
||||
err = json.Unmarshal(data, result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
event, ok := result.Unwrap().(*ctypes.ResultEvent)
|
||||
if !ok {
|
||||
// ignore silently (eg. subscribe, unsubscribe and maybe other events)
|
||||
// TODO: ?
|
||||
return nil
|
||||
}
|
||||
// looks good! let's fire this baby!
|
||||
w.EventSwitch.FireEvent(event.Name, event.Data)
|
||||
w.EventSwitch.FireEvent(result.Name, result.Data)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,8 @@ func Subscribe(wsCtx rpctypes.WSRPCContext, event string) (*ctypes.ResultSubscri
|
||||
types.AddListenerForEvent(wsCtx.GetEventSwitch(), wsCtx.GetRemoteAddr(), event, func(msg types.TMEventData) {
|
||||
// NOTE: EventSwitch callbacks must be nonblocking
|
||||
// NOTE: RPCResponses of subscribed events have id suffix "#event"
|
||||
tmResult := ctypes.TMResult{&ctypes.ResultEvent{event, msg}}
|
||||
wsCtx.TryWriteRPCResponse(rpctypes.NewRPCResponse(wsCtx.Request.ID+"#event", &tmResult, ""))
|
||||
tmResult := &ctypes.ResultEvent{event, msg}
|
||||
wsCtx.TryWriteRPCResponse(rpctypes.NewRPCResponse(wsCtx.Request.ID+"#event", tmResult, ""))
|
||||
})
|
||||
return &ctypes.ResultSubscribe{}, nil
|
||||
}
|
||||
|
@ -1,173 +1,46 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
data "github.com/tendermint/go-wire/data"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
rpc "github.com/tendermint/tendermint/rpc/lib/server"
|
||||
"github.com/tendermint/tendermint/rpc/lib/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
// TODO: better system than "unsafe" prefix
|
||||
var Routes = map[string]*rpc.RPCFunc{
|
||||
// subscribe/unsubscribe are reserved for websocket events.
|
||||
"subscribe": rpc.NewWSRPCFunc(SubscribeResult, "event"),
|
||||
"unsubscribe": rpc.NewWSRPCFunc(UnsubscribeResult, "event"),
|
||||
"subscribe": rpc.NewWSRPCFunc(Subscribe, "event"),
|
||||
"unsubscribe": rpc.NewWSRPCFunc(Unsubscribe, "event"),
|
||||
|
||||
// info API
|
||||
"status": rpc.NewRPCFunc(StatusResult, ""),
|
||||
"net_info": rpc.NewRPCFunc(NetInfoResult, ""),
|
||||
"blockchain": rpc.NewRPCFunc(BlockchainInfoResult, "minHeight,maxHeight"),
|
||||
"genesis": rpc.NewRPCFunc(GenesisResult, ""),
|
||||
"block": rpc.NewRPCFunc(BlockResult, "height"),
|
||||
"commit": rpc.NewRPCFunc(CommitResult, "height"),
|
||||
"tx": rpc.NewRPCFunc(TxResult, "hash,prove"),
|
||||
"validators": rpc.NewRPCFunc(ValidatorsResult, ""),
|
||||
"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusStateResult, ""),
|
||||
"unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxsResult, ""),
|
||||
"num_unconfirmed_txs": rpc.NewRPCFunc(NumUnconfirmedTxsResult, ""),
|
||||
"status": rpc.NewRPCFunc(Status, ""),
|
||||
"net_info": rpc.NewRPCFunc(NetInfo, ""),
|
||||
"blockchain": rpc.NewRPCFunc(BlockchainInfo, "minHeight,maxHeight"),
|
||||
"genesis": rpc.NewRPCFunc(Genesis, ""),
|
||||
"block": rpc.NewRPCFunc(Block, "height"),
|
||||
"commit": rpc.NewRPCFunc(Commit, "height"),
|
||||
"tx": rpc.NewRPCFunc(Tx, "hash,prove"),
|
||||
"validators": rpc.NewRPCFunc(Validators, ""),
|
||||
"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusState, ""),
|
||||
"unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxs, ""),
|
||||
"num_unconfirmed_txs": rpc.NewRPCFunc(NumUnconfirmedTxs, ""),
|
||||
|
||||
// broadcast API
|
||||
"broadcast_tx_commit": rpc.NewRPCFunc(BroadcastTxCommitResult, "tx"),
|
||||
"broadcast_tx_sync": rpc.NewRPCFunc(BroadcastTxSyncResult, "tx"),
|
||||
"broadcast_tx_async": rpc.NewRPCFunc(BroadcastTxAsyncResult, "tx"),
|
||||
"broadcast_tx_commit": rpc.NewRPCFunc(BroadcastTxCommit, "tx"),
|
||||
"broadcast_tx_sync": rpc.NewRPCFunc(BroadcastTxSync, "tx"),
|
||||
"broadcast_tx_async": rpc.NewRPCFunc(BroadcastTxAsync, "tx"),
|
||||
|
||||
// abci API
|
||||
"abci_query": rpc.NewRPCFunc(ABCIQueryResult, "path,data,prove"),
|
||||
"abci_info": rpc.NewRPCFunc(ABCIInfoResult, ""),
|
||||
"abci_query": rpc.NewRPCFunc(ABCIQuery, "path,data,prove"),
|
||||
"abci_info": rpc.NewRPCFunc(ABCIInfo, ""),
|
||||
|
||||
// control API
|
||||
"dial_seeds": rpc.NewRPCFunc(UnsafeDialSeedsResult, "seeds"),
|
||||
"dial_seeds": rpc.NewRPCFunc(UnsafeDialSeeds, "seeds"),
|
||||
"unsafe_flush_mempool": rpc.NewRPCFunc(UnsafeFlushMempool, ""),
|
||||
|
||||
// config is not in general thread safe. expose specifics if you need em
|
||||
// "unsafe_set_config": rpc.NewRPCFunc(UnsafeSetConfigResult, "type,key,value"),
|
||||
// "unsafe_set_config": rpc.NewRPCFunc(UnsafeSetConfig, "type,key,value"),
|
||||
|
||||
// profiler API
|
||||
"unsafe_start_cpu_profiler": rpc.NewRPCFunc(UnsafeStartCPUProfilerResult, "filename"),
|
||||
"unsafe_stop_cpu_profiler": rpc.NewRPCFunc(UnsafeStopCPUProfilerResult, ""),
|
||||
"unsafe_write_heap_profile": rpc.NewRPCFunc(UnsafeWriteHeapProfileResult, "filename"),
|
||||
}
|
||||
|
||||
func SubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
|
||||
res, err := Subscribe(wsCtx, event)
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func UnsubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
|
||||
res, err := Unsubscribe(wsCtx, event)
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func StatusResult() (ctypes.TMResult, error) {
|
||||
res, err := Status()
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func NetInfoResult() (ctypes.TMResult, error) {
|
||||
res, err := NetInfo()
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func UnsafeDialSeedsResult(seeds []string) (ctypes.TMResult, error) {
|
||||
res, err := UnsafeDialSeeds(seeds)
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func BlockchainInfoResult(min, max int) (ctypes.TMResult, error) {
|
||||
res, err := BlockchainInfo(min, max)
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func GenesisResult() (ctypes.TMResult, error) {
|
||||
res, err := Genesis()
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func BlockResult(height int) (ctypes.TMResult, error) {
|
||||
res, err := Block(height)
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func CommitResult(height int) (ctypes.TMResult, error) {
|
||||
res, err := Commit(height)
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func ValidatorsResult() (ctypes.TMResult, error) {
|
||||
res, err := Validators()
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func DumpConsensusStateResult() (ctypes.TMResult, error) {
|
||||
res, err := DumpConsensusState()
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func UnconfirmedTxsResult() (ctypes.TMResult, error) {
|
||||
res, err := UnconfirmedTxs()
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func NumUnconfirmedTxsResult() (ctypes.TMResult, error) {
|
||||
res, err := NumUnconfirmedTxs()
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
// Tx allow user to query the transaction results. `nil` could mean the
|
||||
// transaction is in the mempool, invalidated, or was not send in the first
|
||||
// place.
|
||||
func TxResult(hash []byte, prove bool) (ctypes.TMResult, error) {
|
||||
res, err := Tx(hash, prove)
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func BroadcastTxCommitResult(tx types.Tx) (ctypes.TMResult, error) {
|
||||
res, err := BroadcastTxCommit(tx)
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func BroadcastTxSyncResult(tx types.Tx) (ctypes.TMResult, error) {
|
||||
res, err := BroadcastTxSync(tx)
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func BroadcastTxAsyncResult(tx types.Tx) (ctypes.TMResult, error) {
|
||||
res, err := BroadcastTxAsync(tx)
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func ABCIQueryResult(path string, data data.Bytes, prove bool) (ctypes.TMResult, error) {
|
||||
res, err := ABCIQuery(path, data, prove)
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func ABCIInfoResult() (ctypes.TMResult, error) {
|
||||
res, err := ABCIInfo()
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func UnsafeFlushMempoolResult() (ctypes.TMResult, error) {
|
||||
res, err := UnsafeFlushMempool()
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func UnsafeSetConfigResult(typ, key, value string) (ctypes.TMResult, error) {
|
||||
res, err := UnsafeSetConfig(typ, key, value)
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func UnsafeStartCPUProfilerResult(filename string) (ctypes.TMResult, error) {
|
||||
res, err := UnsafeStartCPUProfiler(filename)
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func UnsafeStopCPUProfilerResult() (ctypes.TMResult, error) {
|
||||
res, err := UnsafeStopCPUProfiler()
|
||||
return ctypes.TMResult{res}, err
|
||||
}
|
||||
|
||||
func UnsafeWriteHeapProfileResult(filename string) (ctypes.TMResult, error) {
|
||||
res, err := UnsafeWriteHeapProfile(filename)
|
||||
return ctypes.TMResult{res}, err
|
||||
"unsafe_start_cpu_profiler": rpc.NewRPCFunc(UnsafeStartCPUProfiler, "filename"),
|
||||
"unsafe_stop_cpu_profiler": rpc.NewRPCFunc(UnsafeStopCPUProfiler, ""),
|
||||
"unsafe_write_heap_profile": rpc.NewRPCFunc(UnsafeWriteHeapProfile, "filename"),
|
||||
}
|
||||
|
@ -8,6 +8,9 @@ import (
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
// Tx allow user to query the transaction results. `nil` could mean the
|
||||
// transaction is in the mempool, invalidated, or was not send in the first
|
||||
// place.
|
||||
func Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
||||
|
||||
// if index is disabled, return error
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"github.com/tendermint/go-crypto"
|
||||
"github.com/tendermint/go-wire/data"
|
||||
"github.com/tendermint/tendermint/p2p"
|
||||
"github.com/tendermint/tendermint/rpc/lib/types"
|
||||
// "github.com/tendermint/tendermint/rpc/lib/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
@ -212,60 +212,3 @@ const (
|
||||
ResultNameUnsafeWriteHeapProfile = "unsafe_write_heap"
|
||||
ResultNameUnsafeFlushMempool = "unsafe_flush_mempool"
|
||||
)
|
||||
|
||||
type TMResultInner interface {
|
||||
rpctypes.Result
|
||||
}
|
||||
|
||||
type TMResult struct {
|
||||
TMResultInner `json:"unwrap"`
|
||||
}
|
||||
|
||||
func (tmr TMResult) MarshalJSON() ([]byte, error) {
|
||||
return tmResultMapper.ToJSON(tmr.TMResultInner)
|
||||
}
|
||||
|
||||
func (tmr *TMResult) UnmarshalJSON(data []byte) (err error) {
|
||||
parsed, err := tmResultMapper.FromJSON(data)
|
||||
if err == nil && parsed != nil {
|
||||
tmr.TMResultInner = parsed.(TMResultInner)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (tmr TMResult) Unwrap() TMResultInner {
|
||||
tmrI := tmr.TMResultInner
|
||||
for wrap, ok := tmrI.(TMResult); ok; wrap, ok = tmrI.(TMResult) {
|
||||
tmrI = wrap.TMResultInner
|
||||
}
|
||||
return tmrI
|
||||
}
|
||||
|
||||
func (tmr TMResult) Empty() bool {
|
||||
return tmr.TMResultInner == nil
|
||||
}
|
||||
|
||||
var tmResultMapper = data.NewMapper(TMResult{}).
|
||||
RegisterImplementation(&ResultGenesis{}, ResultNameGenesis, ResultTypeGenesis).
|
||||
RegisterImplementation(&ResultBlockchainInfo{}, ResultNameBlockchainInfo, ResultTypeBlockchainInfo).
|
||||
RegisterImplementation(&ResultBlock{}, ResultNameBlock, ResultTypeBlock).
|
||||
RegisterImplementation(&ResultCommit{}, ResultNameCommit, ResultTypeCommit).
|
||||
RegisterImplementation(&ResultStatus{}, ResultNameStatus, ResultTypeStatus).
|
||||
RegisterImplementation(&ResultNetInfo{}, ResultNameNetInfo, ResultTypeNetInfo).
|
||||
RegisterImplementation(&ResultDialSeeds{}, ResultNameDialSeeds, ResultTypeDialSeeds).
|
||||
RegisterImplementation(&ResultValidators{}, ResultNameValidators, ResultTypeValidators).
|
||||
RegisterImplementation(&ResultDumpConsensusState{}, ResultNameDumpConsensusState, ResultTypeDumpConsensusState).
|
||||
RegisterImplementation(&ResultBroadcastTx{}, ResultNameBroadcastTx, ResultTypeBroadcastTx).
|
||||
RegisterImplementation(&ResultBroadcastTxCommit{}, ResultNameBroadcastTxCommit, ResultTypeBroadcastTxCommit).
|
||||
RegisterImplementation(&ResultTx{}, ResultNameTx, ResultTypeTx).
|
||||
RegisterImplementation(&ResultUnconfirmedTxs{}, ResultNameUnconfirmedTxs, ResultTypeUnconfirmedTxs).
|
||||
RegisterImplementation(&ResultSubscribe{}, ResultNameSubscribe, ResultTypeSubscribe).
|
||||
RegisterImplementation(&ResultUnsubscribe{}, ResultNameUnsubscribe, ResultTypeUnsubscribe).
|
||||
RegisterImplementation(&ResultEvent{}, ResultNameEvent, ResultTypeEvent).
|
||||
RegisterImplementation(&ResultUnsafeSetConfig{}, ResultNameUnsafeSetConfig, ResultTypeUnsafeSetConfig).
|
||||
RegisterImplementation(&ResultUnsafeProfile{}, ResultNameUnsafeStartCPUProfiler, ResultTypeUnsafeStartCPUProfiler).
|
||||
RegisterImplementation(&ResultUnsafeProfile{}, ResultNameUnsafeStopCPUProfiler, ResultTypeUnsafeStopCPUProfiler).
|
||||
RegisterImplementation(&ResultUnsafeProfile{}, ResultNameUnsafeWriteHeapProfile, ResultTypeUnsafeWriteHeapProfile).
|
||||
RegisterImplementation(&ResultUnsafeFlushMempool{}, ResultNameUnsafeFlushMempool, ResultTypeUnsafeFlushMempool).
|
||||
RegisterImplementation(&ResultABCIQuery{}, ResultNameABCIQuery, ResultTypeABCIQuery).
|
||||
RegisterImplementation(&ResultABCIInfo{}, ResultNameABCIInfo, ResultTypeABCIInfo)
|
||||
|
@ -39,12 +39,11 @@ func TestJSONStatus(t *testing.T) {
|
||||
|
||||
func testStatus(t *testing.T, client rpc.HTTPClient) {
|
||||
chainID := GetConfig().GetString("chain_id")
|
||||
tmResult := new(ctypes.TMResult)
|
||||
_, err := client.Call("status", map[string]interface{}{}, tmResult)
|
||||
result := new(ctypes.ResultStatus)
|
||||
_, err := client.Call("status", map[string]interface{}{}, result)
|
||||
require.Nil(t, err)
|
||||
|
||||
status := tmResult.Unwrap().(*ctypes.ResultStatus)
|
||||
assert.Equal(t, chainID, status.NodeInfo.Network)
|
||||
assert.Equal(t, chainID, result.NodeInfo.Network)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
@ -70,13 +69,12 @@ func TestJSONBroadcastTxSync(t *testing.T) {
|
||||
func testBroadcastTxSync(t *testing.T, client rpc.HTTPClient) {
|
||||
mem := node.MempoolReactor().Mempool
|
||||
initMemSize := mem.Size()
|
||||
tmResult := new(ctypes.TMResult)
|
||||
result := new(ctypes.ResultBroadcastTx)
|
||||
tx := randBytes(t)
|
||||
_, err := client.Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, tmResult)
|
||||
_, err := client.Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, result)
|
||||
require.Nil(t, err)
|
||||
|
||||
res := tmResult.Unwrap().(*ctypes.ResultBroadcastTx)
|
||||
require.Equal(t, abci.CodeType_OK, res.Code)
|
||||
require.Equal(t, abci.CodeType_OK, result.Code)
|
||||
require.Equal(t, initMemSize+1, mem.Size())
|
||||
txs := mem.Reap(1)
|
||||
require.EqualValues(t, tx, txs[0])
|
||||
@ -93,14 +91,13 @@ func testTxKV(t *testing.T) ([]byte, []byte, types.Tx) {
|
||||
}
|
||||
|
||||
func sendTx(t *testing.T, client rpc.HTTPClient) ([]byte, []byte) {
|
||||
tmResult := new(ctypes.TMResult)
|
||||
result := new(ctypes.ResultBroadcastTxCommit)
|
||||
k, v, tx := testTxKV(t)
|
||||
_, err := client.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult)
|
||||
_, err := client.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, result)
|
||||
require.Nil(t, err)
|
||||
bres := tmResult.Unwrap().(*ctypes.ResultBroadcastTxCommit)
|
||||
require.NotNil(t, 0, bres.DeliverTx, "%#v", bres)
|
||||
require.EqualValues(t, 0, bres.CheckTx.Code, "%#v", bres)
|
||||
require.EqualValues(t, 0, bres.DeliverTx.Code, "%#v", bres)
|
||||
require.NotNil(t, 0, result.DeliverTx, "%#v", result)
|
||||
require.EqualValues(t, 0, result.CheckTx.Code, "%#v", result)
|
||||
require.EqualValues(t, 0, result.DeliverTx.Code, "%#v", result)
|
||||
return k, v
|
||||
}
|
||||
|
||||
@ -115,16 +112,15 @@ func TestJSONABCIQuery(t *testing.T) {
|
||||
func testABCIQuery(t *testing.T, client rpc.HTTPClient) {
|
||||
k, _ := sendTx(t, client)
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
tmResult := new(ctypes.TMResult)
|
||||
result := new(ctypes.ResultABCIQuery)
|
||||
_, err := client.Call("abci_query",
|
||||
map[string]interface{}{"path": "", "data": data.Bytes(k), "prove": false}, tmResult)
|
||||
map[string]interface{}{"path": "", "data": data.Bytes(k), "prove": false}, result)
|
||||
require.Nil(t, err)
|
||||
|
||||
resQuery := tmResult.Unwrap().(*ctypes.ResultABCIQuery)
|
||||
require.EqualValues(t, 0, resQuery.Code)
|
||||
require.EqualValues(t, 0, result.Code)
|
||||
|
||||
// XXX: specific to value returned by the dummy
|
||||
require.NotEqual(t, 0, len(resQuery.Value))
|
||||
require.NotEqual(t, 0, len(result.Value))
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
@ -141,15 +137,14 @@ func TestJSONBroadcastTxCommit(t *testing.T) {
|
||||
func testBroadcastTxCommit(t *testing.T, client rpc.HTTPClient) {
|
||||
require := require.New(t)
|
||||
|
||||
tmResult := new(ctypes.TMResult)
|
||||
result := new(ctypes.ResultBroadcastTxCommit)
|
||||
tx := randBytes(t)
|
||||
_, err := client.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult)
|
||||
_, err := client.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, result)
|
||||
require.Nil(err)
|
||||
|
||||
res := tmResult.Unwrap().(*ctypes.ResultBroadcastTxCommit)
|
||||
checkTx := res.CheckTx
|
||||
checkTx := result.CheckTx
|
||||
require.Equal(abci.CodeType_OK, checkTx.Code)
|
||||
deliverTx := res.DeliverTx
|
||||
deliverTx := result.DeliverTx
|
||||
require.Equal(abci.CodeType_OK, deliverTx.Code)
|
||||
mem := node.MempoolReactor().Mempool
|
||||
require.Equal(0, mem.Size())
|
||||
@ -179,16 +174,15 @@ func testTx(t *testing.T, client rpc.HTTPClient, withIndexer bool) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
|
||||
// first we broadcast a tx
|
||||
tmResult := new(ctypes.TMResult)
|
||||
result := new(ctypes.ResultBroadcastTxCommit)
|
||||
txBytes := randBytes(t)
|
||||
tx := types.Tx(txBytes)
|
||||
_, err := client.Call("broadcast_tx_commit", map[string]interface{}{"tx": txBytes}, tmResult)
|
||||
_, err := client.Call("broadcast_tx_commit", map[string]interface{}{"tx": txBytes}, result)
|
||||
require.Nil(err)
|
||||
|
||||
res := tmResult.Unwrap().(*ctypes.ResultBroadcastTxCommit)
|
||||
checkTx := res.CheckTx
|
||||
checkTx := result.CheckTx
|
||||
require.Equal(abci.CodeType_OK, checkTx.Code)
|
||||
deliverTx := res.DeliverTx
|
||||
deliverTx := result.DeliverTx
|
||||
require.Equal(abci.CodeType_OK, deliverTx.Code)
|
||||
mem := node.MempoolReactor().Mempool
|
||||
require.Equal(0, mem.Size())
|
||||
@ -215,24 +209,23 @@ func testTx(t *testing.T, client rpc.HTTPClient, withIndexer bool) {
|
||||
|
||||
// now we query for the tx.
|
||||
// since there's only one tx, we know index=0.
|
||||
tmResult = new(ctypes.TMResult)
|
||||
result2 := new(ctypes.ResultTx)
|
||||
query := map[string]interface{}{
|
||||
"hash": tc.hash,
|
||||
"prove": tc.prove,
|
||||
}
|
||||
_, err = client.Call("tx", query, tmResult)
|
||||
_, err = client.Call("tx", query, result2)
|
||||
valid := (withIndexer && tc.valid)
|
||||
if !valid {
|
||||
require.NotNil(err, idx)
|
||||
} else {
|
||||
require.Nil(err, idx)
|
||||
res2 := tmResult.Unwrap().(*ctypes.ResultTx)
|
||||
assert.Equal(tx, res2.Tx, idx)
|
||||
assert.Equal(res.Height, res2.Height, idx)
|
||||
assert.Equal(0, res2.Index, idx)
|
||||
assert.Equal(abci.CodeType_OK, res2.TxResult.Code, idx)
|
||||
assert.Equal(tx, result2.Tx, idx)
|
||||
assert.Equal(result.Height, result2.Height, idx)
|
||||
assert.Equal(0, result2.Index, idx)
|
||||
assert.Equal(abci.CodeType_OK, result2.TxResult.Code, idx)
|
||||
// time to verify the proof
|
||||
proof := res2.Proof
|
||||
proof := result2.Proof
|
||||
if tc.prove && assert.Equal(tx, proof.Data, idx) {
|
||||
assert.True(proof.Proof.Verify(proof.Index, proof.Total, tx.Hash(), proof.RootHash), idx)
|
||||
}
|
||||
@ -316,8 +309,8 @@ func TestWSTxEvent(t *testing.T) {
|
||||
}()
|
||||
|
||||
// send an tx
|
||||
tmResult := new(ctypes.TMResult)
|
||||
_, err := GetJSONClient().Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, tmResult)
|
||||
result := new(ctypes.ResultBroadcastTx)
|
||||
_, err := GetJSONClient().Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, result)
|
||||
require.Nil(err)
|
||||
|
||||
waitForEvent(t, wsc, eid, true, func() {}, func(eid string, b interface{}) error {
|
||||
@ -374,12 +367,12 @@ func TestWSDoubleFire(t *testing.T) {
|
||||
//
|
||||
//func TestURIUnsafeSetConfig(t *testing.T) {
|
||||
// for _, testCase := range testCasesUnsafeSetConfig {
|
||||
// tmResult := new(ctypes.TMResult)
|
||||
// result := new(ctypes.TMResult)
|
||||
// _, err := GetURIClient().Call("unsafe_set_config", map[string]interface{}{
|
||||
// "type": testCase[0],
|
||||
// "key": testCase[1],
|
||||
// "value": testCase[2],
|
||||
// }, tmResult)
|
||||
// }, result)
|
||||
// require.Nil(t, err)
|
||||
// }
|
||||
// testUnsafeSetConfig(t)
|
||||
@ -387,10 +380,10 @@ func TestWSDoubleFire(t *testing.T) {
|
||||
//
|
||||
//func TestJSONUnsafeSetConfig(t *testing.T) {
|
||||
// for _, testCase := range testCasesUnsafeSetConfig {
|
||||
// tmResult := new(ctypes.TMResult)
|
||||
// result := new(ctypes.TMResult)
|
||||
// _, err := GetJSONClient().Call("unsafe_set_config",
|
||||
// map[string]interface{}{"type": testCase[0], "key": testCase[1], "value": testCase[2]},
|
||||
// tmResult)
|
||||
// result)
|
||||
// require.Nil(t, err)
|
||||
// }
|
||||
// testUnsafeSetConfig(t)
|
||||
|
@ -132,16 +132,15 @@ func waitForEvent(t *testing.T, wsc *client.WSClient, eventid string, dieOnTimeo
|
||||
select {
|
||||
case r := <-wsc.ResultsCh:
|
||||
fmt.Println("GOT IT", string(r))
|
||||
result := new(ctypes.TMResult)
|
||||
result := new(ctypes.ResultEvent)
|
||||
err = json.Unmarshal(r, result)
|
||||
if err != nil {
|
||||
fmt.Println("POOP", err)
|
||||
errCh <- err
|
||||
break LOOP
|
||||
// cant distinguish between error and wrong type ...
|
||||
continue
|
||||
}
|
||||
event, ok := result.Unwrap().(*ctypes.ResultEvent)
|
||||
if ok && event.Name == eventid {
|
||||
goodCh <- event.Data
|
||||
if result.Name == eventid {
|
||||
goodCh <- result.Data
|
||||
break LOOP
|
||||
}
|
||||
case err := <-wsc.ErrorsCh:
|
||||
|
Reference in New Issue
Block a user