SubQuery开发者指南丨清单文件(Manifest File)

一文带你了解清单文件(Manifest File)

Manifest project.yaml 文件可以被看作是项目的入口,它定义了关于 SubQuery 如何索引和转换链数据的大部分细节。

 

Manifest 可以是 YAML 或 JSON 格式。 在本文档中,我们将在所有示例中使用 YAML格式。 以下是一个基本 project.yaml 的标准示例。

 

specVersion: “0.0.1”

description: “”

repository: “https://github.com/subquery/subql-starter”

schema: “./schema.graphql”

network:

endpoint: “wss://polkadot.api.onfinality.io/public-ws” # Optionally provide the HTTP endpoint of a full chain dictionary to speed up processing

dictionary: “https://api.subquery.network/sq/subquery/dictionary-polkadot”

dataSources:

– name: main

kind: substrate/Runtime

startBlock: 1

mapping:

handlers:

– handler: handleBlock

kind: substrate/BlockHandler

– handler: handleEvent

kind: substrate/EventHandler

filter: #Filter is optional but suggested to speed up event processing

module: balances

method: Deposit

– handler: handleCall

kind: substrate/CallHandler

 

• network.endpoint 定义了要编入索引的区块链的 wss 或 ws 端点——这必须是一个完整的存档节点。

 

• network.dictionary 选择性地提供完整链字典的 HTTP 端点以加快处理速度 – 点击链接:https://doc.subquery.network/tutorials_examples/dictionary.html 查看 SubQuery 字典的工作原理。

 

• dataSources 定义了将被过滤和提取的数据,以及要应用的数据转换的映射函数处理程序的位置。

 

◦ Kind 目前只支持 substrate/Runtime

 

◦ startBlock 详细说明了开始索引的块高度。

 

◦ filter 将根据网络端点规范名称过滤要执行的数据源,请参阅网络过滤器:https://doc.subquery.network/create/manifest.html#network-filters

 

