# 索引器 (Indexer)

与 [Zondax](https://zondax.ch/) 合作，为 Namada 区块链开发了一个索引器。

Namada 索引器（又名 `namadexer`）不断地查询 Namada 区块链，并且与 [SDK](/namada-docs-chinese/ji-cheng-zhi-nan-integration-guide/shi-yong-sdk-using-the-sdk.md) 一起，能够将区块、交易以及其他有价值的信息映射到关系数据库（postgres）中。<br>

这对于执行区块链上的分析，包括以容易查询的方式存储历史数据，特别有用。

***

## 设置 (Setting up)

可以在[这里](https://github.com/zondax/namadexer)找到 namada 索引器的源代码，并且设置简单。

`namadexer` 与 [Docker](https://www.docker.com/products/docker-desktop) 一起工作效果最好。

```
git clone https://github.com/Zondax/namadexer.git
cd namadexer
make compose
```

***

## 运行服务器和数据库 (Running the server and db)

一旦 DockerFile 运行完毕，设置 postgres 数据库以及将查询数据库的服务器变得非常简单。

确保在本地机器上[安装](https://www.postgresql.org/download/)了 `postgres`。

**在 docker 中运行 postgres**

```
make postgres 
# or run (and change arguments, e.g port):
# docker run --name postgres -e POSTGRES_PASSWORD=wow -e POSTGRES_DB=blockchain -p 5432:5432 -d postgres
```

一旦 postgres 服务器启动并运行，就可以设置将查询 postgres db 的服务器。

执行以下命令以设置服务器

```
make run_server
```

如果成功，服务器应该作为守护进程在 localhost 的 `30303` 端口上运行。

***

## 运行索引器 (Run the indexer)

首先，确保 `config/Settings.toml` 中的 `Settings.toml` 配置正确。

```
log_level = "info"
network = "public-testnet-14"
 
[database]
host = "0.0.0.0:5435"
user = "postgres"
password = "wow"
dbname = "blockchain"
# Optional field to configure a timeout if database connection 
# fails.
connection_timeout = 20
 
 
[server]
serve_at = "0.0.0.0"
port = 30303
 
[indexer]
tendermint_addr = "0.0.0.0"
port = 26657
 
[jaeger]
enable = false
host = "localhost"
port = 6831
 
[prometheus]
host = "0.0.0.0"
port = 9000
```

{% hint style="info" %}
解读 toml (Interpreting the toml)

重要的是要更改以下参数：

* `indexer.tendermint_addr` - 这应该是同步的 Namada 完整节点的地址和相应端口
* `database.host` - 这应该是运行 postgres 数据库的 tcp 地址（带端口）。
  {% endhint %}

设置完成后，可以开始运行索引器

```
make run_indexer
```

***

## 查询数据库 (Querying the database)

\
在[这里](https://github.com/Zondax/namadexer/blob/main/docs/04-server.md)描述了预定义的端点以查询数据库的文档。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tantalum666.gitbook.io/namada-docs-chinese/ji-cheng-zhi-nan-integration-guide/suo-yin-qi-indexer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
