Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement serialization and Eq for TransactionScript #824

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [BREAKING] Changed the `NoteFile::NoteDetails` type to struct and added a `after_block_num` field (#823).
- Implemented `cteate_note` and `move_asset_into_note` basic wallet procedures (#808).
- [BREAKING] Interface of the `miden::tx::add_asset_to_note` procedure was changed (#808).
- Added serialization and equality comparison for `TransactionScript` (#824).

## 0.4.0 (2024-07-03)

Expand Down
29 changes: 27 additions & 2 deletions objects/src/transaction/tx_args.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use alloc::{collections::BTreeMap, vec::Vec};
use core::ops::Deref;

use assembly::ast::AstSerdeOptions;
use miden_crypto::merkle::InnerNodeInfo;
use vm_processor::{AdviceInputs, AdviceMap};
use vm_core::utils::{ByteReader, ByteWriter, Deserializable, Serializable};
use vm_processor::{AdviceInputs, AdviceMap, DeserializationError};

use super::{Digest, Felt, Word};
use crate::{
Expand Down Expand Up @@ -154,7 +156,7 @@ impl TransactionArgs {
/// - [hash](TransactionScript::hash): the hash of the compiled transaction script.
/// - [inputs](TransactionScript::inputs): a map of key, value inputs that are loaded into the
/// advice inputs' map such that the transaction script can access them.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TransactionScript {
code: ProgramAst,
hash: Digest,
Expand Down Expand Up @@ -222,3 +224,26 @@ impl TransactionScript {
&self.inputs
}
}

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

impl Serializable for TransactionScript {
fn write_into<W: ByteWriter>(&self, target: &mut W) {
self.code.write_into(target, AstSerdeOptions { serialize_imports: true });
self.code.write_source_locations(target);
self.hash.write_into(target);
self.inputs.write_into(target);
}
}

impl Deserializable for TransactionScript {
fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
let mut code = ProgramAst::read_from(source)?;
code.load_source_locations(source)?;
let hash = Digest::read_from(source)?;
let inputs = BTreeMap::<Digest, Vec<Felt>>::read_from(source)?;

Ok(Self { code, hash, inputs })
}
}
Loading