diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a1bc189b7d..0aac63b02b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## Changed +- Make `set_code_hash` generic - [#1906](https://github.com/paritytech/ink/pull/1906) + ## Version 5.0.0-alpha The preview release of the ink! 5.0.0 release. diff --git a/crates/env/src/api.rs b/crates/env/src/api.rs index 3050c21df76..c0880cc9e8f 100644 --- a/crates/env/src/api.rs +++ b/crates/env/src/api.rs @@ -752,19 +752,7 @@ where /// Please refer to the /// [Open Zeppelin docs](https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#modifying-your-contracts) /// for more details and examples. -pub fn set_code_hash(code_hash: &[u8; 32]) -> Result<()> { - ::on_instance(|instance| instance.set_code_hash(code_hash)) -} - -/// Replace the contract code at the specified address with new code. -/// -/// # Compatibility -/// -/// This is new version of the existing [`set_code_hash`] function. We plan to place the -/// old function with this in the next `MAJOR` release. -/// -/// See the original [`set_code_hash`] function for full details. -pub fn set_code_hash2(code_hash: &E::Hash) -> Result<()> +pub fn set_code_hash(code_hash: &E::Hash) -> Result<()> where E: Environment, { diff --git a/crates/ink/src/env_access.rs b/crates/ink/src/env_access.rs index 71aac43ffbb..0cc8e871e81 100644 --- a/crates/ink/src/env_access.rs +++ b/crates/ink/src/env_access.rs @@ -1106,7 +1106,7 @@ where /// /// For more details visit: [`ink_env::set_code_hash`] pub fn set_code_hash(self, code_hash: &E::Hash) -> Result<()> { - ink_env::set_code_hash2::(code_hash) + ink_env::set_code_hash::(code_hash) } pub fn call_runtime(self, call: &Call) -> Result<()> { diff --git a/integration-tests/upgradeable-contracts/set-code-hash/lib.rs b/integration-tests/upgradeable-contracts/set-code-hash/lib.rs index 86851852d56..999f74e5cc4 100644 --- a/integration-tests/upgradeable-contracts/set-code-hash/lib.rs +++ b/integration-tests/upgradeable-contracts/set-code-hash/lib.rs @@ -57,8 +57,8 @@ pub mod incrementer { /// /// In a production contract you would do some authorization here! #[ink(message)] - pub fn set_code(&mut self, code_hash: [u8; 32]) { - ink::env::set_code_hash(&code_hash).unwrap_or_else(|err| { + pub fn set_code(&mut self, code_hash: Hash) { + self.env().set_code_hash(&code_hash).unwrap_or_else(|err| { panic!("Failed to `set_code_hash` to {code_hash:?} due to {err:?}") }); ink::env::debug_println!("Switched code hash to {:?}.", code_hash);