From 074ff19dbc4b08794d3ff0c1edbfe4102ccb61ae Mon Sep 17 00:00:00 2001 From: girazoki Date: Sat, 5 Feb 2022 12:06:44 +0100 Subject: [PATCH] maybe_total_supply in pallet-assets (#10799) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * maybe_total_supply in pallet-assets * Update frame/assets/src/functions.rs Co-authored-by: Bastian Köcher --- substrate/frame/assets/src/functions.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/substrate/frame/assets/src/functions.rs b/substrate/frame/assets/src/functions.rs index e02cc7c8bb..73804fc832 100644 --- a/substrate/frame/assets/src/functions.rs +++ b/substrate/frame/assets/src/functions.rs @@ -55,7 +55,12 @@ impl, I: 'static> Pallet { /// Get the total supply of an asset `id`. pub fn total_supply(id: T::AssetId) -> T::Balance { - Asset::::get(id).map(|x| x.supply).unwrap_or_else(Zero::zero) + Self::maybe_total_supply(id).unwrap_or_default() + } + + /// Get the total supply of an asset `id` if the asset exists. + pub fn maybe_total_supply(id: T::AssetId) -> Option { + Asset::::get(id).map(|x| x.supply) } pub(super) fn new_account(