Skip to content

Commit

Permalink
Remove getter in fee-share (#1365)
Browse files Browse the repository at this point in the history
  • Loading branch information
MJLNSN authored Aug 14, 2024
1 parent 6da58e5 commit 53efdc6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
13 changes: 5 additions & 8 deletions pallets/fee-share/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ pub mod pallet {
}

#[pallet::storage]
#[pallet::getter(fn distribution_infos)]
pub type DistributionInfos<T: Config> =
StorageMap<_, Twox64Concat, DistributionId, Info<AccountIdOf<T>>>;

Expand All @@ -122,18 +121,16 @@ pub mod pallet {
}

#[pallet::storage]
#[pallet::getter(fn distribution_next_id)]
pub type DistributionNextId<T: Config> = StorageValue<_, DistributionId, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn auto_era)]
pub type AutoEra<T: Config> =
StorageValue<_, (BlockNumberFor<T>, BlockNumberFor<T>), ValueQuery>;

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_idle(bn: BlockNumberFor<T>, _remaining_weight: Weight) -> Weight {
let (era_length, next_era) = Self::auto_era();
let (era_length, next_era) = AutoEra::<T>::get();
if bn.eq(&next_era) {
for (distribution_id, info) in DistributionInfos::<T>::iter() {
if info.if_auto {
Expand Down Expand Up @@ -181,7 +178,7 @@ pub mod pallet {
.collect();
ensure!(total_proportion.is_one(), Error::<T>::NotSupportProportion);

let distribution_id = Self::distribution_next_id();
let distribution_id = DistributionNextId::<T>::get();
let receiving_address =
T::FeeSharePalletId::get().into_sub_account_truncating(distribution_id);
let info = Info {
Expand Down Expand Up @@ -211,7 +208,7 @@ pub mod pallet {
) -> DispatchResult {
T::ControlOrigin::ensure_origin(origin)?;

let mut info = Self::distribution_infos(distribution_id)
let mut info = DistributionInfos::<T>::get(distribution_id)
.ok_or(Error::<T>::DistributionNotExist)?;
if let Some(tokens_proportion) = tokens_proportion {
let mut total_proportion = Perbill::from_percent(0);
Expand Down Expand Up @@ -264,7 +261,7 @@ pub mod pallet {
) -> DispatchResult {
T::ControlOrigin::ensure_origin(origin)?;

if let Some(info) = Self::distribution_infos(distribution_id) {
if let Some(info) = DistributionInfos::<T>::get(distribution_id) {
Self::execute_distribute_inner(&info)?;
}

Expand All @@ -280,7 +277,7 @@ pub mod pallet {
) -> DispatchResult {
T::ControlOrigin::ensure_origin(origin)?;

if let Some(info) = Self::distribution_infos(distribution_id) {
if let Some(info) = DistributionInfos::<T>::get(distribution_id) {
Self::execute_distribute_inner(&info)?;
DistributionInfos::<T>::remove(distribution_id);
}
Expand Down
4 changes: 2 additions & 2 deletions pallets/fee-share/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ fn edit_delete_distribution() {
assert_ok!(FeeShare::execute_distribute(RuntimeOrigin::signed(ALICE), 0));
assert_eq!(Tokens::free_balance(KSM, &keeper), 0);

if let Some(infos) = FeeShare::distribution_infos(0) {
if let Some(infos) = DistributionInfos::<Runtime>::get(0) {
assert_eq!(infos.token_type, vec![KSM])
}
assert_ok!(FeeShare::delete_distribution(RuntimeOrigin::signed(ALICE), 0));
assert_eq!(FeeShare::distribution_infos(0), None);
assert_eq!(DistributionInfos::<Runtime>::get(0), None);
});
}

0 comments on commit 53efdc6

Please sign in to comment.