diff --git a/programs/bpf/rust/dup_accounts/src/lib.rs b/programs/bpf/rust/dup_accounts/src/lib.rs index c51384e7f8..e0ade222b4 100644 --- a/programs/bpf/rust/dup_accounts/src/lib.rs +++ b/programs/bpf/rust/dup_accounts/src/lib.rs @@ -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"); diff --git a/programs/bpf/rust/error_handling/src/lib.rs b/programs/bpf/rust/error_handling/src/lib.rs index 303b27d478..e356a0e587 100644 --- a/programs/bpf/rust/error_handling/src/lib.rs +++ b/programs/bpf/rust/error_handling/src/lib.rs @@ -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::(); - +) -> ProgramResult { match instruction_data[0] { 1 => { info!("return success"); diff --git a/programs/bpf/rust/external_spend/src/lib.rs b/programs/bpf/rust/external_spend/src/lib.rs index a77098aaa5..42aa4cff4b 100644 --- a/programs/bpf/rust/external_spend/src/lib.rs +++ b/programs/bpf/rust/external_spend/src/lib.rs @@ -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 diff --git a/programs/bpf/rust/noop/src/lib.rs b/programs/bpf/rust/noop/src/lib.rs index f3bec99608..4d2ac353b7 100644 --- a/programs/bpf/rust/noop/src/lib.rs +++ b/programs/bpf/rust/noop/src/lib.rs @@ -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(); diff --git a/programs/bpf/rust/sysval/src/lib.rs b/programs/bpf/rust/sysval/src/lib.rs index d57429b1c7..ac5bd54052 100644 --- a/programs/bpf/rust/sysval/src/lib.rs +++ b/programs/bpf/rust/sysval/src/lib.rs @@ -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(); diff --git a/sdk/src/entrypoint.rs b/sdk/src/entrypoint.rs index b8ca0c1eda..6999a0aa77 100644 --- a/sdk/src/entrypoint.rs +++ b/sdk/src/entrypoint.rs @@ -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;