difftreelog
panic marcos removed
in: master
2 files changed
README.mddiffbeforeafterboth109 "enable_println": "bool",109 "enable_println": "bool",110 "max_subject_len": "u32"110 "max_subject_len": "u32"111 },111 },112 "AccessMode": {113 "_enum": [114 "Normal",115 "WhiteList"116 ]117 },112 "CollectionMode": {118 "CollectionMode": {113 "_enum": {119 "_enum": {114 "Invalid": null,120 "Invalid": null,139 "CollectionType": {145 "CollectionType": {140 "Owner": "AccountId",146 "Owner": "AccountId",141 "Mode": "CollectionMode",147 "Mode": "CollectionMode",142 "Access": "u8",148 "Access": "AccessMode",143 "DecimalPoints": "u32",149 "DecimalPoints": "u32",144 "Name": "Vec<u16>",150 "Name": "Vec<u16>",145 "Description": "Vec<u16>",151 "Description": "Vec<u16>",155 "LookupSource": "AccountId",161 "LookupSource": "AccountId",156 "Weight": "u64"162 "Weight": "u64"157}163}164158```165```pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -475,10 +475,7 @@
let target_collection = <Collection<T>>::get(collection_id);
if !Self::is_owner_or_admin_permissions(collection_id, sender.clone()) {
- if target_collection.mint_mode == false {
- panic!("Collection is not in mint mode");
- }
-
+ ensure!(target_collection.mint_mode == true, "Collection is not in mint mode");
Self::check_white_list(collection_id, owner.clone())?;
}
@@ -628,26 +625,22 @@
let sender = ensure_signed(origin)?;
let approved_list_exists = <ApprovedList<T>>::contains_key(collection_id, (item_id, from.clone()));
- if approved_list_exists
- {
- Self::check_white_list(collection_id, from.clone())?;
- Self::check_white_list(collection_id, recipient.clone())?;
- let list_itm = <ApprovedList<T>>::get(collection_id, (item_id, from.clone()));
- let opt_item = list_itm.iter().find(|i| i.approved == sender.clone());
- ensure!(opt_item.is_some(), "No approve found");
- ensure!(opt_item.unwrap().amount >= value, "Requested value more than approved");
+ ensure!(approved_list_exists, "Only approved addresses can call this method");
- // remove approve
- let approve_list: Vec<ApprovePermissions<T::AccountId>> = <ApprovedList<T>>::get(collection_id, (item_id, from.clone()))
- .into_iter().filter(|i| i.approved != sender.clone()).collect();
- <ApprovedList<T>>::insert(collection_id, (item_id, from.clone()), approve_list);
- }
- else
- {
- panic!("Only approved addresses can call this method");
- }
+ Self::check_white_list(collection_id, from.clone())?;
+ Self::check_white_list(collection_id, recipient.clone())?;
+ let list_itm = <ApprovedList<T>>::get(collection_id, (item_id, from.clone()));
+ let opt_item = list_itm.iter().find(|i| i.approved == sender.clone());
+ ensure!(opt_item.is_some(), "No approve found");
+ ensure!(opt_item.unwrap().amount >= value, "Requested value more than approved");
+
+ // remove approve
+ let approve_list: Vec<ApprovePermissions<T::AccountId>> = <ApprovedList<T>>::get(collection_id, (item_id, from.clone()))
+ .into_iter().filter(|i| i.approved != sender.clone()).collect();
+ <ApprovedList<T>>::insert(collection_id, (item_id, from.clone()), approve_list);
+
let target_collection = <Collection<T>>::get(collection_id);
match target_collection.mode
@@ -872,11 +865,8 @@
Self::collection_exists(collection_id)?;
let result = Self::is_owner_or_admin_permissions(collection_id, subject.clone());
- if result == true {
- Ok(())
- } else {
- panic!("You do not have permissions to modify this collection")
- }
+ ensure!(result, "You do not have permissions to modify this collection");
+ Ok(())
}
fn is_item_owner(subject: T::AccountId, collection_id: u64, item_id: u64) -> bool {
@@ -902,15 +892,10 @@
fn check_white_list(collection_id: u64, address: T::AccountId) -> DispatchResult {
let mes = "Address is not in white list";
- if <WhiteList<T>>::contains_key(collection_id){
- let wl = <WhiteList<T>>::get(collection_id);
- if !wl.contains(&address.clone()) {
- panic!(mes);
- }
- }
- else {
- panic!(mes);
- }
+ ensure!(<WhiteList<T>>::contains_key(collection_id), mes);
+ let wl = <WhiteList<T>>::get(collection_id);
+ ensure!(wl.contains(&address.clone()), mes);
+
Ok(())
}