diff --git a/cw-orch/src/daemon/traits.rs b/cw-orch/src/daemon/traits.rs index a97dc2698..08c193b44 100644 --- a/cw-orch/src/daemon/traits.rs +++ b/cw-orch/src/daemon/traits.rs @@ -61,6 +61,27 @@ pub trait ConditionalMigrate: CwOrchMigrate + ConditionalUpload { Some(self.migrate(migrate_msg, self.code_id()?)).transpose() } } + /// Uploads the contract if the local contract hash is different from the latest on-chain code hash. + /// Proceeds to migrates the contract if the contract is not running the latest code. + fn upload_and_migrate_if_needed(&self, + migrate_msg: &Self::MigrateMsg, + ) -> Result>>, CwOrchError> { + let mut txs = Vec::with_capacity(2); + + if let Some(tx) = self.upload_if_needed()? { + txs.push(tx); + }; + + if let Some(tx) = self.migrate_if_needed(migrate_msg)? { + txs.push(tx); + }; + + if txs.is_empty() { + Ok(None) + } else { + Ok(Some(txs)) + } + } } impl ConditionalMigrate for T where T: CwOrchMigrate + CwOrchUpload {}