mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-13 05:11:21 +00:00
expose query and info through rpc
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
||||
bc "github.com/tendermint/tendermint/blockchain"
|
||||
"github.com/tendermint/tendermint/consensus"
|
||||
mempl "github.com/tendermint/tendermint/mempool"
|
||||
"github.com/tendermint/tendermint/proxy"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
@ -19,6 +20,7 @@ var mempoolReactor *mempl.MempoolReactor
|
||||
var p2pSwitch *p2p.Switch
|
||||
var privValidator *types.PrivValidator
|
||||
var genDoc *types.GenesisDoc // cache the genesis structure
|
||||
var proxyAppQuery proxy.AppConnQuery
|
||||
|
||||
var config cfg.Config = nil
|
||||
|
||||
@ -57,3 +59,7 @@ func SetPrivValidator(pv *types.PrivValidator) {
|
||||
func SetGenesisDoc(doc *types.GenesisDoc) {
|
||||
genDoc = doc
|
||||
}
|
||||
|
||||
func SetProxyAppQuery(appConn proxy.AppConnQuery) {
|
||||
proxyAppQuery = appConn
|
||||
}
|
||||
|
@ -25,6 +25,9 @@ var Routes = map[string]*rpc.RPCFunc{
|
||||
"unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxsResult, ""),
|
||||
"num_unconfirmed_txs": rpc.NewRPCFunc(NumUnconfirmedTxsResult, ""),
|
||||
|
||||
"tmsp_query": rpc.NewRPCFunc(TMSPQueryResult, "query"),
|
||||
"tmsp_info": rpc.NewRPCFunc(TMSPInfoResult, ""),
|
||||
|
||||
"unsafe_flush_mempool": rpc.NewRPCFunc(UnsafeFlushMempool, ""),
|
||||
"unsafe_set_config": rpc.NewRPCFunc(UnsafeSetConfigResult, "type,key,value"),
|
||||
"unsafe_start_cpu_profiler": rpc.NewRPCFunc(UnsafeStartCPUProfilerResult, "filename"),
|
||||
@ -152,6 +155,22 @@ func BroadcastTxAsyncResult(tx []byte) (ctypes.TMResult, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func TMSPQueryResult(query []byte) (ctypes.TMResult, error) {
|
||||
if r, err := TMSPQuery(query); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return r, nil
|
||||
}
|
||||
}
|
||||
|
||||
func TMSPInfoResult() (ctypes.TMResult, error) {
|
||||
if r, err := TMSPInfo(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return r, nil
|
||||
}
|
||||
}
|
||||
|
||||
func UnsafeFlushMempoolResult() (ctypes.TMResult, error) {
|
||||
if r, err := UnsafeFlushMempool(); err != nil {
|
||||
return nil, err
|
||||
|
17
rpc/core/tmsp.go
Normal file
17
rpc/core/tmsp.go
Normal file
@ -0,0 +1,17 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
func TMSPQuery(query []byte) (*ctypes.ResultTMSPQuery, error) {
|
||||
res := proxyAppQuery.QuerySync(query)
|
||||
return &ctypes.ResultTMSPQuery{res}, nil
|
||||
}
|
||||
|
||||
func TMSPInfo() (*ctypes.ResultTMSPInfo, error) {
|
||||
res := proxyAppQuery.InfoSync()
|
||||
return &ctypes.ResultTMSPInfo{res}, nil
|
||||
}
|
@ -68,6 +68,14 @@ type ResultUnconfirmedTxs struct {
|
||||
Txs []types.Tx `json:"txs"`
|
||||
}
|
||||
|
||||
type ResultTMSPInfo struct {
|
||||
Result tmsp.Result `json:"result"`
|
||||
}
|
||||
|
||||
type ResultTMSPQuery struct {
|
||||
Result tmsp.Result `json:"result"`
|
||||
}
|
||||
|
||||
type ResultUnsafeFlushMempool struct{}
|
||||
|
||||
type ResultUnsafeSetConfig struct{}
|
||||
@ -107,6 +115,10 @@ const (
|
||||
ResultTypeBroadcastTx = byte(0x60)
|
||||
ResultTypeUnconfirmedTxs = byte(0x61)
|
||||
|
||||
// 0x7 bytes are for querying the application
|
||||
ResultTypeTMSPQuery = byte(0x70)
|
||||
ResultTypeTMSPInfo = byte(0x71)
|
||||
|
||||
// 0x8 bytes are for events
|
||||
ResultTypeSubscribe = byte(0x80)
|
||||
ResultTypeUnsubscribe = byte(0x81)
|
||||
@ -145,4 +157,6 @@ var _ = wire.RegisterInterface(
|
||||
wire.ConcreteType{&ResultUnsafeProfile{}, ResultTypeUnsafeStopCPUProfiler},
|
||||
wire.ConcreteType{&ResultUnsafeProfile{}, ResultTypeUnsafeWriteHeapProfile},
|
||||
wire.ConcreteType{&ResultUnsafeFlushMempool{}, ResultTypeUnsafeFlushMempool},
|
||||
wire.ConcreteType{&ResultTMSPQuery{}, ResultTypeTMSPQuery},
|
||||
wire.ConcreteType{&ResultTMSPInfo{}, ResultTypeTMSPInfo},
|
||||
)
|
||||
|
Reference in New Issue
Block a user