Skip to content

Commit

Permalink
fix: set_contracts_state
Browse files Browse the repository at this point in the history
  • Loading branch information
Buckram123 committed Oct 14, 2024
1 parent ebfa5b9 commit e0b6d6e
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions cw-orch-daemon/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,20 +357,13 @@ pub trait DeployedChains<Chain: CwEnv>: cw_orch_core::contract::Deploy<Chain> {
/// Set the default contract state for a contract, so that users can retrieve it in their application when importing the library
/// If a state is provided, it is used for all contracts, otherwise, the state is loaded from the crate's state file.
fn set_contracts_state(&mut self, custom_state: Option<Value>) {
let state;

let state_file = Self::deployed_state_file_path();
if let Some(custom_state) = custom_state {
state = custom_state;
} else if let Some(state_file) = state_file {
if let Ok(module_state_json) = crate::json_lock::read(&state_file) {
state = patch_state_if_old(module_state_json);
} else {
return;
}
} else {
let Some(maybe_old_state) = custom_state.or_else(|| {
Self::deployed_state_file_path()
.and_then(|state_file| crate::json_lock::read(&state_file).ok())
}) else {
return;
}
};
let state = patch_state_if_old(maybe_old_state);

let all_contracts = self.get_contracts_mut();

Expand All @@ -381,8 +374,6 @@ pub trait DeployedChains<Chain: CwEnv>: cw_orch_core::contract::Deploy<Chain> {
// We try to get the code_id for the contract
if contract.code_id().is_err() {
let code_id = state
.get(env_info.chain_name.clone())
.unwrap_or(&Value::Null)
.get(env_info.chain_id.to_string())
.unwrap_or(&Value::Null)
.get("code_ids")
Expand All @@ -399,8 +390,6 @@ pub trait DeployedChains<Chain: CwEnv>: cw_orch_core::contract::Deploy<Chain> {
if contract.address().is_err() {
// Try and get the code id from file
let address = state
.get(env_info.chain_name.clone())
.unwrap_or(&Value::Null)
.get(env_info.chain_id.to_string())
.unwrap_or(&Value::Null)
.get(env_info.deployment_id)
Expand Down

0 comments on commit e0b6d6e

Please sign in to comment.