Skip to content

Commit

Permalink
Rename StorageMap::exists to ::contains_key (Resolves paritytech#4839) (
Browse files Browse the repository at this point in the history
paritytech#4847)

* rename StorageMap::exists(key) to ::contains_key(key)

* bump impl_version
  • Loading branch information
apopiak authored Feb 8, 2020
1 parent aa15e17 commit f123c29
Show file tree
Hide file tree
Showing 26 changed files with 100 additions and 100 deletions.
2 changes: 1 addition & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
2 changes: 1 addition & 1 deletion frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T, I>::exists(who)
!Account::<T, I>::contains_key(who)
}
}
2 changes: 1 addition & 1 deletion frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ decl_module! {

let proposal_hash = T::Hashing::hash_of(&proposal);

ensure!(!<ProposalOf<T, I>>::exists(proposal_hash), Error::<T, I>::DuplicateProposal);
ensure!(!<ProposalOf<T, I>>::contains_key(proposal_hash), Error::<T, I>::DuplicateProposal);

if threshold < 2 {
let seats = Self::members().len() as MemberCount;
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/account_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl<T: Trait> AccountDb<T> for DirectAccountDb {
<ContractInfoOf<T>>::get(account).and_then(|i| i.as_alive().map(|i| i.rent_allowance))
}
fn contract_exists(&self, account: &T::AccountId) -> bool {
<ContractInfoOf<T>>::exists(account)
<ContractInfoOf<T>>::contains_key(account)
}
fn get_balance(&self, account: &T::AccountId) -> BalanceOf<T> {
T::Currency::free_balance(account)
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ fn instantiate_and_call_and_deposit_event() {
]);

assert_ok!(creation);
assert!(ContractInfoOf::<Test>::exists(BOB));
assert!(ContractInfoOf::<Test>::contains_key(BOB));
});
}

