Move KeyedAccount out of solana-program. Native programs are not supported by solana-program
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
//! named accounts for synthesized data accounts for bank state, etc.
|
||||
//!
|
||||
use crate::{
|
||||
account::{Account, KeyedAccount},
|
||||
account_info::AccountInfo,
|
||||
instruction::InstructionError,
|
||||
program_error::ProgramError,
|
||||
pubkey::Pubkey,
|
||||
account::Account, account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey,
|
||||
};
|
||||
|
||||
pub mod clock;
|
||||
@@ -79,13 +75,6 @@ pub trait Sysvar:
|
||||
fn to_account_info(&self, account_info: &mut AccountInfo) -> Option<()> {
|
||||
bincode::serialize_into(&mut account_info.data.borrow_mut()[..], self).ok()
|
||||
}
|
||||
fn from_keyed_account(keyed_account: &KeyedAccount) -> Result<Self, InstructionError> {
|
||||
if !Self::check_id(keyed_account.unsigned_key()) {
|
||||
return Err(InstructionError::InvalidArgument);
|
||||
}
|
||||
Self::from_account(&*keyed_account.try_account_ref()?)
|
||||
.ok_or(InstructionError::InvalidArgument)
|
||||
}
|
||||
fn create_account(&self, lamports: u64) -> Account {
|
||||
let data_len = Self::size_of().max(bincode::serialized_size(self).unwrap() as usize);
|
||||
let mut account = Account::new(lamports, data_len, &id());
|
||||
|
@@ -2,11 +2,7 @@
|
||||
//!
|
||||
pub use crate::rent::Rent;
|
||||
|
||||
use crate::{
|
||||
account::{Account, KeyedAccount},
|
||||
instruction::InstructionError,
|
||||
sysvar::Sysvar,
|
||||
};
|
||||
use crate::{account::Account, sysvar::Sysvar};
|
||||
|
||||
crate::declare_sysvar_id!("SysvarRent111111111111111111111111111111111", Rent);
|
||||
|
||||
@@ -16,18 +12,6 @@ pub fn create_account(lamports: u64, rent: &Rent) -> Account {
|
||||
rent.create_account(lamports)
|
||||
}
|
||||
|
||||
pub fn verify_rent_exemption(
|
||||
keyed_account: &KeyedAccount,
|
||||
rent_sysvar_account: &KeyedAccount,
|
||||
) -> Result<(), InstructionError> {
|
||||
let rent = Rent::from_keyed_account(rent_sysvar_account)?;
|
||||
if !rent.is_exempt(keyed_account.lamports()?, keyed_account.data_len()?) {
|
||||
Err(InstructionError::InsufficientFunds)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
Reference in New Issue
Block a user