* Add solana-program-sdk boilerplate (cherry picked from commit3718771ffb
) # Conflicts: # sdk/Cargo.toml * Initial population of solana-program-sdk (cherry picked from commit63db324204
) # Conflicts: # Cargo.lock * Port programs to solana-program-sdk (cherry picked from commitfe68f7f786
) # Conflicts: # programs/bpf/Cargo.lock # programs/bpf/rust/128bit/Cargo.toml # programs/bpf/rust/128bit_dep/Cargo.toml # programs/bpf/rust/alloc/Cargo.toml # programs/bpf/rust/call_depth/Cargo.toml # programs/bpf/rust/custom_heap/Cargo.toml # programs/bpf/rust/dep_crate/Cargo.toml # programs/bpf/rust/deprecated_loader/Cargo.toml # programs/bpf/rust/dup_accounts/Cargo.toml # programs/bpf/rust/error_handling/Cargo.toml # programs/bpf/rust/external_spend/Cargo.toml # programs/bpf/rust/instruction_introspection/Cargo.toml # programs/bpf/rust/invoke/Cargo.toml # programs/bpf/rust/invoked/Cargo.toml # programs/bpf/rust/iter/Cargo.toml # programs/bpf/rust/many_args/Cargo.toml # programs/bpf/rust/many_args_dep/Cargo.toml # programs/bpf/rust/noop/Cargo.toml # programs/bpf/rust/panic/Cargo.toml # programs/bpf/rust/param_passing/Cargo.toml # programs/bpf/rust/param_passing_dep/Cargo.toml # programs/bpf/rust/rand/Cargo.toml # programs/bpf/rust/ristretto/Cargo.toml # programs/bpf/rust/sanity/Cargo.toml # programs/bpf/rust/sha256/Cargo.toml # programs/bpf/rust/sysval/Cargo.toml * Only activate legacy program feature for the solana-sdk crate (cherry picked from commit85c51f5787
) * Run serum-dex unit tests (cherry picked from commit92ce381d60
) * Rename solana-program-sdk to solana-program (cherry picked from commitdd711ab5fb
) # Conflicts: # programs/bpf/rust/128bit/Cargo.toml # programs/bpf/rust/128bit_dep/Cargo.toml # programs/bpf/rust/alloc/Cargo.toml # programs/bpf/rust/call_depth/Cargo.toml # programs/bpf/rust/custom_heap/Cargo.toml # programs/bpf/rust/dep_crate/Cargo.toml # programs/bpf/rust/deprecated_loader/Cargo.toml # programs/bpf/rust/dup_accounts/Cargo.toml # programs/bpf/rust/error_handling/Cargo.toml # programs/bpf/rust/external_spend/Cargo.toml # programs/bpf/rust/instruction_introspection/Cargo.toml # programs/bpf/rust/invoke/Cargo.toml # programs/bpf/rust/invoked/Cargo.toml # programs/bpf/rust/iter/Cargo.toml # programs/bpf/rust/many_args/Cargo.toml # programs/bpf/rust/many_args_dep/Cargo.toml # programs/bpf/rust/noop/Cargo.toml # programs/bpf/rust/panic/Cargo.toml # programs/bpf/rust/param_passing/Cargo.toml # programs/bpf/rust/param_passing_dep/Cargo.toml # programs/bpf/rust/rand/Cargo.toml # programs/bpf/rust/ristretto/Cargo.toml # programs/bpf/rust/sanity/Cargo.toml # programs/bpf/rust/sha256/Cargo.toml # programs/bpf/rust/sysval/Cargo.toml * Update frozen_abi hashes The movement of files in sdk/ caused ABI hashes to change (cherry picked from commita4956844bd
) * Resolve merge conflicts Co-authored-by: Michael Vines <mvines@gmail.com>
61 lines
1.7 KiB
Rust
61 lines
1.7 KiB
Rust
//! @brief Example Rust-based BPF program that tests sysval use
|
|
|
|
extern crate solana_program;
|
|
use solana_program::{
|
|
account_info::AccountInfo,
|
|
clock::DEFAULT_SLOTS_PER_EPOCH,
|
|
entrypoint,
|
|
entrypoint::ProgramResult,
|
|
info,
|
|
pubkey::Pubkey,
|
|
rent,
|
|
sysvar::{
|
|
self, clock::Clock, fees::Fees, rent::Rent, slot_hashes::SlotHashes,
|
|
stake_history::StakeHistory, Sysvar,
|
|
},
|
|
};
|
|
|
|
entrypoint!(process_instruction);
|
|
fn process_instruction(
|
|
_program_id: &Pubkey,
|
|
accounts: &[AccountInfo],
|
|
_instruction_data: &[u8],
|
|
) -> ProgramResult {
|
|
// Clock
|
|
info!("Clock identifier:");
|
|
sysvar::clock::id().log();
|
|
let clock = Clock::from_account_info(&accounts[2]).expect("clock");
|
|
assert_eq!(clock.slot, DEFAULT_SLOTS_PER_EPOCH + 1);
|
|
|
|
// Fees
|
|
info!("Fees identifier:");
|
|
sysvar::fees::id().log();
|
|
let fees = Fees::from_account_info(&accounts[3]).expect("fees");
|
|
let fee_calculator = fees.fee_calculator;
|
|
assert_eq!(fee_calculator.lamports_per_signature, 0);
|
|
|
|
// Slot Hashes
|
|
info!("SlotHashes identifier:");
|
|
sysvar::slot_hashes::id().log();
|
|
let slot_hashes = SlotHashes::from_account_info(&accounts[4]).expect("slot_hashes");
|
|
assert!(slot_hashes.len() >= 1);
|
|
|
|
// Stake History
|
|
info!("StakeHistory identifier:");
|
|
sysvar::stake_history::id().log();
|
|
let stake_history = StakeHistory::from_account_info(&accounts[5]).expect("stake_history");
|
|
assert!(stake_history.len() >= 1);
|
|
|
|
let rent = Rent::from_account_info(&accounts[6]).unwrap();
|
|
assert_eq!(
|
|
rent.due(
|
|
rent::DEFAULT_LAMPORTS_PER_BYTE_YEAR * rent::DEFAULT_EXEMPTION_THRESHOLD as u64,
|
|
1,
|
|
1.0
|
|
),
|
|
(0, true)
|
|
);
|
|
|
|
Ok(())
|
|
}
|