#![cfg_attr(not(feature = "std"), no_std)]
#![warn(unused_crate_dependencies)]
#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;
pub mod weights;
use frame_support::dispatch::PostDispatchInfo;
use sp_core::H160;
use sp_runtime::traits::Zero;
use sp_std::vec::Vec;
pub use pallet_evm::AddressMapping;
pub use self::{pallet::*, weights::WeightInfo};
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);
#[pallet::config]
pub trait Config: frame_system::Config {
type AddressMapping: AddressMapping<Self::AccountId>;
type WeightInfo: WeightInfo;
}
#[pallet::error]
pub enum Error<T> {
MaxAddressCountExceeded,
}
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(
<T as pallet::Config>::WeightInfo::hotfix_inc_account_sufficients(addresses.len().try_into().unwrap_or(u32::MAX))
)]
pub fn hotfix_inc_account_sufficients(
origin: OriginFor<T>,
addresses: Vec<H160>,
) -> DispatchResultWithPostInfo {
const MAX_ADDRESS_COUNT: usize = 1000;
frame_system::ensure_signed(origin)?;
ensure!(
addresses.len() <= MAX_ADDRESS_COUNT,
Error::<T>::MaxAddressCountExceeded
);
for address in addresses {
let account_id = T::AddressMapping::into_account_id(address);
let nonce = frame_system::Pallet::<T>::account_nonce(&account_id);
let refs = frame_system::Pallet::<T>::consumers(&account_id)
.saturating_add(frame_system::Pallet::<T>::providers(&account_id))
.saturating_add(frame_system::Pallet::<T>::sufficients(&account_id));
if !nonce.is_zero() && refs.is_zero() {
frame_system::Pallet::<T>::inc_sufficients(&account_id);
}
}
Ok(PostDispatchInfo {
actual_weight: None,
pays_fee: Pays::Yes,
})
}
}
}