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

7 years ago
7 years ago
7 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
6 years ago
6 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
6 years ago
6 years ago
7 years ago
  1. # Indexing Transactions
  2. Tendermint allows you to index transactions and later query or subscribe
  3. to their results.
  4. Let's take a look at the `[tx_index]` config section:
  5. ```
  6. ##### transactions indexer configuration options #####
  7. [tx_index]
  8. # What indexer to use for transactions
  9. #
  10. # Options:
  11. # 1) "null"
  12. # 2) "kv" (default) - the simplest possible indexer, backed by key-value storage (defaults to levelDB; see DBBackend).
  13. indexer = "kv"
  14. # Comma-separated list of tags to index (by default the only tag is "tx.hash")
  15. #
  16. # You can also index transactions by height by adding "tx.height" tag here.
  17. #
  18. # It's recommended to index only a subset of tags due to possible memory
  19. # bloat. This is, of course, depends on the indexer's DB and the volume of
  20. # transactions.
  21. index_tags = ""
  22. # When set to true, tells indexer to index all tags (predefined tags:
  23. # "tx.hash", "tx.height" and all tags from DeliverTx responses).
  24. #
  25. # Note this may be not desirable (see the comment above). IndexTags has a
  26. # precedence over IndexAllTags (i.e. when given both, IndexTags will be
  27. # indexed).
  28. index_all_tags = false
  29. ```
  30. By default, Tendermint will index all transactions by their respective
  31. hashes using an embedded simple indexer. Note, we are planning to add
  32. more options in the future (e.g., Postgresql indexer).
  33. ## Adding tags
  34. In your application's `DeliverTx` method, add the `Tags` field with the
  35. pairs of UTF-8 encoded strings (e.g. "account.owner": "Bob", "balance":
  36. "100.0", "date": "2018-01-02").
  37. Example:
  38. ```
  39. func (app *KVStoreApplication) DeliverTx(req types.RequestDeliverTx) types.Result {
  40. ...
  41. tags := []cmn.KVPair{
  42. {[]byte("account.name"), []byte("igor")},
  43. {[]byte("account.address"), []byte("0xdeadbeef")},
  44. {[]byte("tx.amount"), []byte("7")},
  45. }
  46. return types.ResponseDeliverTx{Code: code.CodeTypeOK, Tags: tags}
  47. }
  48. ```
  49. If you want Tendermint to only index transactions by "account.name" tag,
  50. in the config set `tx_index.index_tags="account.name"`. If you to index
  51. all tags, set `index_all_tags=true`
  52. Note, there are a few predefined tags:
  53. - `tx.hash` (transaction's hash)
  54. - `tx.height` (height of the block transaction was committed in)
  55. Tendermint will throw a warning if you try to use any of the above keys.
  56. ## Querying transactions
  57. You can query the transaction results by calling `/tx_search` RPC
  58. endpoint:
  59. ```
  60. curl "localhost:26657/tx_search?query=\"account.name='igor'\"&prove=true"
  61. ```
  62. Check out [API docs](https://tendermint.com/rpc/#txsearch)
  63. for more information on query syntax and other options.
  64. ## Subscribing to transactions
  65. Clients can subscribe to transactions with the given tags via Websocket
  66. by providing a query to `/subscribe` RPC endpoint.
  67. ```
  68. {
  69. "jsonrpc": "2.0",
  70. "method": "subscribe",
  71. "id": "0",
  72. "params": {
  73. "query": "account.name='igor'"
  74. }
  75. }
  76. ```
  77. Check out [API docs](https://tendermint.com/rpc/#subscribe) for
  78. more information on query syntax and other options.