Skip to content

Commit c6c1e51

Browse files
committed
chore: refactor project config
1 parent ea8ac9a commit c6c1e51

File tree

7 files changed

+45
-44
lines changed

7 files changed

+45
-44
lines changed

src/frontend/cli.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::integrate::{self, DevnetOrchestrator};
1212
use crate::poke::load_session;
1313
use crate::publish::{publish_all_contracts, Network};
1414
use crate::runnner::run_scripts;
15-
use crate::types::{MainConfig, MainConfigFile, RequirementConfig};
15+
use crate::types::{ProjectManifest, ProjectManifestFile, RequirementConfig};
1616
use clarity_repl::repl;
1717

1818
use clap::Clap;
@@ -470,12 +470,12 @@ fn execute_changes(changes: Vec<Changes>) {
470470
None => {
471471
path = options.manifest_path.clone();
472472
let file = File::open(path.clone()).unwrap();
473-
let mut config_file_reader = BufReader::new(file);
474-
let mut config_file = vec![];
475-
config_file_reader.read_to_end(&mut config_file).unwrap();
476-
let config_file: MainConfigFile =
477-
toml::from_slice(&config_file[..]).unwrap();
478-
MainConfig::from_config_file(config_file)
473+
let mut project_manifest_file_reader = BufReader::new(file);
474+
let mut project_manifest_file = vec![];
475+
project_manifest_file_reader.read_to_end(&mut project_manifest_file).unwrap();
476+
let project_manifest_file: ProjectManifestFile =
477+
toml::from_slice(&project_manifest_file[..]).unwrap();
478+
ProjectManifest::from_project_manifest_file(project_manifest_file)
479479
}
480480
};
481481

