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.

89 lines
2.9 KiB

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