diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 7b718ca21f..f0e2c79743 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -80,7 +80,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. spec_version: 214, - impl_version: 1, + impl_version: 2, apis: RUNTIME_API_VERSIONS, }; diff --git a/substrate/frame/balances/src/lib.rs b/substrate/frame/balances/src/lib.rs index 4b3e88eb9f..64932fb256 100644 --- a/substrate/frame/balances/src/lib.rs +++ b/substrate/frame/balances/src/lib.rs @@ -1381,6 +1381,6 @@ where { fn is_dead_account(who: &T::AccountId) -> bool { // this should always be exactly equivalent to `Self::account(who).total().is_zero()` - !Account::::exists(who) + !Account::::contains_key(who) } } diff --git a/substrate/frame/collective/src/lib.rs b/substrate/frame/collective/src/lib.rs index 8d811b8dec..ffc62d976a 100644 --- a/substrate/frame/collective/src/lib.rs +++ b/substrate/frame/collective/src/lib.rs @@ -191,7 +191,7 @@ decl_module! { let proposal_hash = T::Hashing::hash_of(&proposal); - ensure!(!>::exists(proposal_hash), Error::::DuplicateProposal); + ensure!(!>::contains_key(proposal_hash), Error::::DuplicateProposal); if threshold < 2 { let seats = Self::members().len() as MemberCount; diff --git a/substrate/frame/contracts/src/account_db.rs b/substrate/frame/contracts/src/account_db.rs index 814983c586..efef02222d 100644 --- a/substrate/frame/contracts/src/account_db.rs +++ b/substrate/frame/contracts/src/account_db.rs @@ -137,7 +137,7 @@ impl AccountDb for DirectAccountDb { >::get(account).and_then(|i| i.as_alive().map(|i| i.rent_allowance)) } fn contract_exists(&self, account: &T::AccountId) -> bool { - >::exists(account) + >::contains_key(account) } fn get_balance(&self, account: &T::AccountId) -> BalanceOf { T::Currency::free_balance(account) diff --git a/substrate/frame/contracts/src/tests.rs b/substrate/frame/contracts/src/tests.rs index 5eb7bce48a..783eca02ca 100644 --- a/substrate/frame/contracts/src/tests.rs +++ b/substrate/frame/contracts/src/tests.rs @@ -460,7 +460,7 @@ fn instantiate_and_call_and_deposit_event() { ]); assert_ok!(creation); - assert!(ContractInfoOf::::exists(BOB)); + assert!(ContractInfoOf::::contains_key(BOB)); }); } diff --git a/substrate/frame/democracy/src/lib.rs b/substrate/frame/democracy/src/lib.rs index da0cccb1d0..9bf08840f4 100644 --- a/substrate/frame/democracy/src/lib.rs +++ b/substrate/frame/democracy/src/lib.rs @@ -294,7 +294,7 @@ decl_storage! { /// Get the vote in a given referendum of a particular voter. The result is meaningful only /// if `voters_for` includes the voter when called with the referendum (you'll get the /// default `Vote` value otherwise). If you don't want to check `voters_for`, then you can - /// also check for simple existence with `VoteOf::exists` first. + /// also check for simple existence with `VoteOf::contains_key` first. pub VoteOf get(fn vote_of): map hasher(blake2_256) (ReferendumIndex, T::AccountId) => Vote; /// Who is able to vote for whom. Value is the fund-holding account, key is the @@ -537,7 +537,7 @@ decl_module! { let info = Self::referendum_info(ref_index).ok_or(Error::::BadIndex)?; let h = info.proposal_hash; - ensure!(!>::exists(h), Error::::AlreadyCanceled); + ensure!(!>::contains_key(h), Error::::AlreadyCanceled); >::insert(h, true); Self::clear_referendum(ref_index); @@ -667,7 +667,7 @@ decl_module! { #[weight = SimpleDispatchInfo::FixedNormal(100_000)] fn set_proxy(origin, proxy: T::AccountId) { let who = ensure_signed(origin)?; - ensure!(!>::exists(&proxy), Error::::AlreadyProxy); + ensure!(!>::contains_key(&proxy), Error::::AlreadyProxy); >::insert(proxy, who) } @@ -725,7 +725,7 @@ decl_module! { #[weight = SimpleDispatchInfo::FixedNormal(500_000)] fn undelegate(origin) { let who = ensure_signed(origin)?; - ensure!(>::exists(&who), Error::::NotDelegated); + ensure!(>::contains_key(&who), Error::::NotDelegated); let (_, conviction) = >::take(&who); // Indefinite lock is reduced to the maximum voting lock that could be possible. let now = >::block_number(); @@ -754,7 +754,7 @@ decl_module! { fn note_preimage(origin, encoded_proposal: Vec) { let who = ensure_signed(origin)?; let proposal_hash = T::Hashing::hash(&encoded_proposal[..]); - ensure!(!>::exists(&proposal_hash), Error::::DuplicatePreimage); + ensure!(!>::contains_key(&proposal_hash), Error::::DuplicatePreimage); let deposit = >::from(encoded_proposal.len() as u32) .saturating_mul(T::PreimageByteDeposit::get()); @@ -772,7 +772,7 @@ decl_module! { fn note_imminent_preimage(origin, encoded_proposal: Vec) { let who = ensure_signed(origin)?; let proposal_hash = T::Hashing::hash(&encoded_proposal[..]); - ensure!(!>::exists(&proposal_hash), Error::::DuplicatePreimage); + ensure!(!>::contains_key(&proposal_hash), Error::::DuplicatePreimage); let queue = >::get(); ensure!(queue.iter().any(|item| &item.1 == &proposal_hash), Error::::NotImminent); @@ -832,7 +832,7 @@ impl Module { /// Return true if `ref_index` is an on-going referendum. pub fn is_active_referendum(ref_index: ReferendumIndex) -> bool { - >::exists(ref_index) + >::contains_key(ref_index) } /// Get all referenda currently active. @@ -913,7 +913,7 @@ impl Module { if recursion_limit == 0 { return (Zero::zero(), Zero::zero()); } >::enumerate() .filter(|(delegator, (delegate, _))| - *delegate == to && !>::exists(&(ref_index, delegator.clone())) + *delegate == to && !>::contains_key(&(ref_index, delegator.clone())) ).fold( (Zero::zero(), Zero::zero()), |(votes_acc, turnout_acc), (delegator, (_delegate, max_conviction))| { @@ -963,7 +963,7 @@ impl Module { /// Actually enact a vote, if legit. fn do_vote(who: T::AccountId, ref_index: ReferendumIndex, vote: Vote) -> DispatchResult { ensure!(Self::is_active_referendum(ref_index), Error::::ReferendumInvalid); - if !>::exists((ref_index, &who)) { + if !>::contains_key((ref_index, &who)) { >::append_or_insert(ref_index, &[&who][..]); } >::insert((ref_index, &who), vote); diff --git a/substrate/frame/elections-phragmen/src/lib.rs b/substrate/frame/elections-phragmen/src/lib.rs index 33d4c46e91..b3dc05fe7b 100644 --- a/substrate/frame/elections-phragmen/src/lib.rs +++ b/substrate/frame/elections-phragmen/src/lib.rs @@ -520,7 +520,7 @@ impl Module { /// /// State: O(1). fn is_voter(who: &T::AccountId) -> bool { - >::exists(who) + >::contains_key(who) } /// Check if `who` is currently an active member. diff --git a/substrate/frame/elections/src/lib.rs b/substrate/frame/elections/src/lib.rs index 899fcfac8a..eb87057f95 100644 --- a/substrate/frame/elections/src/lib.rs +++ b/substrate/frame/elections/src/lib.rs @@ -525,7 +525,7 @@ decl_module! { let who = ensure_signed(origin)?; ensure!(!Self::presentation_active(), Error::::CannotRetractPresenting); - ensure!(>::exists(&who), Error::::RetractNonVoter); + ensure!(>::contains_key(&who), Error::::RetractNonVoter); let index = index as usize; let voter = Self::voter_at(index).ok_or(Error::::InvalidRetractionIndex)?; ensure!(voter == who, Error::::InvalidRetractionIndex); @@ -730,7 +730,7 @@ impl Module { /// If `who` a candidate at the moment? pub fn is_a_candidate(who: &T::AccountId) -> bool { - >::exists(who) + >::contains_key(who) } /// Iff the member `who` still has a seat at blocknumber `n` returns `true`. diff --git a/substrate/frame/generic-asset/src/lib.rs b/substrate/frame/generic-asset/src/lib.rs index 3b8ebe0535..5d246a8afd 100644 --- a/substrate/frame/generic-asset/src/lib.rs +++ b/substrate/frame/generic-asset/src/lib.rs @@ -580,7 +580,7 @@ impl Module { options: AssetOptions, ) -> DispatchResult { let asset_id = if let Some(asset_id) = asset_id { - ensure!(!>::exists(&asset_id), Error::::IdAlreadyTaken); + ensure!(!>::contains_key(&asset_id), Error::::IdAlreadyTaken); ensure!(asset_id < Self::next_asset_id(), Error::::IdUnavailable); asset_id } else { diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 56960b2d1d..80a200e808 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -553,7 +553,7 @@ decl_module! { #[weight = SimpleDispatchInfo::FixedNormal(50_000)] fn set_subs(origin, subs: Vec<(T::AccountId, Data)>) { let sender = ensure_signed(origin)?; - ensure!(>::exists(&sender), Error::::NotFound); + ensure!(>::contains_key(&sender), Error::::NotFound); ensure!(subs.len() <= T::MaxSubAccounts::get() as usize, Error::::TooManySubAccounts); let (old_deposit, old_ids) = >::get(&sender); diff --git a/substrate/frame/im-online/src/lib.rs b/substrate/frame/im-online/src/lib.rs index ff06cb37d4..f7067a5843 100644 --- a/substrate/frame/im-online/src/lib.rs +++ b/substrate/frame/im-online/src/lib.rs @@ -315,7 +315,7 @@ decl_module! { ensure_none(origin)?; let current_session = >::current_index(); - let exists = ::exists( + let exists = ::contains_key( ¤t_session, &heartbeat.authority_index ); @@ -398,7 +398,7 @@ impl Module { fn is_online_aux(authority_index: AuthIndex, authority: &T::ValidatorId) -> bool { let current_session = >::current_index(); - ::exists(¤t_session, &authority_index) || + ::contains_key(¤t_session, &authority_index) || >::get( ¤t_session, authority, @@ -409,7 +409,7 @@ impl Module { /// the authorities series, during the current session. Otherwise `false`. pub fn received_heartbeat_in_current_session(authority_index: AuthIndex) -> bool { let current_session = >::current_index(); - ::exists(¤t_session, &authority_index) + ::contains_key(¤t_session, &authority_index) } /// Note that the given authority has authored a block in the current session. diff --git a/substrate/frame/offences/src/lib.rs b/substrate/frame/offences/src/lib.rs index 2b625873f0..ea6f96cbc3 100644 --- a/substrate/frame/offences/src/lib.rs +++ b/substrate/frame/offences/src/lib.rs @@ -150,7 +150,7 @@ impl Module { for offender in offenders { let report_id = Self::report_id::(time_slot, &offender); - if !>::exists(&report_id) { + if !>::contains_key(&report_id) { any_new = true; >::insert( &report_id, diff --git a/substrate/frame/recovery/src/lib.rs b/substrate/frame/recovery/src/lib.rs index 0309fec12a..668608c892 100644 --- a/substrate/frame/recovery/src/lib.rs +++ b/substrate/frame/recovery/src/lib.rs @@ -401,7 +401,7 @@ decl_module! { ) { let who = ensure_signed(origin)?; // Check account is not already set up for recovery - ensure!(!>::exists(&who), Error::::AlreadyRecoverable); + ensure!(!>::contains_key(&who), Error::::AlreadyRecoverable); // Check user input is valid ensure!(threshold >= 1, Error::::ZeroThreshold); ensure!(!friends.is_empty(), Error::::NotEnoughFriends); @@ -456,9 +456,9 @@ decl_module! { fn initiate_recovery(origin, account: T::AccountId) { let who = ensure_signed(origin)?; // Check that the account is recoverable - ensure!(>::exists(&account), Error::::NotRecoverable); + ensure!(>::contains_key(&account), Error::::NotRecoverable); // Check that the recovery process has not already been started - ensure!(!>::exists(&account, &who), Error::::AlreadyStarted); + ensure!(!>::contains_key(&account, &who), Error::::AlreadyStarted); // Take recovery deposit let recovery_deposit = T::RecoveryDeposit::get(); T::Currency::reserve(&who, recovery_deposit)?; diff --git a/substrate/frame/recovery/src/tests.rs b/substrate/frame/recovery/src/tests.rs index cfc8e25b12..af4eadb58f 100644 --- a/substrate/frame/recovery/src/tests.rs +++ b/substrate/frame/recovery/src/tests.rs @@ -92,9 +92,9 @@ fn recovery_lifecycle_works() { assert_eq!(Balances::free_balance(1), 200); assert_eq!(Balances::free_balance(5), 0); // All storage items are removed from the module - assert!(!>::exists(&5, &1)); - assert!(!>::exists(&5)); - assert!(!>::exists(&5)); + assert!(!>::contains_key(&5, &1)); + assert!(!>::contains_key(&5)); + assert!(!>::contains_key(&5)); }); } diff --git a/substrate/frame/scored-pool/src/lib.rs b/substrate/frame/scored-pool/src/lib.rs index 2a73c4bb68..98a7ed217e 100644 --- a/substrate/frame/scored-pool/src/lib.rs +++ b/substrate/frame/scored-pool/src/lib.rs @@ -265,7 +265,7 @@ decl_module! { /// the index of the transactor in the `Pool`. pub fn submit_candidacy(origin) { let who = ensure_signed(origin)?; - ensure!(!>::exists(&who), Error::::AlreadyInPool); + ensure!(!>::contains_key(&who), Error::::AlreadyInPool); let deposit = T::CandidateDeposit::get(); T::Currency::reserve(&who, deposit)?; diff --git a/substrate/frame/society/src/lib.rs b/substrate/frame/society/src/lib.rs index e45ac30bce..c1e1803c64 100644 --- a/substrate/frame/society/src/lib.rs +++ b/substrate/frame/society/src/lib.rs @@ -530,8 +530,8 @@ decl_module! { #[weight = SimpleDispatchInfo::FixedNormal(50_000)] pub fn bid(origin, value: BalanceOf) -> DispatchResult { let who = ensure_signed(origin)?; - ensure!(!>::exists(&who), Error::::Suspended); - ensure!(!>::exists(&who), Error::::Suspended); + ensure!(!>::contains_key(&who), Error::::Suspended); + ensure!(!>::contains_key(&who), Error::::Suspended); let bids = >::get(); ensure!(!Self::is_bid(&bids, &who), Error::::AlreadyBid); let candidates = >::get(); @@ -640,8 +640,8 @@ decl_module! { pub fn vouch(origin, who: T::AccountId, value: BalanceOf, tip: BalanceOf) -> DispatchResult { let voucher = ensure_signed(origin)?; // Check user is not suspended. - ensure!(!>::exists(&who), Error::::Suspended); - ensure!(!>::exists(&who), Error::::Suspended); + ensure!(!>::contains_key(&who), Error::::Suspended); + ensure!(!>::contains_key(&who), Error::::Suspended); // Check user is not a bid or candidate. let bids = >::get(); ensure!(!Self::is_bid(&bids, &who), Error::::AlreadyBid); @@ -652,7 +652,7 @@ decl_module! { ensure!(!Self::is_member(&members, &who), Error::::AlreadyMember); // Check sender can vouch. ensure!(Self::is_member(&members, &voucher), Error::::NotMember); - ensure!(!>::exists(&voucher), Error::::AlreadyVouching); + ensure!(!>::contains_key(&voucher), Error::::AlreadyVouching); >::insert(&voucher, VouchingStatus::Vouching); Self::put_bid(bids, &who, value.clone(), BidKind::Vouch(voucher.clone(), tip)); @@ -892,7 +892,7 @@ decl_module! { #[weight = SimpleDispatchInfo::FixedNormal(30_000)] fn judge_suspended_member(origin, who: T::AccountId, forgive: bool) { T::SuspensionJudgementOrigin::ensure_origin(origin)?; - ensure!(>::exists(&who), Error::::NotSuspended); + ensure!(>::contains_key(&who), Error::::NotSuspended); if forgive { // Try to add member back to society. Can fail with `MaxMembers` limit. diff --git a/substrate/frame/staking/src/lib.rs b/substrate/frame/staking/src/lib.rs index ca2a2bf092..0c1c9a4942 100644 --- a/substrate/frame/staking/src/lib.rs +++ b/substrate/frame/staking/src/lib.rs @@ -887,13 +887,13 @@ decl_module! { ) { let stash = ensure_signed(origin)?; - if >::exists(&stash) { + if >::contains_key(&stash) { Err(Error::::AlreadyBonded)? } let controller = T::Lookup::lookup(controller)?; - if >::exists(&controller) { + if >::contains_key(&controller) { Err(Error::::AlreadyPaired)? } @@ -1139,7 +1139,7 @@ decl_module! { let stash = ensure_signed(origin)?; let old_controller = Self::bonded(&stash).ok_or(Error::::NotStash)?; let controller = T::Lookup::lookup(controller)?; - if >::exists(&controller) { + if >::contains_key(&controller) { Err(Error::::AlreadyPaired)? } if controller != old_controller { diff --git a/substrate/frame/staking/src/tests.rs b/substrate/frame/staking/src/tests.rs index a9b6e16598..f62a58e20b 100644 --- a/substrate/frame/staking/src/tests.rs +++ b/substrate/frame/staking/src/tests.rs @@ -977,7 +977,7 @@ fn bond_extra_works() { // See `bond_extra_and_withdraw_unbonded_works` for more details and updates on `Exposure`. ExtBuilder::default().build().execute_with(|| { // Check that account 10 is a validator - assert!(>::exists(11)); + assert!(>::contains_key(11)); // Check that account 10 is bonded to account 11 assert_eq!(Staking::bonded(&11), Some(10)); // Check how much is at stake @@ -1375,7 +1375,7 @@ fn slot_stake_is_least_staked_validator_and_exposure_defines_maximum_punishment( // Confirm validator count is 2 assert_eq!(Staking::validator_count(), 2); // Confirm account 10 and 20 are validators - assert!(>::exists(&11) && >::exists(&21)); + assert!(>::contains_key(&11) && >::contains_key(&21)); assert_eq!(Staking::stakers(&11).total, 1000); assert_eq!(Staking::stakers(&21).total, 2000); @@ -1433,10 +1433,10 @@ fn on_free_balance_zero_stash_removes_validator() { assert_ok!(Staking::set_payee(Origin::signed(10), RewardDestination::Stash)); // Check storage items that should be cleaned up - assert!(>::exists(&10)); - assert!(>::exists(&11)); - assert!(>::exists(&11)); - assert!(>::exists(&11)); + assert!(>::contains_key(&10)); + assert!(>::contains_key(&11)); + assert!(>::contains_key(&11)); + assert!(>::contains_key(&11)); // Reduce free_balance of controller to 0 let _ = Balances::slash(&10, u64::max_value()); @@ -1447,10 +1447,10 @@ fn on_free_balance_zero_stash_removes_validator() { assert_eq!(Staking::bonded(&11), Some(10)); // Check storage items have not changed - assert!(>::exists(&10)); - assert!(>::exists(&11)); - assert!(>::exists(&11)); - assert!(>::exists(&11)); + assert!(>::contains_key(&10)); + assert!(>::contains_key(&11)); + assert!(>::contains_key(&11)); + assert!(>::contains_key(&11)); // Reduce free_balance of stash to 0 let _ = Balances::slash(&11, u64::max_value()); @@ -1458,11 +1458,11 @@ fn on_free_balance_zero_stash_removes_validator() { assert_eq!(Balances::total_balance(&11), 0); // Check storage items do not exist - assert!(!>::exists(&10)); - assert!(!>::exists(&11)); - assert!(!>::exists(&11)); - assert!(!>::exists(&11)); - assert!(!>::exists(&11)); + assert!(!>::contains_key(&10)); + assert!(!>::contains_key(&11)); + assert!(!>::contains_key(&11)); + assert!(!>::contains_key(&11)); + assert!(!>::contains_key(&11)); }); } @@ -1474,7 +1474,7 @@ fn on_free_balance_zero_stash_removes_nominator() { // Make 10 a nominator assert_ok!(Staking::nominate(Origin::signed(10), vec![20])); // Check that account 10 is a nominator - assert!(>::exists(11)); + assert!(>::contains_key(11)); // Check the balance of the nominator account assert_eq!(Balances::free_balance(10), 256); // Check the balance of the stash account @@ -1484,10 +1484,10 @@ fn on_free_balance_zero_stash_removes_nominator() { assert_ok!(Staking::set_payee(Origin::signed(10), RewardDestination::Stash)); // Check storage items that should be cleaned up - assert!(>::exists(&10)); - assert!(>::exists(&11)); - assert!(>::exists(&11)); - assert!(>::exists(&11)); + assert!(>::contains_key(&10)); + assert!(>::contains_key(&11)); + assert!(>::contains_key(&11)); + assert!(>::contains_key(&11)); // Reduce free_balance of controller to 0 let _ = Balances::slash(&10, u64::max_value()); @@ -1500,10 +1500,10 @@ fn on_free_balance_zero_stash_removes_nominator() { assert_eq!(Staking::bonded(&11), Some(10)); // Check storage items have not changed - assert!(>::exists(&10)); - assert!(>::exists(&11)); - assert!(>::exists(&11)); - assert!(>::exists(&11)); + assert!(>::contains_key(&10)); + assert!(>::contains_key(&11)); + assert!(>::contains_key(&11)); + assert!(>::contains_key(&11)); // Reduce free_balance of stash to 0 let _ = Balances::slash(&11, u64::max_value()); @@ -1511,11 +1511,11 @@ fn on_free_balance_zero_stash_removes_nominator() { assert_eq!(Balances::total_balance(&11), 0); // Check storage items do not exist - assert!(!>::exists(&10)); - assert!(!>::exists(&11)); - assert!(!>::exists(&11)); - assert!(!>::exists(&11)); - assert!(!>::exists(&11)); + assert!(!>::contains_key(&10)); + assert!(!>::contains_key(&11)); + assert!(!>::contains_key(&11)); + assert!(!>::contains_key(&11)); + assert!(!>::contains_key(&11)); }); } @@ -1968,7 +1968,7 @@ fn offence_ensures_new_era_without_clobbering() { #[test] fn offence_deselects_validator_when_slash_is_zero() { ExtBuilder::default().build().execute_with(|| { - assert!(>::exists(11)); + assert!(>::contains_key(11)); on_offence_now( &[OffenceDetails { offender: ( @@ -1980,7 +1980,7 @@ fn offence_deselects_validator_when_slash_is_zero() { &[Perbill::from_percent(0)], ); assert_eq!(Staking::force_era(), Forcing::ForceNew); - assert!(!>::exists(11)); + assert!(!>::contains_key(11)); }); } @@ -2017,7 +2017,7 @@ fn slash_in_old_span_does_not_deselect() { ExtBuilder::default().build().execute_with(|| { start_era(1); - assert!(>::exists(11)); + assert!(>::contains_key(11)); on_offence_now( &[OffenceDetails { offender: ( @@ -2029,13 +2029,13 @@ fn slash_in_old_span_does_not_deselect() { &[Perbill::from_percent(0)], ); assert_eq!(Staking::force_era(), Forcing::ForceNew); - assert!(!>::exists(11)); + assert!(!>::contains_key(11)); start_era(2); Staking::validate(Origin::signed(10), Default::default()).unwrap(); assert_eq!(Staking::force_era(), Forcing::NotForcing); - assert!(>::exists(11)); + assert!(>::contains_key(11)); start_era(3); @@ -2056,7 +2056,7 @@ fn slash_in_old_span_does_not_deselect() { // not for zero-slash. assert_eq!(Staking::force_era(), Forcing::NotForcing); - assert!(>::exists(11)); + assert!(>::contains_key(11)); on_offence_in_era( &[OffenceDetails { @@ -2072,7 +2072,7 @@ fn slash_in_old_span_does_not_deselect() { // or non-zero. assert_eq!(Staking::force_era(), Forcing::NotForcing); - assert!(>::exists(11)); + assert!(>::contains_key(11)); assert_ledger_consistent(11); }); } diff --git a/substrate/frame/support/src/storage/generator/double_map.rs b/substrate/frame/support/src/storage/generator/double_map.rs index 947235c4bd..ff73fdbedf 100644 --- a/substrate/frame/support/src/storage/generator/double_map.rs +++ b/substrate/frame/support/src/storage/generator/double_map.rs @@ -110,7 +110,7 @@ where Self::storage_double_map_final_key(k1, k2) } - fn exists(k1: KArg1, k2: KArg2) -> bool + fn contains_key(k1: KArg1, k2: KArg2) -> bool where KArg1: EncodeLike, KArg2: EncodeLike, diff --git a/substrate/frame/support/src/storage/generator/linked_map.rs b/substrate/frame/support/src/storage/generator/linked_map.rs index face87edf9..2d0df8fcc8 100644 --- a/substrate/frame/support/src/storage/generator/linked_map.rs +++ b/substrate/frame/support/src/storage/generator/linked_map.rs @@ -326,7 +326,7 @@ where type Enumerator = Enumerator; - fn exists>(key: KeyArg) -> bool { + fn contains_key>(key: KeyArg) -> bool { unhashed::exists(Self::storage_linked_map_final_key(key).as_ref()) } diff --git a/substrate/frame/support/src/storage/generator/map.rs b/substrate/frame/support/src/storage/generator/map.rs index 78f261e7da..c1d9f1b149 100644 --- a/substrate/frame/support/src/storage/generator/map.rs +++ b/substrate/frame/support/src/storage/generator/map.rs @@ -95,7 +95,7 @@ impl> storage::StorageMap } } - fn exists>(key: KeyArg) -> bool { + fn contains_key>(key: KeyArg) -> bool { unhashed::exists(Self::storage_map_final_key(key).as_ref()) } diff --git a/substrate/frame/support/src/storage/mod.rs b/substrate/frame/support/src/storage/mod.rs index f629ac3eb9..3eb1a6f116 100644 --- a/substrate/frame/support/src/storage/mod.rs +++ b/substrate/frame/support/src/storage/mod.rs @@ -126,7 +126,7 @@ pub trait StorageMap { fn hashed_key_for>(key: KeyArg) -> Vec; /// Does the value (explicitly) exist in storage? - fn exists>(key: KeyArg) -> bool; + fn contains_key>(key: KeyArg) -> bool; /// Load the value associated with the given key from the map. fn get>(key: KeyArg) -> Self::Query; @@ -176,7 +176,7 @@ pub trait StorageMap { /// `T` is required to implement `Codec::DecodeLength`. /// /// Note that `0` is returned as the default value if no encoded value exists at the given key. - /// Therefore, this function cannot be used as a sign of _existence_. use the `::exists()` + /// Therefore, this function cannot be used as a sign of _existence_. use the `::contains_key()` /// function for this purpose. fn decode_len>(key: KeyArg) -> Result where V: codec::DecodeLength + Len; @@ -196,7 +196,7 @@ pub trait StorageLinkedMap { type Enumerator: Iterator; /// Does the value (explicitly) exist in storage? - fn exists>(key: KeyArg) -> bool; + fn contains_key>(key: KeyArg) -> bool; /// Load the value associated with the given key from the map. fn get>(key: KeyArg) -> Self::Query; @@ -227,7 +227,7 @@ pub trait StorageLinkedMap { /// `T` is required to implement `Codec::DecodeLength`. /// /// Note that `0` is returned as the default value if no encoded value exists at the given key. - /// Therefore, this function cannot be used as a sign of _existence_. use the `::exists()` + /// Therefore, this function cannot be used as a sign of _existence_. use the `::contains_key()` /// function for this purpose. fn decode_len>(key: KeyArg) -> Result where V: codec::DecodeLength + Len; @@ -270,7 +270,7 @@ pub trait StorageDoubleMap { KArg1: EncodeLike, KArg2: EncodeLike; - fn exists(k1: KArg1, k2: KArg2) -> bool + fn contains_key(k1: KArg1, k2: KArg2) -> bool where KArg1: EncodeLike, KArg2: EncodeLike; @@ -348,7 +348,7 @@ pub trait StorageDoubleMap { /// `V` is required to implement `Codec::DecodeLength`. /// /// Note that `0` is returned as the default value if no encoded value exists at the given key. - /// Therefore, this function cannot be used as a sign of _existence_. use the `::exists()` + /// Therefore, this function cannot be used as a sign of _existence_. use the `::contains_key()` /// function for this purpose. fn decode_len(key1: KArg1, key2: KArg2) -> Result where diff --git a/substrate/frame/support/test/tests/instance.rs b/substrate/frame/support/test/tests/instance.rs index 2c761ca43e..4c509ae18f 100644 --- a/substrate/frame/support/test/tests/instance.rs +++ b/substrate/frame/support/test/tests/instance.rs @@ -348,8 +348,8 @@ fn storage_with_instance_basic_operation() { assert_eq!(Value::get(), 0); let key = 1; - assert_eq!(Map::exists(0), true); - assert_eq!(Map::exists(key), false); + assert_eq!(Map::contains_key(0), true); + assert_eq!(Map::contains_key(key), false); Map::insert(key, 1); assert_eq!(Map::get(key), 1); assert_eq!(Map::take(key), 1); @@ -357,11 +357,11 @@ fn storage_with_instance_basic_operation() { Map::mutate(key, |a| *a=2); assert_eq!(Map::get(key), 2); Map::remove(key); - assert_eq!(Map::exists(key), false); + assert_eq!(Map::contains_key(key), false); assert_eq!(Map::get(key), 0); - assert_eq!(LinkedMap::exists(0), true); - assert_eq!(LinkedMap::exists(key), false); + assert_eq!(LinkedMap::contains_key(0), true); + assert_eq!(LinkedMap::contains_key(key), false); LinkedMap::insert(key, vec![1]); assert_eq!(LinkedMap::enumerate().count(), 2); assert_eq!(LinkedMap::get(key), vec![1]); @@ -373,17 +373,17 @@ fn storage_with_instance_basic_operation() { assert_eq!(LinkedMap::get(key), vec![2]); LinkedMap::remove(key); assert_eq!(LinkedMap::enumerate().count(), 1); - assert_eq!(LinkedMap::exists(key), false); + assert_eq!(LinkedMap::contains_key(key), false); assert_eq!(LinkedMap::get(key), vec![]); - assert_eq!(LinkedMap::exists(key), false); + assert_eq!(LinkedMap::contains_key(key), false); assert_eq!(LinkedMap::enumerate().count(), 1); LinkedMap::insert(key, &vec![1]); assert_eq!(LinkedMap::enumerate().count(), 2); let key1 = 1; let key2 = 1; - assert_eq!(DoubleMap::exists(&0, &0), true); - assert_eq!(DoubleMap::exists(&key1, &key2), false); + assert_eq!(DoubleMap::contains_key(&0, &0), true); + assert_eq!(DoubleMap::contains_key(&key1, &key2), false); DoubleMap::insert(&key1, &key2, &1); assert_eq!(DoubleMap::get(&key1, &key2), 1); assert_eq!(DoubleMap::take(&key1, &key2), 1); diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index a0f3700c9d..03b5d48aad 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -1146,7 +1146,7 @@ impl SignedExtension for CheckEra { fn additional_signed(&self) -> Result { let current_u64 = >::block_number().saturated_into::(); let n = (self.0).0.birth(current_u64).saturated_into::(); - if !>::exists(n) { + if !>::contains_key(n) { Err(InvalidTransaction::AncientBirthBlock.into()) } else { Ok(>::block_hash(n)) diff --git a/substrate/frame/treasury/src/lib.rs b/substrate/frame/treasury/src/lib.rs index 0872bc718c..ef37cc12ee 100644 --- a/substrate/frame/treasury/src/lib.rs +++ b/substrate/frame/treasury/src/lib.rs @@ -371,7 +371,7 @@ decl_module! { fn approve_proposal(origin, #[compact] proposal_id: ProposalIndex) { T::ApproveOrigin::ensure_origin(origin)?; - ensure!(>::exists(proposal_id), Error::::InvalidProposalIndex); + ensure!(>::contains_key(proposal_id), Error::::InvalidProposalIndex); Approvals::mutate(|v| v.push(proposal_id)); } @@ -403,9 +403,9 @@ decl_module! { ensure!(reason.len() <= MAX_SENSIBLE_REASON_LENGTH, Error::::ReasonTooBig); let reason_hash = T::Hashing::hash(&reason[..]); - ensure!(!Reasons::::exists(&reason_hash), Error::::AlreadyKnown); + ensure!(!Reasons::::contains_key(&reason_hash), Error::::AlreadyKnown); let hash = T::Hashing::hash_of(&(&reason_hash, &who)); - ensure!(!Tips::::exists(&hash), Error::::AlreadyKnown); + ensure!(!Tips::::contains_key(&hash), Error::::AlreadyKnown); let deposit = T::TipReportDepositBase::get() + T::TipReportDepositPerByte::get() * (reason.len() as u32).into(); @@ -474,7 +474,7 @@ decl_module! { let tipper = ensure_signed(origin)?; ensure!(T::Tippers::contains(&tipper), BadOrigin); let reason_hash = T::Hashing::hash(&reason[..]); - ensure!(!Reasons::::exists(&reason_hash), Error::::AlreadyKnown); + ensure!(!Reasons::::contains_key(&reason_hash), Error::::AlreadyKnown); let hash = T::Hashing::hash_of(&(&reason_hash, &who)); Reasons::::insert(&reason_hash, &reason); diff --git a/substrate/frame/vesting/src/lib.rs b/substrate/frame/vesting/src/lib.rs index 4a079e7693..2a1ff12716 100644 --- a/substrate/frame/vesting/src/lib.rs +++ b/substrate/frame/vesting/src/lib.rs @@ -212,7 +212,7 @@ impl Module { /// (Re)set or remove the module's currency lock on `who`'s account in accordance with their /// current unvested amount. fn update_lock(who: T::AccountId) -> DispatchResult { - ensure!(Vesting::::exists(&who), Error::::NotVesting); + ensure!(Vesting::::contains_key(&who), Error::::NotVesting); let unvested = Self::vesting_balance(&who); if unvested.is_zero() { T::Currency::remove_lock(VESTING_ID, &who); @@ -257,7 +257,7 @@ impl VestingSchedule for Module where starting_block: T::BlockNumber ) -> DispatchResult { if locked.is_zero() { return Ok(()) } - if Vesting::::exists(who) { + if Vesting::::contains_key(who) { Err(Error::::ExistingVestingSchedule)? } let vesting_schedule = VestingInfo {