Skip to content

refactor: use free functions instead of impl methods in Anchor examples#561

Open
mikemaccana-edwardbot wants to merge 12 commits intosolana-developers:mainfrom
mikemaccana:anchor-free-functions
Open

refactor: use free functions instead of impl methods in Anchor examples#561
mikemaccana-edwardbot wants to merge 12 commits intosolana-developers:mainfrom
mikemaccana:anchor-free-functions

Conversation

@mikemaccana-edwardbot
Copy link
Copy Markdown
Contributor

Based on #558 (Anchor 1.0 stable).

Refactors all Anchor examples to use free handler functions instead of impl blocks on account constraint structs.

Why

The impl pattern is fake OOP — the methods don't modify instance state, they just need access to accounts. Free functions make this explicit and are more consistent with Rust conventions.

Changes

  • ~50 Anchor programs refactored
  • Account constraint structs renamed to end with AccountConstraints
  • ctxcontext throughout
  • self.fieldaccounts.field in handler functions
  • context.accounts.method()instructions::handle_method(&mut context.accounts) in lib.rs

mikemaccana and others added 12 commits April 10, 2026 15:24
- Update anchor-lang and anchor-spl to 1.0.0 in all Cargo.toml files
- Update @anchor-lang/core to 1.0.0 in all package.json files
- Remove stale RC pin comments from Cargo.toml files
- Update .reference/ANCHOR-1.0-MIGRATION.md to reflect stable release
- Keep all existing tests unchanged (no LiteSVM additions)
…amples

Converts all Anchor examples from impl blocks on account constraint structs
to free handler functions. Structs renamed to *AccountConstraints, variable
name ctx → context, self.field → accounts.field throughout.

This removes fake OOP — the methods never modified instance state, they just
needed access to accounts. Free functions make this explicit.
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.

2 participants