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.

101 lines
2.7 KiB

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