Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove getters in fee-share. #1365

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
}