gleeth/utils/hex

Values

pub fn decode(hex_string: String) -> Result(BitArray, String)
pub fn encode(data: BitArray) -> String
pub fn ensure_prefix(hex_string: String) -> String

Add 0x prefix to hex string if not present

pub fn format_block_number(block_hex: String) -> String
pub fn format_wei_to_ether(wei_hex: String) -> String
pub fn format_wei_to_gwei(wei_hex: String) -> String
pub fn format_with_decimal(hex_string: String) -> String

Format a hex value with decimal equivalent for display

pub fn from_int(value: Int) -> String

Convert integer to hex string with 0x prefix

pub fn hex_to_bigint(
  hex_string: String,
) -> Result(bigi.BigInt, Nil)
pub fn hex_to_int(hex_string: String) -> Result(Int, Nil)
pub fn is_valid_hex(hex_string: String) -> Bool
pub fn is_valid_hex_chars(hex_string: String) -> Bool

Validate that a string contains only valid hex characters (after stripping 0x)

pub fn normalize(hex_string: String) -> String

Normalize hex string to lowercase with 0x prefix

pub fn pad_left(hex_string: String, target_length: Int) -> String

Pad hex string to specified length (without 0x prefix)

pub fn strip_prefix(hex_string: String) -> String

Remove 0x prefix from hex string if present

pub fn to_int(hex_string: String) -> Result(Int, Nil)

Parse hex string to integer (with or without 0x prefix)

pub fn validate_length(
  hex_string: String,
  expected_bytes: Int,
) -> Result(String, String)

Validate hex string has correct length for specific data types

pub fn wei_to_ether(wei_hex: String) -> Result(Float, Nil)
pub fn wei_to_gwei(wei_hex: String) -> Result(Float, Nil)
Search Document