add Account::new_data (#4701)

* add account_new_data

* fixup

* fixup
This commit is contained in:
Rob Walker
2019-06-17 15:58:05 -07:00
committed by GitHub
parent fe04fb4cd3
commit d86358eedc
4 changed files with 40 additions and 17 deletions

View File

@@ -46,6 +46,20 @@ impl Account {
}
}
pub fn new_data<T: serde::Serialize>(
lamports: u64,
state: &T,
owner: &Pubkey,
) -> Result<Account, bincode::Error> {
let data = bincode::serialize(state)?;
Ok(Account {
lamports,
data,
owner: *owner,
executable: false,
})
}
pub fn deserialize_data<T: serde::de::DeserializeOwned>(&self) -> Result<T, bincode::Error> {
bincode::deserialize(&self.data)
}