From 06b4ff5035cade00753cad283d7899c3dfef2d81 Mon Sep 17 00:00:00 2001 From: Kazunobu Ndong Date: Fri, 2 Dec 2022 22:23:51 +0900 Subject: [PATCH 1/4] Added the additional check --- pallets/asset_management/src/lib.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pallets/asset_management/src/lib.rs b/pallets/asset_management/src/lib.rs index c56bc28b..914bd14e 100644 --- a/pallets/asset_management/src/lib.rs +++ b/pallets/asset_management/src/lib.rs @@ -174,6 +174,8 @@ pub mod pallet { NotAnAssetAccount, /// The account is not a representative NotARepresentative, + /// Not an active Representative + NotAnActiveRepresentative, /// The asset is not linked to the representative AssetOutOfControl, /// The candidate is not a tenant @@ -184,19 +186,19 @@ pub mod pallet { TenantAssetNotLinked, /// Errors should have helpful documentation associated with them. StorageOverflow, - ///The proposal could not be created + /// The proposal could not be created FailedToCreateProposal, - ///This Preimage already exists + /// This Preimage already exists DuplicatePreimage, - ///Not an owner in the corresponding virtual account + /// Not an owner in the corresponding virtual account NotAnOwner, - ///The Asset Does not Exists + /// The Asset Does not Exists NotAnAsset, - ///This referendum does not exists + /// This referendum does not exists NotAValidReferendum, - ///This referendum is over + /// This referendum is over ReferendumCompleted, - ///Not enough funds in the account + /// Not enough funds in the account NotEnoughFunds, } @@ -453,7 +455,9 @@ pub mod pallet { // Ensure that the caller is a representative let rep = Roles::Pallet::::reps(caller.clone()); - ensure!(rep.is_some(), Error::::NotARepresentative); + let status = Roles::Pallet::::reps(caller.clone()).unwrap().activated; + ensure!(rep.clone().is_some(), Error::::NotARepresentative); + ensure!(status == true, Error::::NotAnActiveRepresentative); // Get the asset virtual account if exists let collection_id: T::NftCollectionId = asset_type.value().into(); From 45fa450cb34f7b7fde825fcc14d7963bd31b8032 Mon Sep 17 00:00:00 2001 From: Kazunobu Ndong Date: Sat, 3 Dec 2022 09:05:34 +0900 Subject: [PATCH 2/4] Changed check position according to review --- pallets/asset_management/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/asset_management/src/lib.rs b/pallets/asset_management/src/lib.rs index 914bd14e..ebdbf45c 100644 --- a/pallets/asset_management/src/lib.rs +++ b/pallets/asset_management/src/lib.rs @@ -454,9 +454,9 @@ pub mod pallet { let caller = ensure_signed(origin.clone())?; // Ensure that the caller is a representative - let rep = Roles::Pallet::::reps(caller.clone()); - let status = Roles::Pallet::::reps(caller.clone()).unwrap().activated; + let rep = Roles::Pallet::::reps(caller.clone()); ensure!(rep.clone().is_some(), Error::::NotARepresentative); + let status = Roles::Pallet::::reps(caller.clone()).unwrap().activated; ensure!(status == true, Error::::NotAnActiveRepresentative); // Get the asset virtual account if exists From 08f63c1c1581217cbdb1cb923247371c292531ba Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Fri, 2 Dec 2022 18:57:54 -0800 Subject: [PATCH 3/4] refactor --- pallets/asset_management/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pallets/asset_management/src/lib.rs b/pallets/asset_management/src/lib.rs index ebdbf45c..81dcdc21 100644 --- a/pallets/asset_management/src/lib.rs +++ b/pallets/asset_management/src/lib.rs @@ -455,9 +455,9 @@ pub mod pallet { // Ensure that the caller is a representative let rep = Roles::Pallet::::reps(caller.clone()); - ensure!(rep.clone().is_some(), Error::::NotARepresentative); - let status = Roles::Pallet::::reps(caller.clone()).unwrap().activated; - ensure!(status == true, Error::::NotAnActiveRepresentative); + ensure!(rep.is_some(), Error::::NotARepresentative); + let rep = rep.unwrap(); + ensure!(rep.activated, Error::::NotAnActiveRepresentative); // Get the asset virtual account if exists let collection_id: T::NftCollectionId = asset_type.value().into(); @@ -466,7 +466,7 @@ pub mod pallet { let asset_account = ownership.unwrap().virtual_account; ensure!( - rep.unwrap().assets_accounts.contains(&asset_account), + rep.assets_accounts.contains(&asset_account), Error::::AssetOutOfControl ); From 7d58305af33b803f42a37bfb57eab399738ae425 Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Fri, 2 Dec 2022 18:58:16 -0800 Subject: [PATCH 4/4] cargo fmt --- pallets/asset_management/src/lib.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pallets/asset_management/src/lib.rs b/pallets/asset_management/src/lib.rs index 81dcdc21..4f0b361a 100644 --- a/pallets/asset_management/src/lib.rs +++ b/pallets/asset_management/src/lib.rs @@ -454,7 +454,7 @@ pub mod pallet { let caller = ensure_signed(origin.clone())?; // Ensure that the caller is a representative - let rep = Roles::Pallet::::reps(caller.clone()); + let rep = Roles::Pallet::::reps(caller.clone()); ensure!(rep.is_some(), Error::::NotARepresentative); let rep = rep.unwrap(); ensure!(rep.activated, Error::::NotAnActiveRepresentative); @@ -465,10 +465,7 @@ pub mod pallet { ensure!(ownership.is_some(), Error::::NotAnAsset); let asset_account = ownership.unwrap().virtual_account; - ensure!( - rep.assets_accounts.contains(&asset_account), - Error::::AssetOutOfControl - ); + ensure!(rep.assets_accounts.contains(&asset_account), Error::::AssetOutOfControl); // Ensure that provided account is a valid tenant let tenant0 = Roles::Pallet::::tenants(tenant.clone());