Skip to content

Commit

Permalink
custom proxy paths in sc config
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaicalinluca committed Mar 20, 2024
1 parent 8afcfb6 commit 477fbbc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
14 changes: 12 additions & 2 deletions framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ const PROXIES_SOURCE_FILE_NAME: &str = "/output/proxy.rs";

impl MetaConfig {
pub fn generate_proxy(&self) {
let file = create_file(PROXIES_SOURCE_FILE_NAME);
write_proxy_to_file(file, &self.original_contract_abi);
if self.sc_config.proxy_paths.is_empty() {
write_proxy_with_explicit_path(PROXIES_SOURCE_FILE_NAME, &self.original_contract_abi);
} else {
for path in &self.sc_config.proxy_paths {
write_proxy_with_explicit_path(path, &self.original_contract_abi);
}
}
}
}

fn write_proxy_with_explicit_path(path: &str, abi: &ContractAbi) {
let file = create_file(path);
write_proxy_to_file(file, abi);
}

fn write_proxy_to_file(mut file: File, abi: &ContractAbi) {
write_header(&mut file);
write_struct_template(&mut file, &abi.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ impl ScConfig {
ScConfig {
default_contract_config_name: config.settings.main.clone().unwrap_or_default(),
contracts,
proxy_paths: config.settings.proxy_paths.clone().unwrap_or_default(),
}
}

Expand All @@ -295,6 +296,7 @@ impl ScConfig {
wasm_crate_name,
abi: original_abi.clone(),
}],
proxy_paths: Vec::new(),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub const SC_CONFIG_FILE_NAMES: &[&str] = &["sc-config.toml", "multicontract.tom
pub struct ScConfig {
pub default_contract_config_name: String,
pub contracts: Vec<ContractVariant>,
pub proxy_paths: Vec<String>
}

impl ScConfig {
Expand Down
3 changes: 3 additions & 0 deletions framework/meta/src/cmd/contract/sc_config/sc_config_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ pub struct ContractVariantSerde {
#[serde(deny_unknown_fields)]
pub struct MultiContractGeneralSettingsSerde {
pub main: Option<String>,

#[serde(rename = "proxy-paths")]
pub proxy_paths: Option<Vec<String>>
}

#[derive(Deserialize, Default, Debug, Clone, PartialEq, Eq)]
Expand Down

0 comments on commit 477fbbc

Please sign in to comment.