1.2.7 • Published 5 months ago

subquery-call-visitor v1.2.7

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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

1.2.7

5 months ago

1.2.6

5 months ago

1.2.5

6 months ago

1.2.4

6 months ago

1.2.3

6 months ago

1.1.1

11 months ago

1.1.0

11 months ago

1.0.1

11 months ago

1.1.2

10 months ago

1.0.0

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago