From fe664c34ff9869542b4e7beb2233937d15c28b28 Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Tue, 2 Apr 2024 15:03:15 +0300 Subject: [PATCH] proxy gen - replace char removed --- .../generate_proxy/proxy_generator.rs | 42 +++++-------------- .../contract/generate_proxy/proxy_naming.rs | 9 +--- 2 files changed, 11 insertions(+), 40 deletions(-) diff --git a/framework/meta/src/cmd/contract/generate_proxy/proxy_generator.rs b/framework/meta/src/cmd/contract/generate_proxy/proxy_generator.rs index 872ea416f8..4528f53af6 100644 --- a/framework/meta/src/cmd/contract/generate_proxy/proxy_generator.rs +++ b/framework/meta/src/cmd/contract/generate_proxy/proxy_generator.rs @@ -145,9 +145,7 @@ where if self .meta_config .original_contract_abi - .build_info - .contract_crate - .name + .get_crate_name_for_code() != extract_struct_crate(type_description.names.rust.as_str()) { continue; @@ -482,20 +480,24 @@ where self.writeln(" },"); } - pub fn clean_paths(&mut self, proxy_crate: &str, rust_type: &str) -> String { + pub fn clean_paths(&mut self, rust_type: &str) -> String { let delimiters = "<>,()[] "; let words: Vec<&str> = rust_type .split(|c| delimiters.contains(c)) .filter(|s| !s.is_empty()) .collect(); + let crate_name = self + .meta_config + .original_contract_abi + .get_crate_name_for_code(); let mut words_replacer: Vec = Vec::new(); for word in &words { - let type_rust_name = word.split("::").last().unwrap().to_string(); - if proxy_crate == extract_struct_crate(word) - || TYPES_FROM_FRAMEWORK.contains(&type_rust_name.as_str()) + let type_rust_name = word.split("::").last().unwrap(); + if crate_name == extract_struct_crate(word) + || TYPES_FROM_FRAMEWORK.contains(&type_rust_name) { - words_replacer.push(type_rust_name); + words_replacer.push(type_rust_name.to_string()); } else { words_replacer.push(word.to_string()); } @@ -545,11 +547,6 @@ where fn adjust_type_name_with_env_api(&mut self, original_rust_name: &str) -> String { self.clean_paths( - self.meta_config - .original_contract_abi - .build_info - .contract_crate - .name, &original_rust_name .replace("multiversx_sc::api::uncallable::UncallableApi", "Env::Api") .replace("$API", "Env::Api"), @@ -558,11 +555,6 @@ where fn adjust_type_name_with_api(&mut self, original_rust_name: &str) -> String { self.clean_paths( - self.meta_config - .original_contract_abi - .build_info - .contract_crate - .name, &original_rust_name .replace("multiversx_sc::api::uncallable::UncallableApi", "Api") .replace("$API", "Api"), @@ -599,15 +591,8 @@ pub mod tests { meta_config: &meta_config, file: None, }; - let name = proxy_generator - .meta_config - .original_contract_abi - .build_info - .contract_crate - .name; let cleaned_path_unsanitized = proxy_generator.clean_paths( - name, "(other_crate::contract_crate::TestStruct, Option>)", ); let expected_result_unsanitized = @@ -636,15 +621,8 @@ pub mod tests { meta_config: &meta_config, file: None, }; - let name = proxy_generator - .meta_config - .original_contract_abi - .build_info - .contract_crate - .name; let cleaned_path_sanitized = proxy_generator.clean_paths( - name, "(contract_crate::other_crate::TestStruct, Option>)", ); let expected_result_sanitized = "(TestStruct, Option>)"; diff --git a/framework/meta/src/cmd/contract/generate_proxy/proxy_naming.rs b/framework/meta/src/cmd/contract/generate_proxy/proxy_naming.rs index ada7559e01..3c4f1dac2e 100644 --- a/framework/meta/src/cmd/contract/generate_proxy/proxy_naming.rs +++ b/framework/meta/src/cmd/contract/generate_proxy/proxy_naming.rs @@ -7,13 +7,6 @@ pub(super) fn proxy_methods_type_name(contract_trait_name: &str) -> String { } pub(super) fn extract_struct_crate(struct_path: &str) -> String { - let struct_crate_name = struct_path - .replace('_', "-") - .replace("multiversx_sc::api::uncallable::UncallableApi", "Api") - .to_string(); - let crate_name = struct_crate_name - .split("::") - .next() - .unwrap_or_else(|| &struct_crate_name); + let crate_name = struct_path.split("::").next().unwrap_or(struct_path); crate_name.to_string() }