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: account ID refactor additional methods #1039

Merged
merged 4 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 7 additions & 2 deletions objects/src/accounts/account_id_prefix.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloc::string::ToString;
use alloc::string::{String, ToString};
use core::fmt;

use miden_crypto::utils::ByteWriter;
Expand Down Expand Up @@ -110,6 +110,11 @@ impl AccountIdPrefix {
account_id::extract_version(self.first_felt.as_int())
.expect("account id prefix should have been constructed with a valid version")
}

/// Returns the prefix as a big-endian, hex-encoded string.
pub fn to_hex(&self) -> String {
format!("0x{:016x}", self.first_felt.as_int())
}
}

// CONVERSIONS FROM ACCOUNT ID PREFIX
Expand Down Expand Up @@ -201,7 +206,7 @@ impl Ord for AccountIdPrefix {

impl fmt::Display for AccountIdPrefix {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "0x{:016x}", self.first_felt.as_int())
write!(f, "{}", self.to_hex())
}
}

Expand Down
5 changes: 5 additions & 0 deletions objects/src/block/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ impl BlockHeader {
self.timestamp
}

/// Returns the block number of the epoch block to which this block belongs.
pub fn get_epoch_block_num(&self) -> u32 {
Copy link
Collaborator

@igamigo igamigo Dec 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd just name this epoch_block_num() since it's a very basic computation over the block num (and also it would be analogous to BlockHeader::block_epoch()).

EDIT: Just saw that the original comment suggested the current naming. If we follow that maybe block_epoch could also have get_ as a prefix? It's a minor detail so no worries either way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the first suggestion matches better with the rest of the methods in BlockHeader

block_num_from_epoch(self.block_epoch())
}

// HELPERS
// --------------------------------------------------------------------------------------------

Expand Down