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.

104 lines
3.0 KiB

  1. package core_types
  2. import (
  3. "github.com/tendermint/go-crypto"
  4. "github.com/tendermint/go-p2p"
  5. "github.com/tendermint/go-wire"
  6. "github.com/tendermint/tendermint/types"
  7. )
  8. type ResultBlockchainInfo struct {
  9. LastHeight int `json:"last_height"`
  10. BlockMetas []*types.BlockMeta `json:"block_metas"`
  11. }
  12. type ResultGetBlock struct {
  13. BlockMeta *types.BlockMeta `json:"block_meta"`
  14. Block *types.Block `json:"block"`
  15. }
  16. type ResultStatus struct {
  17. NodeInfo *p2p.NodeInfo `json:"node_info"`
  18. PubKey crypto.PubKey `json:"pub_key"`
  19. LatestBlockHash []byte `json:"latest_block_hash"`
  20. LatestBlockHeight int `json:"latest_block_height"`
  21. LatestBlockTime int64 `json:"latest_block_time"` // nano
  22. }
  23. type ResultNetInfo struct {
  24. Listening bool `json:"listening"`
  25. Listeners []string `json:"listeners"`
  26. Peers []Peer `json:"peers"`
  27. }
  28. type Peer struct {
  29. p2p.NodeInfo `json:"node_info"`
  30. IsOutbound bool `json:"is_outbound"`
  31. }
  32. type ResultListValidators struct {
  33. BlockHeight int `json:"block_height"`
  34. Validators []*types.Validator `json:"validators"`
  35. }
  36. type ResultDumpConsensusState struct {
  37. RoundState string `json:"round_state"`
  38. PeerRoundStates []string `json:"peer_round_states"`
  39. }
  40. type ResultBroadcastTx struct {
  41. }
  42. type ResultListUnconfirmedTxs struct {
  43. N int `json:"n_txs"`
  44. Txs []types.Tx `json:"txs"`
  45. }
  46. type ResultGenesis struct {
  47. Genesis *types.GenesisDoc `json:"genesis"`
  48. }
  49. type ResultEvent struct {
  50. Event string `json:"event"`
  51. Data types.EventData `json:"data"`
  52. }
  53. //----------------------------------------
  54. // response & result types
  55. type Response struct {
  56. JSONRPC string `json:"jsonrpc"`
  57. ID string `json:"id"`
  58. Result Result `json:"result"`
  59. Error string `json:"error"`
  60. }
  61. const (
  62. ResultTypeBlockchainInfo = byte(0x05)
  63. ResultTypeGetBlock = byte(0x06)
  64. ResultTypeStatus = byte(0x07)
  65. ResultTypeNetInfo = byte(0x08)
  66. ResultTypeListValidators = byte(0x09)
  67. ResultTypeDumpConsensusState = byte(0x0A)
  68. ResultTypeBroadcastTx = byte(0x0E)
  69. ResultTypeListUnconfirmedTxs = byte(0x0F)
  70. ResultTypeGenesis = byte(0x11)
  71. ResultTypeEvent = byte(0x13) // so websockets can respond to rpc functions
  72. )
  73. type Result interface{}
  74. // for wire.readReflect
  75. var _ = wire.RegisterInterface(
  76. struct{ Result }{},
  77. wire.ConcreteType{&ResultBlockchainInfo{}, ResultTypeBlockchainInfo},
  78. wire.ConcreteType{&ResultGetBlock{}, ResultTypeGetBlock},
  79. wire.ConcreteType{&ResultStatus{}, ResultTypeStatus},
  80. wire.ConcreteType{&ResultNetInfo{}, ResultTypeNetInfo},
  81. wire.ConcreteType{&ResultListValidators{}, ResultTypeListValidators},
  82. wire.ConcreteType{&ResultDumpConsensusState{}, ResultTypeDumpConsensusState},
  83. wire.ConcreteType{&ResultBroadcastTx{}, ResultTypeBroadcastTx},
  84. wire.ConcreteType{&ResultListUnconfirmedTxs{}, ResultTypeListUnconfirmedTxs},
  85. wire.ConcreteType{&ResultGenesis{}, ResultTypeGenesis},
  86. wire.ConcreteType{&ResultEvent{}, ResultTypeEvent},
  87. )