Skip to content

Commit e44ae6e

Browse files
Ludo GalabruLudo Galabru
authored andcommitted
chore: cargo fmt, more feedbacks addressed
1 parent b61b726 commit e44ae6e

File tree

4 files changed

+53
-34
lines changed

4 files changed

+53
-34
lines changed

src/deployment/mod.rs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,13 @@ pub fn write_deployment(
667667
let mut base_dir = target_path.clone();
668668
base_dir.pop();
669669
if !base_dir.exists() {
670-
let _ = std::fs::create_dir(base_dir);
670+
if let Err(e) = std::fs::create_dir(&base_dir) {
671+
return Err(format!(
672+
"unable to create directory {}: {:?}",
673+
base_dir.display(),
674+
e
675+
));
676+
}
671677
}
672678
}
673679

@@ -760,7 +766,7 @@ pub fn generate_default_deployment(
760766
.collect::<Vec<QualifiedContractIdentifier>>();
761767
requirements_asts.append(&mut boot_contracts_asts);
762768

763-
// Build the ASTs / DependencySet for requirements - step required for Tests/Devnet/Testnet/Mainnet
769+
// Build the ASTs / DependencySet for requirements - step required for Simnet/Devnet/Testnet/Mainnet
764770
if let Some(ref requirements) = manifest.project.requirements {
765771
let default_cache_path = match PathBuf::from_str(&manifest.project.cache_dir) {
766772
Ok(path) => path,
@@ -985,7 +991,7 @@ pub fn generate_default_deployment(
985991
let ordered_contracts_ids = match ASTDependencyDetector::order_contracts(&dependencies) {
986992
Ok(ordered_contracts_ids) => ordered_contracts_ids
987993
.into_iter()
988-
.map(|c| c.clone())
994+
.map(|c| c)
989995
.collect::<Vec<_>>(),
990996
Err(e) => return Err(format!("unable to order contracts {}", e)),
991997
};
@@ -1017,33 +1023,35 @@ pub fn generate_default_deployment(
10171023
transactions.push(tx);
10181024
}
10191025

1020-
let _tx_chain_limit = 25;
1026+
let tx_chain_limit = 25;
10211027

10221028
let mut batches = vec![];
1023-
for (id, transactions) in transactions.chunks(25).enumerate() {
1029+
for (id, transactions) in transactions.chunks(tx_chain_limit).enumerate() {
10241030
batches.push(TransactionsBatchSpecification {
10251031
id: id,
10261032
transactions: transactions.to_vec(),
10271033
})
10281034
}
10291035

10301036
let mut wallets = vec![];
1031-
for (name, account) in chain_config.accounts.into_iter() {
1032-
let address = match PrincipalData::parse_standard_principal(&account.address) {
1033-
Ok(res) => res,
1034-
Err(_) => {
1035-
return Err(format!(
1036-
"unable to parse wallet {} in a valid Stacks address",
1037-
account.address
1038-
))
1039-
}
1040-
};
1037+
if let StacksNetwork::Simnet = network {
1038+
for (name, account) in chain_config.accounts.into_iter() {
1039+
let address = match PrincipalData::parse_standard_principal(&account.address) {
1040+
Ok(res) => res,
1041+
Err(_) => {
1042+
return Err(format!(
1043+
"unable to parse wallet {} in a valid Stacks address",
1044+
account.address
1045+
))
1046+
}
1047+
};
10411048

1042-
wallets.push(WalletSpecification {
1043-
name,
1044-
address,
1045-
balance: account.balance.into(),
1046-
});
1049+
wallets.push(WalletSpecification {
1050+
name,
1051+
address,
1052+
balance: account.balance.into(),
1053+
});
1054+
}
10471055
}
10481056

10491057
let name = match network {

src/deployment/requirements.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn retrieve_contract(
3636
);
3737

3838
let rt = tokio::runtime::Runtime::new().unwrap();
39-
let response = rt.block_on(async { fetch_contract(request_url).await });
39+
let response = rt.block_on(async { fetch_contract(request_url).await })?;
4040
let code = response.source.to_string();
4141

4242
if use_cache {
@@ -60,12 +60,13 @@ struct Contract {
6060
publish_height: u32,
6161
}
6262

63-
async fn fetch_contract(request_url: String) -> Contract {
64-
let response: Contract = reqwest::get(&request_url)
63+
async fn fetch_contract(request_url: String) -> Result<Contract, String> {
64+
let response = reqwest::get(&request_url)
6565
.await
66-
.expect("Unable to retrieve contract")
66+
.map_err(|_| format!("Unable to retrieve contract {}", request_url))?;
67+
68+
response
6769
.json()
6870
.await
69-
.expect("Unable to parse contract");
70-
return response;
71+
.map_err(|_| format!("Unable to parse contract {}", request_url))?
7172
}

src/frontend/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::deployment::{
22
self, apply_on_chain_deployment, check_deployments, generate_default_deployment,
33
get_absolute_deployment_path, get_default_deployment_path, load_deployment,
4-
load_deployment_if_exists, read_deployment_or_generate_default,
5-
setup_session_with_deployment, write_deployment, DeploymentCommand, DeploymentEvent,
4+
load_deployment_if_exists, read_deployment_or_generate_default, setup_session_with_deployment,
5+
write_deployment, DeploymentCommand, DeploymentEvent,
66
};
77
use crate::generate::{
88
self,

src/integrate/chains_coordinator.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use super::DevnetEvent;
22
use crate::deployment::types::DeploymentSpecification;
33
use crate::deployment::{
4-
apply_on_chain_deployment, read_deployment_or_generate_default,
5-
setup_session_with_deployment, DeploymentCommand, DeploymentEvent,
4+
apply_on_chain_deployment, read_deployment_or_generate_default, setup_session_with_deployment,
5+
DeploymentCommand, DeploymentEvent,
66
};
77
use crate::indexer::{chains, Indexer, IndexerConfig};
88
use crate::integrate::{MempoolAdmissionData, ServiceStatusData, Status};
@@ -115,7 +115,12 @@ pub async fn start_chains_coordinator(
115115
let (deployment_events_tx, deployment_events_rx) = channel();
116116
let (deployment_commands_tx, deployments_command_rx) = channel();
117117

118-
prepare_protocol_deployment(&config.manifest, &config.deployment, deployment_events_tx, deployments_command_rx);
118+
prepare_protocol_deployment(
119+
&config.manifest,
120+
&config.deployment,
121+
deployment_events_tx,
122+
deployments_command_rx,
123+
);
119124

120125
let init_status = DevnetInitializationStatus {
121126
should_deploy_protocol: true,
@@ -195,7 +200,7 @@ pub async fn start_chains_coordinator(
195200
&deployment_commands_tx,
196201
&devnet_event_tx,
197202
&chains_coordinator_commands_tx,
198-
)
203+
)
199204
}
200205
}
201206
}
@@ -592,7 +597,13 @@ pub fn prepare_protocol_deployment(
592597
let deployment = deployment.clone();
593598

594599
std::thread::spawn(move || {
595-
apply_on_chain_deployment(&manifest, deployment, deployment_event_tx, deployment_command_rx, false);
600+
apply_on_chain_deployment(
601+
&manifest,
602+
deployment,
603+
deployment_event_tx,
604+
deployment_command_rx,
605+
false,
606+
);
596607
});
597608
}
598609

@@ -630,7 +641,6 @@ pub fn perform_protocol_deployment(
630641
});
631642
}
632643

633-
634644
pub async fn publish_stacking_orders(
635645
devnet_config: &DevnetConfig,
636646
accounts: &Vec<AccountConfig>,

0 commit comments

Comments
 (0)