Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move utils.Chain into chain-helpers package #790

Merged
merged 6 commits into from
Oct 2, 2023

Conversation

ntn-x2
Copy link
Member

@ntn-x2 ntn-x2 commented Aug 11, 2023

Fixes https://github.com/KILTprotocol/ticket/issues/2869.

We discussed about moving the chain-helpers module into the utils package. but after checking both packages, I found it would be more logic to simply move the chainy stuff of the utils package under the Blockchain namespace of the chain-helpers.

The new utility functions to parse blocks and retrieve extrinsics, can be accessed as in the following snippet:

import { Blockchain } from "@kiltprotocol/chain-helpers"

const extrinsic = await Blockchain.retrieveExtrinsicFromBlock(
    blockNumber,
    ({ events }) =>
      events.some(
        (event) =>
          api.events.publicCredentials.CredentialStored.is(event) &&
          event.data[1].toString() === credentialId
      ),
    api
  )

I made the input api: ApiPromise optional, so that it would allow people to use the default returned by ConfigService.get('api') if they need, but internally it needs to be retrieved once and passed along.

@ntn-x2 ntn-x2 requested a review from rflechtner August 11, 2023 12:46
@ntn-x2 ntn-x2 self-assigned this Aug 11, 2023
Copy link
Contributor

@rflechtner rflechtner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it!

packages/utils/src/Chain.ts Show resolved Hide resolved
@ntn-x2 ntn-x2 merged commit c4ab492 into develop Oct 2, 2023
13 checks passed
@ntn-x2 ntn-x2 deleted the aa/chain-helpers-move branch October 2, 2023 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants