From 78ce57e19bc74d5321f590bc3d51812f59dda7a3 Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Wed, 3 Dec 2025 13:50:10 +0200 Subject: [PATCH 1/3] fix: correct tokens names --- wallet/Cargo.toml | 1 + wallet/src/cli/account.rs | 56 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/wallet/Cargo.toml b/wallet/Cargo.toml index 3b12d8f..aeceb79 100644 --- a/wallet/Cargo.toml +++ b/wallet/Cargo.toml @@ -27,6 +27,7 @@ path = "../key_protocol" [dependencies.nssa] path = "../nssa" +features = ["no_docker"] [dependencies.common] path = "../common" diff --git a/wallet/src/cli/account.rs b/wallet/src/cli/account.rs index 5b23b2b..f6bc90a 100644 --- a/wallet/src/cli/account.rs +++ b/wallet/src/cli/account.rs @@ -178,7 +178,17 @@ impl From for TokedDefinitionAccountView { fn from(value: TokenDefinition) -> Self { Self { account_type: "Token definition".to_string(), - name: hex::encode(value.name), + name: { + let mut name_vec_trim = vec![]; + for ch in value.name { + // Assuming, that name does not have UTF-8 NULL and all zeroes are padding. + if ch == 0 { + break; + } + name_vec_trim.push(ch); + } + String::from_utf8(name_vec_trim).unwrap_or(hex::encode(value.name)) + }, total_supply: value.total_supply, } } @@ -343,3 +353,47 @@ impl WalletSubcommand for AccountSubcommand { } } } + +#[cfg(test)] +mod tests { + use crate::cli::account::{TokedDefinitionAccountView, TokenDefinition}; + + #[test] + fn test_invalid_utf_8_name_of_token() { + let token_def = TokenDefinition { + account_type: 1, + name: [137, 12, 14, 3, 5, 4], + total_supply: 100, + }; + + let token_def_view: TokedDefinitionAccountView = token_def.into(); + + assert_eq!(token_def_view.name, "890c0e030504"); + } + + #[test] + fn test_valid_utf_8_name_of_token_all_bytes() { + let token_def = TokenDefinition { + account_type: 1, + name: [240, 159, 146, 150, 66, 66], + total_supply: 100, + }; + + let token_def_view: TokedDefinitionAccountView = token_def.into(); + + assert_eq!(token_def_view.name, "💖BB"); + } + + #[test] + fn test_valid_utf_8_name_of_token_less_bytes() { + let token_def = TokenDefinition { + account_type: 1, + name: [78, 65, 77, 69, 0, 0], + total_supply: 100, + }; + + let token_def_view: TokedDefinitionAccountView = token_def.into(); + + assert_eq!(token_def_view.name, "NAME"); + } +} From 282b932a8e33f16785814ffa4ccdca4b32478f0e Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Wed, 3 Dec 2025 14:30:23 +0200 Subject: [PATCH 2/3] fix: correct feature --- wallet/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/wallet/Cargo.toml b/wallet/Cargo.toml index aeceb79..3b12d8f 100644 --- a/wallet/Cargo.toml +++ b/wallet/Cargo.toml @@ -27,7 +27,6 @@ path = "../key_protocol" [dependencies.nssa] path = "../nssa" -features = ["no_docker"] [dependencies.common] path = "../common" From fe83a20c4da88ecc9f5b4f81d2814d6f9c84ed98 Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Thu, 4 Dec 2025 14:34:11 +0200 Subject: [PATCH 3/3] fix: suggestion 1 --- wallet/src/cli/account.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/wallet/src/cli/account.rs b/wallet/src/cli/account.rs index f6bc90a..da1734e 100644 --- a/wallet/src/cli/account.rs +++ b/wallet/src/cli/account.rs @@ -179,15 +179,10 @@ impl From for TokedDefinitionAccountView { Self { account_type: "Token definition".to_string(), name: { - let mut name_vec_trim = vec![]; - for ch in value.name { - // Assuming, that name does not have UTF-8 NULL and all zeroes are padding. - if ch == 0 { - break; - } - name_vec_trim.push(ch); - } - String::from_utf8(name_vec_trim).unwrap_or(hex::encode(value.name)) + // Assuming, that name does not have UTF-8 NULL and all zeroes are padding. + let name_trimmed: Vec<_> = + value.name.into_iter().take_while(|ch| *ch != 0).collect(); + String::from_utf8(name_trimmed).unwrap_or(hex::encode(value.name)) }, total_supply: value.total_supply, }