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.6 KiB

8 years ago
8 years ago
  1. package core
  2. import (
  3. abci "github.com/tendermint/tendermint/abci/types"
  4. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  5. "github.com/tendermint/tendermint/version"
  6. cmn "github.com/tendermint/tmlibs/common"
  7. )
  8. // Query the application for some information.
  9. //
  10. // ```shell
  11. // curl 'localhost:26657/abci_query?path=""&data="abcd"&trusted=false'
  12. // ```
  13. //
  14. // ```go
  15. // client := client.NewHTTP("tcp://0.0.0.0:26657", "/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 | int64 | 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 cmn.HexBytes, height int64, 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{*resQuery}, nil
  60. }
  61. // Get some info about the application.
  62. //
  63. // ```shell
  64. // curl 'localhost:26657/abci_info'
  65. // ```
  66. //
  67. // ```go
  68. // client := client.NewHTTP("tcp://0.0.0.0:26657", "/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. }