Expand Down
18 changes: 9 additions & 9 deletions frame/democracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -537,7 +537,7 @@ decl_module! {

let info = Self::referendum_info(ref_index).ok_or(Error::<T>::BadIndex)?;
let h = info.proposal_hash;
ensure!(!<Cancellations<T>>::exists(h), Error::<T>::AlreadyCanceled);
ensure!(!<Cancellations<T>>::contains_key(h), Error::<T>::AlreadyCanceled);

<Cancellations<T>>::insert(h, true);
Self::clear_referendum(ref_index);
Expand Down Expand Up @@ -667,7 +667,7 @@ decl_module! {
#[weight = SimpleDispatchInfo::FixedNormal(100_000)]
fn set_proxy(origin, proxy: T::AccountId) {
let who = ensure_signed(origin)?;
ensure!(!<Proxy<T>>::exists(&proxy), Error::<T>::AlreadyProxy);
ensure!(!<Proxy<T>>::contains_key(&proxy), Error::<T>::AlreadyProxy);
<Proxy<T>>::insert(proxy, who)
}

Expand Down Expand Up @@ -725,7 +725,7 @@ decl_module! {
#[weight = SimpleDispatchInfo::FixedNormal(500_000)]
fn undelegate(origin) {
let who = ensure_signed(origin)?;
ensure!(<Delegations<T>>::exists(&who), Error::<T>::NotDelegated);
ensure!(<Delegations<T>>::contains_key(&who), Error::<T>::NotDelegated);
let (_, conviction) = <Delegations<T>>::take(&who);
// Indefinite lock is reduced to the maximum voting lock that could be possible.
let now = <frame_system::Module<T>>::block_number();
Expand Down Expand Up @@ -754,7 +754,7 @@ decl_module! {
fn note_preimage(origin, encoded_proposal: Vec<u8>) {
let who = ensure_signed(origin)?;
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
ensure!(!<Preimages<T>>::exists(&proposal_hash), Error::<T>::DuplicatePreimage);
ensure!(!<Preimages<T>>::contains_key(&proposal_hash), Error::<T>::DuplicatePreimage);

let deposit = <BalanceOf<T>>::from(encoded_proposal.len() as u32)
.saturating_mul(T::PreimageByteDeposit::get());
Expand All @@ -772,7 +772,7 @@ decl_module! {
fn note_imminent_preimage(origin, encoded_proposal: Vec<u8>) {
let who = ensure_signed(origin)?;
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
ensure!(!<Preimages<T>>::exists(&proposal_hash), Error::<T>::DuplicatePreimage);
ensure!(!<Preimages<T>>::contains_key(&proposal_hash), Error::<T>::DuplicatePreimage);
let queue = <DispatchQueue<T>>::get();
ensure!(queue.iter().any(|item| &item.1 == &proposal_hash), Error::<T>::NotImminent);

Expand Down Expand Up @@ -832,7 +832,7 @@ impl<T: Trait> Module<T> {

/// Return true if `ref_index` is an on-going referendum.
pub fn is_active_referendum(ref_index: ReferendumIndex) -> bool {
<ReferendumInfoOf<T>>::exists(ref_index)
<ReferendumInfoOf<T>>::contains_key(ref_index)
}

/// Get all referenda currently active.
Expand Down Expand Up @@ -913,7 +913,7 @@ impl<T: Trait> Module<T> {
if recursion_limit == 0 { return (Zero::zero(), Zero::zero()); }
<Delegations<T>>::enumerate()
.filter(|(delegator, (delegate, _))|
*delegate == to && !<VoteOf<T>>::exists(&(ref_index, delegator.clone()))
*delegate == to && !<VoteOf<T>>::contains_key(&(ref_index, delegator.clone()))
).fold(
(Zero::zero(), Zero::zero()),
|(votes_acc, turnout_acc), (delegator, (_delegate, max_conviction))| {
Expand Down Expand Up @@ -963,7 +963,7 @@ impl<T: Trait> Module<T> {
/// 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::<T>::ReferendumInvalid);
if !<VoteOf<T>>::exists((ref_index, &who)) {
if !<VoteOf<T>>::contains_key((ref_index, &who)) {
<VotersFor<T>>::append_or_insert(ref_index, &[&who][..]);
}
<VoteOf<T>>::insert((ref_index, &who), vote);
Expand Down
2 changes: 1 addition & 1 deletion frame/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ impl<T: Trait> Module<T> {
///
/// State: O(1).
fn is_voter(who: &T::AccountId) -> bool {
<StakeOf<T>>::exists(who)
<StakeOf<T>>::contains_key(who)
}

/// Check if `who` is currently an active member.
Expand Down
4 changes: 2 additions & 2 deletions frame/elections/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ decl_module! {
let who = ensure_signed(origin)?;

ensure!(!Self::presentation_active(), Error::<T>::CannotRetractPresenting);
ensure!(<VoterInfoOf<T>>::exists(&who), Error::<T>::RetractNonVoter);
ensure!(<VoterInfoOf<T>>::contains_key(&who), Error::<T>::RetractNonVoter);
let index = index as usize;
let voter = Self::voter_at(index).ok_or(Error::<T>::InvalidRetractionIndex)?;
ensure!(voter == who, Error::<T>::InvalidRetractionIndex);
Expand Down Expand Up @@ -730,7 +730,7 @@ impl<T: Trait> Module<T> {

/// If `who` a candidate at the moment?
pub fn is_a_candidate(who: &T::AccountId) -> bool {
<RegisterInfoOf<T>>::exists(who)
<RegisterInfoOf<T>>::contains_key(who)
}

/// Iff the member `who` still has a seat at blocknumber `n` returns `true`.
Expand Down
2 changes: 1 addition & 1 deletion frame/generic-asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ impl<T: Trait> Module<T> {
options: AssetOptions<T::Balance, T::AccountId>,
) -> DispatchResult {
let asset_id = if let Some(asset_id) = asset_id {
ensure!(!<TotalIssuance<T>>::exists(&asset_id), Error::<T>::IdAlreadyTaken);
ensure!(!<TotalIssuance<T>>::contains_key(&asset_id), Error::<T>::IdAlreadyTaken);
ensure!(asset_id < Self::next_asset_id(), Error::<T>::IdUnavailable);
asset_id
} else {
Expand Down
2 changes: 1 addition & 1 deletion frame/identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(<IdentityOf<T>>::exists(&sender), Error::<T>::NotFound);
ensure!(<IdentityOf<T>>::contains_key(&sender), Error::<T>::NotFound);
ensure!(subs.len() <= T::MaxSubAccounts::get() as usize, Error::<T>::TooManySubAccounts);

let (old_deposit, old_ids) = <SubsOf<T>>::get(&sender);
Expand Down
6 changes: 3 additions & 3 deletions frame/im-online/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ decl_module! {
ensure_none(origin)?;

let current_session = <pallet_session::Module<T>>::current_index();
let exists = <ReceivedHeartbeats>::exists(
let exists = <ReceivedHeartbeats>::contains_key(
&current_session,
&heartbeat.authority_index
);
Expand Down Expand Up @@ -398,7 +398,7 @@ impl<T: Trait> Module<T> {
fn is_online_aux(authority_index: AuthIndex, authority: &T::ValidatorId) -> bool {
let current_session = <pallet_session::Module<T>>::current_index();

<ReceivedHeartbeats>::exists(&current_session, &authority_index) ||
<ReceivedHeartbeats>::contains_key(&current_session, &authority_index) ||
<AuthoredBlocks<T>>::get(
&current_session,
authority,
Expand All @@ -409,7 +409,7 @@ impl<T: Trait> Module<T> {
/// the authorities series, during the current session. Otherwise `false`.
pub fn received_heartbeat_in_current_session(authority_index: AuthIndex) -> bool {
let current_session = <pallet_session::Module<T>>::current_index();
<ReceivedHeartbeats>::exists(&current_session, &authority_index)
<ReceivedHeartbeats>::contains_key(&current_session, &authority_index)
}

/// Note that the given authority has authored a block in the current session.
Expand Down
2 changes: 1 addition & 1 deletion frame/offences/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl<T: Trait> Module<T> {
for offender in offenders {
let report_id = Self::report_id::<O>(time_slot, &offender);

if !<Reports<T>>::exists(&report_id) {
if !<Reports<T>>::contains_key(&report_id) {
any_new = true;
<Reports<T>>::insert(
&report_id,
Expand Down
6 changes: 3 additions & 3 deletions frame/recovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ decl_module! {
) {
let who = ensure_signed(origin)?;
// Check account is not already set up for recovery
ensure!(!<Recoverable<T>>::exists(&who), Error::<T>::AlreadyRecoverable);
ensure!(!<Recoverable<T>>::contains_key(&who), Error::<T>::AlreadyRecoverable);
// Check user input is valid
ensure!(threshold >= 1, Error::<T>::ZeroThreshold);
ensure!(!friends.is_empty(), Error::<T>::NotEnoughFriends);
Expand Down Expand Up @@ -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!(<Recoverable<T>>::exists(&account), Error::<T>::NotRecoverable);
ensure!(<Recoverable<T>>::contains_key(&account), Error::<T>::NotRecoverable);
// Check that the recovery process has not already been started
ensure!(!<ActiveRecoveries<T>>::exists(&account, &who), Error::<T>::AlreadyStarted);
ensure!(!<ActiveRecoveries<T>>::contains_key(&account, &who), Error::<T>::AlreadyStarted);
// Take recovery deposit
let recovery_deposit = T::RecoveryDeposit::get();
T::Currency::reserve(&who, recovery_deposit)?;
Expand Down
6 changes: 3 additions & 3 deletions frame/recovery/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(!<ActiveRecoveries<Test>>::exists(&5, &1));
assert!(!<Recoverable<Test>>::exists(&5));
assert!(!<Recovered<Test>>::exists(&5));
assert!(!<ActiveRecoveries<Test>>::contains_key(&5, &1));
assert!(!<Recoverable<Test>>::contains_key(&5));
assert!(!<Recovered<Test>>::contains_key(&5));
});
}

Expand Down
2 changes: 1 addition & 1 deletion frame/scored-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(!<CandidateExists<T, I>>::exists(&who), Error::<T, I>::AlreadyInPool);
ensure!(!<CandidateExists<T, I>>::contains_key(&who), Error::<T, I>::AlreadyInPool);

let deposit = T::CandidateDeposit::get();
T::Currency::reserve(&who, deposit)?;
Expand Down
12 changes: 6 additions & 6 deletions frame/society/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ decl_module! {
#[weight = SimpleDispatchInfo::FixedNormal(50_000)]
pub fn bid(origin, value: BalanceOf<T, I>) -> DispatchResult {
let who = ensure_signed(origin)?;
ensure!(!<SuspendedCandidates<T, I>>::exists(&who), Error::<T, I>::Suspended);
ensure!(!<SuspendedMembers<T, I>>::exists(&who), Error::<T, I>::Suspended);
ensure!(!<SuspendedCandidates<T, I>>::contains_key(&who), Error::<T, I>::Suspended);
ensure!(!<SuspendedMembers<T, I>>::contains_key(&who), Error::<T, I>::Suspended);
let bids = <Bids<T, I>>::get();
ensure!(!Self::is_bid(&bids, &who), Error::<T, I>::AlreadyBid);
let candidates = <Candidates<T, I>>::get();
Expand Down Expand Up @@ -640,8 +640,8 @@ decl_module! {
pub fn vouch(origin, who: T::AccountId, value: BalanceOf<T, I>, tip: BalanceOf<T, I>) -> DispatchResult {
let voucher = ensure_signed(origin)?;
// Check user is not suspended.
ensure!(!<SuspendedCandidates<T, I>>::exists(&who), Error::<T, I>::Suspended);
ensure!(!<SuspendedMembers<T, I>>::exists(&who), Error::<T, I>::Suspended);
ensure!(!<SuspendedCandidates<T, I>>::contains_key(&who), Error::<T, I>::Suspended);
ensure!(!<SuspendedMembers<T, I>>::contains_key(&who), Error::<T, I>::Suspended);
// Check user is not a bid or candidate.
let bids = <Bids<T, I>>::get();
ensure!(!Self::is_bid(&bids, &who), Error::<T, I>::AlreadyBid);
Expand All @@ -652,7 +652,7 @@ decl_module! {
ensure!(!Self::is_member(&members, &who), Error::<T, I>::AlreadyMember);
// Check sender can vouch.
ensure!(Self::is_member(&members, &voucher), Error::<T, I>::NotMember);
ensure!(!<Vouching<T, I>>::exists(&voucher), Error::<T, I>::AlreadyVouching);
ensure!(!<Vouching<T, I>>::contains_key(&voucher), Error::<T, I>::AlreadyVouching);

<Vouching<T, I>>::insert(&voucher, VouchingStatus::Vouching);
Self::put_bid(bids, &who, value.clone(), BidKind::Vouch(voucher.clone(), tip));
Expand Down Expand Up @@ -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!(<SuspendedMembers<T, I>>::exists(&who), Error::<T, I>::NotSuspended);
ensure!(<SuspendedMembers<T, I>>::contains_key(&who), Error::<T, I>::NotSuspended);

if forgive {
// Try to add member back to society. Can fail with `MaxMembers` limit.
Expand Down
6 changes: 3 additions & 3 deletions frame/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,13 +887,13 @@ decl_module! {
) {
let stash = ensure_signed(origin)?;

if <Bonded<T>>::exists(&stash) {
if <Bonded<T>>::contains_key(&stash) {
Err(Error::<T>::AlreadyBonded)?
}

let controller = T::Lookup::lookup(controller)?;

if <Ledger<T>>::exists(&controller) {
if <Ledger<T>>::contains_key(&controller) {
Err(Error::<T>::AlreadyPaired)?
}

Expand Down Expand Up @@ -1139,7 +1139,7 @@ decl_module! {
let stash = ensure_signed(origin)?;
let old_controller = Self::bonded(&stash).ok_or(Error::<T>::NotStash)?;
let controller = T::Lookup::lookup(controller)?;
if <Ledger<T>>::exists(&controller) {
if <Ledger<T>>::contains_key(&controller) {
Err(Error::<T>::AlreadyPaired)?
}
if controller != old_controller {
Expand Down
Loading

0 comments on commit f123c29

Please sign in to comment.