From 041b37e0d6c8289f7a734bca47571d4fc4373da3 Mon Sep 17 00:00:00 2001 From: Marian Vanderka Date: Fri, 6 Dec 2024 15:25:44 +0100 Subject: [PATCH] fixes the symbol naming for liq pools (#860) --- rollup/runtime/src/runtime_config.rs | 37 +++++++++++----------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/rollup/runtime/src/runtime_config.rs b/rollup/runtime/src/runtime_config.rs index 8fcca8151..a8af6e423 100644 --- a/rollup/runtime/src/runtime_config.rs +++ b/rollup/runtime/src/runtime_config.rs @@ -1110,9 +1110,9 @@ pub mod config { asset_1: T::AssetId, asset_2: T::AssetId, ) -> DispatchResult { - let name_lp = format_u128_with_leading_zeros(lp_asset, 8); - let name_asset_1 = format_u128_with_leading_zeros(asset_1, 8); - let name_asset_2 = format_u128_with_leading_zeros(asset_2, 8); + let name_lp = format_asset_id(lp_asset); + let name_asset_1 = format_asset_id(asset_1); + let name_asset_2 = format_asset_id(asset_2); let mut name: Vec = Vec::::new(); name.extend_from_slice(LIQUIDITY_TOKEN_IDENTIFIER); @@ -1157,27 +1157,20 @@ pub mod config { } } - fn format_u128_with_leading_zeros(num: TokenId, width: usize) -> Vec { + // 48 in utf-8 '0' + // 55 in utf-8 '0' + gap between '9' and 'A' + pub fn format_asset_id(num: TokenId) -> Vec { let mut result = Vec::new(); - let mut current = num; - let mut digits = 0; - - while current != 0 { - current /= 10; - digits += 1; - } - - for _ in 0..width - digits { - result.push(b'0'); - } - - current = num; - while current != 0 { - let digit = (current % 10) as u8; - result.push(digit + b'0'); - current /= 10; + for bytes in num.to_be_bytes().iter() { + match (bytes >> 4) as u8 { + x @ 0u8..=9u8 => result.push(x + 48), + x => result.push(x + 55), + } + match (bytes & 0b0000_1111) as u8 { + x @ 0u8..=9u8 => result.push(x + 48), + x => result.push(x + 55), + } } - result } }