From 3f592feb14df9676071b0ea3b447e864fff21294 Mon Sep 17 00:00:00 2001 From: lean-apple Date: Thu, 3 Nov 2022 15:15:10 +0100 Subject: [PATCH 1/8] remove insert and replace with insert_size --- .../ui/contract/pass/example-erc20-works.rs | 10 +++++----- .../ui/contract/pass/example-erc721-works.rs | 12 ++++++------ crates/storage/src/lazy/mapping.rs | 18 ++++-------------- examples/dns/lib.rs | 6 +++--- examples/erc1155/lib.rs | 16 ++++++++-------- examples/erc20/lib.rs | 10 +++++----- examples/erc721/lib.rs | 12 ++++++------ examples/multisig/lib.rs | 16 ++++++++-------- examples/trait-erc20/lib.rs | 10 +++++----- 9 files changed, 50 insertions(+), 60 deletions(-) diff --git a/crates/ink/tests/ui/contract/pass/example-erc20-works.rs b/crates/ink/tests/ui/contract/pass/example-erc20-works.rs index 6ef1b98e10..e9f04b5f59 100644 --- a/crates/ink/tests/ui/contract/pass/example-erc20-works.rs +++ b/crates/ink/tests/ui/contract/pass/example-erc20-works.rs @@ -55,7 +55,7 @@ mod erc20 { pub fn new(total_supply: Balance) -> Self { let mut balances = Mapping::default(); let caller = Self::env().caller(); - balances.insert(&caller, &total_supply); + balances.insert_return_size(&caller, &total_supply); Self::env().emit_event(Transfer { from: None, to: Some(caller), @@ -139,7 +139,7 @@ mod erc20 { #[ink(message)] pub fn approve(&mut self, spender: AccountId, value: Balance) -> Result<()> { let owner = self.env().caller(); - self.allowances.insert((&owner, &spender), &value); + self.allowances.insert_return_size((&owner, &spender), &value); self.env().emit_event(Approval { owner, spender, @@ -176,7 +176,7 @@ mod erc20 { } self.transfer_from_to(&from, &to, value)?; self.allowances - .insert((&from, &caller), &(allowance - value)); + .insert_return_size((&from, &caller), &(allowance - value)); Ok(()) } @@ -199,9 +199,9 @@ mod erc20 { return Err(Error::InsufficientBalance) } - self.balances.insert(from, &(from_balance - value)); + self.balances.insert_return_size(from, &(from_balance - value)); let to_balance = self.balance_of_impl(to); - self.balances.insert(to, &(to_balance + value)); + self.balances.insert_return_size(to, &(to_balance + value)); self.env().emit_event(Transfer { from: Some(*from), to: Some(*to), diff --git a/crates/ink/tests/ui/contract/pass/example-erc721-works.rs b/crates/ink/tests/ui/contract/pass/example-erc721-works.rs index e5b250bf0d..f63b7842cf 100644 --- a/crates/ink/tests/ui/contract/pass/example-erc721-works.rs +++ b/crates/ink/tests/ui/contract/pass/example-erc721-works.rs @@ -175,7 +175,7 @@ mod erc721 { .get(&caller) .map(|c| c - 1) .ok_or(Error::CannotFetchValue)?; - owned_tokens_count.insert(&caller, &count); + owned_tokens_count.insert_return_size(&caller, &count); token_owner.remove(&id); self.env().emit_event(Transfer { @@ -232,7 +232,7 @@ mod erc721 { .get(&from) .map(|c| c - 1) .ok_or(Error::CannotFetchValue)?; - owned_tokens_count.insert(&from, &count); + owned_tokens_count.insert_return_size(&from, &count); token_owner.remove(&id); Ok(()) @@ -256,8 +256,8 @@ mod erc721 { let count = owned_tokens_count.get(to).map(|c| c + 1).unwrap_or(1); - owned_tokens_count.insert(to, &count); - token_owner.insert(&id, to); + owned_tokens_count.insert_return_size(to, &count); + token_owner.insert_return_size(&id, to); Ok(()) } @@ -279,7 +279,7 @@ mod erc721 { }); if approved { - self.operator_approvals.insert((&caller, &to), &()); + self.operator_approvals.insert_return_size((&caller, &to), &()); } else { self.operator_approvals.remove((&caller, &to)); } @@ -304,7 +304,7 @@ mod erc721 { if self.token_approvals.get(&id).is_some() { return Err(Error::CannotInsert) } else { - self.token_approvals.insert(&id, to); + self.token_approvals.insert_return_size(&id, to); } self.env().emit_event(Approval { diff --git a/crates/storage/src/lazy/mapping.rs b/crates/storage/src/lazy/mapping.rs index dadbe51c9c..a146761d2f 100644 --- a/crates/storage/src/lazy/mapping.rs +++ b/crates/storage/src/lazy/mapping.rs @@ -69,7 +69,7 @@ use scale::{ /// let mut instance = Self::default(); /// let caller = Self::env().caller(); /// let value: Balance = Default::default(); -/// instance.balances.insert(&caller, &value); +/// instance.balances.insert_return_size(&caller, &value); /// instance /// } /// @@ -130,16 +130,6 @@ where V: Packed, KeyType: StorageKey, { - /// Insert the given `value` to the contract storage. - #[inline] - pub fn insert(&mut self, key: Q, value: &R) - where - Q: scale::EncodeLike, - R: Storable + scale::EncodeLike, - { - ink_env::set_contract_storage(&(&KeyType::KEY, key), value); - } - /// Insert the given `value` to the contract storage. /// /// Returns the size of the pre-existing value at the specified key if any. @@ -261,7 +251,7 @@ mod tests { fn insert_and_get_work() { ink_env::test::run_test::(|_| { let mut mapping: Mapping = Mapping::new(); - mapping.insert(&1, &2); + mapping.insert_return_size(&1, &2); assert_eq!(mapping.get(&1), Some(2)); Ok(()) @@ -273,7 +263,7 @@ mod tests { fn insert_and_get_work_for_two_mapping_with_same_manual_key() { ink_env::test::run_test::(|_| { let mut mapping: Mapping> = Mapping::new(); - mapping.insert(&1, &2); + mapping.insert_return_size(&1, &2); let mapping2: Mapping> = Mapping::new(); assert_eq!(mapping2.get(&1), Some(2)); @@ -300,7 +290,7 @@ mod tests { // Given let mut mapping: Mapping = Mapping::new(); - mapping.insert(&1, &2); + mapping.insert_return_size(&1, &2); assert_eq!(mapping.get(&1), Some(2)); // When diff --git a/examples/dns/lib.rs b/examples/dns/lib.rs index 6374386304..0eedf89690 100644 --- a/examples/dns/lib.rs +++ b/examples/dns/lib.rs @@ -91,7 +91,7 @@ mod dns { return Err(Error::NameAlreadyExists) } - self.name_to_owner.insert(&name, &caller); + self.name_to_owner.insert_return_size(&name, &caller); self.env().emit_event(Register { name, from: caller }); Ok(()) @@ -107,7 +107,7 @@ mod dns { } let old_address = self.name_to_address.get(&name); - self.name_to_address.insert(&name, &new_address); + self.name_to_address.insert_return_size(&name, &new_address); self.env().emit_event(SetAddress { name, @@ -128,7 +128,7 @@ mod dns { } let old_owner = self.name_to_owner.get(&name); - self.name_to_owner.insert(&name, &to); + self.name_to_owner.insert_return_size(&name, &to); self.env().emit_event(Transfer { name, diff --git a/examples/erc1155/lib.rs b/examples/erc1155/lib.rs index 50379d964b..5064e1eac2 100644 --- a/examples/erc1155/lib.rs +++ b/examples/erc1155/lib.rs @@ -260,7 +260,7 @@ mod erc1155 { // Given that TokenId is a `u128` the likelihood of this overflowing is pretty slim. self.token_id_nonce += 1; - self.balances.insert(&(caller, self.token_id_nonce), &value); + self.balances.insert_return_size(&(caller, self.token_id_nonce), &value); // Emit transfer event but with mint semantics self.env().emit_event(TransferSingle { @@ -287,7 +287,7 @@ mod erc1155 { ensure!(token_id <= self.token_id_nonce, Error::UnexistentToken); let caller = self.env().caller(); - self.balances.insert(&(caller, token_id), &value); + self.balances.insert_return_size(&(caller, token_id), &value); // Emit transfer event but with mint semantics self.env().emit_event(TransferSingle { @@ -321,11 +321,11 @@ mod erc1155 { .get(&(from, token_id)) .expect("Caller should have ensured that `from` holds `token_id`."); sender_balance -= value; - self.balances.insert(&(from, token_id), &sender_balance); + self.balances.insert_return_size(&(from, token_id), &sender_balance); let mut recipient_balance = self.balances.get(&(to, token_id)).unwrap_or(0); recipient_balance += value; - self.balances.insert(&(to, token_id), &recipient_balance); + self.balances.insert_return_size(&(to, token_id), &recipient_balance); let caller = self.env().caller(); self.env().emit_event(TransferSingle { @@ -517,7 +517,7 @@ mod erc1155 { ensure!(operator != caller, Error::SelfApproval); if approved { - self.approvals.insert((&caller, &operator), &()); + self.approvals.insert_return_size((&caller, &operator), &()); } else { self.approvals.remove((&caller, &operator)); } @@ -607,9 +607,9 @@ mod erc1155 { fn init_contract() -> Contract { let mut erc = Contract::new(); - erc.balances.insert((alice(), 1), &10); - erc.balances.insert((alice(), 2), &20); - erc.balances.insert((bob(), 1), &10); + erc.balances.insert_return_size((alice(), 1), &10); + erc.balances.insert_return_size((alice(), 2), &20); + erc.balances.insert_return_size((bob(), 1), &10); erc } diff --git a/examples/erc20/lib.rs b/examples/erc20/lib.rs index a624e48d5f..6480e3e64a 100644 --- a/examples/erc20/lib.rs +++ b/examples/erc20/lib.rs @@ -57,7 +57,7 @@ mod erc20 { pub fn new(total_supply: Balance) -> Self { let mut balances = Mapping::default(); let caller = Self::env().caller(); - balances.insert(&caller, &total_supply); + balances.insert_return_size(&caller, &total_supply); Self::env().emit_event(Transfer { from: None, to: Some(caller), @@ -141,7 +141,7 @@ mod erc20 { #[ink(message)] pub fn approve(&mut self, spender: AccountId, value: Balance) -> Result<()> { let owner = self.env().caller(); - self.allowances.insert((&owner, &spender), &value); + self.allowances.insert_return_size((&owner, &spender), &value); self.env().emit_event(Approval { owner, spender, @@ -178,7 +178,7 @@ mod erc20 { } self.transfer_from_to(&from, &to, value)?; self.allowances - .insert((&from, &caller), &(allowance - value)); + .insert_return_size((&from, &caller), &(allowance - value)); Ok(()) } @@ -201,9 +201,9 @@ mod erc20 { return Err(Error::InsufficientBalance) } - self.balances.insert(from, &(from_balance - value)); + self.balances.insert_return_size(from, &(from_balance - value)); let to_balance = self.balance_of_impl(to); - self.balances.insert(to, &(to_balance + value)); + self.balances.insert_return_size(to, &(to_balance + value)); self.env().emit_event(Transfer { from: Some(*from), to: Some(*to), diff --git a/examples/erc721/lib.rs b/examples/erc721/lib.rs index e85be4fa58..a67d977423 100644 --- a/examples/erc721/lib.rs +++ b/examples/erc721/lib.rs @@ -227,7 +227,7 @@ mod erc721 { .get(&caller) .map(|c| c - 1) .ok_or(Error::CannotFetchValue)?; - owned_tokens_count.insert(&caller, &count); + owned_tokens_count.insert_return_size(&caller, &count); token_owner.remove(&id); self.env().emit_event(Transfer { @@ -284,7 +284,7 @@ mod erc721 { .get(&from) .map(|c| c - 1) .ok_or(Error::CannotFetchValue)?; - owned_tokens_count.insert(&from, &count); + owned_tokens_count.insert_return_size(&from, &count); token_owner.remove(&id); Ok(()) @@ -308,8 +308,8 @@ mod erc721 { let count = owned_tokens_count.get(to).map(|c| c + 1).unwrap_or(1); - owned_tokens_count.insert(to, &count); - token_owner.insert(&id, to); + owned_tokens_count.insert_return_size(to, &count); + token_owner.insert_return_size(&id, to); Ok(()) } @@ -331,7 +331,7 @@ mod erc721 { }); if approved { - self.operator_approvals.insert((&caller, &to), &()); + self.operator_approvals.insert_return_size((&caller, &to), &()); } else { self.operator_approvals.remove((&caller, &to)); } @@ -356,7 +356,7 @@ mod erc721 { if self.token_approvals.contains(&id) { return Err(Error::CannotInsert) } else { - self.token_approvals.insert(&id, to); + self.token_approvals.insert_return_size(&id, to); } self.env().emit_event(Approval { diff --git a/examples/multisig/lib.rs b/examples/multisig/lib.rs index 4b9ac0bb8e..e4dc0e0ba9 100755 --- a/examples/multisig/lib.rs +++ b/examples/multisig/lib.rs @@ -285,7 +285,7 @@ mod multisig { ensure_requirement_is_valid(owners.len() as u32, requirement); for owner in &owners { - contract.is_owner.insert(owner, &()); + contract.is_owner.insert_return_size(owner, &()); } contract.owners = owners; @@ -370,7 +370,7 @@ mod multisig { self.ensure_from_wallet(); self.ensure_no_owner(&new_owner); ensure_requirement_is_valid(self.owners.len() as u32 + 1, self.requirement); - self.is_owner.insert(new_owner, &()); + self.is_owner.insert_return_size(new_owner, &()); self.owners.push(new_owner); self.env().emit_event(OwnerAddition { owner: new_owner }); } @@ -414,7 +414,7 @@ mod multisig { let owner_index = self.owner_index(&old_owner); self.owners[owner_index as usize] = new_owner; self.is_owner.remove(&old_owner); - self.is_owner.insert(new_owner, &()); + self.is_owner.insert_return_size(new_owner, &()); self.clean_owner_confirmations(&old_owner); self.env().emit_event(OwnerRemoval { owner: old_owner }); self.env().emit_event(OwnerAddition { owner: new_owner }); @@ -447,7 +447,7 @@ mod multisig { let trans_id = self.transaction_list.next_id; self.transaction_list.next_id = trans_id.checked_add(1).expect("Transaction ids exhausted."); - self.transactions.insert(trans_id, &transaction); + self.transactions.insert_return_size(trans_id, &transaction); self.transaction_list.transactions.push(trans_id); self.env().emit_event(Submission { transaction: trans_id, @@ -513,7 +513,7 @@ mod multisig { // Will not underflow as there is at least one confirmation confirmation_count -= 1; self.confirmation_count - .insert(&trans_id, &confirmation_count); + .insert_return_size(&trans_id, &confirmation_count); self.env().emit_event(Revocation { transaction: trans_id, from: caller, @@ -604,8 +604,8 @@ mod multisig { let new_confirmation = !self.confirmations.contains(&key); if new_confirmation { count += 1; - self.confirmations.insert(&key, &()); - self.confirmation_count.insert(&transaction, &count); + self.confirmations.insert_return_size(&key, &()); + self.confirmation_count.insert_return_size(&transaction, &count); } let status = { if count >= self.requirement { @@ -663,7 +663,7 @@ mod multisig { self.confirmations.remove(&key); let mut count = self.confirmation_count.get(&trans_id).unwrap_or(0); count -= 1; - self.confirmation_count.insert(&trans_id, &count); + self.confirmation_count.insert_return_size(&trans_id, &count); } } } diff --git a/examples/trait-erc20/lib.rs b/examples/trait-erc20/lib.rs index e48679cb74..eb10e40470 100644 --- a/examples/trait-erc20/lib.rs +++ b/examples/trait-erc20/lib.rs @@ -93,7 +93,7 @@ mod erc20 { pub fn new(total_supply: Balance) -> Self { let mut balances = Mapping::default(); let caller = Self::env().caller(); - balances.insert(&caller, &total_supply); + balances.insert_return_size(&caller, &total_supply); Self::env().emit_event(Transfer { from: None, to: Some(caller), @@ -153,7 +153,7 @@ mod erc20 { #[ink(message)] fn approve(&mut self, spender: AccountId, value: Balance) -> Result<()> { let owner = self.env().caller(); - self.allowances.insert((&owner, &spender), &value); + self.allowances.insert_return_size((&owner, &spender), &value); self.env().emit_event(Approval { owner, spender, @@ -190,7 +190,7 @@ mod erc20 { } self.transfer_from_to(&from, &to, value)?; self.allowances - .insert((&from, &caller), &(allowance - value)); + .insert_return_size((&from, &caller), &(allowance - value)); Ok(()) } } @@ -242,9 +242,9 @@ mod erc20 { return Err(Error::InsufficientBalance) } - self.balances.insert(from, &(from_balance - value)); + self.balances.insert_return_size(from, &(from_balance - value)); let to_balance = self.balance_of_impl(to); - self.balances.insert(to, &(to_balance + value)); + self.balances.insert_return_size(to, &(to_balance + value)); self.env().emit_event(Transfer { from: Some(*from), to: Some(*to), From 9180e79ef777b8542b2880f7f6dee72676390b01 Mon Sep 17 00:00:00 2001 From: lean-apple Date: Thu, 3 Nov 2022 16:25:35 +0100 Subject: [PATCH 2/8] attempt to fix linting --- .../tests/ui/contract/pass/example-erc20-works.rs | 3 +-- examples/erc1155/lib.rs | 12 ++++++++---- examples/erc20/lib.rs | 6 ++++-- examples/erc721/lib.rs | 3 ++- examples/multisig/lib.rs | 6 ++++-- examples/trait-erc20/lib.rs | 6 ++++-- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/crates/ink/tests/ui/contract/pass/example-erc20-works.rs b/crates/ink/tests/ui/contract/pass/example-erc20-works.rs index e9f04b5f59..1ffc0025c1 100644 --- a/crates/ink/tests/ui/contract/pass/example-erc20-works.rs +++ b/crates/ink/tests/ui/contract/pass/example-erc20-works.rs @@ -175,8 +175,7 @@ mod erc20 { return Err(Error::InsufficientAllowance) } self.transfer_from_to(&from, &to, value)?; - self.allowances - .insert_return_size((&from, &caller), &(allowance - value)); + self.allowances.insert_return_size((&from, &caller), &(allowance - value)); Ok(()) } diff --git a/examples/erc1155/lib.rs b/examples/erc1155/lib.rs index 5064e1eac2..85d1e13b46 100644 --- a/examples/erc1155/lib.rs +++ b/examples/erc1155/lib.rs @@ -260,7 +260,8 @@ mod erc1155 { // Given that TokenId is a `u128` the likelihood of this overflowing is pretty slim. self.token_id_nonce += 1; - self.balances.insert_return_size(&(caller, self.token_id_nonce), &value); + self.balances + .insert_return_size(&(caller, self.token_id_nonce), &value); // Emit transfer event but with mint semantics self.env().emit_event(TransferSingle { @@ -287,7 +288,8 @@ mod erc1155 { ensure!(token_id <= self.token_id_nonce, Error::UnexistentToken); let caller = self.env().caller(); - self.balances.insert_return_size(&(caller, token_id), &value); + self.balances + .insert_return_size(&(caller, token_id), &value); // Emit transfer event but with mint semantics self.env().emit_event(TransferSingle { @@ -321,11 +323,13 @@ mod erc1155 { .get(&(from, token_id)) .expect("Caller should have ensured that `from` holds `token_id`."); sender_balance -= value; - self.balances.insert_return_size(&(from, token_id), &sender_balance); + self.balances + .insert_return_size(&(from, token_id), &sender_balance); let mut recipient_balance = self.balances.get(&(to, token_id)).unwrap_or(0); recipient_balance += value; - self.balances.insert_return_size(&(to, token_id), &recipient_balance); + self.balances + .insert_return_size(&(to, token_id), &recipient_balance); let caller = self.env().caller(); self.env().emit_event(TransferSingle { diff --git a/examples/erc20/lib.rs b/examples/erc20/lib.rs index 6480e3e64a..ac72c62c0a 100644 --- a/examples/erc20/lib.rs +++ b/examples/erc20/lib.rs @@ -141,7 +141,8 @@ mod erc20 { #[ink(message)] pub fn approve(&mut self, spender: AccountId, value: Balance) -> Result<()> { let owner = self.env().caller(); - self.allowances.insert_return_size((&owner, &spender), &value); + self.allowances + .insert_return_size((&owner, &spender), &value); self.env().emit_event(Approval { owner, spender, @@ -201,7 +202,8 @@ mod erc20 { return Err(Error::InsufficientBalance) } - self.balances.insert_return_size(from, &(from_balance - value)); + self.balances + .insert_return_size(from, &(from_balance - value)); let to_balance = self.balance_of_impl(to); self.balances.insert_return_size(to, &(to_balance + value)); self.env().emit_event(Transfer { diff --git a/examples/erc721/lib.rs b/examples/erc721/lib.rs index a67d977423..dd609d58fe 100644 --- a/examples/erc721/lib.rs +++ b/examples/erc721/lib.rs @@ -331,7 +331,8 @@ mod erc721 { }); if approved { - self.operator_approvals.insert_return_size((&caller, &to), &()); + self.operator_approvals + .insert_return_size((&caller, &to), &()); } else { self.operator_approvals.remove((&caller, &to)); } diff --git a/examples/multisig/lib.rs b/examples/multisig/lib.rs index e4dc0e0ba9..20e734f22a 100755 --- a/examples/multisig/lib.rs +++ b/examples/multisig/lib.rs @@ -605,7 +605,8 @@ mod multisig { if new_confirmation { count += 1; self.confirmations.insert_return_size(&key, &()); - self.confirmation_count.insert_return_size(&transaction, &count); + self.confirmation_count + .insert_return_size(&transaction, &count); } let status = { if count >= self.requirement { @@ -663,7 +664,8 @@ mod multisig { self.confirmations.remove(&key); let mut count = self.confirmation_count.get(&trans_id).unwrap_or(0); count -= 1; - self.confirmation_count.insert_return_size(&trans_id, &count); + self.confirmation_count + .insert_return_size(&trans_id, &count); } } } diff --git a/examples/trait-erc20/lib.rs b/examples/trait-erc20/lib.rs index eb10e40470..161b666e3c 100644 --- a/examples/trait-erc20/lib.rs +++ b/examples/trait-erc20/lib.rs @@ -153,7 +153,8 @@ mod erc20 { #[ink(message)] fn approve(&mut self, spender: AccountId, value: Balance) -> Result<()> { let owner = self.env().caller(); - self.allowances.insert_return_size((&owner, &spender), &value); + self.allowances + .insert_return_size((&owner, &spender), &value); self.env().emit_event(Approval { owner, spender, @@ -242,7 +243,8 @@ mod erc20 { return Err(Error::InsufficientBalance) } - self.balances.insert_return_size(from, &(from_balance - value)); + self.balances + .insert_return_size(from, &(from_balance - value)); let to_balance = self.balance_of_impl(to); self.balances.insert_return_size(to, &(to_balance + value)); self.env().emit_event(Transfer { From 57451f59ac3cd78988c84b91216738531ce33a5a Mon Sep 17 00:00:00 2001 From: lean-apple Date: Thu, 3 Nov 2022 16:34:38 +0100 Subject: [PATCH 3/8] fix fmt for contract tests --- crates/ink/tests/ui/contract/pass/example-erc20-works.rs | 9 ++++++--- .../ink/tests/ui/contract/pass/example-erc721-works.rs | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/ink/tests/ui/contract/pass/example-erc20-works.rs b/crates/ink/tests/ui/contract/pass/example-erc20-works.rs index 1ffc0025c1..7a0c23b3f1 100644 --- a/crates/ink/tests/ui/contract/pass/example-erc20-works.rs +++ b/crates/ink/tests/ui/contract/pass/example-erc20-works.rs @@ -139,7 +139,8 @@ mod erc20 { #[ink(message)] pub fn approve(&mut self, spender: AccountId, value: Balance) -> Result<()> { let owner = self.env().caller(); - self.allowances.insert_return_size((&owner, &spender), &value); + self.allowances + .insert_return_size((&owner, &spender), &value); self.env().emit_event(Approval { owner, spender, @@ -175,7 +176,8 @@ mod erc20 { return Err(Error::InsufficientAllowance) } self.transfer_from_to(&from, &to, value)?; - self.allowances.insert_return_size((&from, &caller), &(allowance - value)); + self.allowances + .insert_return_size((&from, &caller), &(allowance - value)); Ok(()) } @@ -198,7 +200,8 @@ mod erc20 { return Err(Error::InsufficientBalance) } - self.balances.insert_return_size(from, &(from_balance - value)); + self.balances + .insert_return_size(from, &(from_balance - value)); let to_balance = self.balance_of_impl(to); self.balances.insert_return_size(to, &(to_balance + value)); self.env().emit_event(Transfer { diff --git a/crates/ink/tests/ui/contract/pass/example-erc721-works.rs b/crates/ink/tests/ui/contract/pass/example-erc721-works.rs index f63b7842cf..a89181e0b1 100644 --- a/crates/ink/tests/ui/contract/pass/example-erc721-works.rs +++ b/crates/ink/tests/ui/contract/pass/example-erc721-works.rs @@ -279,7 +279,8 @@ mod erc721 { }); if approved { - self.operator_approvals.insert_return_size((&caller, &to), &()); + self.operator_approvals + .insert_return_size((&caller, &to), &()); } else { self.operator_approvals.remove((&caller, &to)); } From f59ddddca137dbda6f764e4ea6c6e9b00968ab7c Mon Sep 17 00:00:00 2001 From: lean-apple Date: Fri, 4 Nov 2022 14:39:18 +0100 Subject: [PATCH 4/8] rename insert_return_size with shorter name --- .../ui/contract/pass/example-erc20-works.rs | 12 +++++------- .../ui/contract/pass/example-erc721-works.rs | 13 ++++++------- crates/storage/src/lazy/mapping.rs | 10 +++++----- examples/dns/lib.rs | 6 +++--- examples/erc1155/lib.rs | 16 ++++++++-------- examples/erc20/lib.rs | 10 +++++----- examples/erc721/lib.rs | 12 ++++++------ examples/multisig/lib.rs | 16 ++++++++-------- examples/trait-erc20/lib.rs | 10 +++++----- 9 files changed, 51 insertions(+), 54 deletions(-) diff --git a/crates/ink/tests/ui/contract/pass/example-erc20-works.rs b/crates/ink/tests/ui/contract/pass/example-erc20-works.rs index 7a0c23b3f1..6ef1b98e10 100644 --- a/crates/ink/tests/ui/contract/pass/example-erc20-works.rs +++ b/crates/ink/tests/ui/contract/pass/example-erc20-works.rs @@ -55,7 +55,7 @@ mod erc20 { pub fn new(total_supply: Balance) -> Self { let mut balances = Mapping::default(); let caller = Self::env().caller(); - balances.insert_return_size(&caller, &total_supply); + balances.insert(&caller, &total_supply); Self::env().emit_event(Transfer { from: None, to: Some(caller), @@ -139,8 +139,7 @@ mod erc20 { #[ink(message)] pub fn approve(&mut self, spender: AccountId, value: Balance) -> Result<()> { let owner = self.env().caller(); - self.allowances - .insert_return_size((&owner, &spender), &value); + self.allowances.insert((&owner, &spender), &value); self.env().emit_event(Approval { owner, spender, @@ -177,7 +176,7 @@ mod erc20 { } self.transfer_from_to(&from, &to, value)?; self.allowances - .insert_return_size((&from, &caller), &(allowance - value)); + .insert((&from, &caller), &(allowance - value)); Ok(()) } @@ -200,10 +199,9 @@ mod erc20 { return Err(Error::InsufficientBalance) } - self.balances - .insert_return_size(from, &(from_balance - value)); + self.balances.insert(from, &(from_balance - value)); let to_balance = self.balance_of_impl(to); - self.balances.insert_return_size(to, &(to_balance + value)); + self.balances.insert(to, &(to_balance + value)); self.env().emit_event(Transfer { from: Some(*from), to: Some(*to), diff --git a/crates/ink/tests/ui/contract/pass/example-erc721-works.rs b/crates/ink/tests/ui/contract/pass/example-erc721-works.rs index a89181e0b1..e5b250bf0d 100644 --- a/crates/ink/tests/ui/contract/pass/example-erc721-works.rs +++ b/crates/ink/tests/ui/contract/pass/example-erc721-works.rs @@ -175,7 +175,7 @@ mod erc721 { .get(&caller) .map(|c| c - 1) .ok_or(Error::CannotFetchValue)?; - owned_tokens_count.insert_return_size(&caller, &count); + owned_tokens_count.insert(&caller, &count); token_owner.remove(&id); self.env().emit_event(Transfer { @@ -232,7 +232,7 @@ mod erc721 { .get(&from) .map(|c| c - 1) .ok_or(Error::CannotFetchValue)?; - owned_tokens_count.insert_return_size(&from, &count); + owned_tokens_count.insert(&from, &count); token_owner.remove(&id); Ok(()) @@ -256,8 +256,8 @@ mod erc721 { let count = owned_tokens_count.get(to).map(|c| c + 1).unwrap_or(1); - owned_tokens_count.insert_return_size(to, &count); - token_owner.insert_return_size(&id, to); + owned_tokens_count.insert(to, &count); + token_owner.insert(&id, to); Ok(()) } @@ -279,8 +279,7 @@ mod erc721 { }); if approved { - self.operator_approvals - .insert_return_size((&caller, &to), &()); + self.operator_approvals.insert((&caller, &to), &()); } else { self.operator_approvals.remove((&caller, &to)); } @@ -305,7 +304,7 @@ mod erc721 { if self.token_approvals.get(&id).is_some() { return Err(Error::CannotInsert) } else { - self.token_approvals.insert_return_size(&id, to); + self.token_approvals.insert(&id, to); } self.env().emit_event(Approval { diff --git a/crates/storage/src/lazy/mapping.rs b/crates/storage/src/lazy/mapping.rs index a146761d2f..3c5ed0ae11 100644 --- a/crates/storage/src/lazy/mapping.rs +++ b/crates/storage/src/lazy/mapping.rs @@ -69,7 +69,7 @@ use scale::{ /// let mut instance = Self::default(); /// let caller = Self::env().caller(); /// let value: Balance = Default::default(); -/// instance.balances.insert_return_size(&caller, &value); +/// instance.balances.insert(&caller, &value); /// instance /// } /// @@ -134,7 +134,7 @@ where /// /// Returns the size of the pre-existing value at the specified key if any. #[inline] - pub fn insert_return_size(&mut self, key: Q, value: &R) -> Option + pub fn insert(&mut self, key: Q, value: &R) -> Option where Q: scale::EncodeLike, R: Storable + scale::EncodeLike, @@ -251,7 +251,7 @@ mod tests { fn insert_and_get_work() { ink_env::test::run_test::(|_| { let mut mapping: Mapping = Mapping::new(); - mapping.insert_return_size(&1, &2); + mapping.insert(&1, &2); assert_eq!(mapping.get(&1), Some(2)); Ok(()) @@ -263,7 +263,7 @@ mod tests { fn insert_and_get_work_for_two_mapping_with_same_manual_key() { ink_env::test::run_test::(|_| { let mut mapping: Mapping> = Mapping::new(); - mapping.insert_return_size(&1, &2); + mapping.insert(&1, &2); let mapping2: Mapping> = Mapping::new(); assert_eq!(mapping2.get(&1), Some(2)); @@ -290,7 +290,7 @@ mod tests { // Given let mut mapping: Mapping = Mapping::new(); - mapping.insert_return_size(&1, &2); + mapping.insert(&1, &2); assert_eq!(mapping.get(&1), Some(2)); // When diff --git a/examples/dns/lib.rs b/examples/dns/lib.rs index 0eedf89690..6374386304 100644 --- a/examples/dns/lib.rs +++ b/examples/dns/lib.rs @@ -91,7 +91,7 @@ mod dns { return Err(Error::NameAlreadyExists) } - self.name_to_owner.insert_return_size(&name, &caller); + self.name_to_owner.insert(&name, &caller); self.env().emit_event(Register { name, from: caller }); Ok(()) @@ -107,7 +107,7 @@ mod dns { } let old_address = self.name_to_address.get(&name); - self.name_to_address.insert_return_size(&name, &new_address); + self.name_to_address.insert(&name, &new_address); self.env().emit_event(SetAddress { name, @@ -128,7 +128,7 @@ mod dns { } let old_owner = self.name_to_owner.get(&name); - self.name_to_owner.insert_return_size(&name, &to); + self.name_to_owner.insert(&name, &to); self.env().emit_event(Transfer { name, diff --git a/examples/erc1155/lib.rs b/examples/erc1155/lib.rs index 85d1e13b46..7b662b1f4e 100644 --- a/examples/erc1155/lib.rs +++ b/examples/erc1155/lib.rs @@ -261,7 +261,7 @@ mod erc1155 { // Given that TokenId is a `u128` the likelihood of this overflowing is pretty slim. self.token_id_nonce += 1; self.balances - .insert_return_size(&(caller, self.token_id_nonce), &value); + .insert(&(caller, self.token_id_nonce), &value); // Emit transfer event but with mint semantics self.env().emit_event(TransferSingle { @@ -289,7 +289,7 @@ mod erc1155 { let caller = self.env().caller(); self.balances - .insert_return_size(&(caller, token_id), &value); + .insert(&(caller, token_id), &value); // Emit transfer event but with mint semantics self.env().emit_event(TransferSingle { @@ -324,12 +324,12 @@ mod erc1155 { .expect("Caller should have ensured that `from` holds `token_id`."); sender_balance -= value; self.balances - .insert_return_size(&(from, token_id), &sender_balance); + .insert(&(from, token_id), &sender_balance); let mut recipient_balance = self.balances.get(&(to, token_id)).unwrap_or(0); recipient_balance += value; self.balances - .insert_return_size(&(to, token_id), &recipient_balance); + .insert(&(to, token_id), &recipient_balance); let caller = self.env().caller(); self.env().emit_event(TransferSingle { @@ -521,7 +521,7 @@ mod erc1155 { ensure!(operator != caller, Error::SelfApproval); if approved { - self.approvals.insert_return_size((&caller, &operator), &()); + self.approvals.insert((&caller, &operator), &()); } else { self.approvals.remove((&caller, &operator)); } @@ -611,9 +611,9 @@ mod erc1155 { fn init_contract() -> Contract { let mut erc = Contract::new(); - erc.balances.insert_return_size((alice(), 1), &10); - erc.balances.insert_return_size((alice(), 2), &20); - erc.balances.insert_return_size((bob(), 1), &10); + erc.balances.insert((alice(), 1), &10); + erc.balances.insert((alice(), 2), &20); + erc.balances.insert((bob(), 1), &10); erc } diff --git a/examples/erc20/lib.rs b/examples/erc20/lib.rs index ac72c62c0a..78a188ea26 100644 --- a/examples/erc20/lib.rs +++ b/examples/erc20/lib.rs @@ -57,7 +57,7 @@ mod erc20 { pub fn new(total_supply: Balance) -> Self { let mut balances = Mapping::default(); let caller = Self::env().caller(); - balances.insert_return_size(&caller, &total_supply); + balances.insert(&caller, &total_supply); Self::env().emit_event(Transfer { from: None, to: Some(caller), @@ -142,7 +142,7 @@ mod erc20 { pub fn approve(&mut self, spender: AccountId, value: Balance) -> Result<()> { let owner = self.env().caller(); self.allowances - .insert_return_size((&owner, &spender), &value); + .insert((&owner, &spender), &value); self.env().emit_event(Approval { owner, spender, @@ -179,7 +179,7 @@ mod erc20 { } self.transfer_from_to(&from, &to, value)?; self.allowances - .insert_return_size((&from, &caller), &(allowance - value)); + .insert((&from, &caller), &(allowance - value)); Ok(()) } @@ -203,9 +203,9 @@ mod erc20 { } self.balances - .insert_return_size(from, &(from_balance - value)); + .insert(from, &(from_balance - value)); let to_balance = self.balance_of_impl(to); - self.balances.insert_return_size(to, &(to_balance + value)); + self.balances.insert(to, &(to_balance + value)); self.env().emit_event(Transfer { from: Some(*from), to: Some(*to), diff --git a/examples/erc721/lib.rs b/examples/erc721/lib.rs index dd609d58fe..c8f00b5150 100644 --- a/examples/erc721/lib.rs +++ b/examples/erc721/lib.rs @@ -227,7 +227,7 @@ mod erc721 { .get(&caller) .map(|c| c - 1) .ok_or(Error::CannotFetchValue)?; - owned_tokens_count.insert_return_size(&caller, &count); + owned_tokens_count.insert(&caller, &count); token_owner.remove(&id); self.env().emit_event(Transfer { @@ -284,7 +284,7 @@ mod erc721 { .get(&from) .map(|c| c - 1) .ok_or(Error::CannotFetchValue)?; - owned_tokens_count.insert_return_size(&from, &count); + owned_tokens_count.insert(&from, &count); token_owner.remove(&id); Ok(()) @@ -308,8 +308,8 @@ mod erc721 { let count = owned_tokens_count.get(to).map(|c| c + 1).unwrap_or(1); - owned_tokens_count.insert_return_size(to, &count); - token_owner.insert_return_size(&id, to); + owned_tokens_count.insert(to, &count); + token_owner.insert(&id, to); Ok(()) } @@ -332,7 +332,7 @@ mod erc721 { if approved { self.operator_approvals - .insert_return_size((&caller, &to), &()); + .insert((&caller, &to), &()); } else { self.operator_approvals.remove((&caller, &to)); } @@ -357,7 +357,7 @@ mod erc721 { if self.token_approvals.contains(&id) { return Err(Error::CannotInsert) } else { - self.token_approvals.insert_return_size(&id, to); + self.token_approvals.insert(&id, to); } self.env().emit_event(Approval { diff --git a/examples/multisig/lib.rs b/examples/multisig/lib.rs index 20e734f22a..ca04badab5 100755 --- a/examples/multisig/lib.rs +++ b/examples/multisig/lib.rs @@ -285,7 +285,7 @@ mod multisig { ensure_requirement_is_valid(owners.len() as u32, requirement); for owner in &owners { - contract.is_owner.insert_return_size(owner, &()); + contract.is_owner.insert(owner, &()); } contract.owners = owners; @@ -370,7 +370,7 @@ mod multisig { self.ensure_from_wallet(); self.ensure_no_owner(&new_owner); ensure_requirement_is_valid(self.owners.len() as u32 + 1, self.requirement); - self.is_owner.insert_return_size(new_owner, &()); + self.is_owner.insert(new_owner, &()); self.owners.push(new_owner); self.env().emit_event(OwnerAddition { owner: new_owner }); } @@ -414,7 +414,7 @@ mod multisig { let owner_index = self.owner_index(&old_owner); self.owners[owner_index as usize] = new_owner; self.is_owner.remove(&old_owner); - self.is_owner.insert_return_size(new_owner, &()); + self.is_owner.insert(new_owner, &()); self.clean_owner_confirmations(&old_owner); self.env().emit_event(OwnerRemoval { owner: old_owner }); self.env().emit_event(OwnerAddition { owner: new_owner }); @@ -447,7 +447,7 @@ mod multisig { let trans_id = self.transaction_list.next_id; self.transaction_list.next_id = trans_id.checked_add(1).expect("Transaction ids exhausted."); - self.transactions.insert_return_size(trans_id, &transaction); + self.transactions.insert(trans_id, &transaction); self.transaction_list.transactions.push(trans_id); self.env().emit_event(Submission { transaction: trans_id, @@ -513,7 +513,7 @@ mod multisig { // Will not underflow as there is at least one confirmation confirmation_count -= 1; self.confirmation_count - .insert_return_size(&trans_id, &confirmation_count); + .insert(&trans_id, &confirmation_count); self.env().emit_event(Revocation { transaction: trans_id, from: caller, @@ -604,9 +604,9 @@ mod multisig { let new_confirmation = !self.confirmations.contains(&key); if new_confirmation { count += 1; - self.confirmations.insert_return_size(&key, &()); + self.confirmations.insert(&key, &()); self.confirmation_count - .insert_return_size(&transaction, &count); + .insert(&transaction, &count); } let status = { if count >= self.requirement { @@ -665,7 +665,7 @@ mod multisig { let mut count = self.confirmation_count.get(&trans_id).unwrap_or(0); count -= 1; self.confirmation_count - .insert_return_size(&trans_id, &count); + .insert(&trans_id, &count); } } } diff --git a/examples/trait-erc20/lib.rs b/examples/trait-erc20/lib.rs index 161b666e3c..7f0a84369c 100644 --- a/examples/trait-erc20/lib.rs +++ b/examples/trait-erc20/lib.rs @@ -93,7 +93,7 @@ mod erc20 { pub fn new(total_supply: Balance) -> Self { let mut balances = Mapping::default(); let caller = Self::env().caller(); - balances.insert_return_size(&caller, &total_supply); + balances.insert(&caller, &total_supply); Self::env().emit_event(Transfer { from: None, to: Some(caller), @@ -154,7 +154,7 @@ mod erc20 { fn approve(&mut self, spender: AccountId, value: Balance) -> Result<()> { let owner = self.env().caller(); self.allowances - .insert_return_size((&owner, &spender), &value); + .insert((&owner, &spender), &value); self.env().emit_event(Approval { owner, spender, @@ -191,7 +191,7 @@ mod erc20 { } self.transfer_from_to(&from, &to, value)?; self.allowances - .insert_return_size((&from, &caller), &(allowance - value)); + .insert((&from, &caller), &(allowance - value)); Ok(()) } } @@ -244,9 +244,9 @@ mod erc20 { } self.balances - .insert_return_size(from, &(from_balance - value)); + .insert(from, &(from_balance - value)); let to_balance = self.balance_of_impl(to); - self.balances.insert_return_size(to, &(to_balance + value)); + self.balances.insert(to, &(to_balance + value)); self.env().emit_event(Transfer { from: Some(*from), to: Some(*to), From fc26b9254d6119dfa99a45676ca22e651a85bdfd Mon Sep 17 00:00:00 2001 From: lean-apple Date: Fri, 4 Nov 2022 14:53:54 +0100 Subject: [PATCH 5/8] fix fmt for examples --- examples/erc1155/lib.rs | 12 ++++-------- examples/erc20/lib.rs | 6 ++---- examples/erc721/lib.rs | 3 +-- examples/multisig/lib.rs | 6 ++---- examples/trait-erc20/lib.rs | 6 ++---- 5 files changed, 11 insertions(+), 22 deletions(-) diff --git a/examples/erc1155/lib.rs b/examples/erc1155/lib.rs index 7b662b1f4e..50379d964b 100644 --- a/examples/erc1155/lib.rs +++ b/examples/erc1155/lib.rs @@ -260,8 +260,7 @@ mod erc1155 { // Given that TokenId is a `u128` the likelihood of this overflowing is pretty slim. self.token_id_nonce += 1; - self.balances - .insert(&(caller, self.token_id_nonce), &value); + self.balances.insert(&(caller, self.token_id_nonce), &value); // Emit transfer event but with mint semantics self.env().emit_event(TransferSingle { @@ -288,8 +287,7 @@ mod erc1155 { ensure!(token_id <= self.token_id_nonce, Error::UnexistentToken); let caller = self.env().caller(); - self.balances - .insert(&(caller, token_id), &value); + self.balances.insert(&(caller, token_id), &value); // Emit transfer event but with mint semantics self.env().emit_event(TransferSingle { @@ -323,13 +321,11 @@ mod erc1155 { .get(&(from, token_id)) .expect("Caller should have ensured that `from` holds `token_id`."); sender_balance -= value; - self.balances - .insert(&(from, token_id), &sender_balance); + self.balances.insert(&(from, token_id), &sender_balance); let mut recipient_balance = self.balances.get(&(to, token_id)).unwrap_or(0); recipient_balance += value; - self.balances - .insert(&(to, token_id), &recipient_balance); + self.balances.insert(&(to, token_id), &recipient_balance); let caller = self.env().caller(); self.env().emit_event(TransferSingle { diff --git a/examples/erc20/lib.rs b/examples/erc20/lib.rs index 78a188ea26..a624e48d5f 100644 --- a/examples/erc20/lib.rs +++ b/examples/erc20/lib.rs @@ -141,8 +141,7 @@ mod erc20 { #[ink(message)] pub fn approve(&mut self, spender: AccountId, value: Balance) -> Result<()> { let owner = self.env().caller(); - self.allowances - .insert((&owner, &spender), &value); + self.allowances.insert((&owner, &spender), &value); self.env().emit_event(Approval { owner, spender, @@ -202,8 +201,7 @@ mod erc20 { return Err(Error::InsufficientBalance) } - self.balances - .insert(from, &(from_balance - value)); + self.balances.insert(from, &(from_balance - value)); let to_balance = self.balance_of_impl(to); self.balances.insert(to, &(to_balance + value)); self.env().emit_event(Transfer { diff --git a/examples/erc721/lib.rs b/examples/erc721/lib.rs index c8f00b5150..e85be4fa58 100644 --- a/examples/erc721/lib.rs +++ b/examples/erc721/lib.rs @@ -331,8 +331,7 @@ mod erc721 { }); if approved { - self.operator_approvals - .insert((&caller, &to), &()); + self.operator_approvals.insert((&caller, &to), &()); } else { self.operator_approvals.remove((&caller, &to)); } diff --git a/examples/multisig/lib.rs b/examples/multisig/lib.rs index ca04badab5..4b9ac0bb8e 100755 --- a/examples/multisig/lib.rs +++ b/examples/multisig/lib.rs @@ -605,8 +605,7 @@ mod multisig { if new_confirmation { count += 1; self.confirmations.insert(&key, &()); - self.confirmation_count - .insert(&transaction, &count); + self.confirmation_count.insert(&transaction, &count); } let status = { if count >= self.requirement { @@ -664,8 +663,7 @@ mod multisig { self.confirmations.remove(&key); let mut count = self.confirmation_count.get(&trans_id).unwrap_or(0); count -= 1; - self.confirmation_count - .insert(&trans_id, &count); + self.confirmation_count.insert(&trans_id, &count); } } } diff --git a/examples/trait-erc20/lib.rs b/examples/trait-erc20/lib.rs index 7f0a84369c..e48679cb74 100644 --- a/examples/trait-erc20/lib.rs +++ b/examples/trait-erc20/lib.rs @@ -153,8 +153,7 @@ mod erc20 { #[ink(message)] fn approve(&mut self, spender: AccountId, value: Balance) -> Result<()> { let owner = self.env().caller(); - self.allowances - .insert((&owner, &spender), &value); + self.allowances.insert((&owner, &spender), &value); self.env().emit_event(Approval { owner, spender, @@ -243,8 +242,7 @@ mod erc20 { return Err(Error::InsufficientBalance) } - self.balances - .insert(from, &(from_balance - value)); + self.balances.insert(from, &(from_balance - value)); let to_balance = self.balance_of_impl(to); self.balances.insert(to, &(to_balance + value)); self.env().emit_event(Transfer { From 033320d44ada2aa964115b6dee4887305204c65e Mon Sep 17 00:00:00 2001 From: lean-apple Date: Mon, 7 Nov 2022 09:59:13 +0100 Subject: [PATCH 6/8] update changelog file --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa8d3e1ee8..212e3da771 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - Allows to use `Result` as a return type in constructors - [#1446](https://github.com/paritytech/ink/pull/1446) - Introduces conditional compilation to messages, constructors and events - [#1458](https://github.com/paritytech/ink/pull/1458) - - Remove random function from ink!. +- Replace definitely previous `Mapping::insert(key, val)` method by `Mapping::insert_return_size(key, val)` one but under the same method name insert - [#1463](https://github.com/paritytech/ink/pull/1463) ## Version 4.0.0-alpha.3 From 330d9426aa6cc28be5f992d30688c6b8dadf8117 Mon Sep 17 00:00:00 2001 From: lean-apple Date: Mon, 7 Nov 2022 14:10:07 +0100 Subject: [PATCH 7/8] fix changelog file --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b5f3d1445..125dfa392b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,10 +31,10 @@ protocol for future versions of Polkadot. ### Changed - Update `scale-info` requirement to `2.3` ‒ [#1467](https://github.com/paritytech/ink/pull/1467) +- Merge `Mapping::insert(key, val)` and `Mapping::insert_return_size(key, val)` into one method - [#1463](https://github.com/paritytech/ink/pull/1463) ### Removed - Remove `ink_env::random` function ‒ [#1442](https://github.com/paritytech/ink/pull/1442) -- Remove previous insert `Mapping::insert(key, val)` method and replace by `Mapping::insert_return_size(key, val)` behaviour but under the same method name insert - [#1463](https://github.com/paritytech/ink/pull/1463) ## Version 4.0.0-alpha.3 From d9f4b5ee1f867d00caceb761764f7f69ae696efc Mon Sep 17 00:00:00 2001 From: lean-apple Date: Tue, 8 Nov 2022 07:42:05 +0100 Subject: [PATCH 8/8] complete method docs --- crates/storage/src/lazy/mapping.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/storage/src/lazy/mapping.rs b/crates/storage/src/lazy/mapping.rs index 633aacdea0..88e7761775 100644 --- a/crates/storage/src/lazy/mapping.rs +++ b/crates/storage/src/lazy/mapping.rs @@ -132,7 +132,7 @@ where { /// Insert the given `value` to the contract storage. /// - /// Returns the size of the pre-existing value at the specified key if any. + /// Returns the size in bytes of the pre-existing value at the specified key if any. #[inline] pub fn insert(&mut self, key: Q, value: &R) -> Option where