rialo_s_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/rialo_s_program/sysvar/instructions
11//! [`rent`]: https://docs.rs/solana-rent/latest
12//!
13//! All sysvar accounts are owned by the account identified by [`rialo_s_sysvar::ID`].
14//!
15//! [`rialo_s_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 {
23 rialo_s_pubkey::{declare_deprecated_id, declare_id, Pubkey},
24 rialo_s_sdk_ids::sysvar::{check_id, id, ID},
25};
26
27/// A type that holds sysvar data and has an associated sysvar `Pubkey`.
28pub trait SysvarId {
29 /// The `Pubkey` of the sysvar.
30 fn id() -> Pubkey;
31
32 /// Returns `true` if the given pubkey is the program ID.
33 fn check_id(pubkey: &Pubkey) -> bool;
34}
35
36/// Implements [`SysvarId`] for a module that already uses
37/// `declare_id``
38#[macro_export]
39macro_rules! impl_sysvar_id(
40 ($type:ty) => {
41 impl $crate::SysvarId for $type {
42 fn id() -> $crate::Pubkey {
43 id()
44 }
45
46 fn check_id(pubkey: &$crate::Pubkey) -> bool {
47 check_id(pubkey)
48 }
49 }
50 }
51);
52
53/// Implements [`SysvarId`] for a module that already uses
54/// `declare_deprecated_id``
55#[macro_export]
56macro_rules! impl_deprecated_sysvar_id(
57 ($type:ty) => {
58 impl $crate::SysvarId for $type {
59 fn id() -> $crate::Pubkey {
60 #[allow(deprecated)]
61 id()
62 }
63
64 fn check_id(pubkey: &$crate::Pubkey) -> bool {
65 #[allow(deprecated)]
66 check_id(pubkey)
67 }
68 }
69 }
70);
71
72/// Declares an ID that implements [`SysvarId`].
73#[macro_export]
74macro_rules! declare_sysvar_id(
75 ($name:expr, $type:ty) => (
76 $crate::declare_id!($name);
77 $crate::impl_sysvar_id!($type);
78 )
79);