mirror of
https://github.com/tendermint/tendermint.git
synced 2025-12-23 06:15:19 +00:00
This commit is contained in:
@@ -4,12 +4,13 @@ order: 6
|
||||
|
||||
# Indexing Transactions
|
||||
|
||||
Tendermint allows you to index transactions and later query or subscribe to their results.
|
||||
|
||||
Events can be used to index transactions and blocks according to what happened
|
||||
during their execution. Note that the set of events returned for a block from
|
||||
`BeginBlock` and `EndBlock` are merged. In case both methods return the same
|
||||
type, only the key-value pairs defined in `EndBlock` are used.
|
||||
Tendermint allows you to index transactions and blocks and later query or
|
||||
subscribe to their results. Transactions are indexed by `TxResult.Events` and
|
||||
blocks are indexed by `Response(Begin|End)Block.Events`. However, transactions
|
||||
are also indexed by a primary key which includes the transaction hash and maps
|
||||
to and stores the corresponding `TxResult`. Blocks are indexed by a primary key
|
||||
which includes the block height and maps to and stores the block height, i.e.
|
||||
the block itself is never stored.
|
||||
|
||||
Each event contains a type and a list of attributes, which are key-value pairs
|
||||
denoting something about what happened during the method's execution. For more
|
||||
@@ -17,7 +18,7 @@ details on `Events`, see the
|
||||
[ABCI](https://github.com/tendermint/spec/blob/master/spec/abci/abci.md#events)
|
||||
documentation.
|
||||
|
||||
An Event has a composite key associated with it. A `compositeKey` is
|
||||
An `Event` has a composite key associated with it. A `compositeKey` is
|
||||
constructed by its type and key separated by a dot.
|
||||
|
||||
For example:
|
||||
@@ -44,11 +45,29 @@ Let's take a look at the `[tx_index]` config section:
|
||||
indexer = "kv"
|
||||
```
|
||||
|
||||
By default, Tendermint will index all transactions by their respective
|
||||
hashes and height using an embedded simple indexer.
|
||||
By default, Tendermint will index all transactions by their respective hashes
|
||||
and height and blocks by their height.
|
||||
|
||||
You can turn off indexing completely by setting `tx_index` to `null`.
|
||||
|
||||
## Default Indexes
|
||||
|
||||
The Tendermint tx and block event indexer indexes a few select reserved events
|
||||
by default.
|
||||
|
||||
### Transactions
|
||||
|
||||
The following indexes are indexed by default:
|
||||
|
||||
- `tx.height`
|
||||
- `tx.hash`
|
||||
|
||||
### Blocks
|
||||
|
||||
The following indexes are indexed by default:
|
||||
|
||||
- `block.height`
|
||||
|
||||
## Adding Events
|
||||
|
||||
Applications are free to define which events to index. Tendermint does not
|
||||
@@ -77,19 +96,21 @@ func (app *KVStoreApplication) DeliverTx(req types.RequestDeliverTx) types.Resul
|
||||
}
|
||||
```
|
||||
|
||||
The transaction will be indexed (if the indexer is not `null`) with a certain attribute if the attribute's `Index` field is set to `true`.
|
||||
In the above example, all attributes will be indexed.
|
||||
If the indexer is not `null`, the transaction will be indexed. Each event is
|
||||
indexed using a composite key in the form of `{eventType}.{eventAttribute}={eventValue}`,
|
||||
e.g. `transfer.sender=bob`.
|
||||
|
||||
## Querying Transactions
|
||||
## Querying Transactions Events
|
||||
|
||||
You can query the transaction results by calling `/tx_search` RPC endpoint:
|
||||
You can query for a paginated set of transaction by their events by calling the
|
||||
`/tx_search` RPC endpoint:
|
||||
|
||||
```bash
|
||||
curl "localhost:26657/tx_search?query=\"account.name='igor'\"&prove=true"
|
||||
curl "localhost:26657/tx_search?query=\"message.sender='cosmos1...'\"&prove=true"
|
||||
```
|
||||
|
||||
Check out [API docs](https://docs.tendermint.com/master/rpc/#/Info/tx_search) for more information
|
||||
on query syntax and other options.
|
||||
Check out [API docs](https://docs.tendermint.com/master/rpc/#/Info/tx_search)
|
||||
for more information on query syntax and other options.
|
||||
|
||||
## Subscribing to Transactions
|
||||
|
||||
@@ -102,10 +123,22 @@ a query to `/subscribe` RPC endpoint.
|
||||
"method": "subscribe",
|
||||
"id": "0",
|
||||
"params": {
|
||||
"query": "account.name='igor'"
|
||||
"query": "message.sender='cosmos1...'"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Check out [API docs](https://docs.tendermint.com/master/rpc/#subscribe) for more information
|
||||
on query syntax and other options.
|
||||
|
||||
## Querying Blocks Events
|
||||
|
||||
You can query for a paginated set of blocks by their events by calling the
|
||||
`/block_search` RPC endpoint:
|
||||
|
||||
```bash
|
||||
curl "localhost:26657/block_search?query=\"block.height > 10 AND val_set.num_changed > 0\""
|
||||
```
|
||||
|
||||
Check out [API docs](https://docs.tendermint.com/master/rpc/#/Info/block_search)
|
||||
for more information on query syntax and other options.
|
||||
|
||||
Reference in New Issue
Block a user