diff --git a/CHANGELOG.md b/CHANGELOG.md index c7fdf4ba6..2215f2983 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Changes +- Implemented `to_hex` for `AccountIdPrefix` and `epoch_block_num` for `BlockHeader` (#1039). - Added tracing to the `miden-tx-prover` CLI (#1014). - Added health check endpoints to the prover service (#1006). - Implemented serialization for `AccountHeader` (#996). diff --git a/objects/src/accounts/account_id_prefix.rs b/objects/src/accounts/account_id_prefix.rs index b198741c4..5124e2873 100644 --- a/objects/src/accounts/account_id_prefix.rs +++ b/objects/src/accounts/account_id_prefix.rs @@ -1,4 +1,4 @@ -use alloc::string::ToString; +use alloc::string::{String, ToString}; use core::fmt; use miden_crypto::utils::ByteWriter; @@ -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 @@ -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()) } } diff --git a/objects/src/block/header.rs b/objects/src/block/header.rs index 5e91651e3..7ae216b26 100644 --- a/objects/src/block/header.rs +++ b/objects/src/block/header.rs @@ -186,6 +186,11 @@ impl BlockHeader { self.timestamp } + /// Returns the block number of the epoch block to which this block belongs. + pub fn epoch_block_num(&self) -> u32 { + block_num_from_epoch(self.block_epoch()) + } + // HELPERS // --------------------------------------------------------------------------------------------