Repository: paritytech/substrate
File: frame/system/src/lib.rs (Rust)

Code before:
	}

	/// True if the account has some outstanding consumer references.
	pub fn is_provider_required(who: &T::AccountId) -> bool {
		Account::<T>::get(who).consumers != 0
	}

	/// True if the account has no outstanding consumer references or more than one provider.
	pub fn can_dec_provider(who: &T::AccountId) -> bool {
		let a = Account::<T>::get(who);
		a.consumers == 0 || a.providers > 1
	}

	/// True if the account has at least one provider reference and adding `amount` consumer
	/// references would not take it above the the maximum.
	pub fn can_accrue_consumers(who: &T::AccountId, amount: u32) -> bool {
		let a = Account::<T>::get(who);
		match a.consumers.checked_add(amount) {
			Some(c) => a.providers > 0 && c <= T::MaxConsumers::max_consumers(),
			None => false,
		}
	}

	/// True if the account has at least one provider reference and fewer consumer references than
	/// the maximum.
	pub fn can_inc_consumer(who: &T::AccountId) -> bool {
		let a = Account::<T>::get(who);
		a.providers > 0 && a.consumers < T::MaxConsumers::max_consumers()
	}

	/// Deposits an event into this block's event record.
	///
	/// NOTE: Events not registered at the genesis block and quietly omitted.
	pub fn deposit_event(event: impl Into<T::RuntimeEvent>) {
		Self::deposit_event_indexed(&[], event.into());
	}

	/// Deposits an event into this block's event record adding this event
	/// to the corresponding topic indexes.
	///
	/// This will update storage entries that correspond to the specified topics.
	/// It is expected that light-clients could subscribe to this topics.
	///
	/// NOTE: Events not registered at the genesis block and quietly omitted.
	pub fn deposit_event_indexed(topics: &[T::Hash], event: T::RuntimeEvent) {
		let block_number = Self::block_number();
		// Don't populate events on genesis.
		if block_number.is_zero() {
			return
		}


Review comment (suggestion):
`can_accrue_consumer` is strictly more general than `can_inc_consumer`, so I was wondering whether we should modify the function body of the latter to call the former instead, i.e. have the body simply be `Self::can_accrue_consumers(who, 1)`.

Code after:
	}

	/// True if the account has some outstanding consumer references.
	pub fn is_provider_required(who: &T::AccountId) -> bool {
		Account::<T>::get(who).consumers != 0
	}

	/// True if the account has no outstanding consumer references or more than one provider.
	pub fn can_dec_provider(who: &T::AccountId) -> bool {
		let a = Account::<T>::get(who);
		a.consumers == 0 || a.providers > 1
	}

	/// True if the account has at least one provider reference and adding `amount` consumer
	/// references would not take it above the the maximum.
	pub fn can_accrue_consumers(who: &T::AccountId, amount: u32) -> bool {
		let a = Account::<T>::get(who);
		match a.consumers.checked_add(amount) {
			Some(c) => a.providers > 0 && c <= T::MaxConsumers::max_consumers(),
			None => false,
		}
	}

	/// True if the account has at least one provider reference and fewer consumer references than
	/// the maximum.
	pub fn can_inc_consumer(who: &T::AccountId) -> bool {
		Self::can_accrue_consumers(who, 1)
	}

	/// Deposits an event into this block's event record.
	///
	/// NOTE: Events not registered at the genesis block and quietly omitted.
	pub fn deposit_event(event: impl Into<T::RuntimeEvent>) {
		Self::deposit_event_indexed(&[], event.into());
	}

	/// Deposits an event into this block's event record adding this event
	/// to the corresponding topic indexes.
	///
	/// This will update storage entries that correspond to the specified topics.
	/// It is expected that light-clients could subscribe to this topics.
	///
	/// NOTE: Events not registered at the genesis block and quietly omitted.
	pub fn deposit_event_indexed(topics: &[T::Hash], event: T::RuntimeEvent) {
		let block_number = Self::block_number();
		// Don't populate events on genesis.
		if block_number.is_zero() {
			return
		}

		let phase = ExecutionPhase::<T>::get().unwrap_or_default();