◦ mapping.handlers 将列出所有映射函数及其相应的处理程序类型(https://doc.subquery.network/create/mapping.html),以及额外的映射过滤器(https://doc.subquery.network/create/manifest.html#mapping-filters)。

 

网络过滤器(Network Filters)

 

通常用户会创建一个 SubQuery 项目,并希望在他们的测试网和主网环境(例如 Polkadot 和 Kusama)中重复使用它。 在网络之间,各种选项可能不同(例如索引起始块)。 因此,我们允许用户为每个数据源定义不同的细节,这意味着一个 SubQuery 项目仍然可以跨多个网络使用。

 

用户可以在 dataSources 命令上添加 filter 命令来决定在网络上运行哪个数据源。

 

下面的示例显示了 Polkadot 和 Kusama 网络的不同数据源。

 

network:

endpoint: “wss://polkadot.api.onfinality.io/public-ws”

#Create a template to avoid redundancy

definitions:

mapping: &mymapping

handlers:

– handler: handleBlock

kind: substrate/BlockHandler

dataSources:

– name: polkadotRuntime

kind: substrate/Runtime

filter: #Optional

specName: polkadot

startBlock: 1000

mapping: *mymapping #use template here

– name: kusamaRuntime

kind: substrate/Runtime

filter:

specName: kusama

startBlock: 12000

mapping: *mymapping # can reuse or change

 

映射过滤器(Mapping Filters)

 

Mapping filters 是一个非常有用的功能,它可以决定什么块、事件或外在因素会触发映射处理程序。

 

只有满足过滤条件的传入数据才会被映射函数处理。 映射过滤器是选择性使用的,但我们建议使用,因为它们会显着减少 SubQuery 项目处理的数据量并提高索引性能。

 

#Example filter from callHandler

filter:

module: balances

method: Deposit

success: true

下表说明了不同处理程序支持的过滤器。

处理程序

支持的过滤器

BlockHandler

specVersion

EventHandler

module,method

CallHandler

module,method ,success

 

• 任何基于底层的链都支持 module 和 method filters。

 

• success filter 采用布尔值,可用于按成功状态过滤外在因素。

 

• specVersion filter 指定了substrate 区块的spec 版本范围。以下示例描述如何设置版本范围。

 

filter:

specVersion: [23, 24] #Index block with specVersion in between 23 and 24 (inclusive).

specVersion: [100] #Index block with specVersion greater than or equal 100.

specVersion: [null, 23] #Index block with specVersion less than or equal 23.

 

定制链(Custom Chains)

 

您还可以通过在 project.yaml 中加入链类型来索引自定义链中的数据。 在 network.types 中声明此区块链支持的特定类型。 我们支持底层运行模块时使用的其他类型。

 

我们还支持 typesAlias、typesBundle、typesChain 和 typesSpec。

转载声明:本文 由CoinON抓取收录,观点仅代表作者本人,不代表CoinON资讯立场,CoinON不对所包含内容的准确性、可靠性或完整性提供任何明示或暗示的保证。若以此作为投资依据,请自行承担全部责任。

声明:图文来源于网络,如有侵权请联系删除

风险提示:投资有风险,入市需谨慎。本资讯不作为投资理财建议。

(1)
打赏 微信扫一扫 微信扫一扫
上一篇 2021年9月22日 下午4:27
下一篇 2021年9月22日 下午6:17

相关推荐

SubQuery开发者指南丨清单文件(Manifest File)

星期三 2021-09-22 16:36:37

Manifest project.yaml 文件可以被看作是项目的入口,它定义了关于 SubQuery 如何索引和转换链数据的大部分细节。

 

Manifest 可以是 YAML 或 JSON 格式。 在本文档中,我们将在所有示例中使用 YAML格式。 以下是一个基本 project.yaml 的标准示例。

 

specVersion: “0.0.1”

description: “”

repository: “https://github.com/subquery/subql-starter”

schema: “./schema.graphql”

network:

endpoint: “wss://polkadot.api.onfinality.io/public-ws” # Optionally provide the HTTP endpoint of a full chain dictionary to speed up processing

dictionary: “https://api.subquery.network/sq/subquery/dictionary-polkadot”

dataSources:

– name: main

kind: substrate/Runtime

startBlock: 1

mapping:

handlers:

– handler: handleBlock

kind: substrate/BlockHandler

– handler: handleEvent

kind: substrate/EventHandler

filter: #Filter is optional but suggested to speed up event processing

module: balances

method: Deposit

– handler: handleCall

kind: substrate/CallHandler

 

• network.endpoint 定义了要编入索引的区块链的 wss 或 ws 端点——这必须是一个完整的存档节点。

 

• network.dictionary 选择性地提供完整链字典的 HTTP 端点以加快处理速度 – 点击链接:https://doc.subquery.network/tutorials_examples/dictionary.html 查看 SubQuery 字典的工作原理。

 

• dataSources 定义了将被过滤和提取的数据,以及要应用的数据转换的映射函数处理程序的位置。

 

◦ Kind 目前只支持 substrate/Runtime

 

◦ startBlock 详细说明了开始索引的块高度。

 

◦ filter 将根据网络端点规范名称过滤要执行的数据源,请参阅网络过滤器:https://doc.subquery.network/create/manifest.html#network-filters

 

◦ mapping.handlers 将列出所有映射函数及其相应的处理程序类型(https://doc.subquery.network/create/mapping.html),以及额外的映射过滤器(https://doc.subquery.network/create/manifest.html#mapping-filters)。

 

网络过滤器(Network Filters)

 

通常用户会创建一个 SubQuery 项目,并希望在他们的测试网和主网环境(例如 Polkadot 和 Kusama)中重复使用它。 在网络之间,各种选项可能不同(例如索引起始块)。 因此,我们允许用户为每个数据源定义不同的细节,这意味着一个 SubQuery 项目仍然可以跨多个网络使用。

 

用户可以在 dataSources 命令上添加 filter 命令来决定在网络上运行哪个数据源。

 

下面的示例显示了 Polkadot 和 Kusama 网络的不同数据源。

 

network:

endpoint: “wss://polkadot.api.onfinality.io/public-ws”

#Create a template to avoid redundancy

definitions:

mapping: &mymapping

handlers:

– handler: handleBlock

kind: substrate/BlockHandler

dataSources:

– name: polkadotRuntime

kind: substrate/Runtime

filter: #Optional

specName: polkadot

startBlock: 1000

mapping: *mymapping #use template here

– name: kusamaRuntime

kind: substrate/Runtime

filter:

specName: kusama

startBlock: 12000

mapping: *mymapping # can reuse or change

 

映射过滤器(Mapping Filters)

 

Mapping filters 是一个非常有用的功能,它可以决定什么块、事件或外在因素会触发映射处理程序。

 

只有满足过滤条件的传入数据才会被映射函数处理。 映射过滤器是选择性使用的,但我们建议使用,因为它们会显着减少 SubQuery 项目处理的数据量并提高索引性能。

 

#Example filter from callHandler

filter:

module: balances

method: Deposit

success: true

下表说明了不同处理程序支持的过滤器。

处理程序

支持的过滤器

BlockHandler

specVersion

EventHandler

module,method

CallHandler

module,method ,success

 

• 任何基于底层的链都支持 module 和 method filters。

 

• success filter 采用布尔值,可用于按成功状态过滤外在因素。

 

• specVersion filter 指定了substrate 区块的spec 版本范围。以下示例描述如何设置版本范围。

 

filter:

specVersion: [23, 24] #Index block with specVersion in between 23 and 24 (inclusive).

specVersion: [100] #Index block with specVersion greater than or equal 100.

specVersion: [null, 23] #Index block with specVersion less than or equal 23.

 

定制链(Custom Chains)

 

您还可以通过在 project.yaml 中加入链类型来索引自定义链中的数据。 在 network.types 中声明此区块链支持的特定类型。 我们支持底层运行模块时使用的其他类型。

 

我们还支持 typesAlias、typesBundle、typesChain 和 typesSpec。