Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added all deployed chains getter #149

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions cw-orch/src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,44 @@ pub trait Deploy<Chain: CwEnv>: Sized {
}
}

/// Gets all the chain ids on which the library is deployed on
/// This loads all chains that are registered in the crate-local daemon_state file
/// The state file should have the following format :
/// {
/// "juno":{
/// "juno-1":{
/// ...
/// },
/// "uni-6": {

/// }
/// }
/// ...
/// }
/// So this function actually looks for the second level of indices in the deployed_state_file
fn get_all_deployed_chains(&self) -> Vec<String> {
let deployed_state_file = self.deployed_state_file_path();
if let Some(state_file) = deployed_state_file {
if let Ok(module_state_json) = read_json(&state_file) {
let all_chain_ids: Vec<String> = module_state_json
.as_object()
.unwrap()
.into_iter()
.flat_map(|(_, v)| {
v.as_object()
.unwrap()
.into_iter()
.map(|(chain_id, _)| chain_id.clone())
.collect::<Vec<_>>()
})
.collect();

return all_chain_ids;
}
}
vec![]
}

/// Sets the custom state file path for exporting the state with the package.
// TODO, we might want to enforce the projects to redefine this function ?
fn deployed_state_file_path(&self) -> Option<String> {
Expand Down