Skip to content

Conversation

@lorisleiva
Copy link
Member

@lorisleiva lorisleiva commented Nov 6, 2024

This PR adds a new dynamic-parsers package that allows us to dynamically identify and parse accounts and instructions from a RootNode and a byte array.

It uses the newly created dynamic-codecs under the hood to decode data dynamically and uses DiscriminatorNodes to identify accounts and instructions from a given byte array.

Here's a quick usage overview.

const parsedData = parseAccountData(rootNode, bytes); // For parsing accounts. OR
const parsedData = parseInstructionData(rootNode, bytes); // For parsing instructions.

if(!parsedData) throw new Error("Could not identify account/instruction on the program");

parsedData.data // the JSON-compatible decoded data.
parsedData.path // the NodePath identified by the bytes on the program.

const node = getLastNodeFromPath(parsedData.path)
//    ^ The account/instruction node used to decode the bytes.

See the README of the new package for more information.

@changeset-bot
Copy link

changeset-bot bot commented Nov 6, 2024

🦋 Changeset detected

Latest commit: fc2cbef

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@codama/dynamic-parsers Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @lorisleiva and the rest of your teammates on Graphite Graphite

@lorisleiva lorisleiva force-pushed the loris/dynamic-parsers branch 6 times, most recently from 15e807c to d065ea1 Compare November 6, 2024 16:58
@lorisleiva lorisleiva force-pushed the loris/dynamic-parsers branch from d065ea1 to fc2cbef Compare November 6, 2024 17:00
@lorisleiva lorisleiva marked this pull request as ready for review November 6, 2024 17:05
@lorisleiva lorisleiva requested review from febo and ngundotra November 6, 2024 17:06
Copy link

@ngundotra ngundotra left a comment

Choose a reason for hiding this comment

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

LGTM! Great clean package.

We had some offline discussion about how to support events, but that discussion should not block this package!

@lorisleiva lorisleiva merged commit c698fe5 into main Nov 6, 2024
4 checks passed
@lorisleiva lorisleiva deleted the loris/dynamic-parsers branch November 6, 2024 22:04
@github-actions github-actions bot mentioned this pull request Nov 6, 2024
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.

3 participants