From cb64a53563ac360688e10a8800e300b514871d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 24 Jan 2023 14:25:07 +0100 Subject: [PATCH 1/4] 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 --- frame/assets/src/benchmarking.rs | 2 +- frame/assets/src/functions.rs | 8 ++++++-- frame/assets/src/lib.rs | 2 +- 3 files changed, 8 insertions(+), 4 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..e962207133616 100644 --- a/frame/assets/src/functions.rs +++ b/frame/assets/src/functions.rs @@ -355,17 +355,21 @@ impl, I: 'static> Pallet { ensure!(check_issuer == details.issuer, Error::::NoPermission); } 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); + Ok(()) })?; + Self::deposit_event(Event::Issued { asset_id: id, owner: beneficiary.clone(), - total_supply: amount, + amount, }); + Ok(()) } diff --git a/frame/assets/src/lib.rs b/frame/assets/src/lib.rs index 93e416c3bec4c..6373f1709b166 100644 --- a/frame/assets/src/lib.rs +++ b/frame/assets/src/lib.rs @@ -445,7 +445,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, From 6b3a420bed331684eafe44f1ab8090c8e8585622 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 24 Jan 2023 22:14:24 +0000 Subject: [PATCH 2/4] ".git/.scripts/commands/fmt/fmt.sh" --- frame/assets/src/functions.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/frame/assets/src/functions.rs b/frame/assets/src/functions.rs index e962207133616..b540f02b87c82 100644 --- a/frame/assets/src/functions.rs +++ b/frame/assets/src/functions.rs @@ -354,21 +354,14 @@ impl, I: 'static> Pallet { if let Some(check_issuer) = maybe_check_issuer { ensure!(check_issuer == details.issuer, Error::::NoPermission); } - debug_assert!( - details.supply.checked_add(&amount).is_some(), - "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(), - amount, - }); + Self::deposit_event(Event::Issued { asset_id: id, owner: beneficiary.clone(), amount }); Ok(()) } From 839249a050f3d0d59078233237863f465dcf6f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 25 Jan 2023 11:16:10 +0100 Subject: [PATCH 3/4] Fix compilation --- frame/assets/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/assets/src/lib.rs b/frame/assets/src/lib.rs index 6373f1709b166..340adfaf10806 100644 --- a/frame/assets/src/lib.rs +++ b/frame/assets/src/lib.rs @@ -152,7 +152,7 @@ pub use types::*; use scale_info::TypeInfo; use sp_runtime::{ traits::{ - AtLeast32BitUnsigned, Bounded, CheckedAdd, CheckedSub, Saturating, StaticLookup, Zero, + AtLeast32BitUnsigned, CheckedAdd, CheckedSub, Saturating, StaticLookup, Zero, }, ArithmeticError, TokenError, }; @@ -427,7 +427,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); From 8225d1c6185be84e1bcabd715c8bba39031dd8b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 25 Jan 2023 12:07:03 +0100 Subject: [PATCH 4/4] FMT --- frame/assets/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frame/assets/src/lib.rs b/frame/assets/src/lib.rs index 340adfaf10806..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, CheckedAdd, CheckedSub, Saturating, StaticLookup, Zero, - }, + traits::{AtLeast32BitUnsigned, CheckedAdd, CheckedSub, Saturating, StaticLookup, Zero}, ArithmeticError, TokenError, }; use sp_std::{borrow::Borrow, prelude::*};