Expand description
Information about the network’s clock, ticks, slots, etc.
The clock sysvar provides access to the Clock
type, which includes the
current slot, the current epoch, and the approximate real-world time of the
slot.
Clock
implements Sysvar::get
and can be loaded efficiently without
passing the sysvar account ID to the program.
See also the Solana documentation on the clock sysvar.
§Examples
Accessing via on-chain program directly:
fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
let clock = Clock::get()?;
msg!("clock: {:#?}", clock);
Ok(())
}
Accessing via on-chain program’s account parameters:
fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
let account_info_iter = &mut accounts.iter();
let clock_account_info = next_account_info(account_info_iter)?;
assert!(clock::check_id(clock_account_info.key));
let clock = Clock::from_account_info(clock_account_info)?;
msg!("clock: {:#?}", clock);
Ok(())
}
Accessing via the RPC client:
fn print_sysvar_clock(client: &RpcClient) -> Result<()> {
let clock = client.get_account(&clock::ID)?;
let data: Clock = bincode::deserialize(&clock.data)?;
Ok(())
}
Structs§
- A representation of network time.
Constants§
- The const program ID.
Functions§
- Returns
true
if given pubkey is the program ID. - Returns the program ID.