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.

96 lines
1.8 KiB

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