tendermint/rpc/core/pipe.go

97 lines
1.8 KiB
Go
Raw Normal View History

package core
import (
2016-05-11 20:33:09 -07:00
cfg "github.com/tendermint/go-config"
2016-10-14 18:36:42 -07:00
"github.com/tendermint/go-crypto"
2015-11-01 11:34:08 -08:00
"github.com/tendermint/go-p2p"
2016-05-11 20:33:09 -07:00
2015-04-01 17:30:16 -07:00
"github.com/tendermint/tendermint/consensus"
2016-08-22 13:00:48 -07:00
"github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/types"
2017-01-12 12:53:32 -08:00
abci "github.com/tendermint/abci/types"
)
2016-10-14 18:36:42 -07:00
//-----------------------------------------------------
// Interfaces for use by RPC
// NOTE: these methods must be thread safe!
2016-10-14 18:36:42 -07:00
type BlockStore interface {
Height() int
LoadBlockMeta(height int) *types.BlockMeta
LoadBlock(height int) *types.Block
}
type Consensus interface {
GetValidators() (int, []*types.Validator)
GetRoundState() *consensus.RoundState
}
type Mempool interface {
Size() int
2017-01-12 12:53:32 -08:00
CheckTx(types.Tx, func(*abci.Response)) error
2016-10-14 18:36:42 -07:00
Reap(int) []types.Tx
Flush()
}
type P2P interface {
Listeners() []p2p.Listener
Peers() p2p.IPeerSet
NumPeers() (outbound, inbound, dialig int)
NodeInfo() *p2p.NodeInfo
IsListening() bool
DialSeeds([]string)
}
var (
// external, thread safe interfaces
eventSwitch types.EventSwitch
proxyAppQuery proxy.AppConnQuery
config cfg.Config
// interfaces defined above
blockStore BlockStore
consensusState Consensus
mempool Mempool
p2pSwitch P2P
// objects
pubKey crypto.PubKey
genDoc *types.GenesisDoc // cache the genesis structure
)
2016-05-11 20:33:09 -07:00
func SetConfig(c cfg.Config) {
config = c
}
2016-10-09 23:58:13 -07:00
func SetEventSwitch(evsw types.EventSwitch) {
2016-06-27 17:43:09 -07:00
eventSwitch = evsw
}
2016-10-14 18:36:42 -07:00
func SetBlockStore(bs BlockStore) {
blockStore = bs
}
2016-10-14 18:36:42 -07:00
func SetConsensusState(cs Consensus) {
consensusState = cs
}
2016-10-14 18:36:42 -07:00
func SetMempool(mem Mempool) {
mempool = mem
}
2016-10-14 18:36:42 -07:00
func SetSwitch(sw P2P) {
p2pSwitch = sw
}
2016-10-14 18:36:42 -07:00
func SetPubKey(pk crypto.PubKey) {
pubKey = pk
}
2015-06-14 15:18:17 -07:00
2015-12-01 20:12:01 -08:00
func SetGenesisDoc(doc *types.GenesisDoc) {
2015-06-14 15:18:17 -07:00
genDoc = doc
}
2016-08-22 13:00:48 -07:00
func SetProxyAppQuery(appConn proxy.AppConnQuery) {
proxyAppQuery = appConn
}