feat: support additionalPrograms via #[codama(program(...))] directive#82
Merged
lorisleiva merged 7 commits intocodama-idl:mainfrom Mar 12, 2026
Merged
Conversation
Contributor
Author
|
Pushed minor refactor based on feeback in 81 and 82 |
lorisleiva
reviewed
Mar 5, 2026
Member
lorisleiva
left a comment
There was a problem hiding this comment.
Nice, this is looking really good! I've made some comments mainly on adding higher-level tests with modules and trying to extract some common logic on the directive itself to clean up the visitors slightly.
Add a program directive that allows CodamaPda structs to declare they belong to an external program. The PDA is wrapped in a ProgramNode with the given name and address, which CombineModulesVisitor routes to additionalPrograms in the IDL. Usage: #[derive(CodamaPda)] #[codama(program(name = "associatedToken", address = "AToken..."))] #[codama(seed(name = "owner", type = public_key))] struct AssociatedToken;
…shared helper
- Change ProgramDirective.name from String to CamelCaseString
- Add update_or_wrap_program_node() method on ProgramDirective to consolidate
wrapping/updating logic across all visitors
- Refactor set_accounts, set_instructions, set_errors, set_pdas visitors to
use the shared helper instead of duplicating inline logic
- Support #[codama(program(...))] on mod blocks via CombineModulesVisitor
- Add combine_modules_visitor tests for program directive scenarios
refactor: extract ProgramDirective::apply to reduce repeated match pattern
Consolidates the 7 repeated `match get_last(filter) { Some => helper, None => node }`
blocks across visitors into a single ProgramDirective::apply() static method.
dc72a70 to
0a1a2f7
Compare
Contributor
Author
|
Thanks for the feedback @lorisleiva. I think we're good but lmk if the tests/refactor don't quite get at what you're thinking.
|
lorisleiva
approved these changes
Mar 12, 2026
Member
lorisleiva
left a comment
There was a problem hiding this comment.
Perfection! Sorry for the late reply. Just a small test request but good to merge otherwise! 🙌
codama-korok-visitors/tests/combine_modules_visitor/program_directive.rs
Show resolved
Hide resolved
Ensures items with program directives are correctly separated from the main program regardless of declaration order within a module.
Contributor
Author
|
Awesome. Thanks @lorisleiva. Added that additional test. Should be gtg. |
Member
|
Thank you! will publish a new set of crates today. |
Member
|
@amilz New crates published! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#[codama(program(name = "...", address = "..."))]directive for declaring external program ownership on first-class nodes.CodamaPda,CodamaInstruction,CodamaInstructions,CodamaAccount,CodamaAccounts, andCodamaErrors.ProgramNodewith the given name/address.CombineModulesVisitorroutes it toadditionalProgramsautomatically.Usage
Then reference in instructions via
pda("associatedToken", program = "associatedToken", [...]). The IDL gets anadditionalProgramsentry with the program's address and PDA seeds, and account defaults usepdaLinkNodewith aprogramLinkNodereference.Verified against an escrow program with ATA vault accounts — IDL output is correct.
How it works
ProgramDirectiveparsesnameandaddressviaSetOnce(same pattern asErrorDirective)SetPdasVisitor: wrapsPdaNodein aProgramNodewhen directive presentSetInstructionsVisitor: wrapsInstructionNode(struct) or sets name/address onProgramNode(enum)SetAccountsVisitor: applies to existingAccountNodeorProgramNodeviaapply_program_directivehelperSetErrorsVisitor: sets name/address onProgramNode(enum)CombineModulesVisitorsees non-matchingpublic_key→ routes toadditional_programsTest plan
cargo fmt --check && cargo clippy --all-targets -- -D warnings && cargo testCloses #68