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: Require Discriminator trait impl when using the zero constraint #3118

Conversation

acheroncrypto
Copy link
Collaborator

Problem

zero constraint assumes the discriminator length is always 8:

let mut __data: &[u8] = &#field.try_borrow_data()?;
let mut __disc_bytes = [0u8; 8];
__disc_bytes.copy_from_slice(&__data[..8]);
let __discriminator = u64::from_le_bytes(__disc_bytes);
if __discriminator != 0 {
return Err(anchor_lang::error::Error::from(anchor_lang::error::ErrorCode::ConstraintZero).with_account_name(#name_str));
}

Summary of changes

  • Get the discriminator length in zero constraint from the account's Discriminator trait implementation
  • Require using Account or AccountLoader when using the zero constraint to give a more friendly error message rather than rustc generated compile error

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

Custom parse errors give friendlier error messages compared to generic `rustc` compile errors
Copy link

vercel bot commented Jul 25, 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 293ee91 into coral-xyz:master Jul 25, 2024
47 of 48 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