跳转到内容

自托管 Indexer API

本指南将带你设置自托管 Indexer API。

  • 需要运行中的 PostgreSQL 实例,并具有有效的用户和数据库。本示例中的用户为 postgres,数据库为 indexer
  • 如果希望使用 Docker,必须已安装 Docker。安装指南

运行服务需要定义配置文件。先使用以下模板:

health_check_port: 8084
server_config:
processor_config:
type: default_processor
postgres_connection_string: postgresql://postgres:@localhost:5432/indexer
indexer_grpc_data_service_address: 127.0.0.1:50051
indexer_grpc_http2_ping_interval_in_secs: 60
indexer_grpc_http2_ping_timeout_in_secs: 10
auth_token: AUTH_TOKEN

接下来可能需要修改其中一些字段的值。下面介绍几个字段。

这是希望运行的处理器。可在此处查看可用处理器。一些示例:

  • coin_processor
  • ans_processor
  • token_v2_processor

这是 PostgreSQL 数据库的连接字符串,格式应为 postgresql://<username>:<password>@<host>:<port>/<database>

这是交易流服务的 URL。若使用 Labs 托管实例,可在此页面找到每个网络的 URL。请确保为要索引的网络选择正确 URL。若在本地运行服务,值应为 127.0.0.1:50051

这是用于连接交易流服务的身份验证令牌。若使用 Labs 托管实例,可通过 API Gateway 获得 API 密钥。详见此页面

克隆仓库:

Terminal window
# SSH
git clone git@github.com:aptos-labs/aptos-indexer-processors-v2.git
# HTTPS
git clone https://github.com/aptos-labs/aptos-indexer-processors-v2.git

前往服务目录:

Terminal window
cd aptos-indexer-processors
cd rust/processor

运行服务:

Terminal window
cargo run --release -- -c config.yaml

要使用 Docker 运行服务,请使用以下命令:

Terminal window
docker run -it --network host --mount type=bind,source=/tmp/config.yaml,target=/config.yaml aptoslabs/indexer-processor-rust -c /config.yaml

该命令将容器绑定到主机网络,并将配置文件从主机挂载到容器。本次调用假设主机中的配置文件位于 /tmp/config.yaml

在 DockerHub 上查看镜像:https://hub.docker.com/r/aptoslabs/indexer-processor-rust/tags