Add ProgramError::CustomError and truncate value to 32 bytes

This commit is contained in:
Tyera Eulberg
2019-03-11 13:40:52 -06:00
committed by Greg Fitzgerald
parent 56b0ba2601
commit 804378e8f7
2 changed files with 14 additions and 1 deletions

View File

@ -107,7 +107,14 @@ fn execute_instruction(
executable_accounts,
program_accounts,
tick_height,
)?;
)
.map_err(|err| match err {
ProgramError::CustomError(mut error) => {
error.truncate(32);
ProgramError::CustomError(error)
}
e => e,
})?;
// Verify the instruction
for ((pre_program_id, pre_lamports, pre_userdata), post_account) in

View File

@ -36,6 +36,12 @@ pub enum ProgramError {
/// SystemInstruction::Assign was attempted on an account unowned by the system program
AssignOfUnownedAccount,
/// CustomError allows on-chain programs to implement program-specific error types and see
/// them returned by the Solana runtime. A CustomError may be any type that is serialized
/// to a Vec of bytes, max length 32 bytes. Any CustomError Vec greater than this length will
/// be truncated by the runtime.
CustomError(Vec<u8>),
}
impl std::fmt::Display for ProgramError {