mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-24 10:11:48 +00:00
Prepare rpc responses for go-data compatibility, still use go-wire
This commit is contained in:
@ -4,12 +4,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
data "github.com/tendermint/go-wire/data"
|
|
||||||
events "github.com/tendermint/tmlibs/events"
|
|
||||||
"github.com/tendermint/tendermint/rpc/lib/client"
|
|
||||||
wire "github.com/tendermint/go-wire"
|
wire "github.com/tendermint/go-wire"
|
||||||
|
data "github.com/tendermint/go-wire/data"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
|
"github.com/tendermint/tendermint/rpc/lib/client"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
|
events "github.com/tendermint/tmlibs/events"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -56,7 +56,7 @@ func (c *HTTP) Status() (*ctypes.ResultStatus, error) {
|
|||||||
return nil, errors.Wrap(err, "Status")
|
return nil, errors.Wrap(err, "Status")
|
||||||
}
|
}
|
||||||
// note: panics if rpc doesn't match. okay???
|
// note: panics if rpc doesn't match. okay???
|
||||||
return (*tmResult).(*ctypes.ResultStatus), nil
|
return tmResult.Unwrap().(*ctypes.ResultStatus), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HTTP) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
|
func (c *HTTP) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
|
||||||
@ -65,7 +65,7 @@ func (c *HTTP) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "ABCIInfo")
|
return nil, errors.Wrap(err, "ABCIInfo")
|
||||||
}
|
}
|
||||||
return (*tmResult).(*ctypes.ResultABCIInfo), nil
|
return tmResult.Unwrap().(*ctypes.ResultABCIInfo), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HTTP) ABCIQuery(path string, data data.Bytes, prove bool) (*ctypes.ResultABCIQuery, error) {
|
func (c *HTTP) ABCIQuery(path string, data data.Bytes, prove bool) (*ctypes.ResultABCIQuery, error) {
|
||||||
@ -76,7 +76,7 @@ func (c *HTTP) ABCIQuery(path string, data data.Bytes, prove bool) (*ctypes.Resu
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "ABCIQuery")
|
return nil, errors.Wrap(err, "ABCIQuery")
|
||||||
}
|
}
|
||||||
return (*tmResult).(*ctypes.ResultABCIQuery), nil
|
return tmResult.Unwrap().(*ctypes.ResultABCIQuery), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HTTP) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
func (c *HTTP) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
||||||
@ -85,7 +85,7 @@ func (c *HTTP) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "broadcast_tx_commit")
|
return nil, errors.Wrap(err, "broadcast_tx_commit")
|
||||||
}
|
}
|
||||||
return (*tmResult).(*ctypes.ResultBroadcastTxCommit), nil
|
return tmResult.Unwrap().(*ctypes.ResultBroadcastTxCommit), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HTTP) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
func (c *HTTP) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
||||||
@ -102,7 +102,7 @@ func (c *HTTP) broadcastTX(route string, tx types.Tx) (*ctypes.ResultBroadcastTx
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, route)
|
return nil, errors.Wrap(err, route)
|
||||||
}
|
}
|
||||||
return (*tmResult).(*ctypes.ResultBroadcastTx), nil
|
return tmResult.Unwrap().(*ctypes.ResultBroadcastTx), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HTTP) NetInfo() (*ctypes.ResultNetInfo, error) {
|
func (c *HTTP) NetInfo() (*ctypes.ResultNetInfo, error) {
|
||||||
@ -111,7 +111,7 @@ func (c *HTTP) NetInfo() (*ctypes.ResultNetInfo, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "NetInfo")
|
return nil, errors.Wrap(err, "NetInfo")
|
||||||
}
|
}
|
||||||
return (*tmResult).(*ctypes.ResultNetInfo), nil
|
return tmResult.Unwrap().(*ctypes.ResultNetInfo), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HTTP) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
|
func (c *HTTP) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
|
||||||
@ -120,7 +120,7 @@ func (c *HTTP) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "DumpConsensusState")
|
return nil, errors.Wrap(err, "DumpConsensusState")
|
||||||
}
|
}
|
||||||
return (*tmResult).(*ctypes.ResultDumpConsensusState), nil
|
return tmResult.Unwrap().(*ctypes.ResultDumpConsensusState), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HTTP) BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error) {
|
func (c *HTTP) BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error) {
|
||||||
@ -131,7 +131,7 @@ func (c *HTTP) BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchai
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "BlockchainInfo")
|
return nil, errors.Wrap(err, "BlockchainInfo")
|
||||||
}
|
}
|
||||||
return (*tmResult).(*ctypes.ResultBlockchainInfo), nil
|
return tmResult.Unwrap().(*ctypes.ResultBlockchainInfo), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HTTP) Genesis() (*ctypes.ResultGenesis, error) {
|
func (c *HTTP) Genesis() (*ctypes.ResultGenesis, error) {
|
||||||
@ -140,7 +140,7 @@ func (c *HTTP) Genesis() (*ctypes.ResultGenesis, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "Genesis")
|
return nil, errors.Wrap(err, "Genesis")
|
||||||
}
|
}
|
||||||
return (*tmResult).(*ctypes.ResultGenesis), nil
|
return tmResult.Unwrap().(*ctypes.ResultGenesis), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HTTP) Block(height int) (*ctypes.ResultBlock, error) {
|
func (c *HTTP) Block(height int) (*ctypes.ResultBlock, error) {
|
||||||
@ -149,7 +149,7 @@ func (c *HTTP) Block(height int) (*ctypes.ResultBlock, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "Block")
|
return nil, errors.Wrap(err, "Block")
|
||||||
}
|
}
|
||||||
return (*tmResult).(*ctypes.ResultBlock), nil
|
return tmResult.Unwrap().(*ctypes.ResultBlock), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HTTP) Commit(height int) (*ctypes.ResultCommit, error) {
|
func (c *HTTP) Commit(height int) (*ctypes.ResultCommit, error) {
|
||||||
@ -158,7 +158,7 @@ func (c *HTTP) Commit(height int) (*ctypes.ResultCommit, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "Commit")
|
return nil, errors.Wrap(err, "Commit")
|
||||||
}
|
}
|
||||||
return (*tmResult).(*ctypes.ResultCommit), nil
|
return tmResult.Unwrap().(*ctypes.ResultCommit), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HTTP) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
func (c *HTTP) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
||||||
@ -171,7 +171,7 @@ func (c *HTTP) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "Tx")
|
return nil, errors.Wrap(err, "Tx")
|
||||||
}
|
}
|
||||||
return (*tmResult).(*ctypes.ResultTx), nil
|
return tmResult.Unwrap().(*ctypes.ResultTx), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HTTP) Validators() (*ctypes.ResultValidators, error) {
|
func (c *HTTP) Validators() (*ctypes.ResultValidators, error) {
|
||||||
@ -180,7 +180,7 @@ func (c *HTTP) Validators() (*ctypes.ResultValidators, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "Validators")
|
return nil, errors.Wrap(err, "Validators")
|
||||||
}
|
}
|
||||||
return (*tmResult).(*ctypes.ResultValidators), nil
|
return tmResult.Unwrap().(*ctypes.ResultValidators), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/** websocket event stuff here... **/
|
/** websocket event stuff here... **/
|
||||||
@ -340,7 +340,7 @@ func (w *WSEvents) parseEvent(data []byte) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
event, ok := (*result).(*ctypes.ResultEvent)
|
event, ok := result.Unwrap().(*ctypes.ResultEvent)
|
||||||
if !ok {
|
if !ok {
|
||||||
// ignore silently (eg. subscribe, unsubscribe and maybe other events)
|
// ignore silently (eg. subscribe, unsubscribe and maybe other events)
|
||||||
return nil
|
return nil
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/tendermint/rpc/lib/types"
|
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
|
"github.com/tendermint/tendermint/rpc/lib/types"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ func Subscribe(wsCtx rpctypes.WSRPCContext, event string) (*ctypes.ResultSubscri
|
|||||||
types.AddListenerForEvent(wsCtx.GetEventSwitch(), wsCtx.GetRemoteAddr(), event, func(msg types.TMEventData) {
|
types.AddListenerForEvent(wsCtx.GetEventSwitch(), wsCtx.GetRemoteAddr(), event, func(msg types.TMEventData) {
|
||||||
// NOTE: EventSwitch callbacks must be nonblocking
|
// NOTE: EventSwitch callbacks must be nonblocking
|
||||||
// NOTE: RPCResponses of subscribed events have id suffix "#event"
|
// NOTE: RPCResponses of subscribed events have id suffix "#event"
|
||||||
tmResult := ctypes.TMResult(&ctypes.ResultEvent{event, msg})
|
tmResult := ctypes.TMResult{&ctypes.ResultEvent{event, msg}}
|
||||||
wsCtx.TryWriteRPCResponse(rpctypes.NewRPCResponse(wsCtx.Request.ID+"#event", &tmResult, ""))
|
wsCtx.TryWriteRPCResponse(rpctypes.NewRPCResponse(wsCtx.Request.ID+"#event", &tmResult, ""))
|
||||||
})
|
})
|
||||||
return &ctypes.ResultSubscribe{}, nil
|
return &ctypes.ResultSubscribe{}, nil
|
||||||
|
@ -2,8 +2,8 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
data "github.com/tendermint/go-wire/data"
|
data "github.com/tendermint/go-wire/data"
|
||||||
rpc "github.com/tendermint/tendermint/rpc/lib/server"
|
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
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/rpc/lib/types"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
@ -50,100 +50,124 @@ var Routes = map[string]*rpc.RPCFunc{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
|
func SubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
|
||||||
return Subscribe(wsCtx, event)
|
res, err := Subscribe(wsCtx, event)
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnsubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
|
func UnsubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
|
||||||
return Unsubscribe(wsCtx, event)
|
res, err := Unsubscribe(wsCtx, event)
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func StatusResult() (ctypes.TMResult, error) {
|
func StatusResult() (ctypes.TMResult, error) {
|
||||||
return Status()
|
res, err := Status()
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func NetInfoResult() (ctypes.TMResult, error) {
|
func NetInfoResult() (ctypes.TMResult, error) {
|
||||||
return NetInfo()
|
res, err := NetInfo()
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnsafeDialSeedsResult(seeds []string) (ctypes.TMResult, error) {
|
func UnsafeDialSeedsResult(seeds []string) (ctypes.TMResult, error) {
|
||||||
return UnsafeDialSeeds(seeds)
|
res, err := UnsafeDialSeeds(seeds)
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func BlockchainInfoResult(min, max int) (ctypes.TMResult, error) {
|
func BlockchainInfoResult(min, max int) (ctypes.TMResult, error) {
|
||||||
return BlockchainInfo(min, max)
|
res, err := BlockchainInfo(min, max)
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenesisResult() (ctypes.TMResult, error) {
|
func GenesisResult() (ctypes.TMResult, error) {
|
||||||
return Genesis()
|
res, err := Genesis()
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func BlockResult(height int) (ctypes.TMResult, error) {
|
func BlockResult(height int) (ctypes.TMResult, error) {
|
||||||
return Block(height)
|
res, err := Block(height)
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func CommitResult(height int) (ctypes.TMResult, error) {
|
func CommitResult(height int) (ctypes.TMResult, error) {
|
||||||
return Commit(height)
|
res, err := Commit(height)
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func ValidatorsResult() (ctypes.TMResult, error) {
|
func ValidatorsResult() (ctypes.TMResult, error) {
|
||||||
return Validators()
|
res, err := Validators()
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func DumpConsensusStateResult() (ctypes.TMResult, error) {
|
func DumpConsensusStateResult() (ctypes.TMResult, error) {
|
||||||
return DumpConsensusState()
|
res, err := DumpConsensusState()
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnconfirmedTxsResult() (ctypes.TMResult, error) {
|
func UnconfirmedTxsResult() (ctypes.TMResult, error) {
|
||||||
return UnconfirmedTxs()
|
res, err := UnconfirmedTxs()
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func NumUnconfirmedTxsResult() (ctypes.TMResult, error) {
|
func NumUnconfirmedTxsResult() (ctypes.TMResult, error) {
|
||||||
return NumUnconfirmedTxs()
|
res, err := NumUnconfirmedTxs()
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tx allow user to query the transaction results. `nil` could mean the
|
// 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
|
// transaction is in the mempool, invalidated, or was not send in the first
|
||||||
// place.
|
// place.
|
||||||
func TxResult(hash []byte, prove bool) (ctypes.TMResult, error) {
|
func TxResult(hash []byte, prove bool) (ctypes.TMResult, error) {
|
||||||
return Tx(hash, prove)
|
res, err := Tx(hash, prove)
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func BroadcastTxCommitResult(tx types.Tx) (ctypes.TMResult, error) {
|
func BroadcastTxCommitResult(tx types.Tx) (ctypes.TMResult, error) {
|
||||||
return BroadcastTxCommit(tx)
|
res, err := BroadcastTxCommit(tx)
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func BroadcastTxSyncResult(tx types.Tx) (ctypes.TMResult, error) {
|
func BroadcastTxSyncResult(tx types.Tx) (ctypes.TMResult, error) {
|
||||||
return BroadcastTxSync(tx)
|
res, err := BroadcastTxSync(tx)
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func BroadcastTxAsyncResult(tx types.Tx) (ctypes.TMResult, error) {
|
func BroadcastTxAsyncResult(tx types.Tx) (ctypes.TMResult, error) {
|
||||||
return BroadcastTxAsync(tx)
|
res, err := BroadcastTxAsync(tx)
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func ABCIQueryResult(path string, data data.Bytes, prove bool) (ctypes.TMResult, error) {
|
func ABCIQueryResult(path string, data data.Bytes, prove bool) (ctypes.TMResult, error) {
|
||||||
return ABCIQuery(path, data, prove)
|
res, err := ABCIQuery(path, data, prove)
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func ABCIInfoResult() (ctypes.TMResult, error) {
|
func ABCIInfoResult() (ctypes.TMResult, error) {
|
||||||
return ABCIInfo()
|
res, err := ABCIInfo()
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnsafeFlushMempoolResult() (ctypes.TMResult, error) {
|
func UnsafeFlushMempoolResult() (ctypes.TMResult, error) {
|
||||||
return UnsafeFlushMempool()
|
res, err := UnsafeFlushMempool()
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnsafeSetConfigResult(typ, key, value string) (ctypes.TMResult, error) {
|
func UnsafeSetConfigResult(typ, key, value string) (ctypes.TMResult, error) {
|
||||||
return UnsafeSetConfig(typ, key, value)
|
res, err := UnsafeSetConfig(typ, key, value)
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnsafeStartCPUProfilerResult(filename string) (ctypes.TMResult, error) {
|
func UnsafeStartCPUProfilerResult(filename string) (ctypes.TMResult, error) {
|
||||||
return UnsafeStartCPUProfiler(filename)
|
res, err := UnsafeStartCPUProfiler(filename)
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnsafeStopCPUProfilerResult() (ctypes.TMResult, error) {
|
func UnsafeStopCPUProfilerResult() (ctypes.TMResult, error) {
|
||||||
return UnsafeStopCPUProfiler()
|
res, err := UnsafeStopCPUProfiler()
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnsafeWriteHeapProfileResult(filename string) (ctypes.TMResult, error) {
|
func UnsafeWriteHeapProfileResult(filename string) (ctypes.TMResult, error) {
|
||||||
return UnsafeWriteHeapProfile(filename)
|
res, err := UnsafeWriteHeapProfile(filename)
|
||||||
|
return ctypes.TMResult{res}, err
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
|
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
"github.com/tendermint/go-crypto"
|
"github.com/tendermint/go-crypto"
|
||||||
"github.com/tendermint/go-wire"
|
|
||||||
"github.com/tendermint/go-wire/data"
|
"github.com/tendermint/go-wire/data"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
"github.com/tendermint/tendermint/rpc/lib/types"
|
"github.com/tendermint/tendermint/rpc/lib/types"
|
||||||
@ -175,34 +174,98 @@ const (
|
|||||||
ResultTypeUnsafeFlushMempool = byte(0xa4)
|
ResultTypeUnsafeFlushMempool = byte(0xa4)
|
||||||
)
|
)
|
||||||
|
|
||||||
type TMResult interface {
|
const (
|
||||||
|
// for the blockchain
|
||||||
|
ResultNameGenesis = "genesis"
|
||||||
|
ResultNameBlockchainInfo = "info"
|
||||||
|
ResultNameBlock = "block"
|
||||||
|
ResultNameCommit = "commit"
|
||||||
|
|
||||||
|
// for the network
|
||||||
|
ResultNameStatus = "status"
|
||||||
|
ResultNameNetInfo = "netinfo"
|
||||||
|
ResultNameDialSeeds = "dialseeds"
|
||||||
|
|
||||||
|
// for the consensus
|
||||||
|
ResultNameValidators = "validators"
|
||||||
|
ResultNameDumpConsensusState = "consensus"
|
||||||
|
|
||||||
|
// for txs / the application
|
||||||
|
ResultNameBroadcastTx = "broadcast_tx"
|
||||||
|
ResultNameUnconfirmedTxs = "unconfirmed_tx"
|
||||||
|
ResultNameBroadcastTxCommit = "broadcast_tx_commit"
|
||||||
|
ResultNameTx = "tx"
|
||||||
|
|
||||||
|
// for querying the application
|
||||||
|
ResultNameABCIQuery = "abci_query"
|
||||||
|
ResultNameABCIInfo = "abci_info"
|
||||||
|
|
||||||
|
// for events
|
||||||
|
ResultNameSubscribe = "subscribe"
|
||||||
|
ResultNameUnsubscribe = "unsubscribe"
|
||||||
|
ResultNameEvent = "event"
|
||||||
|
|
||||||
|
// for testing
|
||||||
|
ResultNameUnsafeSetConfig = "unsafe_set_config"
|
||||||
|
ResultNameUnsafeStartCPUProfiler = "unsafe_start_profiler"
|
||||||
|
ResultNameUnsafeStopCPUProfiler = "unsafe_stop_profiler"
|
||||||
|
ResultNameUnsafeWriteHeapProfile = "unsafe_write_heap"
|
||||||
|
ResultNameUnsafeFlushMempool = "unsafe_flush_mempool"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TMResultInner interface {
|
||||||
rpctypes.Result
|
rpctypes.Result
|
||||||
}
|
}
|
||||||
|
|
||||||
// for wire.readReflect
|
type TMResult struct {
|
||||||
var _ = wire.RegisterInterface(
|
TMResultInner
|
||||||
struct{ TMResult }{},
|
}
|
||||||
wire.ConcreteType{&ResultGenesis{}, ResultTypeGenesis},
|
|
||||||
wire.ConcreteType{&ResultBlockchainInfo{}, ResultTypeBlockchainInfo},
|
func (tmr TMResult) MarshalJSON() ([]byte, error) {
|
||||||
wire.ConcreteType{&ResultBlock{}, ResultTypeBlock},
|
return tmResultMapper.ToJSON(tmr.TMResultInner)
|
||||||
wire.ConcreteType{&ResultCommit{}, ResultTypeCommit},
|
}
|
||||||
wire.ConcreteType{&ResultStatus{}, ResultTypeStatus},
|
|
||||||
wire.ConcreteType{&ResultNetInfo{}, ResultTypeNetInfo},
|
func (tmr *TMResult) UnmarshalJSON(data []byte) (err error) {
|
||||||
wire.ConcreteType{&ResultDialSeeds{}, ResultTypeDialSeeds},
|
parsed, err := tmResultMapper.FromJSON(data)
|
||||||
wire.ConcreteType{&ResultValidators{}, ResultTypeValidators},
|
if err == nil && parsed != nil {
|
||||||
wire.ConcreteType{&ResultDumpConsensusState{}, ResultTypeDumpConsensusState},
|
tmr.TMResultInner = parsed.(TMResultInner)
|
||||||
wire.ConcreteType{&ResultBroadcastTx{}, ResultTypeBroadcastTx},
|
}
|
||||||
wire.ConcreteType{&ResultBroadcastTxCommit{}, ResultTypeBroadcastTxCommit},
|
return
|
||||||
wire.ConcreteType{&ResultTx{}, ResultTypeTx},
|
}
|
||||||
wire.ConcreteType{&ResultUnconfirmedTxs{}, ResultTypeUnconfirmedTxs},
|
|
||||||
wire.ConcreteType{&ResultSubscribe{}, ResultTypeSubscribe},
|
func (tmr TMResult) Unwrap() TMResultInner {
|
||||||
wire.ConcreteType{&ResultUnsubscribe{}, ResultTypeUnsubscribe},
|
tmrI := tmr.TMResultInner
|
||||||
wire.ConcreteType{&ResultEvent{}, ResultTypeEvent},
|
for wrap, ok := tmrI.(TMResult); ok; wrap, ok = tmrI.(TMResult) {
|
||||||
wire.ConcreteType{&ResultUnsafeSetConfig{}, ResultTypeUnsafeSetConfig},
|
tmrI = wrap.TMResultInner
|
||||||
wire.ConcreteType{&ResultUnsafeProfile{}, ResultTypeUnsafeStartCPUProfiler},
|
}
|
||||||
wire.ConcreteType{&ResultUnsafeProfile{}, ResultTypeUnsafeStopCPUProfiler},
|
return tmrI
|
||||||
wire.ConcreteType{&ResultUnsafeProfile{}, ResultTypeUnsafeWriteHeapProfile},
|
}
|
||||||
wire.ConcreteType{&ResultUnsafeFlushMempool{}, ResultTypeUnsafeFlushMempool},
|
|
||||||
wire.ConcreteType{&ResultABCIQuery{}, ResultTypeABCIQuery},
|
func (tmr TMResult) Empty() bool {
|
||||||
wire.ConcreteType{&ResultABCIInfo{}, ResultTypeABCIInfo},
|
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)
|
||||||
|
@ -42,7 +42,7 @@ func testStatus(t *testing.T, client rpc.HTTPClient) {
|
|||||||
_, err := client.Call("status", map[string]interface{}{}, tmResult)
|
_, err := client.Call("status", map[string]interface{}{}, tmResult)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
status := (*tmResult).(*ctypes.ResultStatus)
|
status := tmResult.Unwrap().(*ctypes.ResultStatus)
|
||||||
assert.Equal(t, chainID, status.NodeInfo.Network)
|
assert.Equal(t, chainID, status.NodeInfo.Network)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ func testBroadcastTxSync(t *testing.T, client rpc.HTTPClient) {
|
|||||||
_, err := client.Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, tmResult)
|
_, err := client.Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, tmResult)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
res := (*tmResult).(*ctypes.ResultBroadcastTx)
|
res := tmResult.Unwrap().(*ctypes.ResultBroadcastTx)
|
||||||
require.Equal(t, abci.CodeType_OK, res.Code)
|
require.Equal(t, abci.CodeType_OK, res.Code)
|
||||||
require.Equal(t, initMemSize+1, mem.Size())
|
require.Equal(t, initMemSize+1, mem.Size())
|
||||||
txs := mem.Reap(1)
|
txs := mem.Reap(1)
|
||||||
@ -96,7 +96,7 @@ func sendTx(t *testing.T, client rpc.HTTPClient) ([]byte, []byte) {
|
|||||||
k, v, tx := testTxKV(t)
|
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}, tmResult)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
bres := (*tmResult).(*ctypes.ResultBroadcastTxCommit)
|
bres := tmResult.Unwrap().(*ctypes.ResultBroadcastTxCommit)
|
||||||
require.NotNil(t, 0, bres.DeliverTx, "%#v", bres)
|
require.NotNil(t, 0, bres.DeliverTx, "%#v", bres)
|
||||||
require.EqualValues(t, 0, bres.CheckTx.Code, "%#v", bres)
|
require.EqualValues(t, 0, bres.CheckTx.Code, "%#v", bres)
|
||||||
require.EqualValues(t, 0, bres.DeliverTx.Code, "%#v", bres)
|
require.EqualValues(t, 0, bres.DeliverTx.Code, "%#v", bres)
|
||||||
@ -119,7 +119,7 @@ func testABCIQuery(t *testing.T, client rpc.HTTPClient) {
|
|||||||
map[string]interface{}{"path": "", "data": k, "prove": false}, tmResult)
|
map[string]interface{}{"path": "", "data": k, "prove": false}, tmResult)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
resQuery := (*tmResult).(*ctypes.ResultABCIQuery)
|
resQuery := tmResult.Unwrap().(*ctypes.ResultABCIQuery)
|
||||||
require.EqualValues(t, 0, resQuery.Code)
|
require.EqualValues(t, 0, resQuery.Code)
|
||||||
|
|
||||||
// XXX: specific to value returned by the dummy
|
// XXX: specific to value returned by the dummy
|
||||||
@ -145,7 +145,7 @@ func testBroadcastTxCommit(t *testing.T, client rpc.HTTPClient) {
|
|||||||
_, err := client.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult)
|
_, err := client.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult)
|
||||||
require.Nil(err)
|
require.Nil(err)
|
||||||
|
|
||||||
res := (*tmResult).(*ctypes.ResultBroadcastTxCommit)
|
res := tmResult.Unwrap().(*ctypes.ResultBroadcastTxCommit)
|
||||||
checkTx := res.CheckTx
|
checkTx := res.CheckTx
|
||||||
require.Equal(abci.CodeType_OK, checkTx.Code)
|
require.Equal(abci.CodeType_OK, checkTx.Code)
|
||||||
deliverTx := res.DeliverTx
|
deliverTx := res.DeliverTx
|
||||||
@ -184,7 +184,7 @@ func testTx(t *testing.T, client rpc.HTTPClient, withIndexer bool) {
|
|||||||
_, err := client.Call("broadcast_tx_commit", map[string]interface{}{"tx": txBytes}, tmResult)
|
_, err := client.Call("broadcast_tx_commit", map[string]interface{}{"tx": txBytes}, tmResult)
|
||||||
require.Nil(err)
|
require.Nil(err)
|
||||||
|
|
||||||
res := (*tmResult).(*ctypes.ResultBroadcastTxCommit)
|
res := tmResult.Unwrap().(*ctypes.ResultBroadcastTxCommit)
|
||||||
checkTx := res.CheckTx
|
checkTx := res.CheckTx
|
||||||
require.Equal(abci.CodeType_OK, checkTx.Code)
|
require.Equal(abci.CodeType_OK, checkTx.Code)
|
||||||
deliverTx := res.DeliverTx
|
deliverTx := res.DeliverTx
|
||||||
@ -225,7 +225,7 @@ func testTx(t *testing.T, client rpc.HTTPClient, withIndexer bool) {
|
|||||||
require.NotNil(err, idx)
|
require.NotNil(err, idx)
|
||||||
} else {
|
} else {
|
||||||
require.Nil(err, idx)
|
require.Nil(err, idx)
|
||||||
res2 := (*tmResult).(*ctypes.ResultTx)
|
res2 := tmResult.Unwrap().(*ctypes.ResultTx)
|
||||||
assert.Equal(tx, res2.Tx, idx)
|
assert.Equal(tx, res2.Tx, idx)
|
||||||
assert.Equal(res.Height, res2.Height, idx)
|
assert.Equal(res.Height, res2.Height, idx)
|
||||||
assert.Equal(0, res2.Index, idx)
|
assert.Equal(0, res2.Index, idx)
|
||||||
|
@ -18,9 +18,9 @@ import (
|
|||||||
"github.com/tendermint/tendermint/config/tendermint_test"
|
"github.com/tendermint/tendermint/config/tendermint_test"
|
||||||
nm "github.com/tendermint/tendermint/node"
|
nm "github.com/tendermint/tendermint/node"
|
||||||
"github.com/tendermint/tendermint/proxy"
|
"github.com/tendermint/tendermint/proxy"
|
||||||
client "github.com/tendermint/tendermint/rpc/lib/client"
|
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
core_grpc "github.com/tendermint/tendermint/rpc/grpc"
|
core_grpc "github.com/tendermint/tendermint/rpc/grpc"
|
||||||
|
client "github.com/tendermint/tendermint/rpc/lib/client"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ func waitForEvent(t *testing.T, wsc *client.WSClient, eventid string, dieOnTimeo
|
|||||||
errCh <- err
|
errCh <- err
|
||||||
break LOOP
|
break LOOP
|
||||||
}
|
}
|
||||||
event, ok := (*result).(*ctypes.ResultEvent)
|
event, ok := result.Unwrap().(*ctypes.ResultEvent)
|
||||||
if ok && event.Name == eventid {
|
if ok && event.Name == eventid {
|
||||||
goodCh <- event.Data
|
goodCh <- event.Data
|
||||||
break LOOP
|
break LOOP
|
||||||
|
Reference in New Issue
Block a user