การสนับสนุน EVM ของ Substrate

SubQuery TeamAbout 1 min

การสนับสนุน EVM ของ Substrate

เรามีตัวประมวลผลแหล่งข้อมูลแบบกำหนดเองได้ สำหรับ EVM ของ Moonbeam และ Moonriver ซึ่งทำให้มีวิธีง่ายๆในการคัดกรองและจัดทำดัชนี ทั้งกิจกรรม EVM และ Substrate บนเครือข่ายของ Moonbeam ภายในโครงการ SubQuery เดียวเท่านั้น

เครือข่ายที่สนับสนุน:

ชื่อเครือข่ายEndpoint ของ WebsocketEndpoint ของ Dictionary
Moonbeamwss://moonbeam.api.onfinality.io/public-wshttps://api.subquery.network/sq/subquery/moonbeam-dictionary
Moonriverwss://moonriver.api.onfinality.io/public-wshttps://api.subquery.network/sq/subquery/moonriver-dictionary
Moonbase Alphawss://moonbeam-alpha.api.onfinality.io/public-wshttps://api.subquery.network/sq/subquery/moonbase-alpha-dictionary

คุณยังสามารถอ้างอิงถึงโปรเจ็กต์ตัวอย่างของ Moonriver EVM แบบพื้นฐานopen in new window ที่มี event handler และ call handler ด้วย ซึ่งโปรเจ็กต์นี้โฮสต์อยู่ใน SubQuery Explorer แล้วที่นี่open in new window

เริ่มต้นใช้งาน

  1. เพิ่มแหล่งข้อมูลที่กำหนดเอง ในรูปแบบ dependency yarn add @subql/contract-processors
  2. เพิ่มแหล่งข้อมูลที่กำหนดเองตามที่อธิบายไว้ด้านล่าง
  3. เพิ่มตัวจัดการ หรือ handle สำหรับแหล่งข้อมูลที่กำหนดเองให้กับโค้ดของคุณ

ข้อมูลจำเพาะของแหล่งข้อมูล

ฟิลด์ประเภทจำเป็นต้องมีคำอธิบาย
processor.file'./node_modules/@subql/contract-processors/dist/moonbeam.js'ใช่ไฟล์ที่อ้างอิงถึงโค้ดของตัวประมวลผลข้อมูล
processor.optionsProcessorOptionsไม่ตัวเลือกเฉพาะสำหรับโปรเซสเซอร์ของ Moonbeam
assets{ [key: String]: { file: String }}ไม่เป้าหมายของไฟล์สินทรัพย์ภายนอก

ตัวเลือกโปรเซสเซอร์

ฟิลด์ประเภทจำเป็นต้องมีคำอธิบาย
abiStringไม่ABI ที่โปรเซสเซอร์ใช้เพื่อแยกวิเคราะห์ arguments ต้องเป็น key ของassets
addressString or nullไม่แอดเดรสในสัญญา (contact address) ที่เกิดเหตุการณ์เป็น from หรือ call null จะจับการ call ในการสร้าง contact

MoonbeamCall

ทำงานในลักษณะเดียวกับ substrate/CallHandler ยกเว้นมี handler argument ที่แตกต่างกันและมีการเปลี่ยนแปลงการคัดกรองเล็กน้อย

ฟิลด์ประเภทจำเป็นต้องมีคำอธิบาย
kind'substrate/MoonbeamCall'ใช่ระบุว่านี่คือ handler ประเภท Call
filterCall Filterไม่คัดกรองแหล่งข้อมูลเพื่อดำเนินการ

Call Filters

ฟิลด์ประเภทตัวอย่างคำอธิบาย
functionString0x095ea7b3, approve(address to,uint256 value)เป็นได้ทั้งสตริง Function Signatureopen in new window หรือฟังก์ชัน sighash เพื่อคัดกรองฟังก์ชันที่ called ในสัญญา (contract)
fromString0x6bd193ee6d2104f14f94e2ca6efefae561a4334bแอดเดรส Ethereum ที่ส่งธุรกรรม

Handlers (ตัวดำเนินการ)

