miden_objects/conversion/
note_file.rs1use crate::note_file::{NoteFile, NoteSyncHint};
2use crate::proto;
3
4#[cfg(test)]
5mod tests;
6
7impl From<&NoteSyncHint> for proto::note_file::NoteSyncHint {
11 fn from(hint: &NoteSyncHint) -> Self {
12 Self {
13 after_block_num: Some(hint.after_block_num().into()),
14 tag: hint.tag().as_u32(),
15 }
16 }
17}
18
19impl From<NoteSyncHint> for proto::note_file::NoteSyncHint {
20 fn from(hint: NoteSyncHint) -> Self {
21 Self::from(&hint)
22 }
23}
24
25impl From<&NoteFile> for proto::note_file::NoteFile {
29 fn from(file: &NoteFile) -> Self {
30 let version = proto::note_file::note_file::Version::V1(file.into());
31 Self { version: Some(version) }
32 }
33}
34
35impl From<NoteFile> for proto::note_file::NoteFile {
36 fn from(file: NoteFile) -> Self {
37 Self::from(&file)
38 }
39}
40
41impl From<&NoteFile> for proto::note_file::NoteFileV1 {
42 fn from(file: &NoteFile) -> Self {
43 use proto::note_file::note_file_v1::Variant;
44
45 let variant = match file {
46 NoteFile::NoteId(note_id) => Variant::NoteId(note_id.into()),
47 NoteFile::ExpectedNote { details, sync_hint } => {
48 Variant::ExpectedNote(proto::note_file::ExpectedNote {
49 details: Some(details.into()),
50 sync_hint: Some(sync_hint.into()),
51 })
52 },
53 NoteFile::Committed { note, proof } => {
54 Variant::CommittedNote(proto::note_file::CommittedNote {
55 note: Some(note.into()),
56 proof: Some((¬e.id(), proof).into()),
57 })
58 },
59 };
60 Self { variant: Some(variant) }
61 }
62}