subquery-call-visitor
TypeScript icon, indicating that this package has built-in type declarations

1.2.7 • Public • Published

SubQuery Call Visitor

npm

Package that allows you to easily traverse nested Substrate calls

Getting started

Install package

yarn add subquery-call-visitor
yarn install

Setup visitor

const callWalk = CreateCallWalk()

const visitor = CreateCallVisitorBuilder()
    .on("balances", "transfer", handleTransfer)
    .ignoreFailedCalls(true)
    .build()


async function handleTransfer(visitedCall: VisitedCall): Promise<void> {
   // your logic
}

Register handlers

In order for SubQuery indexer to index nested calls you should add the following to your project

  1. Add a common handler
export async function handleNestedCalls(extrinsic: SubstrateExtrinsic): Promise<void> {
    await callWalk.walk(extrinsic, visitor)
}
  1. Register common handler in project.yaml:
datasources:
  mapping:
  handlers:
  - handler: handleNestedCalls
    kind: substrate/CallHandler
    filter:
      module: proxy
      method: proxy
      # you may add success flag if you want to visit only success root extrinsics
      success: true 

  - handler: handleNestedCalls
    kind: substrate/CallHandler
    filter:
      module: proxy
      method: proxyAnnounced
      success: true

  - handler: handleNestedCalls
    kind: substrate/CallHandler
    filter:
      module: utility
      method: batch
      success: true

  - handler: handleNestedCalls
    kind: substrate/CallHandler
    filter:
      module: utility
      method: batchAll
      success: true

  - handler: handleNestedCalls
    kind: substrate/CallHandler
    filter:
      module: utility
      method: forceBatch
      success: true

  - handler: handleNestedCalls
    kind: substrate/CallHandler
    filter:
      module: multisig
      method: asMulti
      success: true

  - handler: handleNestedCalls
    kind: substrate/CallHandler
    filter:
      module: multisig
      method: asMultiThreshold1
      success: true

  - handler: handleNestedCalls
    kind: substrate/CallHandler
    filter:
      module: utility
      method: asDerivative
      success: true

Development

You can use following command to update package as dependency in another project. Note that you should remove subquery-call-visitor from package.json first.

npm link /<path_to_visitor_package>

This will crete symlink to subquery-call-visitor and allow applying changes in realtime

When you are done with development and want to switch back to remote version, run the following:

npm unlink /<path_to_visitor_package>

License

SubQuery Call Visitor is available under the Apache 2.0 license. See the LICENSE file for more info. © Novasama Technologies GmbH 2023

Readme

Keywords

none

Package Sidebar

Install

npm i subquery-call-visitor

Weekly Downloads

1

Version

1.2.7

License

MIT

Unpacked Size

59.1 kB

Total Files

47

Last publish

Collaborators

  • novasama-tech
  • erussel