Repository navigation
[2.x] Return decoded nodes from dynamic parsers - #1216
Conversation
|
trevor-cortex
left a comment
There was a problem hiding this comment.
Summary
Swaps getNodeValueCodec for getNodeCodec in parseData, so every parser now returns the DecodedAccountNode / DecodedEventNode / DecodedInstructionNode of @codama/dynamic-codecs instead of the local ParsedData<TNode> wrapper. ParsedInstruction becomes DecodedInstructionNode & { accounts, remainingAccounts }, with remainingAccounts now required and named accounts carrying identifier rather than name. A new ParseDataOptions = CodecVisitorOptions & IdentifyDataOptions threads bytesEncoding through, and parseInstruction takes CodecVisitorOptions directly (its programAddress still comes from the instruction). README and tests are updated accordingly.
The implementation is a thin, correct delegation. Things I checked:
- Option splitting in
parseDatais explicit ({ programAddress }→identifyData,{ bytesEncoding }→getNodeCodec) rather than forwarding the merged object, so neither side sees keys it doesn't own. Identification only encodes discriminator constants, so it genuinely doesn't needbytesEncoding— nothing is lost there. - The
as GetDecodedNodeFromKind<TKind>cast is the same shape of erasure as the previouspath as NodePath<ParsableNode>and is sound:getNodeCodecon aParsableNodepath yields the union of the three decoded node types, and the kind filter already narrowed the path. - Unparsable bytes keep the same
try/catch → undefinedcontract; the "truncated data" and "unknown program" tests still cover it. parseInstructionoptions type isCodecVisitorOptions, notParseDataOptions— correct, since passing aprogramAddressthere would silently conflict withinstruction.programAddress.- README anchors (
#decoded-nodes,#value-format,#formatting) all exist inpackages/dynamic-codecs/README.md. - No other in-repo consumers of
ParsedData,.datafrom the parsers, ornameon parsed accounts that this would break (@codama/dynamic-clientdoesn't depend ondynamic-parserson this branch).
Things to watch out for
ParsedInstructioninheritsdata?: DecodedTypeNodefromDecodedInstructionNode, so for data-less instructions (e.g. theclosetest)parsed.dataisundefinedwhileparsed.valueis alsoundefined. That's consistent with dynamic-codecs, but the "Decoded nodes" intro in this README says every parser returns "the decoded nodes of itsdata" without that caveat — see inline.- The first
parseAccountDatatest assertstoStrictEqual(getNodeCodec(...).decode(...)), which is mostly tautological on its own; it's fine because the two tests right after it pin down the actual shape (path/value/preOffset/postOffsetandisDecodedNode(result.data, 'structTypeNode')).
Notes for subsequent reviewers
- Changeset: none in the PR, which matches the convention on the other
[2.x]PRs (seeded major changeset at the end of the migration). When that changeset is written, this PR contributes:ParsedDataremoved;data→valueon all parser results;accounts[].name→identifierandremainingAccountsnow required onParsedInstruction; newParseDataOptions/bytesEncodingoption on all parsers andparseInstruction. - Behaviour of identification, the single-candidate fallback, and program selection is untouched — only the decode step and the return shape changed.
95df4cd to
dbc49ce
Compare
dbc49ce to
7a17377
Compare
7256a9f to
46c664f
Compare
7a17377 to
6bcd8c7
Compare
46c664f to
cbd7116
Compare
0d78a47 to
50bd2bc
Compare
62035f2 to
ebd5a98
Compare
1a602d4 to
ca4dea7
Compare
06c0d0a to
9dbd31f
Compare
ca4dea7 to
a938ada
Compare
9dbd31f to
4a978e5
Compare
99dd664 to
faa3e5d
Compare
4a978e5 to
1d26fb1
Compare
faa3e5d to
775a40c
Compare
8093254 to
239b195
Compare
9c4cc3c to
dd87bae
Compare
239b195 to
e128735
Compare
dd87bae to
9e05227
Compare

This PR makes the parsers of
@codama/dynamic-parsersreturn the decoded nodes of@codama/dynamic-codecs, so parsed accounts, events and instructions keep the node of every decoded value, e.g. to format it.parseAccountData,parseEventData,parseInstructionDataandparseDatareturnDecodedAccountNode,DecodedEventNodeandDecodedInstructionNode.ParsedDatais removed, and the plain value moves fromdatatovalue.ParsedInstruction: aDecodedInstructionNodewith its namedaccountsand itsremainingAccounts, which is now always present. Named accounts carry theiridentifierinstead of aname.ParseDataOptionsaddsbytesEncodingtoprogramAddress, andparseInstructionacceptsbytesEncodingtoo.undefinedwhen nothing is identified or when the identified node cannot decode the bytes.