Add macros for deprecacted ids (#18907)

This commit is contained in:
Jack May
2021-07-26 20:54:46 -07:00
committed by GitHub
parent a4024168de
commit eaeeffa5a3
4 changed files with 101 additions and 1 deletions

View File

@ -62,6 +62,8 @@ pub mod vote {
}
}
/// Same as `declare_id` except report that this id has been deprecated
pub use solana_sdk_macro::program_declare_deprecated_id as declare_deprecated_id;
/// Convenience macro to declare a static public key and functions to interact with it
///
/// Input: a single literal base58 string representation of a program's id

View File

@ -51,6 +51,34 @@ macro_rules! declare_sysvar_id(
)
);
#[macro_export]
macro_rules! declare_deprecated_sysvar_id(
($name:expr, $type:ty) => (
$crate::declare_deprecated_id!($name);
impl $crate::sysvar::SysvarId for $type {
fn id() -> $crate::pubkey::Pubkey {
#[allow(deprecated)]
id()
}
fn check_id(pubkey: &$crate::pubkey::Pubkey) -> bool {
#[allow(deprecated)]
check_id(pubkey)
}
}
#[cfg(test)]
#[test]
fn test_sysvar_id() {
#[allow(deprecated)]
if !$crate::sysvar::is_sysvar_id(&id()) {
panic!("sysvar::is_sysvar_id() doesn't know about {}", $name);
}
}
)
);
// Owner pubkey for sysvar accounts
crate::declare_id!("Sysvar1111111111111111111111111111111111111");