idl_build.rs 1.2 KB

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