miden_node_persistence/
collections.rs1use miden_protobuf::{BuildUnchecked, ConversionError, DecodeMessage, Verify};
2use miden_protocol::block::BlockSignatures;
3use miden_protocol::note::{NoteAssets, NoteHeader};
4use miden_protocol::transaction::InputNoteCommitment;
5
6use crate::{PersistenceError, ProtobufValue, generated};
7
8impl ProtobufValue for BlockSignatures {
9 type Message = generated::BlockSignatures;
10 fn to_proto(&self) -> Self::Message {
11 Self::Message {
12 signatures: self.as_signatures().iter().map(Into::into).collect(),
13 }
14 }
15 fn from_proto(message: Self::Message) -> Result<Self, PersistenceError> {
16 let signatures = message.decode_fields()?.signatures.verify_infallible();
17 Self::new(signatures).map_err(|err| ConversionError::new(err).into())
18 }
19}
20impl ProtobufValue for NoteAssets {
21 type Message = generated::NoteAssets;
22 fn to_proto(&self) -> Self::Message {
23 Self::Message {
24 assets: self.iter().map(Into::into).collect(),
25 }
26 }
27 fn from_proto(message: Self::Message) -> Result<Self, PersistenceError> {
28 let assets = message.decode_fields()?.assets.verify()?;
29 Self::new(assets).map_err(|err| ConversionError::new(err).into())
30 }
31}
32impl ProtobufValue for Vec<InputNoteCommitment> {
33 type Message = generated::InputNoteCommitments;
34 fn to_proto(&self) -> Self::Message {
35 Self::Message {
36 notes: self.iter().map(Into::into).collect(),
37 }
38 }
39 fn from_proto(message: Self::Message) -> Result<Self, PersistenceError> {
40 Ok(message.decode_fields()?.notes.build_unchecked()?)
41 }
42}
43impl ProtobufValue for Vec<NoteHeader> {
44 type Message = generated::NoteHeaders;
45 fn to_proto(&self) -> Self::Message {
46 Self::Message {
47 notes: self.iter().copied().map(Into::into).collect(),
48 }
49 }
50 fn from_proto(message: Self::Message) -> Result<Self, PersistenceError> {
51 Ok(message.decode_fields()?.notes.verify()?)
52 }
53}