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.

97 lines
2.6 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. // | height | uint64 | 0 | false | Height (0 means latest) |
  47. // | trusted | bool | false | false | Does not include a proof of the data inclusion |
  48. func ABCIQuery(path string, data data.Bytes, height uint64, trusted bool) (*ctypes.ResultABCIQuery, error) {
  49. resQuery, err := proxyAppQuery.QuerySync(abci.RequestQuery{
  50. Path: path,
  51. Data: data,
  52. Height: height,
  53. Prove: !trusted,
  54. })
  55. if err != nil {
  56. return nil, err
  57. }
  58. logger.Info("ABCIQuery", "path", path, "data", data, "result", resQuery)
  59. return &ctypes.ResultABCIQuery{
  60. resQuery.Result(),
  61. }, nil
  62. }
  63. // Get some info about the application.
  64. //
  65. // ```shell
  66. // curl 'localhost:46657/abci_info'
  67. // ```
  68. //
  69. // ```go
  70. // client := client.NewHTTP("tcp://0.0.0.0:46657", "/websocket")
  71. // info, err := client.ABCIInfo()
  72. // ```
  73. //
  74. // > The above command returns JSON structured like this:
  75. //
  76. // ```json
  77. // {
  78. // "error": "",
  79. // "result": {
  80. // "response": {
  81. // "data": "{\"size\":3}"
  82. // }
  83. // },
  84. // "id": "",
  85. // "jsonrpc": "2.0"
  86. // }
  87. // ```
  88. func ABCIInfo() (*ctypes.ResultABCIInfo, error) {
  89. resInfo, err := proxyAppQuery.InfoSync(abci.RequestInfo{version.Version})
  90. if err != nil {
  91. return nil, err
  92. }
  93. return &ctypes.ResultABCIInfo{resInfo}, nil
  94. }