Skip to content

Commit

Permalink
Merge pull request #372 from 0xPolygonMiden/bobbin-acct-serde
Browse files Browse the repository at this point in the history
Implement Serializable and Deserializable on Account
  • Loading branch information
bobbinth authored Dec 19, 2023
2 parents a365f31 + 40d1d0c commit a4b6cec
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions objects/src/accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,28 @@ impl ToAdviceInputs for Account {
// SERIALIZATION
// ================================================================================================

impl Serializable for Account {
fn write_into<W: ByteWriter>(&self, target: &mut W) {
self.id.write_into(target);
self.vault.write_into(target);
self.storage.write_into(target);
self.code.write_into(target);
self.nonce.write_into(target);
}
}

impl Deserializable for Account {
fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
let id = AccountId::read_from(source)?;
let vault = AccountVault::read_from(source)?;
let storage = AccountStorage::read_from(source)?;
let code = AccountCode::read_from(source)?;
let nonce = Felt::read_from(source)?;

Ok(Self::new(id, vault, storage, code, nonce))
}
}

#[cfg(feature = "serde")]
mod vault_serialization {
use super::AccountVault;
Expand Down

0 comments on commit a4b6cec

Please sign in to comment.