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.

105 lines
2.8 KiB

7 years ago
8 years ago
  1. package core
  2. import (
  3. abci "github.com/tendermint/tendermint/abci/types"
  4. cmn "github.com/tendermint/tendermint/libs/common"
  5. "github.com/tendermint/tendermint/proxy"
  6. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  7. )
  8. // Query the application for some information.
  9. //
  10. // ```shell
  11. // curl 'localhost:26657/abci_query?path=""&data="abcd"&prove=false'
  12. // ```
  13. //
  14. // ```go
  15. // client := client.NewHTTP("tcp://0.0.0.0:26657", "/websocket")
  16. // err := client.Start()
  17. // if err != nil {
  18. // // handle error
  19. // }
  20. // defer client.Stop()
  21. // result, err := client.ABCIQuery("", "abcd", true)
  22. // ```
  23. //
  24. // > The above command returns JSON structured like this:
  25. //
  26. // ```json
  27. // {
  28. // "error": "",
  29. // "result": {
  30. // "response": {
  31. // "log": "exists",
  32. // "height": "0",
  33. // "proof": "010114FED0DAD959F36091AD761C922ABA3CBF1D8349990101020103011406AA2262E2F448242DF2C2607C3CDC705313EE3B0001149D16177BC71E445476174622EA559715C293740C",
  34. // "value": "61626364",
  35. // "key": "61626364",
  36. // "index": "-1",
  37. // "code": "0"
  38. // }
  39. // },
  40. // "id": "",
  41. // "jsonrpc": "2.0"
  42. // }
  43. // ```
  44. //
  45. // ### Query Parameters
  46. //
  47. // | Parameter | Type | Default | Required | Description |
  48. // |-----------+--------+---------+----------+------------------------------------------------|
  49. // | path | string | false | false | Path to the data ("/a/b/c") |
  50. // | data | []byte | false | true | Data |
  51. // | height | int64 | 0 | false | Height (0 means latest) |
  52. // | prove | bool | false | false | Includes proof if true |
  53. func ABCIQuery(path string, data cmn.HexBytes, height int64, prove bool) (*ctypes.ResultABCIQuery, error) {
  54. resQuery, err := proxyAppQuery.QuerySync(abci.RequestQuery{
  55. Path: path,
  56. Data: data,
  57. Height: height,
  58. Prove: prove,
  59. })
  60. if err != nil {
  61. return nil, err
  62. }
  63. logger.Info("ABCIQuery", "path", path, "data", data, "result", resQuery)
  64. return &ctypes.ResultABCIQuery{*resQuery}, nil
  65. }
  66. // Get some info about the application.
  67. //
  68. // ```shell
  69. // curl 'localhost:26657/abci_info'
  70. // ```
  71. //
  72. // ```go
  73. // client := client.NewHTTP("tcp://0.0.0.0:26657", "/websocket")
  74. // err := client.Start()
  75. // if err != nil {
  76. // // handle error
  77. // }
  78. // defer client.Stop()
  79. // info, err := client.ABCIInfo()
  80. // ```
  81. //
  82. // > The above command returns JSON structured like this:
  83. //
  84. // ```json
  85. // {
  86. // "error": "",
  87. // "result": {
  88. // "response": {
  89. // "data": "{\"size\":3}"
  90. // }
  91. // },
  92. // "id": "",
  93. // "jsonrpc": "2.0"
  94. // }
  95. // ```
  96. func ABCIInfo() (*ctypes.ResultABCIInfo, error) {
  97. resInfo, err := proxyAppQuery.InfoSync(proxy.RequestInfo)
  98. if err != nil {
  99. return nil, err
  100. }
  101. return &ctypes.ResultABCIInfo{*resInfo}, nil
  102. }