Update programs using simple error mapping to use CustomError

This commit is contained in:
Tyera Eulberg
2019-03-11 14:50:31 -06:00
committed by Greg Fitzgerald
parent db5370c5df
commit 1a9ef37251
6 changed files with 12 additions and 8 deletions

View File

@@ -12,6 +12,7 @@ edition = "2018"
bincode = "1.1.2"
log = "0.4.2"
serde = "1.0.89"
serde_derive = "1.0.89"
solana-sdk = { path = "../../sdk", version = "0.12.0" }
[dev-dependencies]

View File

@@ -1,5 +1,7 @@
use log::*;
use serde_derive::Serialize;
use solana_sdk::account::KeyedAccount;
use solana_sdk::custom_error;
use solana_sdk::native_program::ProgramError;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::system_instruction::SystemInstruction;
@@ -8,7 +10,7 @@ use solana_sdk::system_program;
const FROM_ACCOUNT_INDEX: usize = 0;
const TO_ACCOUNT_INDEX: usize = 1;
#[derive(Debug, Clone, PartialEq)]
#[derive(Serialize, Debug, Clone, PartialEq)]
enum SystemError {
AccountAlreadyInUse,
ResultWithNegativeLamports,
@@ -96,11 +98,10 @@ pub fn entrypoint(
program_id,
} => create_system_account(keyed_accounts, lamports, space, &program_id).map_err(|e| {
match e {
SystemError::AccountAlreadyInUse => ProgramError::InvalidArgument,
SystemError::ResultWithNegativeLamports => {
ProgramError::ResultWithNegativeLamports
}
SystemError::SourceNotSystemAccount => ProgramError::InvalidArgument,
e => ProgramError::CustomError(custom_error!(e)),
}
}),
SystemInstruction::Assign { program_id } => {