You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.2 KiB

7 years ago
8 years ago
8 years ago
8 years ago
  1. package core
  2. import (
  3. crypto "github.com/tendermint/go-crypto"
  4. "github.com/tendermint/tendermint/consensus"
  5. p2p "github.com/tendermint/tendermint/p2p"
  6. "github.com/tendermint/tendermint/proxy"
  7. sm "github.com/tendermint/tendermint/state"
  8. "github.com/tendermint/tendermint/state/txindex"
  9. "github.com/tendermint/tendermint/types"
  10. "github.com/tendermint/tmlibs/log"
  11. )
  12. //----------------------------------------------
  13. // These interfaces are used by RPC and must be thread safe
  14. type Consensus interface {
  15. GetState() *sm.State
  16. GetValidators() (int, []*types.Validator)
  17. GetRoundState() *consensus.RoundState
  18. }
  19. type P2P interface {
  20. Listeners() []p2p.Listener
  21. Peers() p2p.IPeerSet
  22. NumPeers() (outbound, inbound, dialig int)
  23. NodeInfo() *p2p.NodeInfo
  24. IsListening() bool
  25. DialSeeds(*p2p.AddrBook, []string) error
  26. }
  27. //----------------------------------------------
  28. // These package level globals come with setters
  29. // that are expected to be called only once, on startup
  30. var (
  31. // external, thread safe interfaces
  32. eventSwitch types.EventSwitch
  33. proxyAppQuery proxy.AppConnQuery
  34. // interfaces defined in types and above
  35. blockStore types.BlockStore
  36. mempool types.Mempool
  37. consensusState Consensus
  38. p2pSwitch P2P
  39. // objects
  40. pubKey crypto.PubKey
  41. genDoc *types.GenesisDoc // cache the genesis structure
  42. addrBook *p2p.AddrBook
  43. txIndexer txindex.TxIndexer
  44. consensusReactor *consensus.ConsensusReactor
  45. logger log.Logger
  46. )
  47. func SetEventSwitch(evsw types.EventSwitch) {
  48. eventSwitch = evsw
  49. }
  50. func SetBlockStore(bs types.BlockStore) {
  51. blockStore = bs
  52. }
  53. func SetMempool(mem types.Mempool) {
  54. mempool = mem
  55. }
  56. func SetConsensusState(cs Consensus) {
  57. consensusState = cs
  58. }
  59. func SetSwitch(sw P2P) {
  60. p2pSwitch = sw
  61. }
  62. func SetPubKey(pk crypto.PubKey) {
  63. pubKey = pk
  64. }
  65. func SetGenesisDoc(doc *types.GenesisDoc) {
  66. genDoc = doc
  67. }
  68. func SetAddrBook(book *p2p.AddrBook) {
  69. addrBook = book
  70. }
  71. func SetProxyAppQuery(appConn proxy.AppConnQuery) {
  72. proxyAppQuery = appConn
  73. }
  74. func SetTxIndexer(indexer txindex.TxIndexer) {
  75. txIndexer = indexer
  76. }
  77. func SetConsensusReactor(conR *consensus.ConsensusReactor) {
  78. consensusReactor = conR
  79. }
  80. func SetLogger(l log.Logger) {
  81. logger = l
  82. }