Skip to content
Snippets Groups Projects
Commit dc65a0a3 authored by Éloïs's avatar Éloïs
Browse files

manual ud: not emit event if 0 UDs claimed

parent a1c03b00
No related branches found
No related tags found
1 merge request!83feat(runtime): create UDs manually with new call universalDividend.claim_uds
This commit is part of merge request !83. Comments created here will be created in the context of that merge request.
......@@ -274,38 +274,35 @@ pub mod pallet {
total_weight
}
fn do_claim_uds(who: &T::AccountId) -> DispatchResultWithPostInfo {
let (uds_count, uds_total) =
T::MembersStorage::try_mutate_exists(who, |maybe_first_eligible_ud| {
if let Some(FirstEligibleUd(Some(ref mut first_ud_index))) =
maybe_first_eligible_ud
{
let current_ud_index = CurrentUdIndex::<T>::get();
if first_ud_index.get() >= current_ud_index {
Ok((0, Zero::zero()))
} else {
let (uds_count, uds_total) = compute_claim_uds::compute_claim_uds(
current_ud_index,
first_ud_index.get(),
PastReevals::<T>::get().into_iter(),
);
let _ = core::mem::replace(
first_ud_index,
core::num::NonZeroU16::new(current_ud_index)
.expect("unrechable because current_ud_index is never zero."),
);
Ok((uds_count, uds_total))
}
T::MembersStorage::try_mutate_exists(who, |maybe_first_eligible_ud| {
if let Some(FirstEligibleUd(Some(ref mut first_ud_index))) = maybe_first_eligible_ud
{
let current_ud_index = CurrentUdIndex::<T>::get();
if first_ud_index.get() >= current_ud_index {
DispatchResultWithPostInfo::Ok(().into())
} else {
Err::<_, DispatchError>(Error::<T>::AccountNotAllowedToClaimUds.into())
let (uds_count, uds_total) = compute_claim_uds::compute_claim_uds(
current_ud_index,
first_ud_index.get(),
PastReevals::<T>::get().into_iter(),
);
let _ = core::mem::replace(
first_ud_index,
core::num::NonZeroU16::new(current_ud_index)
.expect("unrechable because current_ud_index is never zero."),
);
T::Currency::deposit_creating(who, uds_total);
Self::deposit_event(Event::UdsClaimed {
count: uds_count,
total: uds_total,
who: who.clone(),
});
Ok(().into())
}
})?;
T::Currency::deposit_creating(who, uds_total);
Self::deposit_event(Event::UdsClaimed {
count: uds_count,
total: uds_total,
who: who.clone(),
});
Ok(().into())
} else {
Err(Error::<T>::AccountNotAllowedToClaimUds.into())
}
})
}
fn do_transfer_ud(
origin: OriginFor<T>,
......
......@@ -15,7 +15,7 @@
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
use crate::mock::*;
use frame_support::{assert_err, assert_ok};
use frame_support::{assert_err, assert_ok, assert_storage_noop};
#[test]
fn test_claim_uds() {
......@@ -35,12 +35,7 @@ fn test_claim_uds() {
// Alice can claim UDs, but this should be a no-op.
run_to_block(1);
assert_ok!(UniversalDividend::claim_uds(Origin::signed(1)));
System::assert_has_event(Event::UniversalDividend(crate::Event::UdsClaimed {
count: 0,
total: 0,
who: 1,
}));
assert_storage_noop!(assert_ok!(UniversalDividend::claim_uds(Origin::signed(1))));
assert_eq!(Balances::free_balance(1), 0);
// Dave is not a member, he can't claim UDs
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment