Skip to content

Commit

Permalink
feat: account ID refactor additional methods (#1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomyrd authored Dec 26, 2024
1 parent 64d7a2e commit 487e8b9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
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 epoch_block_num(&self) -> u32 {
block_num_from_epoch(self.block_epoch())
}

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

Expand Down

0 comments on commit 487e8b9

Please sign in to comment.