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.

94 lines
1.9 KiB

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