make executable, vote and stake account rent exempt (#6017)
* add missing convenience method * require vote account to be exempt * make stake account rent exempt * making executable rent exempt * rent will be initialized in genesis * add test for update_rent
This commit is contained in:
@@ -49,6 +49,30 @@ pub fn create_account(lamports: u64, rent_calculator: &RentCalculator) -> Accoun
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
use crate::account::KeyedAccount;
|
||||
use crate::instruction::InstructionError;
|
||||
|
||||
pub fn from_keyed_account(account: &KeyedAccount) -> Result<Rent, InstructionError> {
|
||||
if !check_id(account.unsigned_key()) {
|
||||
return Err(InstructionError::InvalidArgument);
|
||||
}
|
||||
Rent::from_account(account.account).ok_or(InstructionError::InvalidArgument)
|
||||
}
|
||||
|
||||
pub fn verify_rent_exemption(
|
||||
account: &KeyedAccount,
|
||||
rent_sysvar_account: &KeyedAccount,
|
||||
) -> Result<(), InstructionError> {
|
||||
if !from_keyed_account(rent_sysvar_account)?
|
||||
.rent_calculator
|
||||
.is_exempt(account.account.lamports, account.account.data.len())
|
||||
{
|
||||
Err(InstructionError::InsufficientFunds)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
Reference in New Issue
Block a user