2020-01-21 10:59:19 -08:00
|
|
|
//! @brief Example Rust-based BPF program that tests duplicate accounts passed via accounts
|
|
|
|
|
|
|
|
extern crate solana_sdk;
|
|
|
|
use solana_sdk::{
|
|
|
|
account_info::AccountInfo, entrypoint, entrypoint::SUCCESS, info, pubkey::Pubkey,
|
|
|
|
};
|
|
|
|
|
|
|
|
entrypoint!(process_instruction);
|
2020-01-24 13:41:14 -08:00
|
|
|
fn process_instruction(
|
|
|
|
_program_id: &Pubkey,
|
|
|
|
accounts: &mut [AccountInfo],
|
|
|
|
instruction_data: &[u8],
|
|
|
|
) -> u32 {
|
2020-01-21 10:59:19 -08:00
|
|
|
const FAILURE: u32 = 1;
|
|
|
|
|
2020-01-24 13:41:14 -08:00
|
|
|
match instruction_data[0] {
|
2020-01-21 10:59:19 -08:00
|
|
|
1 => {
|
|
|
|
info!("modify first account data");
|
2020-01-24 14:34:59 -08:00
|
|
|
accounts[2].borrow_mut().data[0] = 1;
|
2020-01-21 10:59:19 -08:00
|
|
|
}
|
|
|
|
2 => {
|
|
|
|
info!("modify first account data");
|
2020-01-24 14:34:59 -08:00
|
|
|
accounts[3].borrow_mut().data[0] = 2;
|
2020-01-21 10:59:19 -08:00
|
|
|
}
|
|
|
|
3 => {
|
2020-01-24 10:54:26 -08:00
|
|
|
info!("modify both account data");
|
2020-01-24 14:34:59 -08:00
|
|
|
accounts[2].borrow_mut().data[0] += 1;
|
|
|
|
accounts[3].borrow_mut().data[0] += 2;
|
2020-01-21 10:59:19 -08:00
|
|
|
}
|
|
|
|
4 => {
|
|
|
|
info!("modify first account lamports");
|
2020-01-24 14:34:59 -08:00
|
|
|
*accounts[1].borrow_mut().lamports -= 1;
|
|
|
|
*accounts[2].borrow_mut().lamports += 1;
|
2020-01-21 10:59:19 -08:00
|
|
|
}
|
|
|
|
5 => {
|
|
|
|
info!("modify first account lamports");
|
2020-01-24 14:34:59 -08:00
|
|
|
*accounts[1].borrow_mut().lamports -= 2;
|
|
|
|
*accounts[3].borrow_mut().lamports += 2;
|
2020-01-21 10:59:19 -08:00
|
|
|
}
|
|
|
|
6 => {
|
2020-01-24 10:54:26 -08:00
|
|
|
info!("modify both account lamports");
|
2020-01-24 14:34:59 -08:00
|
|
|
*accounts[1].borrow_mut().lamports -= 3;
|
|
|
|
*accounts[2].borrow_mut().lamports += 1;
|
|
|
|
*accounts[3].borrow_mut().lamports += 2;
|
2020-01-21 10:59:19 -08:00
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
info!("Unrecognized command");
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SUCCESS
|
|
|
|
}
|