Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions crates/miden-objects/src/block/block_inputs.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use alloc::collections::BTreeMap;

use miden_core::utils::{ByteReader, ByteWriter, Deserializable, Serializable};

use crate::account::AccountId;
use crate::block::{AccountWitness, BlockHeader, NullifierWitness};
use crate::note::{NoteId, NoteInclusionProof, Nullifier};
use crate::transaction::PartialBlockchain;
use crate::utils::serde::DeserializationError;

// BLOCK INPUTS
// ================================================================================================
Expand Down Expand Up @@ -128,3 +131,35 @@ impl BlockInputs {
&mut self.account_witnesses
}
}

// SERIALIZATION
// ================================================================================================

impl Serializable for BlockInputs {
fn write_into<W: ByteWriter>(&self, target: &mut W) {
self.prev_block_header.write_into(target);
self.partial_blockchain.write_into(target);
self.account_witnesses.write_into(target);
self.nullifier_witnesses.write_into(target);
self.unauthenticated_note_proofs.write_into(target);
}
Comment on lines +139 to +145
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like deconstructing in these type of situations so that one is forced to revisit this if you add a new field

Suggested change
fn write_into<W: ByteWriter>(&self, target: &mut W) {
self.prev_block_header.write_into(target);
self.partial_blockchain.write_into(target);
self.account_witnesses.write_into(target);
self.nullifier_witnesses.write_into(target);
self.unauthenticated_note_proofs.write_into(target);
}
fn write_into<W: ByteWriter>(&self, target: &mut W) {
let Self {
prev_block_header,
partial_blockchain,
account_witnesses,
nullifier_witnesses,
unauthenticated_note_proofs,
} = self;
prev_block_header.write_into(target);
partial_blockchain.write_into(target);
account_witnesses.write_into(target);
nullifier_witnesses.write_into(target);
unauthenticated_note_proofs.write_into(target);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent point, will remember in future

}

impl Deserializable for BlockInputs {
fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
let prev_block_header = BlockHeader::read_from(source)?;
let partial_blockchain = PartialBlockchain::read_from(source)?;
let account_witnesses = BTreeMap::<AccountId, AccountWitness>::read_from(source)?;
let nullifier_witnesses = BTreeMap::<Nullifier, NullifierWitness>::read_from(source)?;
let unauthenticated_note_proofs =
BTreeMap::<NoteId, NoteInclusionProof>::read_from(source)?;

Ok(Self::new(
prev_block_header,
partial_blockchain,
account_witnesses,
nullifier_witnesses,
unauthenticated_note_proofs,
))
}
}
Loading