Handler นี้จะไม่เหมือนกับ handler ทั่วไป เนื่องจากคุณจะไม่ได้ SubstrateExtrinsic เป็นพารามิเตอร์ แต่คุณจะได้ MoonbeamCall ซึ่งอิงตามประเภท TransactionResponseopen in new window ของ Ethers แทน

การเปลี่ยนแปลงจากประเภท TransactionResponse:

  • ไม่มีคุณสมบัติ wait และ confirmations
  • คุณสมบัติ success ถูกเพิ่มในรายการเพื่อให้ทราบว่าการทำธุรกรรมประสบความสำเร็จหรือไม่
  • args จะถูกเพิ่ม ถ้าหากมีการระบุในฟิลด์ abi และสามารถทำการ parse argument ได้สำเร็จ

MoonbeamEvent

ทำงานในลักษณะเดียวกับ substrate/CallHandler ยกเว้นมี handler argument ที่แตกต่างกันและมีการเปลี่ยนแปลงการคัดกรองเล็กน้อย

ฟิลด์ประเภทจำเป็นต้องมีคำอธิบาย
kind'substrate/MoonbeamEvent'ใช่ระบุว่านี่คือ handler ประเภท Event
filterEvent Filterไม่คัดกรองแหล่งข้อมูลเพื่อดำเนินการ

Event Filters (การคัดกรองอีเว้นท์)

ฟิลด์ประเภทตัวอย่างคำอธิบาย
topicsString arrayTransfer(address indexed from,address indexed to,uint256 value)หัวข้อการคัดกรอง อ้างอิงตามการคัดกรอง log ของ Ethereum JSON-PRC โดยสามารถดูเอกสารเพิ่มเติมได้ที่นี่open in new window.

หมายเหตุ: มีการปรับปรุงสองสามอย่างจากการคัดกรอง log พื้นฐาน:

  • หัวข้อไม่จำเป็นต้องมี pad เป็น 0
  • Event Fragmentopen in new window สามารถจัดเตรียมสตริงและแปลงเป็น id โดยอัตโนมัติ

Handlers (ตัวดำเนินการ)

Handler นี้จะไม่เหมือนกับ handler ทั่วไป เนื่องจากคุณจะไม่ได้ SubstrateEvent เป็นพารามิเตอร์ แต่คุณจะได้ MoonbeamEvent ซึ่งอิงตามประเภทของ Logopen in new window ของ Ethers แทน

การเปลี่ยนจากประเภท Log:

  • args จะถูกเพิ่ม ถ้าหากมีการระบุในฟิลด์ abi และสามารถทำการ parse argument ได้สำเร็จ

ตัวอย่างแหล่งข้อมูล

นี่คือการดึงข้อมูลจากไฟล์ Manifest project.yaml

dataSources:
  - kind: substrate/Moonbeam
    startBlock: 752073
    processor:
      file: "./node_modules/@subql/contract-processors/dist/moonbeam.js"
      options:
        # Must be a key of assets
        abi: erc20
        # Contract address (or recipient if transfer) to filter, if `null` should be for contract creation
        address: "0x6bd193ee6d2104f14f94e2ca6efefae561a4334b"
    assets:
      erc20:
        file: "./erc20.abi.json"
    mapping:
      file: "./dist/index.js"
      handlers:
        - handler: handleMoonriverEvent
          kind: substrate/MoonbeamEvent
          filter:
            topics:
              - Transfer(address indexed from,address indexed to,uint256 value)
        - handler: handleMoonriverCall
          kind: substrate/MoonbeamCall
          filter:
            ## The function can either be the function fragment or signature
            # function: '0x095ea7b3'
            # function: '0x7ff36ab500000000000000000000000000000000000000000000000000000000'
            # function: approve(address,uint256)
            function: approve(address to,uint256 value)
            from: "0x6bd193ee6d2104f14f94e2ca6efefae561a4334b"

ข้อจำกัดที่ทราบ

  • ตอนนี้ยังไม่มีวิธีการทำ query สถานะ EVM ภายใน handler
  • ไม่มีวิธีที่จะได้รับใบตอบรับการทำธุรกรรมกับ call handlers
  • คุณสมบัติ blockHash ไม่ได้กำหนดไว้ในขณะนี้ คุณสามารถใช้คุณสมบัติ blockNumber แทนได้