Add BPF program entrypoint return type (#8111)

This commit is contained in:
Jack May 2020-02-04 12:25:42 -08:00 committed by GitHub
parent 78f6ddc5b7
commit b6d09f1901
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 19 deletions

View File

@ -2,7 +2,8 @@
extern crate solana_sdk;
use solana_sdk::{
account_info::AccountInfo, entrypoint, info, program_error::ProgramError, pubkey::Pubkey,
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, info,
program_error::ProgramError, pubkey::Pubkey,
};
entrypoint!(process_instruction);
@ -10,7 +11,7 @@ fn process_instruction(
_program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> Result<(), ProgramError> {
) -> ProgramResult {
match instruction_data[0] {
1 => {
info!("modify first account data");

View File

@ -6,7 +6,9 @@ use num_traits::FromPrimitive;
use solana_sdk::{
account_info::AccountInfo,
entrypoint, info,
entrypoint,
entrypoint::ProgramResult,
info,
instruction_processor_utils::DecodeError,
program_error::{PrintProgramError, ProgramError},
pubkey::Pubkey,
@ -48,9 +50,7 @@ fn process_instruction(
_program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> Result<(), ProgramError> {
ProgramError::CustomError(42).print::<MyError>();
) -> ProgramResult {
match instruction_data[0] {
1 => {
info!("return success");

View File

@ -2,7 +2,7 @@
extern crate solana_sdk;
use solana_sdk::{
account_info::AccountInfo, entrypoint, program_error::ProgramError, pubkey::Pubkey,
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, pubkey::Pubkey,
};
entrypoint!(process_instruction);
@ -10,7 +10,7 @@ fn process_instruction(
_program_id: &Pubkey,
accounts: &[AccountInfo],
_instruction_data: &[u8],
) -> Result<(), ProgramError> {
) -> ProgramResult {
// 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

View File

@ -5,8 +5,7 @@
extern crate solana_sdk;
use solana_sdk::{
account_info::AccountInfo, entrypoint, info, log::*, program_error::ProgramError,
pubkey::Pubkey,
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, info, log::*, pubkey::Pubkey,
};
#[derive(Debug, PartialEq)]
@ -26,7 +25,7 @@ fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> Result<(), ProgramError> {
) -> ProgramResult {
info!("Program identifier:");
program_id.log();

View File

@ -4,9 +4,10 @@ extern crate solana_sdk;
use solana_sdk::{
account_info::AccountInfo,
clock::{get_segment_from_slot, DEFAULT_SLOTS_PER_EPOCH, DEFAULT_SLOTS_PER_SEGMENT},
entrypoint, info,
entrypoint,
entrypoint::ProgramResult,
info,
log::Log,
program_error::ProgramError,
pubkey::Pubkey,
rent,
sysvar::{
@ -20,7 +21,7 @@ fn process_instruction(
_program_id: &Pubkey,
accounts: &[AccountInfo],
_instruction_data: &[u8],
) -> Result<(), ProgramError> {
) -> ProgramResult {
// Clock
info!("Clock identifier:");
sysvar::clock::id().log();

View File

@ -7,19 +7,20 @@ use std::{
cell::RefCell,
mem::size_of,
rc::Rc,
// Hide Result from bindgen gets confused about generics in non-generic type declarations
result::Result as ResultGeneric,
slice::{from_raw_parts, from_raw_parts_mut},
};
pub type ProgramResult = ResultGeneric<(), ProgramError>;
/// User implemented function to process an instruction
///
/// program_id: Program ID of the currently executing program
/// accounts: Accounts passed as part of the instruction
/// instruction_data: Instruction data
pub type ProcessInstruction = fn(
program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> Result<(), ProgramError>;
pub type ProcessInstruction =
fn(program_id: &Pubkey, accounts: &[AccountInfo], instruction_data: &[u8]) -> ProgramResult;
/// Programs indicate success with a return value of 0
pub const SUCCESS: u64 = 0;