miden_protocol/batch/
batch_id.rs1use miden_crypto_derive::WordWrapper;
2
3use crate::Word;
4use crate::account::AccountId;
5use crate::transaction::{OrderedTransactionHeaders, ProvenTransaction, TransactionId};
6use crate::utils::serde::{
7 ByteReader,
8 ByteWriter,
9 Deserializable,
10 DeserializationError,
11 Serializable,
12};
13
14#[derive(Debug, Copy, Clone, Eq, Ord, PartialEq, PartialOrd, Hash, WordWrapper)]
24pub struct BatchId(Word);
25
26impl BatchId {
27 pub fn from_transactions<'tx, T>(txs: T) -> Self
29 where
30 T: Iterator<Item = &'tx ProvenTransaction>,
31 {
32 Self::from_ids(txs.map(|tx| (tx.id(), tx.account_id())))
33 }
34
35 pub fn from_ids(iter: impl IntoIterator<Item = (TransactionId, AccountId)>) -> Self {
37 Self(OrderedTransactionHeaders::compute_commitment(iter))
40 }
41}
42
43impl core::fmt::Display for BatchId {
44 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
45 write!(f, "{}", self.to_hex())
46 }
47}
48
49impl Serializable for BatchId {
53 fn write_into<W: ByteWriter>(&self, target: &mut W) {
54 self.0.write_into(target);
55 }
56}
57
58impl Deserializable for BatchId {
59 fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
60 Ok(Self(Word::read_from(source)?))
61 }
62}