Add sysvar support (#5838)
This commit is contained in:
@ -2,9 +2,9 @@
|
||||
# Note: This crate must be built using build.sh
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-tick-height"
|
||||
name = "solana-bpf-rust-clock"
|
||||
version = "0.19.0-pre0"
|
||||
description = "Solana BPF noop program written in Rust"
|
||||
description = "Solana BPF clock sysvar test"
|
||||
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
license = "Apache-2.0"
|
||||
@ -12,7 +12,6 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
byteorder = { version = "1", default-features = false }
|
||||
solana-sdk = { path = "../../../../sdk/", version = "0.19.0-pre0", default-features = false }
|
||||
|
||||
[features]
|
||||
@ -24,4 +23,4 @@ members = []
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
name = "solana_bpf_rust_tick_height"
|
||||
name = "solana_bpf_rust_clock"
|
28
programs/bpf/rust/clock/src/lib.rs
Normal file
28
programs/bpf/rust/clock/src/lib.rs
Normal file
@ -0,0 +1,28 @@
|
||||
//! @brief Example Rust-based BPF program that prints out the parameters passed to it
|
||||
|
||||
extern crate solana_sdk;
|
||||
use solana_sdk::{
|
||||
account_info::AccountInfo, entrypoint, entrypoint::SUCCESS, info, pubkey::Pubkey,
|
||||
sysvar::clock::Clock,
|
||||
};
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
fn process_instruction(_program_id: &Pubkey, accounts: &mut [AccountInfo], _data: &[u8]) -> u32 {
|
||||
match Clock::from(&accounts[2]) {
|
||||
Some(clock) => {
|
||||
info!("slot, segment, epoch, stakers_epoch");
|
||||
info!(
|
||||
clock.slot,
|
||||
clock.segment, clock.epoch, clock.stakers_epoch, 0
|
||||
);
|
||||
assert_eq!(clock.slot, 42);
|
||||
}
|
||||
None => {
|
||||
info!("Failed to get clock from account 2");
|
||||
panic!();
|
||||
}
|
||||
}
|
||||
|
||||
info!("Success");
|
||||
SUCCESS
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
//! @brief Example Rust-based BPF program that prints out the parameters passed to it
|
||||
|
||||
extern crate solana_sdk;
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use solana_sdk::{
|
||||
account_info::AccountInfo, entrypoint, entrypoint::SUCCESS, info, pubkey::Pubkey,
|
||||
};
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
fn process_instruction(_program_id: &Pubkey, accounts: &mut [AccountInfo], _data: &[u8]) -> u32 {
|
||||
let tick_height = LittleEndian::read_u64(accounts[2].data);
|
||||
assert_eq!(10u64, tick_height);
|
||||
|
||||
info!("Success");
|
||||
SUCCESS
|
||||
}
|
Reference in New Issue
Block a user