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

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