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 Account utility type to get accounts from bytes #3091

Conversation

acheroncrypto
Copy link
Collaborator

Problem

Similar to #2885, there isn't a convenient method to get deserialized program account from bytes.

Summary of changes

Add Account enum similar to Event enum added in #2897:

/// An enum that includes all accounts of the declared program as a tuple variant.
///
/// See [`Self::try_from_bytes`] to create an instance from bytes.
pub enum Account {
    SomeAccount(SomeAccount),
    OtherAccount(OtherAccount),
}

impl Account {
    /// Try to create an account based on the given bytes.
    ///
    /// This method returns an error if the discriminator of the given bytes don't match
    /// with any of the existing accounts, or if the deserialization fails.
    pub fn try_from_bytes(bytes: &[u8]) -> Result<Self> {
        // ...
    }
}

This is accesible from program_name::utils::Account where program_name is declared as declare_program!(program_name).

Copy link

vercel bot commented Jul 18, 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 1177174 into coral-xyz:master Jul 18, 2024
2 of 3 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