mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-25 17:34:36 +00:00
remove TMResult. ::drinks champagne::
This commit is contained in:
+2
-2
@@ -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
|
||||
}
|
||||
|
||||
+23
-150
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user