diff --git a/framework/meta/src/cmd/contract.rs b/framework/meta/src/cmd/contract.rs index d182d6bf2d..846a33c073 100644 --- a/framework/meta/src/cmd/contract.rs +++ b/framework/meta/src/cmd/contract.rs @@ -1,7 +1,7 @@ mod generate_snippets; mod meta_abi; mod meta_config; -pub mod output_contract; +pub mod sc_config; use std::path::Path; @@ -9,7 +9,7 @@ use crate::cli_args::{ContractCliAction, ContractCliArgs}; use clap::Parser; use meta_config::MetaConfig; use multiversx_sc::contract_base::ContractAbiProvider; -use output_contract::OutputContractGlobalConfig; +use sc_config::ScConfig; /// Entry point in the program from the contract meta crates. pub fn cli_main() { @@ -35,23 +35,23 @@ pub fn cli_main() { fn process_original_abi(cli_args: &ContractCliArgs) -> MetaConfig { let input_abi = ::abi(); let mut meta_config = MetaConfig::create(input_abi, cli_args.load_abi_git_version); - meta_config.output_contracts.validate_output_contracts(); + meta_config.sc_config.validate_contract_variants(); meta_config.write_contract_abis(); meta_config.write_esdt_attribute_abis(); meta_config.generate_wasm_crates(); meta_config } -pub fn multi_contract_config(contract_crate_path: &Path) -> OutputContractGlobalConfig +pub fn multi_contract_config(contract_crate_path: &Path) -> ScConfig where AbiObj: ContractAbiProvider, { let original_contract_abi = ::abi(); - let output_contracts = OutputContractGlobalConfig::load_from_crate_or_default( + let sc_config = ScConfig::load_from_crate_or_default( contract_crate_path, &original_contract_abi, ); - output_contracts.validate_output_contracts(); - output_contracts + sc_config.validate_contract_variants(); + sc_config } diff --git a/framework/meta/src/cmd/contract/generate_snippets/snippet_gen_main.rs b/framework/meta/src/cmd/contract/generate_snippets/snippet_gen_main.rs index e46ffa83a7..d85c1cc48c 100644 --- a/framework/meta/src/cmd/contract/generate_snippets/snippet_gen_main.rs +++ b/framework/meta/src/cmd/contract/generate_snippets/snippet_gen_main.rs @@ -19,7 +19,7 @@ use super::{ impl MetaConfig { pub fn generate_rust_snippets(&self, args: &GenerateSnippetsArgs) { - let main_contract = self.output_contracts.main_contract(); + let main_contract = self.sc_config.main_contract(); let crate_name = &main_contract.contract_name; let snake_case_name = &main_contract.public_name_snake_case(); let wasm_output_file_path_expr = format!("\"file:../output/{crate_name}.wasm\""); diff --git a/framework/meta/src/cmd/contract/meta_abi.rs b/framework/meta/src/cmd/contract/meta_abi.rs index b6f7cca343..e07ab9771f 100644 --- a/framework/meta/src/cmd/contract/meta_abi.rs +++ b/framework/meta/src/cmd/contract/meta_abi.rs @@ -8,16 +8,16 @@ use crate::{ esdt_attr_file_json::create_new_esdt_attr_file, }; -use super::{meta_config::MetaConfig, output_contract::OutputContract}; +use super::{meta_config::MetaConfig, sc_config::ContractVariant}; -fn write_contract_abi(output_contract: &OutputContract, git_version: &str, output_path: &str) { - let mut abi_json = ContractAbiJson::from(&output_contract.abi); +fn write_contract_abi(contract_variant: &ContractVariant, git_version: &str, output_path: &str) { + let mut abi_json = ContractAbiJson::from(&contract_variant.abi); if let Some(build_info) = &mut abi_json.build_info { build_info.contract_crate.git_version = git_version.to_string(); } let abi_string = serialize_abi_to_json(&abi_json); - let abi_file_path = format!("{output_path}/{}", output_contract.abi_output_name(),); + let abi_file_path = format!("{output_path}/{}", contract_variant.abi_output_name(),); let mut abi_file = File::create(abi_file_path).unwrap(); write!(abi_file, "{abi_string}").unwrap(); } @@ -26,9 +26,9 @@ impl MetaConfig { pub fn write_contract_abis(&self) { create_dir_all(&self.output_dir).unwrap(); let git_version = self.git_describe(); - for output_contract in &self.output_contracts.contracts { + for contract_variant in &self.sc_config.contracts { write_contract_abi( - output_contract, + contract_variant, git_version.as_str(), self.output_dir.as_str(), ); diff --git a/framework/meta/src/cmd/contract/meta_config.rs b/framework/meta/src/cmd/contract/meta_config.rs index 8d08db794b..43d8c86be0 100644 --- a/framework/meta/src/cmd/contract/meta_config.rs +++ b/framework/meta/src/cmd/contract/meta_config.rs @@ -4,7 +4,7 @@ use multiversx_sc::abi::ContractAbi; use crate::{cli_args::BuildArgs, tools::check_tools_installed, CargoTomlContents}; -use super::output_contract::{OutputContract, OutputContractGlobalConfig}; +use super::sc_config::{ContractVariant, ScConfig}; const OUTPUT_RELATIVE_PATH: &str = "../output"; const SNIPPETS_RELATIVE_PATH: &str = "../interact-rs"; @@ -17,20 +17,20 @@ pub struct MetaConfig { pub output_dir: String, pub snippets_dir: String, pub original_contract_abi: ContractAbi, - pub output_contracts: OutputContractGlobalConfig, + pub sc_config: ScConfig, } impl MetaConfig { pub fn create(original_contract_abi: ContractAbi, load_abi_git_version: bool) -> MetaConfig { - let output_contracts = - OutputContractGlobalConfig::load_from_crate_or_default("..", &original_contract_abi); + let sc_config = + ScConfig::load_from_crate_or_default("..", &original_contract_abi); MetaConfig { load_abi_git_version, output_dir: OUTPUT_RELATIVE_PATH.to_string(), snippets_dir: SNIPPETS_RELATIVE_PATH.to_string(), original_contract_abi, - output_contracts, + sc_config, } } @@ -44,21 +44,21 @@ impl MetaConfig { } fn create_wasm_crate_dirs(&self) { - for output_contract in &self.output_contracts.contracts { - output_contract.create_wasm_crate_dir(); + for contract_variant in &self.sc_config.contracts { + contract_variant.create_wasm_crate_dir(); } } /// Cargo.toml files for secondary contracts are generated from the main contract Cargo.toml, /// by changing the package name. pub fn generate_cargo_toml_for_secondary_contracts(&mut self) { - let main_contract = self.output_contracts.main_contract_mut(); + let main_contract = self.sc_config.main_contract_mut(); let main_cargo_toml_contents = CargoTomlContents::load_from_file(main_contract.cargo_toml_path()); main_contract.wasm_crate_name = main_cargo_toml_contents.package_name(); - for secondary_contract in self.output_contracts.secondary_contracts() { + for secondary_contract in self.sc_config.secondary_contracts() { secondary_contract_cargo_toml(secondary_contract, &main_cargo_toml_contents) .save_to_file(secondary_contract.cargo_toml_path()); } @@ -66,7 +66,7 @@ impl MetaConfig { } fn secondary_contract_cargo_toml( - secondary_contract: &OutputContract, + secondary_contract: &ContractVariant, main_cargo_toml_contents: &CargoTomlContents, ) -> CargoTomlContents { let mut cargo_toml_contents = main_cargo_toml_contents.clone(); @@ -80,16 +80,16 @@ fn secondary_contract_cargo_toml( impl MetaConfig { fn generate_wasm_src_lib(&self) { - for output_contract in &self.output_contracts.contracts { - output_contract.generate_wasm_src_lib_file(); + for contract_variant in &self.sc_config.contracts { + contract_variant.generate_wasm_src_lib_file(); } } pub fn build(&mut self, mut build_args: BuildArgs) { check_tools_installed(&mut build_args); - for output_contract in &self.output_contracts.contracts { - output_contract.build_contract(&build_args, self.output_dir.as_str()); + for contract_variant in &self.sc_config.contracts { + contract_variant.build_contract(&build_args, self.output_dir.as_str()); } } @@ -100,15 +100,15 @@ impl MetaConfig { } fn clean_contract_crates(&self) { - for output_contract in &self.output_contracts.contracts { - output_contract.cargo_clean(); + for contract_variant in &self.sc_config.contracts { + contract_variant.cargo_clean(); } } /// Updates the Cargo.lock on all wasm crates. pub fn update(&self) { - for output_contract in &self.output_contracts.contracts { - output_contract.cargo_update(); + for contract_variant in &self.sc_config.contracts { + contract_variant.cargo_update(); } } @@ -125,7 +125,7 @@ impl MetaConfig { return true; } - self.output_contracts + self.sc_config .secondary_contracts() .any(|contract| contract.wasm_crate_dir_name().as_str() == dir_name) } diff --git a/framework/meta/src/cmd/contract/output_contract.rs b/framework/meta/src/cmd/contract/sc_config.rs similarity index 66% rename from framework/meta/src/cmd/contract/output_contract.rs rename to framework/meta/src/cmd/contract/sc_config.rs index b318524979..e28adf5d01 100644 --- a/framework/meta/src/cmd/contract/output_contract.rs +++ b/framework/meta/src/cmd/contract/sc_config.rs @@ -11,7 +11,7 @@ mod wasm_update; pub use multi_contract_serde::*; pub use oc_builder::*; -pub use oc_config::OutputContract; -pub use oc_global_config::OutputContractGlobalConfig; -pub use oc_settings::OutputContractSettings; +pub use oc_config::ContractVariant; +pub use oc_global_config::ScConfig; +pub use oc_settings::ContractVariantSettings; pub use wasm_build::*; diff --git a/framework/meta/src/cmd/contract/output_contract/multi_contract_serde.rs b/framework/meta/src/cmd/contract/sc_config/multi_contract_serde.rs similarity index 93% rename from framework/meta/src/cmd/contract/output_contract/multi_contract_serde.rs rename to framework/meta/src/cmd/contract/sc_config/multi_contract_serde.rs index 3f1e7ee2c4..23633bd054 100644 --- a/framework/meta/src/cmd/contract/output_contract/multi_contract_serde.rs +++ b/framework/meta/src/cmd/contract/sc_config/multi_contract_serde.rs @@ -6,14 +6,14 @@ pub struct MultiContractConfigSerde { #[serde(default)] pub settings: MultiContractGeneralSettingsSerde, #[serde(default)] - pub contracts: HashMap, + pub contracts: HashMap, #[serde(default)] #[serde(rename = "labels-for-contracts")] pub labels_for_contracts: HashMap>, } #[derive(Deserialize, Debug)] -pub struct OutputContractSerde { +pub struct ContractVariantSerde { pub name: Option, #[serde(default)] diff --git a/framework/meta/src/cmd/contract/output_contract/oc_builder.rs b/framework/meta/src/cmd/contract/sc_config/oc_builder.rs similarity index 85% rename from framework/meta/src/cmd/contract/output_contract/oc_builder.rs rename to framework/meta/src/cmd/contract/sc_config/oc_builder.rs index 65a85c55fe..7ae3c34c90 100644 --- a/framework/meta/src/cmd/contract/output_contract/oc_builder.rs +++ b/framework/meta/src/cmd/contract/sc_config/oc_builder.rs @@ -8,12 +8,12 @@ use std::{ use super::{ oc_global_config::SC_CONFIG_FILE_NAMES, oc_settings::{parse_allocator, parse_check_ei, parse_stack_size}, - MultiContractConfigSerde, OutputContract, OutputContractGlobalConfig, OutputContractSerde, - OutputContractSettings, + MultiContractConfigSerde, ContractVariant, ScConfig, ContractVariantSerde, + ContractVariantSettings, }; -/// Temporary structure, to help create instances of `OutputContract`. Not publicly exposed. -struct OutputContractBuilder { +/// Temporary structure, to help create instances of `ContractVariant`. Not publicly exposed. +struct ContractVariantBuilder { pub contract_id: String, pub explicit_name: String, pub add_unlabelled: bool, @@ -21,10 +21,10 @@ struct OutputContractBuilder { pub add_endpoints: BTreeSet, pub collected_endpoints: Vec, endpoint_names: HashSet, // help keep endpoints unique - pub settings: OutputContractSettings, + pub settings: ContractVariantSettings, } -impl Default for OutputContractBuilder { +impl Default for ContractVariantBuilder { fn default() -> Self { Self { contract_id: Default::default(), @@ -39,16 +39,16 @@ impl Default for OutputContractBuilder { } } -impl OutputContractBuilder { +impl ContractVariantBuilder { fn new(id: String) -> Self { - OutputContractBuilder { + ContractVariantBuilder { contract_id: id.clone(), explicit_name: id, ..Default::default() } } - fn map_from_config(kvp: (&String, &OutputContractSerde)) -> (String, OutputContractBuilder) { + fn map_from_config(kvp: (&String, &ContractVariantSerde)) -> (String, ContractVariantBuilder) { let (contract_id, cms) = kvp; let external_view = cms.external_view.unwrap_or_default(); let mut collected_endpoints = Vec::new(); @@ -57,17 +57,17 @@ impl OutputContractBuilder { multiversx_sc::external_view_contract::external_view_contract_constructor_abi(), ) } - let default = OutputContractBuilder::default(); + let default = ContractVariantBuilder::default(); ( contract_id.clone(), - OutputContractBuilder { + ContractVariantBuilder { contract_id: contract_id.clone(), explicit_name: cms.name.clone().unwrap_or(default.explicit_name), add_unlabelled: cms.add_unlabelled.unwrap_or(default.add_unlabelled), add_labels: cms.add_labels.iter().cloned().collect(), add_endpoints: cms.add_endpoints.iter().cloned().collect(), collected_endpoints, - settings: OutputContractSettings { + settings: ContractVariantSettings { external_view: cms.external_view.unwrap_or(default.settings.external_view), panic_message: cms.panic_message.unwrap_or(default.settings.panic_message), check_ei: parse_check_ei(&cms.ei), @@ -98,14 +98,14 @@ impl OutputContractBuilder { } fn process_labels_for_contracts( - contract_builders: &mut HashMap, + contract_builders: &mut HashMap, labels_for_contracts: &HashMap>, ) { for (label, targets) in labels_for_contracts { for target in targets { contract_builders .entry(target.clone()) - .or_insert_with(|| OutputContractBuilder::new(target.clone())) + .or_insert_with(|| ContractVariantBuilder::new(target.clone())) .add_labels .insert(label.clone()); } @@ -124,7 +124,7 @@ fn endpoint_matches_labels(endpoint_abi: &EndpointAbi, labels: &BTreeSet } fn collect_unlabelled_endpoints( - contract_builders: &mut HashMap, + contract_builders: &mut HashMap, original_abi: &ContractAbi, ) { for builder in contract_builders.values_mut() { @@ -139,7 +139,7 @@ fn collect_unlabelled_endpoints( } fn collect_labelled_endpoints( - contract_builders: &mut HashMap, + contract_builders: &mut HashMap, original_abi: &ContractAbi, ) { for builder in contract_builders.values_mut() { @@ -152,7 +152,7 @@ fn collect_labelled_endpoints( } fn collect_add_endpoints( - contract_builders: &mut HashMap, + contract_builders: &mut HashMap, original_abi: &ContractAbi, ) { for builder in contract_builders.values_mut() { @@ -164,7 +164,7 @@ fn collect_add_endpoints( } } -fn build_contract_abi(builder: OutputContractBuilder, original_abi: &ContractAbi) -> ContractAbi { +fn build_contract_abi(builder: ContractVariantBuilder, original_abi: &ContractAbi) -> ContractAbi { let mut constructors = Vec::new(); let mut endpoints = Vec::new(); let mut promise_callbacks = Vec::new(); @@ -198,10 +198,10 @@ fn default_wasm_crate_name(contract_name: &str) -> String { format!("{contract_name}-wasm") } -fn build_contract(builder: OutputContractBuilder, original_abi: &ContractAbi) -> OutputContract { +fn build_contract(builder: ContractVariantBuilder, original_abi: &ContractAbi) -> ContractVariant { let contract_name = builder.wasm_name().clone(); let wasm_crate_name = default_wasm_crate_name(&contract_name); - OutputContract { + ContractVariant { main: false, settings: builder.settings.clone(), contract_id: builder.contract_id.clone(), @@ -212,7 +212,7 @@ fn build_contract(builder: OutputContractBuilder, original_abi: &ContractAbi) -> } fn set_main_contract_flag( - contracts: &mut [OutputContract], + contracts: &mut [ContractVariant], default_contract_config_name_opt: &Option, ) { if let Some(default_contract_config_name) = default_contract_config_name_opt { @@ -236,7 +236,7 @@ fn set_main_contract_flag( } } -fn validate_output_contracts(contracts: &[OutputContract]) { +fn validate_contract_variants(contracts: &[ContractVariant]) { for contract in contracts { if contract.main { assert!( @@ -247,27 +247,27 @@ fn validate_output_contracts(contracts: &[OutputContract]) { } } -impl OutputContractGlobalConfig { - /// Assembles an `OutputContractConfig` from a raw config object that was loaded via Serde. +impl ScConfig { + /// Assembles an `ContractVariantConfig` from a raw config object that was loaded via Serde. /// /// In most cases the config will be loaded from a .toml file, use `load_from_file` for that. pub fn load_from_config(config: &MultiContractConfigSerde, original_abi: &ContractAbi) -> Self { - let mut contract_builders: HashMap = config + let mut contract_builders: HashMap = config .contracts .iter() - .map(OutputContractBuilder::map_from_config) + .map(ContractVariantBuilder::map_from_config) .collect(); collect_unlabelled_endpoints(&mut contract_builders, original_abi); collect_labelled_endpoints(&mut contract_builders, original_abi); collect_add_endpoints(&mut contract_builders, original_abi); process_labels_for_contracts(&mut contract_builders, &config.labels_for_contracts); - let mut contracts: Vec = contract_builders + let mut contracts: Vec = contract_builders .into_values() .map(|builder| build_contract(builder, original_abi)) .collect(); set_main_contract_flag(&mut contracts, &config.settings.main); - validate_output_contracts(&contracts); - OutputContractGlobalConfig { + validate_contract_variants(&contracts); + ScConfig { default_contract_config_name: config.settings.main.clone().unwrap_or_default(), contracts, } @@ -279,11 +279,11 @@ impl OutputContractGlobalConfig { pub fn default_config(original_abi: &ContractAbi) -> Self { let default_contract_config_name = original_abi.build_info.contract_crate.name.to_string(); let wasm_crate_name = default_wasm_crate_name(&default_contract_config_name); - OutputContractGlobalConfig { + ScConfig { default_contract_config_name: default_contract_config_name.clone(), - contracts: vec![OutputContract { + contracts: vec![ContractVariant { main: true, - settings: OutputContractSettings::default(), + settings: ContractVariantSettings::default(), contract_id: default_contract_config_name.clone(), contract_name: default_contract_config_name, wasm_crate_name, diff --git a/framework/meta/src/cmd/contract/output_contract/oc_config.rs b/framework/meta/src/cmd/contract/sc_config/oc_config.rs similarity index 96% rename from framework/meta/src/cmd/contract/output_contract/oc_config.rs rename to framework/meta/src/cmd/contract/sc_config/oc_config.rs index db97e05e82..321aea39de 100644 --- a/framework/meta/src/cmd/contract/output_contract/oc_config.rs +++ b/framework/meta/src/cmd/contract/sc_config/oc_config.rs @@ -1,13 +1,13 @@ use std::path::PathBuf; -use super::OutputContractSettings; +use super::ContractVariantSettings; use crate::cli_args::BuildArgs; use multiversx_sc::abi::ContractAbi; /// Represents a contract created by the framework when building. /// /// It might have only some of the endpoints written by the developer and maybe some other function. -pub struct OutputContract { +pub struct ContractVariant { /// If it is the main contract, then the wasm crate is called just `wasm`, ///and the wasm `Cargo.toml` is provided by the dev. pub main: bool, @@ -28,13 +28,13 @@ pub struct OutputContract { pub wasm_crate_name: String, /// Collection of flags, specified in the multicontract config. - pub settings: OutputContractSettings, + pub settings: ContractVariantSettings, /// Filtered and processed ABI of the output contract. pub abi: ContractAbi, } -impl OutputContract { +impl ContractVariant { pub fn public_name_snake_case(&self) -> String { self.contract_name.replace('-', "_") } @@ -158,9 +158,9 @@ impl OutputContract { } } -impl std::fmt::Debug for OutputContract { +impl std::fmt::Debug for ContractVariant { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.debug_struct("OutputContract") + f.debug_struct("ContractVariant") .field("main", &self.main) .field("config_name", &self.contract_id) .field("public_name", &self.contract_name) diff --git a/framework/meta/src/cmd/contract/output_contract/oc_global_config.rs b/framework/meta/src/cmd/contract/sc_config/oc_global_config.rs similarity index 67% rename from framework/meta/src/cmd/contract/output_contract/oc_global_config.rs rename to framework/meta/src/cmd/contract/sc_config/oc_global_config.rs index 26f895f933..1bfb2ffa71 100644 --- a/framework/meta/src/cmd/contract/output_contract/oc_global_config.rs +++ b/framework/meta/src/cmd/contract/sc_config/oc_global_config.rs @@ -1,4 +1,4 @@ -use super::{oc_validate::validate_output_contract, OutputContract}; +use super::{oc_validate::validate_contract_variant, ContractVariant}; /// Allowed file names for the SC config. /// @@ -10,72 +10,72 @@ pub const SC_CONFIG_FILE_NAMES: &[&str] = &["sc-config.toml", "multicontract.tom /// An entire project configuration. /// -/// It can contain one or several output contracts. +/// It can contain one or several contract variants. #[derive(Debug)] -pub struct OutputContractGlobalConfig { +pub struct ScConfig { pub default_contract_config_name: String, - pub contracts: Vec, + pub contracts: Vec, } -impl OutputContractGlobalConfig { - pub fn main_contract(&self) -> &OutputContract { +impl ScConfig { + pub fn main_contract(&self) -> &ContractVariant { self.contracts .iter() .find(|contract| contract.main) .unwrap_or_else(|| { panic!( - "Could not find default contract '{}' among the output contracts.", + "Could not find default contract '{}' among the contract variants.", self.default_contract_config_name ) }) } - pub fn main_contract_mut(&mut self) -> &mut OutputContract { + pub fn main_contract_mut(&mut self) -> &mut ContractVariant { self.contracts .iter_mut() .find(|contract| contract.main) .unwrap_or_else(|| { panic!( - "Could not find default contract '{}' among the output contracts.", + "Could not find default contract '{}' among the contract variants.", self.default_contract_config_name ) }) } - pub fn secondary_contracts(&self) -> impl Iterator { + pub fn secondary_contracts(&self) -> impl Iterator { self.contracts.iter().filter(move |contract| !contract.main) } - pub fn secondary_contracts_mut(&mut self) -> impl Iterator { + pub fn secondary_contracts_mut(&mut self) -> impl Iterator { self.contracts .iter_mut() .filter(move |contract| !contract.main) } - pub fn get_contract_by_id(&self, contract_id: String) -> Option<&OutputContract> { + pub fn get_contract_by_id(&self, contract_id: String) -> Option<&ContractVariant> { self.contracts .iter() .find(|contract| contract.contract_id == contract_id) } - pub fn get_contract_by_name(&self, contract_name: String) -> Option<&OutputContract> { + pub fn get_contract_by_name(&self, contract_name: String) -> Option<&ContractVariant> { self.contracts .iter() .find(|contract| contract.contract_name == contract_name) } /// Yields the contract with the given public name. - pub fn find_contract(&self, contract_name: &str) -> &OutputContract { + pub fn find_contract(&self, contract_name: &str) -> &ContractVariant { self.contracts .iter() .find(|contract| contract.contract_name == contract_name) - .unwrap_or_else(|| panic!("output contract {contract_name} not found")) + .unwrap_or_else(|| panic!("contract variant {contract_name} not found")) } - pub fn validate_output_contracts(&self) { + pub fn validate_contract_variants(&self) { for contract in &self.contracts { - validate_output_contract(contract).unwrap_or_else(|err| { - panic!("Invalid output contract {}: {err}", contract.contract_name) + validate_contract_variant(contract).unwrap_or_else(|err| { + panic!("Invalid contract variant {}: {err}", contract.contract_name) }); } } diff --git a/framework/meta/src/cmd/contract/output_contract/oc_settings.rs b/framework/meta/src/cmd/contract/sc_config/oc_settings.rs similarity index 92% rename from framework/meta/src/cmd/contract/output_contract/oc_settings.rs rename to framework/meta/src/cmd/contract/sc_config/oc_settings.rs index 6184d0ae09..d6dc1c6f99 100644 --- a/framework/meta/src/cmd/contract/output_contract/oc_settings.rs +++ b/framework/meta/src/cmd/contract/sc_config/oc_settings.rs @@ -10,7 +10,7 @@ use crate::ei::EIVersion; /// Collection of flags, specified in the multicontract config. #[derive(Clone, PartialEq, Eq, Debug)] -pub struct OutputContractSettings { +pub struct ContractVariantSettings { /// External view contracts are just readers of data from another contract. pub external_view: bool, @@ -33,9 +33,9 @@ pub struct OutputContractSettings { pub kill_legacy_callback: bool, } -impl Default for OutputContractSettings { +impl Default for ContractVariantSettings { fn default() -> Self { - OutputContractSettings { + ContractVariantSettings { external_view: Default::default(), panic_message: Default::default(), check_ei: Some(EIVersion::default()), diff --git a/framework/meta/src/cmd/contract/output_contract/oc_settings/oc_allocator.rs b/framework/meta/src/cmd/contract/sc_config/oc_settings/oc_allocator.rs similarity index 100% rename from framework/meta/src/cmd/contract/output_contract/oc_settings/oc_allocator.rs rename to framework/meta/src/cmd/contract/sc_config/oc_settings/oc_allocator.rs diff --git a/framework/meta/src/cmd/contract/output_contract/oc_settings/oc_parse.rs b/framework/meta/src/cmd/contract/sc_config/oc_settings/oc_parse.rs similarity index 100% rename from framework/meta/src/cmd/contract/output_contract/oc_settings/oc_parse.rs rename to framework/meta/src/cmd/contract/sc_config/oc_settings/oc_parse.rs diff --git a/framework/meta/src/cmd/contract/output_contract/oc_settings/oc_parse_stack_size.rs b/framework/meta/src/cmd/contract/sc_config/oc_settings/oc_parse_stack_size.rs similarity index 100% rename from framework/meta/src/cmd/contract/output_contract/oc_settings/oc_parse_stack_size.rs rename to framework/meta/src/cmd/contract/sc_config/oc_settings/oc_parse_stack_size.rs diff --git a/framework/meta/src/cmd/contract/output_contract/oc_validate.rs b/framework/meta/src/cmd/contract/sc_config/oc_validate.rs similarity index 91% rename from framework/meta/src/cmd/contract/output_contract/oc_validate.rs rename to framework/meta/src/cmd/contract/sc_config/oc_validate.rs index 81dcccc94f..9181ff536e 100644 --- a/framework/meta/src/cmd/contract/output_contract/oc_validate.rs +++ b/framework/meta/src/cmd/contract/sc_config/oc_validate.rs @@ -1,15 +1,15 @@ use multiversx_sc::abi::{ContractAbi, EndpointAbi}; -use super::OutputContract; +use super::ContractVariant; -pub fn validate_output_contract(output_contract: &OutputContract) -> Result<(), String> { - check_single_constructor(output_contract)?; - validate_contract_var_args(&output_contract.abi)?; +pub fn validate_contract_variant(contract_variant: &ContractVariant) -> Result<(), String> { + check_single_constructor(contract_variant)?; + validate_contract_var_args(&contract_variant.abi)?; Ok(()) } -fn check_single_constructor(output_contract: &OutputContract) -> Result<(), String> { - match output_contract.abi.constructors.len() { +fn check_single_constructor(contract_variant: &ContractVariant) -> Result<(), String> { + match contract_variant.abi.constructors.len() { 0 => Err("Missing constructor. Add a method annotated with `#[init]`.".to_string()), 1 => Ok(()), _ => Err("More than one contrctructor present. Exactly one method annotated with `#[init]` is required.".to_string()), diff --git a/framework/meta/src/cmd/contract/output_contract/wasm_build.rs b/framework/meta/src/cmd/contract/sc_config/wasm_build.rs similarity index 99% rename from framework/meta/src/cmd/contract/output_contract/wasm_build.rs rename to framework/meta/src/cmd/contract/sc_config/wasm_build.rs index 2b7afff532..879a726a09 100644 --- a/framework/meta/src/cmd/contract/output_contract/wasm_build.rs +++ b/framework/meta/src/cmd/contract/sc_config/wasm_build.rs @@ -1,6 +1,6 @@ use std::{ffi::OsStr, fs, process::Command}; -use super::OutputContract; +use super::ContractVariant; use crate::{ abi_json::ContractAbiJson, cli_args::BuildArgs, @@ -10,7 +10,7 @@ use crate::{ tools, }; -impl OutputContract { +impl ContractVariant { pub fn build_contract(&self, build_args: &BuildArgs, output_path: &str) { let mut command = self.compose_build_command(build_args); @@ -164,7 +164,7 @@ fn validate_ei(import_names: &[String], check_ei: &Option) { } } -impl OutputContract { +impl ContractVariant { fn run_twiggy(&self, build_args: &BuildArgs, output_path: &str) { if build_args.has_twiggy_call() { let output_wasm_path = format!("{output_path}/{}", self.wasm_output_name(build_args)); diff --git a/framework/meta/src/cmd/contract/output_contract/wasm_clean.rs b/framework/meta/src/cmd/contract/sc_config/wasm_clean.rs similarity index 90% rename from framework/meta/src/cmd/contract/output_contract/wasm_clean.rs rename to framework/meta/src/cmd/contract/sc_config/wasm_clean.rs index ece0f042a9..eea7496239 100644 --- a/framework/meta/src/cmd/contract/output_contract/wasm_clean.rs +++ b/framework/meta/src/cmd/contract/sc_config/wasm_clean.rs @@ -1,8 +1,8 @@ use std::process::Command; -use super::OutputContract; +use super::ContractVariant; -impl OutputContract { +impl ContractVariant { /// Runs `cargo clean` in the corresponding wasm crate. pub fn cargo_clean(&self) { let exit_status = Command::new("cargo") diff --git a/framework/meta/src/cmd/contract/output_contract/wasm_crate_gen.rs b/framework/meta/src/cmd/contract/sc_config/wasm_crate_gen.rs similarity index 98% rename from framework/meta/src/cmd/contract/output_contract/wasm_crate_gen.rs rename to framework/meta/src/cmd/contract/sc_config/wasm_crate_gen.rs index 115fcabf83..141bc8a266 100644 --- a/framework/meta/src/cmd/contract/output_contract/wasm_crate_gen.rs +++ b/framework/meta/src/cmd/contract/sc_config/wasm_crate_gen.rs @@ -7,7 +7,7 @@ use std::{ str::FromStr, }; -use super::OutputContract; +use super::ContractVariant; const PREFIX_AUTO_GENERATED: &str = "// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. @@ -44,7 +44,7 @@ const FEATURES_DEFAULT: &str = " #![feature(lang_items)] "; -impl OutputContract { +impl ContractVariant { /// Makes sure that all the necessary wasm crate directories exist. pub fn create_wasm_crate_dir(&self) { fs::create_dir_all(PathBuf::from(&self.wasm_crate_path()).join("src")).unwrap(); @@ -107,7 +107,7 @@ fn write_stat_comment(wasm_lib_file: &mut File, label: &str, number: usize) { writeln!(wasm_lib_file, "// {label:<35} {number:3}").unwrap(); } -impl OutputContract { +impl ContractVariant { /// Writing some nicely formatted comments breaking down all exported functions. fn write_stat_comments(&self, wasm_lib_file: &mut File) { write_stat_comment(wasm_lib_file, "Init:", NUM_INIT); diff --git a/framework/meta/src/cmd/contract/output_contract/wasm_update.rs b/framework/meta/src/cmd/contract/sc_config/wasm_update.rs similarity index 90% rename from framework/meta/src/cmd/contract/output_contract/wasm_update.rs rename to framework/meta/src/cmd/contract/sc_config/wasm_update.rs index d5d37bd2a8..17ad612b16 100644 --- a/framework/meta/src/cmd/contract/output_contract/wasm_update.rs +++ b/framework/meta/src/cmd/contract/sc_config/wasm_update.rs @@ -1,8 +1,8 @@ use std::process::Command; -use super::OutputContract; +use super::ContractVariant; -impl OutputContract { +impl ContractVariant { /// Runs `cargo update` in the corresponding wasm crate. pub fn cargo_update(&self) { let exit_status = Command::new("cargo") diff --git a/framework/meta/tests/multi_contract_test.rs b/framework/meta/tests/multi_contract_test.rs index 1bb728f201..e7a409f12f 100644 --- a/framework/meta/tests/multi_contract_test.rs +++ b/framework/meta/tests/multi_contract_test.rs @@ -1,6 +1,6 @@ use multiversx_sc::abi::{ContractAbi, EndpointAbi}; -use multiversx_sc_meta::cmd::contract::output_contract::{ - MultiContractConfigSerde, OutputContractGlobalConfig, +use multiversx_sc_meta::cmd::contract::sc_config::{ + MultiContractConfigSerde, ScConfig, }; fn get_serialized_toml() -> MultiContractConfigSerde { @@ -88,11 +88,11 @@ fn test_serialize_multi_contract() { } #[test] -fn test_output_contract_config() { +fn test_sc_config() { let serde = get_serialized_toml(); let abi = get_contract_abi(); - let contract_config = OutputContractGlobalConfig::load_from_config(&serde, &abi); + let contract_config = ScConfig::load_from_config(&serde, &abi); assert_eq!( contract_config.default_contract_config_name,