diff --git a/crates/proto/src/domain/merkle.rs b/crates/proto/src/domain/merkle.rs index f21bec087..3a1bb2a38 100644 --- a/crates/proto/src/domain/merkle.rs +++ b/crates/proto/src/domain/merkle.rs @@ -6,29 +6,29 @@ use miden_objects::{ use super::{convert, try_convert}; use crate::{ errors::{ConversionError, MissingFieldHelper}, - generated, + generated as proto, }; // MERKLE PATH // ================================================================================================ -impl From<&MerklePath> for generated::merkle::MerklePath { +impl From<&MerklePath> for proto::merkle::MerklePath { fn from(value: &MerklePath) -> Self { - let siblings = value.nodes().iter().map(generated::digest::Digest::from).collect(); - generated::merkle::MerklePath { siblings } + let siblings = value.nodes().iter().map(proto::digest::Digest::from).collect(); + proto::merkle::MerklePath { siblings } } } -impl From for generated::merkle::MerklePath { +impl From for proto::merkle::MerklePath { fn from(value: MerklePath) -> Self { (&value).into() } } -impl TryFrom<&generated::merkle::MerklePath> for MerklePath { +impl TryFrom<&proto::merkle::MerklePath> for MerklePath { type Error = ConversionError; - fn try_from(merkle_path: &generated::merkle::MerklePath) -> Result { + fn try_from(merkle_path: &proto::merkle::MerklePath) -> Result { merkle_path.siblings.iter().map(Digest::try_from).collect() } } @@ -38,7 +38,7 @@ impl TryFrom<&generated::merkle::MerklePath> for MerklePath { impl From for generated::mmr::MmrDelta { fn from(value: MmrDelta) -> Self { - let data = value.data.into_iter().map(generated::digest::Digest::from).collect(); + let data = value.data.into_iter().map(proto::digest::Digest::from).collect(); generated::mmr::MmrDelta { forest: value.forest as u64, data } } } diff --git a/crates/proto/src/domain/notes.rs b/crates/proto/src/domain/notes.rs index 10cb5db4f..2f348df48 100644 --- a/crates/proto/src/domain/notes.rs +++ b/crates/proto/src/domain/notes.rs @@ -9,20 +9,17 @@ use crate::{ convert, domain::blocks::BlockInclusionProof, errors::{ConversionError, MissingFieldHelper}, - generated::note::{ - NoteAuthenticationInfo as NoteAuthenticationInfoProto, - NoteInclusionInBlockProof as NoteInclusionInBlockProofPb, NoteMetadata as NoteMetadataPb, - }, + generated::note as proto, try_convert, }; -impl TryFrom for NoteMetadata { +impl TryFrom for NoteMetadata { type Error = ConversionError; - fn try_from(value: NoteMetadataPb) -> Result { + fn try_from(value: proto::NoteMetadata) -> Result { let sender = value .sender - .ok_or_else(|| NoteMetadataPb::missing_field(stringify!(sender)))? + .ok_or_else(|| proto::NoteMetadata::missing_field(stringify!(sender)))? .try_into()?; let note_type = NoteType::try_from(value.note_type as u64)?; let tag = NoteTag::from(value.tag); @@ -35,7 +32,7 @@ impl TryFrom for NoteMetadata { } } -impl From for NoteMetadataPb { +impl From for proto::NoteMetadata { fn from(val: NoteMetadata) -> Self { let sender = Some(val.sender().into()); let note_type = val.note_type() as u32; @@ -53,7 +50,7 @@ impl From for NoteMetadataPb { } } -impl From<(&NoteId, &NoteInclusionProof)> for NoteInclusionInBlockProofPb { +impl From<(&NoteId, &NoteInclusionProof)> for proto::NoteInclusionInBlockProof { fn from((note_id, proof): (&NoteId, &NoteInclusionProof)) -> Self { Self { note_id: Some(note_id.into()), @@ -64,18 +61,18 @@ impl From<(&NoteId, &NoteInclusionProof)> for NoteInclusionInBlockProofPb { } } -impl TryFrom<&NoteInclusionInBlockProofPb> for (NoteId, NoteInclusionProof) { +impl TryFrom<&proto::NoteInclusionInBlockProof> for (NoteId, NoteInclusionProof) { type Error = ConversionError; fn try_from( - proof: &NoteInclusionInBlockProofPb, + proof: &proto::NoteInclusionInBlockProof, ) -> Result<(NoteId, NoteInclusionProof), Self::Error> { Ok(( Digest::try_from( proof .note_id .as_ref() - .ok_or(NoteInclusionInBlockProofPb::missing_field(stringify!(note_id)))?, + .ok_or(proto::NoteInclusionInBlockProof::missing_field(stringify!(note_id)))?, )? .into(), NoteInclusionProof::new( @@ -84,7 +81,9 @@ impl TryFrom<&NoteInclusionInBlockProofPb> for (NoteId, NoteInclusionProof) { proof .merkle_path .as_ref() - .ok_or(NoteInclusionInBlockProofPb::missing_field(stringify!(merkle_path)))? + .ok_or(proto::NoteInclusionInBlockProof::missing_field(stringify!( + merkle_path + )))? .try_into()?, )?, )) @@ -107,7 +106,7 @@ impl NoteAuthenticationInfo { } } -impl From for NoteAuthenticationInfoProto { +impl From for proto::NoteAuthenticationInfo { fn from(value: NoteAuthenticationInfo) -> Self { Self { note_proofs: convert(&value.note_proofs), @@ -116,10 +115,10 @@ impl From for NoteAuthenticationInfoProto { } } -impl TryFrom for NoteAuthenticationInfo { +impl TryFrom for NoteAuthenticationInfo { type Error = ConversionError; - fn try_from(value: NoteAuthenticationInfoProto) -> Result { + fn try_from(value: proto::NoteAuthenticationInfo) -> Result { let result = Self { block_proofs: try_convert(value.block_proofs)?, note_proofs: try_convert(&value.note_proofs)?, diff --git a/crates/proto/src/domain/nullifiers.rs b/crates/proto/src/domain/nullifiers.rs index 0b3cc0d0c..b52701b84 100644 --- a/crates/proto/src/domain/nullifiers.rs +++ b/crates/proto/src/domain/nullifiers.rs @@ -5,19 +5,19 @@ use miden_objects::{ use crate::{ errors::{ConversionError, MissingFieldHelper}, - generated::{digest::Digest, responses::NullifierBlockInputRecord}, + generated::{digest as proto, responses::NullifierBlockInputRecord}, }; // FROM NULLIFIER // ================================================================================================ -impl From<&Nullifier> for Digest { +impl From<&Nullifier> for proto::Digest { fn from(value: &Nullifier) -> Self { (*value).inner().into() } } -impl From for Digest { +impl From for proto::Digest { fn from(value: Nullifier) -> Self { value.inner().into() } @@ -26,10 +26,10 @@ impl From for Digest { // INTO NULLIFIER // ================================================================================================ -impl TryFrom for Nullifier { +impl TryFrom for Nullifier { type Error = ConversionError; - fn try_from(value: Digest) -> Result { + fn try_from(value: proto::Digest) -> Result { let digest: RpoDigest = value.try_into()?; Ok(digest.into()) } diff --git a/crates/proto/src/domain/transactions.rs b/crates/proto/src/domain/transactions.rs index 5f22cad37..d4f71c32f 100644 --- a/crates/proto/src/domain/transactions.rs +++ b/crates/proto/src/domain/transactions.rs @@ -1,32 +1,29 @@ use miden_objects::{crypto::hash::rpo::RpoDigest, transaction::TransactionId}; -use crate::{ - errors::ConversionError, - generated::{digest::Digest, transaction::TransactionId as TransactionIdPb}, -}; +use crate::{errors::ConversionError, generated as proto}; // FROM TRANSACTION ID // ================================================================================================ -impl From<&TransactionId> for Digest { +impl From<&TransactionId> for proto::digest::Digest { fn from(value: &TransactionId) -> Self { (*value).inner().into() } } -impl From for Digest { +impl From for proto::digest::Digest { fn from(value: TransactionId) -> Self { value.inner().into() } } -impl From<&TransactionId> for TransactionIdPb { +impl From<&TransactionId> for proto::transaction::TransactionId { fn from(value: &TransactionId) -> Self { - TransactionIdPb { id: Some(value.into()) } + proto::transaction::TransactionId { id: Some(value.into()) } } } -impl From for TransactionIdPb { +impl From for proto::transaction::TransactionId { fn from(value: TransactionId) -> Self { (&value).into() } @@ -35,19 +32,19 @@ impl From for TransactionIdPb { // INTO TRANSACTION ID // ================================================================================================ -impl TryFrom for TransactionId { +impl TryFrom for TransactionId { type Error = ConversionError; - fn try_from(value: Digest) -> Result { + fn try_from(value: proto::digest::Digest) -> Result { let digest: RpoDigest = value.try_into()?; Ok(digest.into()) } } -impl TryFrom for TransactionId { +impl TryFrom for TransactionId { type Error = ConversionError; - fn try_from(value: TransactionIdPb) -> Result { + fn try_from(value: proto::transaction::TransactionId) -> Result { value .id .ok_or(ConversionError::MissingFieldInProtobufRepresentation {