|
1 | 1 | use alloc::collections::BTreeMap; |
| 2 | +use alloc::string::String; |
2 | 3 | use alloc::sync::Arc; |
3 | 4 | use alloc::vec::Vec; |
| 5 | +use core::fmt::Display; |
4 | 6 |
|
5 | 7 | use miden_core::mast::MastNodeExt; |
6 | 8 | use miden_crypto::merkle::InnerNodeInfo; |
| 9 | +use miden_crypto_derive::WordWrapper; |
7 | 10 | use miden_mast_package::Package; |
8 | 11 |
|
9 | 12 | use super::{Felt, Hasher, Word}; |
@@ -276,6 +279,42 @@ impl Deserializable for TransactionArgs { |
276 | 279 | } |
277 | 280 | } |
278 | 281 |
|
| 282 | +// TRANSACTION SCRIPT ROOT |
| 283 | +// ================================================================================================ |
| 284 | + |
| 285 | +/// The MAST root of a [`TransactionScript`]. |
| 286 | +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, WordWrapper)] |
| 287 | +pub struct TransactionScriptRoot(Word); |
| 288 | + |
| 289 | +impl From<TransactionScriptRoot> for Word { |
| 290 | + fn from(root: TransactionScriptRoot) -> Self { |
| 291 | + root.0 |
| 292 | + } |
| 293 | +} |
| 294 | + |
| 295 | +impl Display for TransactionScriptRoot { |
| 296 | + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 297 | + Display::fmt(&self.0, f) |
| 298 | + } |
| 299 | +} |
| 300 | + |
| 301 | +impl Serializable for TransactionScriptRoot { |
| 302 | + fn write_into<W: ByteWriter>(&self, target: &mut W) { |
| 303 | + target.write(self.0); |
| 304 | + } |
| 305 | + |
| 306 | + fn get_size_hint(&self) -> usize { |
| 307 | + self.0.get_size_hint() |
| 308 | + } |
| 309 | +} |
| 310 | + |
| 311 | +impl Deserializable for TransactionScriptRoot { |
| 312 | + fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> { |
| 313 | + let word: Word = source.read()?; |
| 314 | + Ok(Self::from_raw(word)) |
| 315 | + } |
| 316 | +} |
| 317 | + |
279 | 318 | // TRANSACTION SCRIPT |
280 | 319 | // ================================================================================================ |
281 | 320 |
|
@@ -334,8 +373,8 @@ impl TransactionScript { |
334 | 373 | } |
335 | 374 |
|
336 | 375 | /// Returns the commitment of this transaction script (i.e., the script's MAST root). |
337 | | - pub fn root(&self) -> Word { |
338 | | - self.mast[self.entrypoint].digest() |
| 376 | + pub fn root(&self) -> TransactionScriptRoot { |
| 377 | + TransactionScriptRoot::from_raw(self.mast[self.entrypoint].digest()) |
339 | 378 | } |
340 | 379 |
|
341 | 380 | /// Returns a new [TransactionScript] with the provided advice map entries merged into the |
|
0 commit comments