Proposed: PDA generation, compile-time safety, etc#95
Open
ioxde wants to merge 13 commits intocodama-idl:mainfrom
Open
Proposed: PDA generation, compile-time safety, etc#95ioxde wants to merge 13 commits intocodama-idl:mainfrom
ioxde wants to merge 13 commits intocodama-idl:mainfrom
Conversation
When an instruction account has a pdaValueNode default (linked or inline), the builder now auto-derives the address instead of requiring it to be set explicitly. PDA-defaulted accounts are emitted as sequential let bindings, topologically sorted by seed dependencies, so accounts that reference other PDA-defaulted accounts resolve correctly. Constant seed rendering dispatches by value type: strings produce b"...", byte arrays &[...], and numbers &Nu64.to_le_bytes(). Bumps @codama/nodes-from-anchor to ^1.4.0 for extractPdasVisitor support (codama-idl/codama#984).
The generated from_bytes() blindly deserialized without checking that the discriminator bytes matched, silently accepting wrong account data. The TryFrom<&AccountInfo> and fetch_* helpers had no owner validation, and the Anchor AccountDeserialize::try_deserialize defaulted to unchecked deserialization with no discriminator gate. - from_bytes() now rejects data with a mismatched discriminator prefix - TryFrom<&AccountInfo> checks account_info.owner before deserializing - fetch_all_* and fetch_all_maybe_* check account.owner before deserializing - TryFrom delegates to from_bytes() instead of duplicating deserialization - Anchor try_deserialize checks the discriminator before calling unchecked - Anchor Discriminator trait uses the real constant instead of [0; 8]
…rams Move required accounts (no defaults, not IDL-optional) and required args (no defaults, not Option types) from Option fields with setter methods into mandatory constructor parameters on both Builder and CpiBuilder. This shifts missing-field errors from runtime .expect() panics to compile-time type errors. Accounts with defaults (PDA, publicKey, programId) remain optional with setters. PDA seed resolution uses direct field access for required fields instead of .expect(). programIdValueNode accounts unwrap with the program's own ID as fallback.
🦋 Changeset detectedLatest commit: b0994c5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
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.
This PR isn't meant to be accepted because it has multiple changes I personally have needed. I have a
solana v2version of this as well (which I'm currently using).I didn't want to waste a lot of time separating these commits out if the changes aren't wanted. Please advise which, if any, changes are wanted upstream for a PR.
Changes
rename_allandDisplayFromStrfor u64/i64/u128/i128 to serde featurefeatureFlagsnot emittingcfg_attrfor traits absent from defaultstry_deserializeRelated