Sysvar account_into return program error rather than option (#8121)
This commit is contained in:
parent
b6d09f1901
commit
b5a735878a
|
@ -4,6 +4,7 @@ use crate::{
|
||||||
account::{Account, KeyedAccount},
|
account::{Account, KeyedAccount},
|
||||||
account_info::AccountInfo,
|
account_info::AccountInfo,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
|
program_error::ProgramError,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -70,8 +71,8 @@ pub trait Sysvar:
|
||||||
fn to_account(&self, account: &mut Account) -> Option<()> {
|
fn to_account(&self, account: &mut Account) -> Option<()> {
|
||||||
bincode::serialize_into(&mut account.data[..], self).ok()
|
bincode::serialize_into(&mut account.data[..], self).ok()
|
||||||
}
|
}
|
||||||
fn from_account_info(account_info: &AccountInfo) -> Option<Self> {
|
fn from_account_info(account_info: &AccountInfo) -> Result<Self, ProgramError> {
|
||||||
bincode::deserialize(&account_info.data.borrow()).ok()
|
bincode::deserialize(&account_info.data.borrow()).map_err(|_| ProgramError::InvalidArgument)
|
||||||
}
|
}
|
||||||
fn to_account_info(&self, account_info: &mut AccountInfo) -> Option<()> {
|
fn to_account_info(&self, account_info: &mut AccountInfo) -> Option<()> {
|
||||||
bincode::serialize_into(&mut account_info.data.borrow_mut()[..], self).ok()
|
bincode::serialize_into(&mut account_info.data.borrow_mut()[..], self).ok()
|
||||||
|
|
Loading…
Reference in New Issue