SubQuery開發者指南丨清單文件(Manifest File) - 冷萃財經

SubQuery開發者指南丨清單文件(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 端點以加快處理速度 – 點擊鏈接: 查看 SubQuery 字典的工作原理。

 

• dataSources 定義了將被過濾和提取的數據,以及要應用的數據轉換的映射函數處理程序的位置。

 

◦ Kind 目前只支持 substrate/Runtime

 

◦ startBlock 詳細說明了開始索引的塊高度。

 

◦ filter 將根據網路端點規範名稱過濾要執行的數據源,請參閱網路過濾器:

 

◦ mapping.handlers 將列出所有映射函數及其相應的處理程序類型(),以及額外的映射過濾器()。

 

網路過濾器(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

下表說明了不同處理程序支持的過濾器。

處理程序

支持的過濾器

specVersion

module,method

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。

冷萃財經原創,作者:awing,轉載請註明出處:https://www.lccjd.top/2021/09/22/subquery%e5%bc%80%e5%8f%91%e8%80%85%e6%8c%87%e5%8d%97%e4%b8%a8%e6%b8%85%e5%8d%95%e6%96%87%e4%bb%b6%ef%bc%88manifest-file%ef%bc%89/?variant=zh-tw

0

掃一掃,分享到微信

猜你喜歡

文章評論

電子郵件地址不會被公開。 必填項已用*標註

後發表評論

    上一篇

    美國CFTC專員:沒有國會批准,CFTC就沒有加密貨幣執法資源

    下一篇

    一文了解波卡的通貨膨脹

    微信公眾號

    微信公眾號