diff --git a/CHANGELOG.md b/CHANGELOG.md index e2a772a595..b2cb52457e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,11 +21,13 @@ - [BREAKING] Added cycle counts to notes returned by `NoteConsumptionInfo` and removed public fields from related types ([#2772](https://github.com/0xMiden/miden-base/issues/2772)). - [BREAKING] Removed unused `payback_attachment` from `SwapNoteStorage` and `attachment` from `MintNoteStorage` ([#2789](https://github.com/0xMiden/protocol/pull/2789)). - Automatically enable `concurrent` feature in `miden-tx` for `std` context ([#2791](https://github.com/0xMiden/protocol/pull/2791)). +- Added `TransactionScript::from_package()` method to create `TransactionScript` from `miden-mast-package::Package` ([#2779](https://github.com/0xMiden/protocol/pull/2779)). ### Fixes - Made deserialization of `AccountCode` more robust ([#2788](https://github.com/0xMiden/protocol/pull/2788)). + ## 0.14.3 (2026-04-07) - [BREAKING] Updated for compatibility with miden-vm v0.22.1 (`Arc` return types, `MastArtifact`/`PackageKind` removal) ([#2742](https://github.com/0xMiden/protocol/pull/2742)). diff --git a/crates/miden-protocol/src/errors/mod.rs b/crates/miden-protocol/src/errors/mod.rs index b13ec8d068..d4c8cfa68c 100644 --- a/crates/miden-protocol/src/errors/mod.rs +++ b/crates/miden-protocol/src/errors/mod.rs @@ -762,6 +762,8 @@ impl PartialBlockchainError { pub enum TransactionScriptError { #[error("failed to assemble transaction script:\n{}", PrintDiagnostic::new(.0))] AssemblyError(Report), + #[error("failed to convert package to transaction script:\n{}", PrintDiagnostic::new(.0))] + PackageNotProgram(Report), } // TRANSACTION INPUT ERROR diff --git a/crates/miden-protocol/src/transaction/tx_args.rs b/crates/miden-protocol/src/transaction/tx_args.rs index 1e6657bfaf..a92c9019b7 100644 --- a/crates/miden-protocol/src/transaction/tx_args.rs +++ b/crates/miden-protocol/src/transaction/tx_args.rs @@ -4,9 +4,11 @@ use alloc::vec::Vec; use miden_core::mast::MastNodeExt; use miden_crypto::merkle::InnerNodeInfo; +use miden_mast_package::Package; use super::{Felt, Hasher, Word}; use crate::account::auth::{PublicKeyCommitment, Signature}; +use crate::errors::TransactionScriptError; use crate::note::{NoteId, NoteRecipient}; use crate::utils::serde::{ ByteReader, @@ -308,6 +310,20 @@ impl TransactionScript { Self { mast, entrypoint } } + /// Creates a [TransactionScript] from a [`Package`]. + /// + /// The package must be an executable (i.e., its target type must be + /// [`TargetType::Executable`](miden_mast_package::TargetType::Executable)). + /// + /// # Errors + /// Returns an error if the package cannot be converted to an executable program. + pub fn from_package(package: &Package) -> Result { + let program = + package.try_into_program().map_err(TransactionScriptError::PackageNotProgram)?; + + Ok(TransactionScript::new(program)) + } + // PUBLIC ACCESSORS // --------------------------------------------------------------------------------------------