Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lang: Add #[instruction] attribute proc-macro #3137

Conversation

acheroncrypto
Copy link
Collaborator

Problem

There is no way to override the default 8-byte Anchor discriminators of program instructions.

Summary of changes

Add #[instruction] attribute proc-macro that can be used to override Anchor defaults of program instructions.

This macro currently only allows overriding discriminators, but the functionality can be extended to override other defaults in the future.

Example

#[instruction(discriminator = [0, 1, 2, 3])]
pub fn my_ix(_ctx: Context<MyIx>) -> Result<()> {
    Ok(())
}

More examples can be found in the custom-discriminator tests.

Note

The initial design was to introduce a new #[discriminator] macro to share the implementation of instructions, accounts and events, as mentioned in #2728 (comment). However, given there is a demand from the users to override the other defaults of Anchor (e.g. serialization), it became clear that introducing a new macro for all of the overrides would not scale well.


Note: This PR is part of a greater effort explained in #3097.

Copy link

vercel bot commented Jul 30, 2024

@acheroncrypto is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@acheroncrypto acheroncrypto merged commit 3f945f6 into coral-xyz:master Jul 30, 2024
49 of 50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant