Skip to content

Commit

Permalink
Add upload_and_migrate_if_needed function to ConditionalMigrate
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberHoward committed Jun 21, 2023
1 parent 75ccce8 commit cb700f3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cw-orch/src/daemon/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ pub trait ConditionalMigrate: CwOrchMigrate<Daemon> + 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<Option<Vec<TxResponse<Daemon>>>, 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<T> ConditionalMigrate for T where T: CwOrchMigrate<Daemon> + CwOrchUpload<Daemon> {}

0 comments on commit cb700f3

Please sign in to comment.