Add sysvar support (#5838)

This commit is contained in:
Jack May
2019-09-09 10:55:35 -07:00
committed by GitHub
parent ee0c570d54
commit a317e9513f
17 changed files with 156 additions and 110 deletions

View File

@ -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"

View 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
}

View File

@ -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
}