Skip to content

Commit

Permalink
doc chain_id
Browse files Browse the repository at this point in the history
  • Loading branch information
odesenfans committed Aug 29, 2024
1 parent c108591 commit 77a998a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/starknet-os-types/src/chain_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ pub fn chain_id_to_felt(chain_id: &ChainId) -> Felt {
Felt::from_bytes_be_slice(chain_id.to_string().as_bytes())
}

/// Builds a ChainId from a felt.
/// This function reads the felt as ASCII bytes. Leading zeroes are skipped.
pub fn chain_id_from_felt(felt: Felt) -> ChainId {
// Skip leading zeroes
let chain_id_bytes: Vec<_> = felt.to_bytes_be().into_iter().skip_while(|byte| *byte == 0u8).collect();
let chain_id_str = String::from_utf8_lossy(&chain_id_bytes);
ChainId::from(chain_id_str.into_owned())
Expand Down

0 comments on commit 77a998a

Please sign in to comment.