src/integrate/orchestrator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::DevnetEvent;
22
use crate::integrate::{ServiceStatusData, Status};
3-
use crate::types::{ChainConfig, DevnetConfigFile, MainConfig};
3+
use crate::types::{ChainConfig, DevnetConfigFile, ProjectManifest};
44
use bollard::container::{
55
Config, CreateContainerOptions, KillContainerOptions, ListContainersOptions,
66
PruneContainersOptions, WaitContainerOptions,
@@ -49,7 +49,7 @@ impl DevnetOrchestrator {
4949
network_config_path.push("Devnet.toml");
5050

5151
let mut network_config = ChainConfig::from_path(&network_config_path);
52-
let project_config = MainConfig::from_path(&manifest_path);
52+
let project_config = ProjectManifest::from_path(&manifest_path);
5353
let name = project_config.project.name.clone();
5454
let network_name = format!("{}.devnet", name);
5555

src/poke/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::publish::Network;
2-
use crate::types::{ChainConfig, MainConfig};
2+
use crate::types::{ChainConfig, ProjectManifest};
33
use clarity_repl::{repl, Terminal};
44
use std::fs;
55
use std::path::PathBuf;
@@ -24,7 +24,7 @@ pub fn load_session(
2424
Network::Mainnet => "Mainnet.toml",
2525
});
2626

27-
let mut project_config = MainConfig::from_path(&manifest_path);
27+
let mut project_config = ProjectManifest::from_path(&manifest_path);
2828
let chain_config = ChainConfig::from_path(&chain_config_path);
2929

3030
let mut deployer_address = None;

src/runnner/deno.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use swc_common::comments::CommentKind;
4747

4848
mod sessions {
4949
use super::TransactionArgs;
50-
use crate::types::{ChainConfig, MainConfig};
50+
use crate::types::{ChainConfig, ProjectManifest};
5151
use clarity_repl::clarity::analysis::ContractAnalysis;
5252
use clarity_repl::repl::settings::Account;
5353
use clarity_repl::repl::{self, Session};
@@ -91,7 +91,7 @@ mod sessions {
9191
chain_config_path.push("settings");
9292
chain_config_path.push("Devnet.toml");
9393

94-
let project_config = MainConfig::from_path(manifest_path);
94+
let project_config = ProjectManifest::from_path(manifest_path);
9595
let chain_config = ChainConfig::from_path(&chain_config_path);
9696

9797
let mut deployer_address = None;

src/types/chain_config.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,26 +173,26 @@ impl ChainConfig {
173173
panic!(error)
174174
}
175175
};
176-
let mut config_file_reader = BufReader::new(path);
177-
let mut config_file_buffer = vec![];
178-
config_file_reader
179-
.read_to_end(&mut config_file_buffer)
176+
let mut chain_config_file_reader = BufReader::new(path);
177+
let mut chain_config_file_buffer = vec![];
178+
chain_config_file_reader
179+
.read_to_end(&mut chain_config_file_buffer)
180180
.unwrap();
181-
let mut config_file: ChainConfigFile = toml::from_slice(&config_file_buffer[..]).unwrap();
182-
ChainConfig::from_config_file(&mut config_file)
181+
let mut chain_config_file: ChainConfigFile = toml::from_slice(&chain_config_file_buffer[..]).unwrap();
182+
ChainConfig::from_chain_config_file(&mut chain_config_file)
183183
}
184184

185-
pub fn from_config_file(config_file: &mut ChainConfigFile) -> ChainConfig {
185+
pub fn from_chain_config_file(chain_config_file: &mut ChainConfigFile) -> ChainConfig {
186186
let network = NetworkConfig {
187-
name: config_file.network.name.clone(),
188-
node_rpc_address: config_file.network.node_rpc_address.clone(),
189-
deployment_fee_rate: config_file.network.deployment_fee_rate.unwrap_or(10),
187+
name: chain_config_file.network.name.clone(),
188+
node_rpc_address: chain_config_file.network.node_rpc_address.clone(),
189+
deployment_fee_rate: chain_config_file.network.deployment_fee_rate.unwrap_or(10),
190190
};
191191

192192
let mut accounts = BTreeMap::new();
193193
let is_mainnet = network.name == "mainnet".to_string();
194194

195-
match &config_file.accounts {
195+
match &chain_config_file.accounts {
196196
Some(Value::Table(entries)) => {
197197
for (account_name, account_settings) in entries.iter() {
198198
match account_settings {
@@ -248,8 +248,8 @@ impl ChainConfig {
248248
_ => {}
249249
};
250250

251-
let devnet = if config_file.network.name == "devnet" {
252-
let mut devnet_config = match config_file.devnet.take() {
251+
let devnet = if chain_config_file.network.name == "devnet" {
252+
let mut devnet_config = match chain_config_file.devnet.take() {
253253
Some(conf) => conf,
254254
_ => DevnetConfigFile::default(),
255255
};

src/types/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
mod chain_config;
2-
mod project_config;
2+
mod project_manifest;
33

44
pub use chain_config::{
55
compute_addresses, AccountConfig, ChainConfig, ChainConfigFile, DevnetConfig, DevnetConfigFile,
66
PoxStackingOrder, DEFAULT_DERIVATION_PATH,
77
};
8-
pub use project_config::{ContractConfig, MainConfig, MainConfigFile, RequirementConfig};
8+
pub use project_manifest::{ContractConfig, ProjectManifest, ProjectManifestFile, RequirementConfig};
9+
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::process;
77
use toml::value::Value;
88

99
#[derive(Serialize, Deserialize, Debug)]
10-
pub struct MainConfigFile {
10+
pub struct ProjectManifestFile {
1111
project: ProjectConfigFile,
1212
contracts: Option<Value>,
1313
}
@@ -20,7 +20,7 @@ pub struct ProjectConfigFile {
2020
}
2121

2222
#[derive(Serialize, Deserialize, Debug)]
23-
pub struct MainConfig {
23+
pub struct ProjectManifest {
2424
pub project: ProjectConfig,
2525
#[serde(serialize_with = "toml::ser::tables_last")]
2626
pub contracts: BTreeMap<String, ContractConfig>,
@@ -50,22 +50,22 @@ pub struct NotebookConfig {
5050
pub path: String,
5151
}
5252

53-
impl MainConfig {
54-
pub fn from_path(path: &PathBuf) -> MainConfig {
53+
impl ProjectManifest {
54+
pub fn from_path(path: &PathBuf) -> ProjectManifest {
5555
let path = match File::open(path) {
5656
Ok(path) => path,
5757
Err(_e) => {
5858
println!("Error: unable to locate Clarinet.toml in current directory");
5959
std::process::exit(1);
6060
}
6161
};
62-
let mut config_file_reader = BufReader::new(path);
63-
let mut config_file_buffer = vec![];
64-
config_file_reader
65-
.read_to_end(&mut config_file_buffer)
62+
let mut project_manifest_file_reader = BufReader::new(path);
63+
let mut project_manifest_file_buffer = vec![];
64+
project_manifest_file_reader
65+
.read_to_end(&mut project_manifest_file_buffer)
6666
.unwrap();
67-
let config_file: MainConfigFile = toml::from_slice(&config_file_buffer[..]).unwrap();
68-
MainConfig::from_config_file(config_file)
67+
let project_manifest_file: ProjectManifestFile = toml::from_slice(&project_manifest_file_buffer[..]).unwrap();
68+
ProjectManifest::from_project_manifest_file(project_manifest_file)
6969
}
7070

7171
pub fn ordered_contracts(&self) -> Vec<(String, ContractConfig)> {
@@ -124,21 +124,21 @@ impl MainConfig {
124124
dst
125125
}
126126

127-
pub fn from_config_file(config_file: MainConfigFile) -> MainConfig {
127+
pub fn from_project_manifest_file(project_manifest_file: ProjectManifestFile) -> ProjectManifest {
128128
let project = ProjectConfig {
129-
name: config_file.project.name.clone(),
129+
name: project_manifest_file.project.name.clone(),
130130
requirements: None,
131-
costs_version: config_file.project.costs_version.unwrap_or(1),
131+
costs_version: project_manifest_file.project.costs_version.unwrap_or(1),
132132
};
133133

134-
let mut config = MainConfig {
134+
let mut config = ProjectManifest {
135135
project,
136136
contracts: BTreeMap::new(),
137137
};
138138
let mut config_contracts = BTreeMap::new();
139139
let mut config_requirements: Vec<RequirementConfig> = Vec::new();
140140

141-
match config_file.project.requirements {
141+
match project_manifest_file.project.requirements {
142142
Some(Value::Array(requirements)) => {
143143
for link_settings in requirements.iter() {
144144
match link_settings {
@@ -156,7 +156,7 @@ impl MainConfig {
156156
_ => {}
157157
};
158158

159-
match config_file.contracts {
159+
match project_manifest_file.contracts {
160160
Some(Value::Table(contracts)) => {
161161
for (contract_name, contract_settings) in contracts.iter() {
162162
match contract_settings {

0 commit comments

Comments
 (0)