Repository navigation
[2.x] Return decoded nodes from dynamic parsers - #1216
lorisleiva wants to merge 1 commit into
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

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.