From 0f56b13e984102c38159e0d000fd44162563da5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 25 Jan 2023 12:57:01 +0100 Subject: [PATCH] pallet-assets: Rename `total_supply` to `amount` (#13229) * pallet-assets: Rename `total_supply` to `amount` We are actually passing the `amount` on assets being minted and not the total supply. Closes: https://github.com/paritytech/substrate/issues/13210 * ".git/.scripts/commands/fmt/fmt.sh" * Fix compilation * FMT Co-authored-by: command-bot <> --- frame/assets/src/benchmarking.rs | 2 +- frame/assets/src/functions.rs | 15 ++++++--------- frame/assets/src/lib.rs | 8 +++----- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/frame/assets/src/benchmarking.rs b/frame/assets/src/benchmarking.rs index ede5b4e77fac6..235d1d9374504 100644 --- a/frame/assets/src/benchmarking.rs +++ b/frame/assets/src/benchmarking.rs @@ -220,7 +220,7 @@ benchmarks_instance_pallet! { let amount = T::Balance::from(100u32); }: _(SystemOrigin::Signed(caller.clone()), asset_id, caller_lookup, amount) verify { - assert_last_event::(Event::Issued { asset_id: asset_id.into(), owner: caller, total_supply: amount }.into()); + assert_last_event::(Event::Issued { asset_id: asset_id.into(), owner: caller, amount }.into()); } burn { diff --git a/frame/assets/src/functions.rs b/frame/assets/src/functions.rs index 2cdf2d7c4c8f6..b540f02b87c82 100644 --- a/frame/assets/src/functions.rs +++ b/frame/assets/src/functions.rs @@ -354,18 +354,15 @@ impl, I: 'static> Pallet { if let Some(check_issuer) = maybe_check_issuer { ensure!(check_issuer == details.issuer, Error::::NoPermission); } - debug_assert!( - T::Balance::max_value() - details.supply >= amount, - "checked in prep; qed" - ); + debug_assert!(details.supply.checked_add(&amount).is_some(), "checked in prep; qed"); + details.supply = details.supply.saturating_add(amount); + Ok(()) })?; - Self::deposit_event(Event::Issued { - asset_id: id, - owner: beneficiary.clone(), - total_supply: amount, - }); + + Self::deposit_event(Event::Issued { asset_id: id, owner: beneficiary.clone(), amount }); + Ok(()) } diff --git a/frame/assets/src/lib.rs b/frame/assets/src/lib.rs index 93e416c3bec4c..c2480a20636b0 100644 --- a/frame/assets/src/lib.rs +++ b/frame/assets/src/lib.rs @@ -151,9 +151,7 @@ pub use types::*; use scale_info::TypeInfo; use sp_runtime::{ - traits::{ - AtLeast32BitUnsigned, Bounded, CheckedAdd, CheckedSub, Saturating, StaticLookup, Zero, - }, + traits::{AtLeast32BitUnsigned, CheckedAdd, CheckedSub, Saturating, StaticLookup, Zero}, ArithmeticError, TokenError, }; use sp_std::{borrow::Borrow, prelude::*}; @@ -427,7 +425,7 @@ pub mod pallet { *amount, |details| -> DispatchResult { debug_assert!( - T::Balance::max_value() - details.supply >= *amount, + details.supply.checked_add(&amount).is_some(), "checked in prep; qed" ); details.supply = details.supply.saturating_add(*amount); @@ -445,7 +443,7 @@ pub mod pallet { /// Some asset class was created. Created { asset_id: T::AssetId, creator: T::AccountId, owner: T::AccountId }, /// Some assets were issued. - Issued { asset_id: T::AssetId, owner: T::AccountId, total_supply: T::Balance }, + Issued { asset_id: T::AssetId, owner: T::AccountId, amount: T::Balance }, /// Some assets were transferred. Transferred { asset_id: T::AssetId,