Account->AccountSharedData (#15691)
This commit is contained in:
committed by
GitHub
parent
61c7ce857e
commit
8a3135d17b
@@ -1,21 +1,22 @@
|
||||
use crate::account::Account;
|
||||
use crate::account::AccountSharedData;
|
||||
use crate::account::ReadableAccount;
|
||||
pub use solana_program::feature::*;
|
||||
|
||||
pub fn from_account(account: &Account) -> Option<Feature> {
|
||||
if account.owner != id() {
|
||||
pub fn from_account<T: ReadableAccount>(account: &T) -> Option<Feature> {
|
||||
if account.owner() != &id() {
|
||||
None
|
||||
} else {
|
||||
bincode::deserialize(&account.data).ok()
|
||||
bincode::deserialize(account.data()).ok()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_account(feature: &Feature, account: &mut Account) -> Option<()> {
|
||||
pub fn to_account(feature: &Feature, account: &mut AccountSharedData) -> Option<()> {
|
||||
bincode::serialize_into(&mut account.data[..], feature).ok()
|
||||
}
|
||||
|
||||
pub fn create_account(feature: &Feature, lamports: u64) -> Account {
|
||||
pub fn create_account(feature: &Feature, lamports: u64) -> AccountSharedData {
|
||||
let data_len = Feature::size_of().max(bincode::serialized_size(feature).unwrap() as usize);
|
||||
let mut account = Account::new(lamports, data_len, &id());
|
||||
let mut account = AccountSharedData::new(lamports, data_len, &id());
|
||||
to_account(feature, &mut account).unwrap();
|
||||
account
|
||||
}
|
||||
@@ -26,7 +27,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn feature_deserialize_none() {
|
||||
let just_initialized = Account::new(42, Feature::size_of(), &id());
|
||||
let just_initialized = AccountSharedData::new(42, Feature::size_of(), &id());
|
||||
assert_eq!(
|
||||
from_account(&just_initialized),
|
||||
Some(Feature { activated_at: None })
|
||||
|
Reference in New Issue
Block a user