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.

110 lines
2.4 KiB

7 years ago
7 years ago
8 years ago
  1. package core
  2. import (
  3. "fmt"
  4. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  5. )
  6. // Get network info.
  7. //
  8. // ```shell
  9. // curl 'localhost:46657/net_info'
  10. // ```
  11. //
  12. // ```go
  13. // client := client.NewHTTP("tcp://0.0.0.0:46657", "/websocket")
  14. // info, err := client.NetInfo()
  15. // ```
  16. //
  17. // > The above command returns JSON structured like this:
  18. //
  19. // ```json
  20. // {
  21. // "error": "",
  22. // "result": {
  23. // "peers": [],
  24. // "listeners": [
  25. // "Listener(@10.0.2.15:46656)"
  26. // ],
  27. // "listening": true
  28. // },
  29. // "id": "",
  30. // "jsonrpc": "2.0"
  31. // }
  32. // ```
  33. func NetInfo() (*ctypes.ResultNetInfo, error) {
  34. listening := p2pSwitch.IsListening()
  35. listeners := []string{}
  36. for _, listener := range p2pSwitch.Listeners() {
  37. listeners = append(listeners, listener.String())
  38. }
  39. peers := []ctypes.Peer{}
  40. for _, peer := range p2pSwitch.Peers().List() {
  41. peers = append(peers, ctypes.Peer{
  42. NodeInfo: *peer.NodeInfo(),
  43. IsOutbound: peer.IsOutbound(),
  44. ConnectionStatus: peer.Status(),
  45. })
  46. }
  47. return &ctypes.ResultNetInfo{
  48. Listening: listening,
  49. Listeners: listeners,
  50. Peers: peers,
  51. }, nil
  52. }
  53. func UnsafeDialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) {
  54. if len(seeds) == 0 {
  55. return &ctypes.ResultDialSeeds{}, fmt.Errorf("No seeds provided")
  56. }
  57. // starts go routines to dial each seed after random delays
  58. logger.Info("DialSeeds", "addrBook", addrBook, "seeds", seeds)
  59. err := p2pSwitch.DialSeeds(addrBook, seeds)
  60. if err != nil {
  61. return &ctypes.ResultDialSeeds{}, err
  62. }
  63. return &ctypes.ResultDialSeeds{"Dialing seeds in progress. See /net_info for details"}, nil
  64. }
  65. // Get genesis file.
  66. //
  67. // ```shell
  68. // curl 'localhost:46657/genesis'
  69. // ```
  70. //
  71. // ```go
  72. // client := client.NewHTTP("tcp://0.0.0.0:46657", "/websocket")
  73. // genesis, err := client.Genesis()
  74. // ```
  75. //
  76. // > The above command returns JSON structured like this:
  77. //
  78. // ```json
  79. // {
  80. // "error": "",
  81. // "result": {
  82. // "genesis": {
  83. // "app_hash": "",
  84. // "validators": [
  85. // {
  86. // "name": "",
  87. // "amount": 10,
  88. // "pub_key": {
  89. // "data": "68DFDA7E50F82946E7E8546BED37944A422CD1B831E70DF66BA3B8430593944D",
  90. // "type": "ed25519"
  91. // }
  92. // }
  93. // ],
  94. // "chain_id": "test-chain-6UTNIN",
  95. // "genesis_time": "2017-05-29T15:05:41.671Z"
  96. // }
  97. // },
  98. // "id": "",
  99. // "jsonrpc": "2.0"
  100. // }
  101. // ```
  102. func Genesis() (*ctypes.ResultGenesis, error) {
  103. return &ctypes.ResultGenesis{genDoc}, nil
  104. }