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.

100 lines
3.0 KiB

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