trezoa_epoch_stake/
lib.rs

1//! API for retrieving epoch stake information.
2//!
3//! On-chain programs can use this API to retrieve the total stake for the
4//! current epoch or the stake for a specific vote account using the
5//! `trz_get_epoch_stake` syscall.
6
7use trezoa_pubkey::Pubkey;
8
9fn get_epoch_stake(var_addr: *const u8) -> u64 {
10    #[cfg(target_os = "trezoa")]
11    {
12        unsafe { trezoa_define_syscall::definitions::trz_get_epoch_stake(var_addr) }
13    }
14
15    #[cfg(not(target_os = "trezoa"))]
16    {
17        core::hint::black_box(var_addr);
18        0
19    }
20}
21
22/// Get the current epoch's total stake.
23pub fn get_epoch_total_stake() -> u64 {
24    get_epoch_stake(std::ptr::null::<Pubkey>() as *const u8)
25}
26
27/// Get the current epoch stake for a given vote address.
28///
29/// If the provided vote address corresponds to an account that is not a vote
30/// account or does not exist, returns `0` for active stake.
31pub fn get_epoch_stake_for_vote_account(vote_address: &Pubkey) -> u64 {
32    get_epoch_stake(vote_address as *const _ as *const u8)
33}