anchor_spl/
idl_build.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/// Crate a default [`anchor_lang::IdlBuild`] implementation for the given type.
///
/// This is used in order to make wrapper accounts of `anchor-spl` work with `idl-build` feature.
macro_rules! impl_idl_build {
    ($ty: ty) => {
        impl anchor_lang::IdlBuild for $ty {}

        // This is not used for the IDL generation since default `IdlBuild` impl doesn't include
        // the type in the IDL but it stil needs to be added in order to make compilation work.
        //
        // TODO: Find a better way to handle discriminators of wrapped external accounts.
        impl anchor_lang::Discriminator for $ty {
            const DISCRIMINATOR: [u8; 8] = [0; 8];
        }
    };
}

#[cfg(feature = "metadata")]
impl_idl_build!(crate::metadata::MetadataAccount);
#[cfg(feature = "metadata")]
impl_idl_build!(crate::metadata::MasterEditionAccount);
#[cfg(feature = "metadata")]
impl_idl_build!(crate::metadata::TokenRecordAccount);

#[cfg(feature = "stake")]
impl_idl_build!(crate::stake::StakeAccount);

impl_idl_build!(crate::token::Mint);
impl_idl_build!(crate::token::TokenAccount);

impl_idl_build!(crate::token_interface::Mint);
impl_idl_build!(crate::token_interface::TokenAccount);