Skip to content

Commit

Permalink
charge content owners based on pricing (fix bug)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raid5594 committed Aug 17, 2023
1 parent c638a3a commit a316d65
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pallets/ddc-accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use scale_info::TypeInfo;
use sp_runtime::{
traits::{AccountIdConversion, AtLeast32BitUnsigned, Saturating, Zero},
RuntimeDebug,
SaturatedConversion,
};

use sp_staking::EraIndex;
Expand Down Expand Up @@ -566,13 +567,14 @@ pub mod pallet {
// Charge payments from content owners
pub fn charge_payments_new(
paying_accounts: Vec<BucketsDetails<BalanceOf<T>>>,
pricing: u128,
) -> DispatchResult {
let mut total_charged = BalanceOf::<T>::zero();

for bucket_details in paying_accounts.iter() {
let bucket: Bucket<T::AccountId> = Self::buckets(bucket_details.bucket_id).unwrap();
let content_owner = bucket.owner_id;
let amount = bucket_details.amount;
let amount = bucket_details.amount * pricing.saturated_into::<BalanceOf<T>>();

let mut ledger = Self::ledger(&content_owner).ok_or(Error::<T>::NotController)?;
if ledger.active >= amount {
Expand Down
3 changes: 2 additions & 1 deletion pallets/ddc-validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ pub mod pallet {
Error::<T>::ContentOwnersDoubleSpend
);

<ddc_accounts::pallet::Pallet::<T>>::charge_payments_new(paying_accounts);
let pricing: u128 = <ddc_staking::pallet::Pallet::<T>>::pricing().unwrap();
<ddc_accounts::pallet::Pallet::<T>>::charge_payments_new(paying_accounts, pricing);

EraContentOwnersCharged::<T>::insert(era, controller, true);

Expand Down

0 comments on commit a316d65

Please sign in to comment.