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

Make set_code_hash generic #1906

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 1 addition & 13 deletions crates/env/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
<EnvInstance as OnInstance>::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<E>(code_hash: &E::Hash) -> Result<()>
pub fn set_code_hash<E>(code_hash: &E::Hash) -> Result<()>
where
E: Environment,
{
Expand Down
2 changes: 1 addition & 1 deletion crates/ink/src/env_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<E>(code_hash)
ink_env::set_code_hash::<E>(code_hash)
}

pub fn call_runtime<Call: scale::Encode>(self, call: &Call) -> Result<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down