The Graph 是一种使用 GraphQL 在以太坊和 IPFS 上快速构建去中心化应用程序 (dApp) 的协议。
Graph Node 是一个开源 Rust 实现,它的事件源来自以太坊区块链,以确定性地更新可通过 GraphQL 端点查询的数据存储。
有关详细说明和更多上下文,请查看入门指南。
要构建并运行此项目,您需要在系统上安装以下软件:
rustfmt
是默认 Rust 安装的一部分,是构建时的要求。对于以太坊网络数据,您可以运行自己的以太坊节点或使用您选择的以太坊节点提供商。
最低硬件要求:
cargo
构建图形节点,需要 8GB RAM。运行图形节点的最简单方法是使用官方 Docker compose 设置。这将启动 Postgres 数据库、IPFS 节点和图形节点。请按照此处的说明进行操作。
这是一个显示工作图形节点的快速示例。它是 Gravatars 的子图。
ipfs init
然后运行ipfs daemon
。initdb -D .postgres -E UTF8 --locale=C
然后运行pg_ctl -D .postgres -l logfile start
和createdb graph-node
。sudo apt-get install -y clang libpq-dev libssl-dev pkg-config
yarn
yarn codegen
cargo build
。设置完所有依赖项后,您可以运行以下命令:
cargo run -p graph-node --release --
--postgres-url postgresql://USERNAME[:PASSWORD]@localhost:5432/graph-node
--ethereum-rpc NETWORK_NAME:[CAPABILITIES]:URL
--ipfs 127.0.0.1:5001
尝试使用您的操作系统用户名作为USERNAME
和PASSWORD
。有关设置连接字符串的详细信息,请查看 Postgres 文档。 graph-node
使用一些 Postgres 扩展。如果运行graph-node
的 Postgres 用户是超级用户, graph-node
将在初始化数据库时启用这些扩展。如果 Postgres 用户不是超级用户,您将需要手动创建扩展,因为只有超级用户才可以这样做。要创建它们,您需要以超级用户身份连接,在许多安装中是postgres
用户:
psql -q -X -U < SUPERUSER > graph-node << EOF
create extension pg_trgm;
create extension pg_stat_statements;
create extension btree_gist;
create extension postgres_fdw;
grant usage on foreign data wrapper postgres_fdw to <USERNAME>;
EOF
这还将在http://127.0.0.1:8000/
上启动 GraphiQL 界面。
yarn create-local
然后您可以部署子图:
yarn deploy-local
这将构建子图并将其部署到图节点。它应该立即开始为子图建立索引。
USAGE:
graph-node [FLAGS] [OPTIONS] --ethereum-ipc <NETWORK_NAME:FILE> --ethereum-rpc <NETWORK_NAME:URL> --ethereum-ws <NETWORK_NAME:URL> --ipfs <HOST:PORT> --postgres-url <URL>
FLAGS:
--debug Enable debug logging
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
--admin-port <PORT> Port for the JSON-RPC admin server [default: 8020]
--elasticsearch-password <PASSWORD>
Password to use for Elasticsearch logging [env: ELASTICSEARCH_PASSWORD]
--elasticsearch-url <URL>
Elasticsearch service to write subgraph logs to [env: ELASTICSEARCH_URL=]
--elasticsearch-user <USER> User to use for Elasticsearch logging [env: ELASTICSEARCH_USER=]
--ethereum-ipc <NETWORK_NAME:[CAPABILITIES]:FILE>
Ethereum network name (e.g. 'mainnet'), optional comma-separated capabilities (eg full,archive), and an Ethereum IPC pipe, separated by a ':'
--ethereum-polling-interval <MILLISECONDS>
How often to poll the Ethereum node for new blocks [env: ETHEREUM_POLLING_INTERVAL=] [default: 500]
--ethereum-rpc <NETWORK_NAME:[CAPABILITIES]:URL>
Ethereum network name (e.g. 'mainnet'), optional comma-separated capabilities (eg 'full,archive'), and an Ethereum RPC URL, separated by a ':'
--ethereum-ws <NETWORK_NAME:[CAPABILITIES]:URL>
Ethereum network name (e.g. 'mainnet'), optional comma-separated capabilities (eg `full,archive), and an Ethereum WebSocket URL, separated by a ':'
--node-id <NODE_ID>
A unique identifier for this node instance. Should have the same value between consecutive node restarts [default: default]
--http-port <PORT> Port for the GraphQL HTTP server [default: 8000]
--ipfs <HOST:PORT> HTTP address of an IPFS node
--postgres-url <URL> Location of the Postgres database used for storing entities
--subgraph <[NAME:]IPFS_HASH> Name and IPFS hash of the subgraph manifest
--ws-port <PORT> Port for the GraphQL WebSocket server [default: 8001]
命令行参数通常是运行graph-node
实例所需的全部内容。对于高级用途,可以通过环境变量进一步配置graph-node
的各个方面。非常大的graph-node
实例还可以跨多个数据库拆分查询和索引工作。
node
— 本地图节点。graph
— 提供系统组件特征和通用数据类型的库。core
— 提供核心组件实现的库,供所有节点使用。chain/ethereum
— 一个包含用于从以太坊获取数据的组件的库。graphql
— 具有 API 模式生成、内省等功能的 GraphQL 实现。mock
— 为所有系统组件提供模拟实现的库。runtime/wasm
— 用于运行 WASM 数据提取脚本的库。server/http
— 通过 HTTP 提供 GraphQL 服务器的库。store/postgres
— 具有 GraphQL 友好界面和审核日志的 Postgres 存储。 ? = 进行中
? = 功能完成。需要额外的测试。
✅ = 功能完整
特征 | 地位 |
---|---|
以太坊 | |
索引智能合约事件 | ✅ |
处理链条重组 | ✅ |
映射 | |
基于 WASM 的映射 | ✅ |
TypeScript 到 WASM 工具链 | ✅ |
自动生成的 TypeScript 类型 | ✅ |
GraphQL | |
通过ID查询实体 | ✅ |
查询实体集合 | ✅ |
分页 | ✅ |
过滤 | ✅ |
基于块的过滤 | ✅ |
实体关系 | ✅ |
订阅 | ✅ |
请检查 CONTRIBUTING.md 了解我们使用的开发流程和约定。以下是优先考虑的问题列表。
版权所有 © 2018-2019 Graph Protocol, Inc. 和贡献者。
Graph 获得 MIT 许可证和 Apache 许可证 2.0 版的双重许可。
除非适用法律要求或书面同意,否则根据许可分发的软件均按“原样”分发,不带任何明示或暗示的保证或条件。请参阅许可证,了解许可证下管理权限和限制的特定语言。