Skip to main content

anchor_spl/
idl_build.rs

1/// Crate a default [`anchor_lang::IdlBuild`] implementation for the given type.
2///
3/// This is used in order to make wrapper accounts of `anchor-spl` work with `idl-build` feature.
4macro_rules! impl_idl_build {
5    ($ty: ty) => {
6        impl anchor_lang::IdlBuild for $ty {}
7
8        // This is not used for the IDL generation since default `IdlBuild` impl doesn't include
9        // the type in the IDL but it still needs to be added in order to make compilation work.
10        //
11        // TODO: Find a better way to handle discriminators of wrapped external accounts.
12        impl anchor_lang::Discriminator for $ty {
13            const DISCRIMINATOR: &'static [u8] = &[];
14        }
15    };
16}
17
18#[cfg(feature = "metadata")]
19impl_idl_build!(crate::metadata::MetadataAccount);
20#[cfg(feature = "metadata")]
21impl_idl_build!(crate::metadata::MasterEditionAccount);
22#[cfg(feature = "metadata")]
23impl_idl_build!(crate::metadata::TokenRecordAccount);
24
25#[cfg(feature = "stake")]
26impl_idl_build!(crate::stake::StakeAccount);
27
28impl_idl_build!(crate::token::Mint);
29impl_idl_build!(crate::token::TokenAccount);
30
31impl_idl_build!(crate::token_interface::Mint);
32impl_idl_build!(crate::token_interface::TokenAccount);