@ -1,5 +1,4 @@
|
||||
use crate::pubkey::Pubkey;
|
||||
use crate::Epoch;
|
||||
use crate::{pubkey::Pubkey, timing::Epoch};
|
||||
use std::{cmp, fmt};
|
||||
|
||||
/// An Account with data that is stored on chain
|
||||
@ -64,6 +63,19 @@ impl Account {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new_data_with_space<T: serde::Serialize>(
|
||||
lamports: u64,
|
||||
state: &T,
|
||||
space: usize,
|
||||
owner: &Pubkey,
|
||||
) -> Result<Account, bincode::Error> {
|
||||
let mut account = Self::new(lamports, space, owner);
|
||||
|
||||
account.serialize_data(state)?;
|
||||
|
||||
Ok(account)
|
||||
}
|
||||
|
||||
pub fn deserialize_data<T: serde::de::DeserializeOwned>(&self) -> Result<T, bincode::Error> {
|
||||
bincode::deserialize(&self.data)
|
||||
}
|
||||
|
@ -28,6 +28,3 @@ pub mod transport;
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
pub type Epoch = u64;
|
||||
pub type Slot = u64;
|
||||
|
Reference in New Issue
Block a user