git.delta.rocks / unique-network / refs/commits / 3356493153eb

difftreelog

fix combine init_collection fns

Daniel Shiposha2023-10-25parent: #30ec3c7.patch.diff
in: master

1 file changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
1156 debug_assert!(credit.peek().is_zero())1156 debug_assert!(credit.peek().is_zero())
1157 }1157 }
11581158
1159 {
1160 ensure!(
1161 data.token_prefix.len() <= MAX_TOKEN_PREFIX_LENGTH as usize,
1162 Error::<T>::CollectionTokenPrefixLimitExceeded
1163 );
1164 }
1165
1166 let created_count = <CreatedCollectionCount<T>>::get()
1167 .0
1168 .checked_add(1)
1169 .ok_or(ArithmeticError::Overflow)?;
1170 let destroyed_count = <DestroyedCollectionCount<T>>::get().0;
1171 let id = CollectionId(created_count);
1172
1173 // bound Total number of collections
1174 ensure!(
1175 created_count - destroyed_count <= COLLECTION_NUMBER_LIMIT,
1176 <Error<T>>::TotalCollectionsLimitExceeded
1177 );
1178
1179 // =========
1180
1181 let collection = Collection {
1182 owner: owner.as_sub().clone(),
1183 name: data.name,
1184 mode: data.mode.clone(),
1185 description: data.description,
1186 token_prefix: data.token_prefix,
1187 sponsorship: data
1188 .pending_sponsor
1189 .map(|sponsor| SponsorshipState::Unconfirmed(sponsor.as_sub().clone()))
1190 .unwrap_or_default(),
1191 limits: data
1192 .limits
1159 Self::init_collection_internal(owner, data)1193 .map(|limits| Self::clamp_limits(data.mode.clone(), &Default::default(), limits))
1194 .unwrap_or_else(|| Ok(CollectionLimits::default()))?,
1195 permissions: data
1196 .permissions
1197 .map(|permissions| {
1198 Self::clamp_permissions(data.mode.clone(), &Default::default(), permissions)
1199 })
1200 .unwrap_or_else(|| Ok(CollectionPermissions::default()))?,
1201 flags: data.flags,
1202 };
1203
1204 let mut collection_properties = CollectionPropertiesT::new();
1205 collection_properties
1206 .try_set_from_iter(data.properties.into_iter())
1207 .map_err(<Error<T>>::from)?;
1208
1209 CollectionProperties::<T>::insert(id, collection_properties);
1210
1211 let mut token_props_permissions = PropertiesPermissionMap::new();
1212 token_props_permissions
1213 .try_set_from_iter(data.token_property_permissions.into_iter())
1214 .map_err(<Error<T>>::from)?;
1215
1216 CollectionPropertyPermissions::<T>::insert(id, token_props_permissions);
1217
1218 let mut admin_amount = 0u32;
1219 for admin in data.admin_list.iter() {
1220 if !<IsAdmin<T>>::get((id, admin)) {
1221 <IsAdmin<T>>::insert((id, admin), true);
1222 admin_amount = admin_amount
1223 .checked_add(1)
1224 .ok_or(<Error<T>>::CollectionAdminCountExceeded)?;
1225 }
1226 }
1227 ensure!(
1228 admin_amount <= Self::collection_admins_limit(),
1229 <Error<T>>::CollectionAdminCountExceeded,
1230 );
1231 <AdminAmount<T>>::insert(id, admin_amount);
1232
1233 <CreatedCollectionCount<T>>::put(created_count);
1234 <Pallet<T>>::deposit_event(Event::CollectionCreated(
1235 id,
1236 data.mode.id(),
1237 owner.as_sub().clone(),
1238 ));
1239 <PalletEvm<T>>::deposit_log(
1240 erc::CollectionHelpersEvents::CollectionCreated {
1241 owner: *owner.as_eth(),
1242 collection_id: eth::collection_id_to_address(id),
1243 }
1244 .to_log(T::ContractAddress::get()),
1245 );
1246 <CollectionById<T>>::insert(id, collection);
1247 Ok(id)
1160 }1248 }
1161
1162 fn init_collection_internal(
1163 owner: T::CrossAccountId,
1164 data: CreateCollectionData<T::CrossAccountId>,
1165 ) -> Result<CollectionId, DispatchError> {
1166 {
1167 ensure!(
1168 data.token_prefix.len() <= MAX_TOKEN_PREFIX_LENGTH as usize,
1169 Error::<T>::CollectionTokenPrefixLimitExceeded
1170 );
1171 }
1172
1173 let created_count = <CreatedCollectionCount<T>>::get()
1174 .0
1175 .checked_add(1)
1176 .ok_or(ArithmeticError::Overflow)?;
1177 let destroyed_count = <DestroyedCollectionCount<T>>::get().0;
1178 let id = CollectionId(created_count);
1179
1180 // bound Total number of collections
1181 ensure!(
1182 created_count - destroyed_count <= COLLECTION_NUMBER_LIMIT,
1183 <Error<T>>::TotalCollectionsLimitExceeded
1184 );
1185
1186 // =========
1187
1188 let collection = Collection {
1189 owner: owner.as_sub().clone(),
1190 name: data.name,
1191 mode: data.mode.clone(),
1192 description: data.description,
1193 token_prefix: data.token_prefix,
1194 sponsorship: data
1195 .pending_sponsor
1196 .map(|sponsor| SponsorshipState::Unconfirmed(sponsor.as_sub().clone()))
1197 .unwrap_or_default(),
1198 limits: data
1199 .limits
1200 .map(|limits| Self::clamp_limits(data.mode.clone(), &Default::default(), limits))
1201 .unwrap_or_else(|| Ok(CollectionLimits::default()))?,
1202 permissions: data
1203 .permissions
1204 .map(|permissions| {
1205 Self::clamp_permissions(data.mode.clone(), &Default::default(), permissions)
1206 })
1207 .unwrap_or_else(|| Ok(CollectionPermissions::default()))?,
1208 flags: data.flags,
1209 };
1210
1211 let mut collection_properties = CollectionPropertiesT::new();
1212 collection_properties
1213 .try_set_from_iter(data.properties.into_iter())
1214 .map_err(<Error<T>>::from)?;
1215
1216 CollectionProperties::<T>::insert(id, collection_properties);
1217
1218 let mut token_props_permissions = PropertiesPermissionMap::new();
1219 token_props_permissions
1220 .try_set_from_iter(data.token_property_permissions.into_iter())
1221 .map_err(<Error<T>>::from)?;
1222
1223 CollectionPropertyPermissions::<T>::insert(id, token_props_permissions);
1224
1225 let mut admin_amount = 0u32;
1226 for admin in data.admin_list.iter() {
1227 if !<IsAdmin<T>>::get((id, admin)) {
1228 <IsAdmin<T>>::insert((id, admin), true);
1229 admin_amount = admin_amount
1230 .checked_add(1)
1231 .ok_or(<Error<T>>::CollectionAdminCountExceeded)?;
1232 }
1233 }
1234 ensure!(
1235 admin_amount <= Self::collection_admins_limit(),
1236 <Error<T>>::CollectionAdminCountExceeded,
1237 );
1238 <AdminAmount<T>>::insert(id, admin_amount);
1239
1240 <CreatedCollectionCount<T>>::put(created_count);
1241 <Pallet<T>>::deposit_event(Event::CollectionCreated(
1242 id,
1243 data.mode.id(),
1244 owner.as_sub().clone(),
1245 ));
1246 <PalletEvm<T>>::deposit_log(
1247 erc::CollectionHelpersEvents::CollectionCreated {
1248 owner: *owner.as_eth(),
1249 collection_id: eth::collection_id_to_address(id),
1250 }
1251 .to_log(T::ContractAddress::get()),
1252 );
1253 <CollectionById<T>>::insert(id, collection);
1254 Ok(id)
1255 }
12561249
1257 /// Destroy collection.1250 /// Destroy collection.
1258 ///1251 ///