difftreelog
fix add create_multiple_items_common
in: master
1 file changed
pallets/fungible/src/lib.rsdiffbeforeafterboth428 }428 }429429430 /// Minting tokens for multiple IDs.430 /// Minting tokens for multiple IDs.431 /// It is a utility function used in [`create_multiple_items`][`Pallet::create_multiple_items`]431 /// See [`create_item`][`Pallet::create_item`] for more details.432 /// and [`create_multiple_items_foreign`][`Pallet::create_multiple_items_foreign`]432 pub fn create_multiple_items(433 pub fn create_multiple_items_common(433 collection: &FungibleHandle<T>,434 collection: &FungibleHandle<T>,434 sender: &T::CrossAccountId,435 sender: &T::CrossAccountId,435 data: BTreeMap<T::CrossAccountId, u128>,436 data: BTreeMap<T::CrossAccountId, u128>,436 nesting_budget: &dyn Budget,437 nesting_budget: &dyn Budget,437 ) -> DispatchResult {438 ) -> DispatchResult {438 // Foreign collection check439 ensure!(440 !<ForeignCollection<T>>::get(collection.id),441 <CommonError<T>>::NoPermission442 );443444 if !collection.is_owner_or_admin(sender) {445 ensure!(446 collection.permissions.mint_mode(),447 <CommonError<T>>::PublicMintingNotAllowed448 );449 collection.check_allowlist(sender)?;450451 for (owner, _) in data.iter() {452 collection.check_allowlist(owner)?;453 }454 }455456 let total_supply = data439 let total_supply = data457 .iter()440 .iter()511 }494 }512495513 /// Minting tokens for multiple IDs.496 /// Minting tokens for multiple IDs.514 /// See [`create_item_foreign`][`Pallet::create_item_foreign`] for more details.497 /// See [`create_item`][`Pallet::create_item`] for more details.515 pub fn create_multiple_items_foreign(498 pub fn create_multiple_items(516 collection: &FungibleHandle<T>,499 collection: &FungibleHandle<T>,517 sender: &T::CrossAccountId,500 sender: &T::CrossAccountId,518 data: BTreeMap<T::CrossAccountId, u128>,501 data: BTreeMap<T::CrossAccountId, u128>,519 nesting_budget: &dyn Budget,502 nesting_budget: &dyn Budget,520 ) -> DispatchResult {503 ) -> DispatchResult {521 let total_supply = data504 // Foreign collection check522 .iter()523 .map(|(_, v)| *v)524 .try_fold(<TotalSupply<T>>::get(collection.id), |acc, v| {505 ensure!(525 acc.checked_add(v)506 !<ForeignCollection<T>>::get(collection.id),507 <CommonError<T>>::NoPermission526 })508 );527 .ok_or(ArithmeticError::Overflow)?;509528510 if !collection.is_owner_or_admin(sender) {511 ensure!(512 collection.permissions.mint_mode(),513 <CommonError<T>>::PublicMintingNotAllowed529 let mut balances = data;514 );530 for (k, v) in balances.iter_mut() {515 collection.check_allowlist(sender)?;531 *v = <Balance<T>>::get((collection.id, &k))532 .checked_add(*v)533 .ok_or(ArithmeticError::Overflow)?;534 }535516536 for (to, _) in balances.iter() {517 for (owner, _) in data.iter() {537 <PalletStructure<T>>::check_nesting(538 sender.clone(),539 to,540 collection.id,518 collection.check_allowlist(owner)?;541 TokenId::default(),542 nesting_budget,543 )?;544 }519 }545520 }546 // =========521547548 <TotalSupply<T>>::insert(collection.id, total_supply);549 for (user, amount) in balances {550 <Balance<T>>::insert((collection.id, &user), amount);551 <PalletStructure<T>>::nest_if_sent_to_token_unchecked(552 &user,553 collection.id,554 TokenId::default(),555 );556 <PalletEvm<T>>::deposit_log(522 Self::create_multiple_items_common(557 ERC20Events::Transfer {558 from: H160::default(),559 to: *user.as_eth(),560 value: amount.into(),561 }562 .to_log(collection_id_to_address(collection.id)),563 );564 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(565 collection.id,523 collection,566 TokenId::default(),524 sender,567 user.clone(),525 data,568 amount,526 nesting_budget,569 ));527 )570 }571572 Ok(())573 }528 }529530 /// Minting tokens for multiple IDs.531 /// See [`create_item_foreign`][`Pallet::create_item_foreign`] for more details.532 pub fn create_multiple_items_foreign(533 collection: &FungibleHandle<T>,534 sender: &T::CrossAccountId,535 data: BTreeMap<T::CrossAccountId, u128>,536 nesting_budget: &dyn Budget,537 ) -> DispatchResult {538 Self::create_multiple_items_common(539 collection,540 sender,541 data,542 nesting_budget,543 )544 }574545575 fn set_allowance_unchecked(546 fn set_allowance_unchecked(576 collection: &FungibleHandle<T>,547 collection: &FungibleHandle<T>,