Cleanup program account def (#5833)

This commit is contained in:
Jack May
2019-09-06 17:32:14 -07:00
committed by GitHub
parent 81c36699c4
commit 1833db51a5
7 changed files with 86 additions and 53 deletions

View File

@ -1,15 +1,14 @@
//! @brief Example Rust-based BPF program that moves a lamport from one account to another
extern crate solana_sdk;
use solana_sdk::entrypoint;
use solana_sdk::entrypoint::*;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::{account_info::AccountInfo, entrypoint, entrypoint::SUCCESS, pubkey::Pubkey};
entrypoint!(process_instruction);
fn process_instruction(_program_id: &Pubkey, ka: &mut [SolKeyedAccount], _data: &[u8]) -> u32 {
fn process_instruction(_program_id: &Pubkey, accounts: &mut [AccountInfo], _data: &[u8]) -> u32 {
// account 0 is the mint and not owned by this program, any debit of its lamports
// should result in a failed program execution. Test to ensure that this debit
// is seen by the runtime and fails as expected
*ka[0].lamports -= 1;
*accounts[0].lamports -= 1;
SUCCESS
}

View File

@ -3,10 +3,9 @@
#![allow(unreachable_code)]
extern crate solana_sdk;
use solana_sdk::entrypoint::*;
use solana_sdk::log::*;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::{entrypoint, info};
use solana_sdk::{
account_info::AccountInfo, entrypoint, entrypoint::SUCCESS, info, log::*, pubkey::Pubkey,
};
#[derive(Debug, PartialEq)]
struct SStruct {
@ -21,7 +20,7 @@ fn return_sstruct() -> SStruct {
}
entrypoint!(process_instruction);
fn process_instruction(program_id: &Pubkey, ka: &mut [SolKeyedAccount], data: &[u8]) -> u32 {
fn process_instruction(program_id: &Pubkey, accounts: &mut [AccountInfo], data: &[u8]) -> u32 {
info!("Program identifier:");
program_id.log();
@ -29,7 +28,7 @@ fn process_instruction(program_id: &Pubkey, ka: &mut [SolKeyedAccount], data: &[
// the no-op program, no account keys or input data are expected but real
// programs will have specific requirements so they can do their work.
info!("Account keys and instruction input data:");
sol_log_params(ka, data);
sol_log_params(accounts, data);
{
// Test - use std methods, unwrap

View File

@ -2,13 +2,13 @@
extern crate solana_sdk;
use byteorder::{ByteOrder, LittleEndian};
use solana_sdk::entrypoint::*;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::{entrypoint, info};
use solana_sdk::{
account_info::AccountInfo, entrypoint, entrypoint::SUCCESS, info, pubkey::Pubkey,
};
entrypoint!(process_instruction);
fn process_instruction(_program_id: &Pubkey, ka: &mut [SolKeyedAccount], _data: &[u8]) -> u32 {
let tick_height = LittleEndian::read_u64(ka[2].data);
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");