From 5068bb0570abe35ea5337debbcc3fcd3ede2231b Mon Sep 17 00:00:00 2001 From: jack Date: Tue, 2 Jul 2024 14:10:31 +0800 Subject: [PATCH 1/5] add max supply global state for inflation asset --- src/rgb20/wrapper.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/rgb20/wrapper.rs b/src/rgb20/wrapper.rs index 4bcaf37..66cfa80 100644 --- a/src/rgb20/wrapper.rs +++ b/src/rgb20/wrapper.rs @@ -251,6 +251,16 @@ impl Rgb20 { .sum() } + // max_supply for the inflation asset + pub fn max_supply(&self) -> Amount { + self.0 + .global("maxSupply") + .expect("RGB20 interface requires global `maxSupply`") + .iter() + .map(Amount::from_strict_val_unchecked) + .sum() + } + pub fn total_burned_supply(&self) -> Amount { self.0 .global("burnedSupply") From 9bc11c12543a337443fd8766b4ad65d1e9b145fd Mon Sep 17 00:00:00 2001 From: jack Date: Tue, 2 Jul 2024 15:12:30 +0800 Subject: [PATCH 2/5] fix add asset tag --- src/rgb20/issuer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rgb20/issuer.rs b/src/rgb20/issuer.rs index 61f36b4..8c8500b 100644 --- a/src/rgb20/issuer.rs +++ b/src/rgb20/issuer.rs @@ -270,7 +270,7 @@ impl PrimaryIssue { self.builder = self .builder .add_asset_tag("inflationAllowance", tag) - .expect("invalid RGB20 schema (max supply mismatch)"); + .expect("invalid RGB20 inflation allowance tag (inflation allowance mismatch)"); self.inflation = Some(supply) } } From 006d813a16cf1dff18a3dc9cb88c5586c1fcab96 Mon Sep 17 00:00:00 2001 From: jack Date: Tue, 2 Jul 2024 14:10:31 +0800 Subject: [PATCH 3/5] add max supply global state for inflation asset --- src/rgb20/wrapper.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/rgb20/wrapper.rs b/src/rgb20/wrapper.rs index 4bcaf37..66cfa80 100644 --- a/src/rgb20/wrapper.rs +++ b/src/rgb20/wrapper.rs @@ -251,6 +251,16 @@ impl Rgb20 { .sum() } + // max_supply for the inflation asset + pub fn max_supply(&self) -> Amount { + self.0 + .global("maxSupply") + .expect("RGB20 interface requires global `maxSupply`") + .iter() + .map(Amount::from_strict_val_unchecked) + .sum() + } + pub fn total_burned_supply(&self) -> Amount { self.0 .global("burnedSupply") From 902b87f3ddb26810772d06b1eea195f8b1d92687 Mon Sep 17 00:00:00 2001 From: jack Date: Thu, 4 Jul 2024 16:12:53 +0800 Subject: [PATCH 4/5] if there is no `max supply`, then default to `issued supply` --- src/rgb20/wrapper.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/rgb20/wrapper.rs b/src/rgb20/wrapper.rs index 66cfa80..1538e9f 100644 --- a/src/rgb20/wrapper.rs +++ b/src/rgb20/wrapper.rs @@ -251,11 +251,16 @@ impl Rgb20 { .sum() } - // max_supply for the inflation asset + // Max supply for the inflation asset, if there is no `max supply`, then it will + // default to the non-inflatable asset `issued supply` pub fn max_supply(&self) -> Amount { self.0 .global("maxSupply") - .expect("RGB20 interface requires global `maxSupply`") + .unwrap_or( + self.0 + .global("issuedSupply") + .expect("RGB20 interface requires global `issuedSupply`"), + ) .iter() .map(Amount::from_strict_val_unchecked) .sum() From 609a81cc5851c354f29310210c51e42a6f3653fd Mon Sep 17 00:00:00 2001 From: jack Date: Thu, 11 Jul 2024 17:26:20 +0800 Subject: [PATCH 5/5] unwrap_or to unwrap_or_else --- src/rgb20/wrapper.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rgb20/wrapper.rs b/src/rgb20/wrapper.rs index 1538e9f..2e9d5f4 100644 --- a/src/rgb20/wrapper.rs +++ b/src/rgb20/wrapper.rs @@ -256,11 +256,11 @@ impl Rgb20 { pub fn max_supply(&self) -> Amount { self.0 .global("maxSupply") - .unwrap_or( + .unwrap_or_else(|_| { self.0 .global("issuedSupply") - .expect("RGB20 interface requires global `issuedSupply`"), - ) + .expect("RGB20 interface requires global `issuedSupply`") + }) .iter() .map(Amount::from_strict_val_unchecked) .sum()