Skip to content

Commit

Permalink
style: update protobuf aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasArrachea committed Jan 10, 2025
1 parent 28b8fd8 commit 4afe936
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
35 changes: 19 additions & 16 deletions crates/proto/src/domain/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ use miden_objects::{

use crate::{
errors::{ConversionError, MissingFieldHelper},
generated::{
account as proto,
responses::{AccountBlockInputRecord, AccountTransactionInputRecord},
},
generated as proto,
};

// ACCOUNT ID
// ================================================================================================

impl Display for proto::AccountId {
impl Display for proto::account::AccountId {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "0x")?;
for byte in &self.id {
Expand All @@ -29,7 +26,7 @@ impl Display for proto::AccountId {
}
}

impl Debug for proto::AccountId {
impl Debug for proto::account::AccountId {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Display::fmt(self, f)
}
Expand All @@ -38,13 +35,13 @@ impl Debug for proto::AccountId {
// INTO PROTO ACCOUNT ID
// ------------------------------------------------------------------------------------------------

impl From<&AccountId> for proto::AccountId {
impl From<&AccountId> for proto::account::AccountId {
fn from(account_id: &AccountId) -> Self {
(*account_id).into()
}
}

impl From<AccountId> for proto::AccountId {
impl From<AccountId> for proto::account::AccountId {
fn from(account_id: AccountId) -> Self {
Self { id: account_id.to_bytes() }
}
Expand All @@ -53,10 +50,10 @@ impl From<AccountId> for proto::AccountId {
// FROM PROTO ACCOUNT ID
// ------------------------------------------------------------------------------------------------

impl TryFrom<proto::AccountId> for AccountId {
impl TryFrom<proto::account::AccountId> for AccountId {
type Error = ConversionError;

fn try_from(account_id: proto::AccountId) -> Result<Self, Self::Error> {
fn try_from(account_id: proto::account::AccountId) -> Result<Self, Self::Error> {
AccountId::read_from_bytes(&account_id.id).map_err(|_| ConversionError::NotAValidFelt)
}
}
Expand Down Expand Up @@ -106,7 +103,7 @@ pub struct AccountInputRecord {
pub proof: MerklePath,
}

impl From<AccountInputRecord> for AccountBlockInputRecord {
impl From<AccountInputRecord> for proto::responses::AccountBlockInputRecord {
fn from(from: AccountInputRecord) -> Self {
Self {
account_id: Some(from.account_id.into()),
Expand All @@ -116,23 +113,29 @@ impl From<AccountInputRecord> for AccountBlockInputRecord {
}
}

impl TryFrom<AccountBlockInputRecord> for AccountInputRecord {
impl TryFrom<proto::responses::AccountBlockInputRecord> for AccountInputRecord {
type Error = ConversionError;

fn try_from(account_input_record: AccountBlockInputRecord) -> Result<Self, Self::Error> {
fn try_from(
account_input_record: proto::responses::AccountBlockInputRecord,
) -> Result<Self, Self::Error> {
Ok(Self {
account_id: account_input_record
.account_id
.ok_or(AccountBlockInputRecord::missing_field(stringify!(account_id)))?
.ok_or(proto::responses::AccountBlockInputRecord::missing_field(stringify!(
account_id
)))?
.try_into()?,
account_hash: account_input_record
.account_hash
.ok_or(AccountBlockInputRecord::missing_field(stringify!(account_hash)))?
.ok_or(proto::responses::AccountBlockInputRecord::missing_field(stringify!(
account_hash
)))?
.try_into()?,
proof: account_input_record
.proof
.as_ref()
.ok_or(AccountBlockInputRecord::missing_field(stringify!(proof)))?
.ok_or(proto::responses::AccountBlockInputRecord::missing_field(stringify!(proof)))?
.try_into()?,
})
}
Expand Down
14 changes: 7 additions & 7 deletions crates/proto/src/domain/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,23 +207,23 @@ mod test {
use hex::{FromHex, ToHex};
use proptest::prelude::*;

use crate::generated::digest::Digest;
use crate::generated::digest as proto;

#[test]
fn hex_digest() {
let digest = Digest {
let digest = proto::Digest {
d0: 3488802789098113751,
d1: 5271242459988994564,
d2: 17816570245237064784,
d3: 10910963388447438895,
};
let encoded: String = ToHex::encode_hex(&digest);
let round_trip: Result<Digest, _> = FromHex::from_hex::<&[u8]>(encoded.as_ref());
let round_trip: Result<proto::Digest, _> = FromHex::from_hex::<&[u8]>(encoded.as_ref());
assert_eq!(digest, round_trip.unwrap());

let digest = Digest { d0: 0, d1: 0, d2: 0, d3: 0 };
let digest = proto::Digest { d0: 0, d1: 0, d2: 0, d3: 0 };
let encoded: String = ToHex::encode_hex(&digest);
let round_trip: Result<Digest, _> = FromHex::from_hex::<&[u8]>(encoded.as_ref());
let round_trip: Result<proto::Digest, _> = FromHex::from_hex::<&[u8]>(encoded.as_ref());
assert_eq!(digest, round_trip.unwrap());
}

Expand All @@ -235,9 +235,9 @@ mod test {
d2: u64,
d3: u64,
) {
let digest = Digest { d0, d1, d2, d3 };
let digest = proto::Digest { d0, d1, d2, d3 };
let encoded: String = ToHex::encode_hex(&digest);
let round_trip: Result<Digest, _> = FromHex::from_hex::<&[u8]>(encoded.as_ref());
let round_trip: Result<proto::Digest, _> = FromHex::from_hex::<&[u8]>(encoded.as_ref());
assert_eq!(digest, round_trip.unwrap());
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/proto/src/domain/notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl From<NoteMetadata> for proto::NoteMetadata {
let execution_hint: u64 = val.execution_hint().into();
let aux = val.aux().into();

crate::generated::note::NoteMetadata {
proto::NoteMetadata {
sender,
note_type,
tag,
Expand Down
6 changes: 3 additions & 3 deletions crates/store/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
use deadpool_sqlite::{Config as SqliteConfig, Hook, HookError, Pool, Runtime};
use miden_node_proto::{
domain::accounts::{AccountInfo, AccountSummary},
generated::note::{Note as NotePb, NoteSyncRecord as NoteSyncRecordPb},
generated::note as proto,
};
use miden_objects::{
accounts::{AccountDelta, AccountId},
Expand Down Expand Up @@ -68,7 +68,7 @@ pub struct NoteRecord {
pub merkle_path: MerklePath,
}

impl From<NoteRecord> for NotePb {
impl From<NoteRecord> for proto::Note {
fn from(note: NoteRecord) -> Self {
Self {
block_num: note.block_num,
Expand Down Expand Up @@ -105,7 +105,7 @@ pub struct NoteSyncRecord {
pub merkle_path: MerklePath,
}

impl From<NoteSyncRecord> for NoteSyncRecordPb {
impl From<NoteSyncRecord> for proto::NoteSyncRecord {
fn from(note: NoteSyncRecord) -> Self {
Self {
note_index: note.note_index.leaf_index_value().into(),
Expand Down

0 comments on commit 4afe936

Please sign in to comment.