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.

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