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.

95 lines
2.4 KiB

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