solana_sysvar_id/lib.rs
1//! Access to special accounts with dynamically-updated data.
2//!
3//! Sysvars are special accounts that contain dynamically-updated data about the
4//! network cluster, the blockchain history, and the executing transaction. Each
5//! sysvar is defined in its own crate. The [`clock`], [`epoch_schedule`],
6//! [`instructions`], and [`rent`] sysvars are most useful to on-chain programs.
7//!
8//! [`clock`]: https://docs.rs/solana-clock/latest
9//! [`epoch_schedule`]: https://docs.rs/solana-epoch-schedule/latest
10//! [`instructions`]: https://docs.rs/solana-program/latest/solana_program/sysvar/instructions
11//! [`rent`]: https://docs.rs/solana-rent/latest
12//!
13//! All sysvar accounts are owned by the account identified by [`solana_sysvar::ID`].
14//!
15//! [`solana_sysvar::ID`]: crate::ID
16//!
17//! For more details see the Solana [documentation on sysvars][sysvardoc].
18//!
19//! [sysvardoc]: https://docs.solanalabs.com/runtime/sysvars
20
21/// Re-export types required for macros
22pub use solana_pubkey::{declare_deprecated_id, declare_id, Pubkey};
23
24/// A type that holds sysvar data and has an associated sysvar `Pubkey`.
25pub trait SysvarId {
26 /// The `Pubkey` of the sysvar.
27 fn id() -> Pubkey;
28
29 /// Returns `true` if the given pubkey is the program ID.
30 fn check_id(pubkey: &Pubkey) -> bool;
31}
32
33/// Declares an ID that implements [`SysvarId`].
34#[macro_export]
35macro_rules! declare_sysvar_id(
36 ($name:expr, $type:ty) => (
37 $crate::declare_id!($name);
38
39 impl $crate::SysvarId for $type {
40 fn id() -> $crate::Pubkey {
41 id()
42 }
43
44 fn check_id(pubkey: &$crate::Pubkey) -> bool {
45 check_id(pubkey)
46 }
47 }
48 )
49);
50
51/// Same as [`declare_sysvar_id`] except that it reports that this ID has been deprecated.
52#[macro_export]
53macro_rules! declare_deprecated_sysvar_id(
54 ($name:expr, $type:ty) => (
55 $crate::declare_deprecated_id!($name);
56
57 impl $crate::SysvarId for $type {
58 fn id() -> $crate::Pubkey {
59 #[allow(deprecated)]
60 id()
61 }
62
63 fn check_id(pubkey: &$crate::Pubkey) -> bool {
64 #[allow(deprecated)]
65 check_id(pubkey)
66 }
67 }
68 )
69);
70
71// Owner pubkey for sysvar accounts
72solana_pubkey::declare_id!("Sysvar1111111111111111111111111111111111111");