difftreelog
Merge pull request #421 from UniqueNetwork/release-v924011
in: master
Release v924011
6 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -553,65 +553,7 @@
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_runtime_upgrade() -> Weight {
- if StorageVersion::get::<Pallet<T>>() < StorageVersion::new(1) {
- use up_data_structs::{CollectionVersion1, CollectionVersion2};
- <CollectionById<T>>::translate::<CollectionVersion1<T::AccountId>, _>(|id, v| {
- let mut props = Vec::new();
- if !v.offchain_schema.is_empty() {
- props.push(Property {
- key: b"_old_offchainSchema".to_vec().try_into().unwrap(),
- value: v
- .offchain_schema
- .clone()
- .into_inner()
- .try_into()
- .expect("offchain schema too big"),
- });
- }
- if !v.variable_on_chain_schema.is_empty() {
- props.push(Property {
- key: b"_old_variableOnChainSchema".to_vec().try_into().unwrap(),
- value: v
- .variable_on_chain_schema
- .clone()
- .into_inner()
- .try_into()
- .expect("offchain schema too big"),
- });
- }
- if !v.const_on_chain_schema.is_empty() {
- props.push(Property {
- key: b"_old_constOnChainSchema".to_vec().try_into().unwrap(),
- value: v
- .const_on_chain_schema
- .clone()
- .into_inner()
- .try_into()
- .expect("offchain schema too big"),
- });
- }
- props.push(Property {
- key: b"_old_schemaVersion".to_vec().try_into().unwrap(),
- value: match v.schema_version {
- SchemaVersion::ImageURL => b"ImageUrl".as_slice(),
- SchemaVersion::Unique => b"Unique".as_slice(),
- }
- .to_vec()
- .try_into()
- .unwrap(),
- });
- Self::set_scoped_collection_properties(
- id,
- PropertyScope::None,
- props.into_iter(),
- )
- .expect("existing data larger than properties");
- let mut new = CollectionVersion2::from(v.clone());
- new.permissions.access = Some(v.access);
- new.permissions.mint_mode = Some(v.mint_mode);
- Some(new)
- });
- }
+ StorageVersion::new(1).put::<Pallet<T>>();
0
}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -183,61 +183,7 @@
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_runtime_upgrade() -> Weight {
- if StorageVersion::get::<Pallet<T>>() < StorageVersion::new(1) {
- let mut had_consts = BTreeSet::new();
- <TokenData<T>>::translate::<ItemDataVersion1<T::CrossAccountId>, _>(
- |(collection, token), v| {
- let mut props = vec![];
- if !v.const_data.is_empty() {
- props.push(Property {
- key: b"_old_constData".to_vec().try_into().unwrap(),
- value: v
- .const_data
- .clone()
- .into_inner()
- .try_into()
- .expect("const too long"),
- });
- had_consts.insert(collection);
- }
- if !v.variable_data.is_empty() {
- props.push(Property {
- key: b"_old_variableData".to_vec().try_into().unwrap(),
- value: v
- .variable_data
- .clone()
- .into_inner()
- .try_into()
- .expect("variable too long"),
- })
- }
- if !props.is_empty() {
- Self::set_scoped_token_properties(
- collection,
- token,
- PropertyScope::None,
- props.into_iter(),
- )
- .expect("existing token data exceeds property storage");
- }
- Some(<ItemDataVersion2<T::CrossAccountId>>::from(v))
- },
- );
- for collection in had_consts {
- <PalletCommon<T>>::set_property_permission_unchecked(
- collection,
- PropertyKeyPermission {
- key: b"_old_constData".to_vec().try_into().unwrap(),
- permission: PropertyPermission {
- mutable: false,
- collection_admin: true,
- token_owner: false,
- },
- },
- )
- .expect("failed to configure permission");
- }
- }
+ StorageVersion::new(1).put::<Pallet<T>>();
0
}
pallets/refungible/src/lib.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use frame_support::{ensure, BoundedVec};20use up_data_structs::{21 AccessMode, CollectionId, CustomDataLimit, MAX_REFUNGIBLE_PIECES, TokenId,22 CreateCollectionData, CreateRefungibleExData, mapping::TokenAddressMapping, budget::Budget,23};24use pallet_evm::account::CrossAccountId;25use pallet_common::{Error as CommonError, Event as CommonEvent, Pallet as PalletCommon};26use pallet_structure::Pallet as PalletStructure;27use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};28use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};29use core::ops::Deref;30use codec::{Encode, Decode, MaxEncodedLen};31use scale_info::TypeInfo;3233pub use pallet::*;34#[cfg(feature = "runtime-benchmarks")]35pub mod benchmarking;36pub mod common;37pub mod erc;38pub mod weights;39pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;4041#[struct_versioning::versioned(version = 2, upper)]42#[derive(Encode, Decode, Default, TypeInfo, MaxEncodedLen)]43pub struct ItemData {44 pub const_data: BoundedVec<u8, CustomDataLimit>,4546 #[version(..2)]47 pub variable_data: BoundedVec<u8, CustomDataLimit>,48}4950#[frame_support::pallet]51pub mod pallet {52 use super::*;53 use frame_support::{54 Blake2_128, Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key,55 traits::StorageVersion,56 };57 use frame_system::pallet_prelude::*;58 use up_data_structs::{CollectionId, TokenId};59 use super::weights::WeightInfo;6061 #[pallet::error]62 pub enum Error<T> {63 /// Not Refungible item data used to mint in Refungible collection.64 NotRefungibleDataUsedToMintFungibleCollectionToken,65 /// Maximum refungibility exceeded66 WrongRefungiblePieces,67 /// Refungible token can't be repartitioned by user who isn't owns all pieces68 RepartitionWhileNotOwningAllPieces,69 /// Refungible token can't nest other tokens70 RefungibleDisallowsNesting,71 /// Setting item properties is not allowed72 SettingPropertiesNotAllowed,73 }7475 #[pallet::config]76 pub trait Config:77 frame_system::Config + pallet_common::Config + pallet_structure::Config78 {79 type WeightInfo: WeightInfo;80 }8182 const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);8384 #[pallet::pallet]85 #[pallet::storage_version(STORAGE_VERSION)]86 #[pallet::generate_store(pub(super) trait Store)]87 pub struct Pallet<T>(_);8889 #[pallet::storage]90 pub type TokensMinted<T: Config> =91 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;92 #[pallet::storage]93 pub type TokensBurnt<T: Config> =94 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;9596 #[pallet::storage]97 pub type TokenData<T: Config> = StorageNMap<98 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),99 Value = ItemData,100 QueryKind = ValueQuery,101 >;102103 #[pallet::storage]104 pub type TotalSupply<T: Config> = StorageNMap<105 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),106 Value = u128,107 QueryKind = ValueQuery,108 >;109110 /// Used to enumerate tokens owned by account111 #[pallet::storage]112 pub type Owned<T: Config> = StorageNMap<113 Key = (114 Key<Twox64Concat, CollectionId>,115 Key<Blake2_128Concat, T::CrossAccountId>,116 Key<Twox64Concat, TokenId>,117 ),118 Value = bool,119 QueryKind = ValueQuery,120 >;121122 #[pallet::storage]123 pub type AccountBalance<T: Config> = StorageNMap<124 Key = (125 Key<Twox64Concat, CollectionId>,126 // Owner127 Key<Blake2_128Concat, T::CrossAccountId>,128 ),129 Value = u32,130 QueryKind = ValueQuery,131 >;132133 #[pallet::storage]134 pub type Balance<T: Config> = StorageNMap<135 Key = (136 Key<Twox64Concat, CollectionId>,137 Key<Twox64Concat, TokenId>,138 // Owner139 Key<Blake2_128Concat, T::CrossAccountId>,140 ),141 Value = u128,142 QueryKind = ValueQuery,143 >;144145 #[pallet::storage]146 pub type Allowance<T: Config> = StorageNMap<147 Key = (148 Key<Twox64Concat, CollectionId>,149 Key<Twox64Concat, TokenId>,150 // Owner151 Key<Blake2_128, T::CrossAccountId>,152 // Spender153 Key<Blake2_128Concat, T::CrossAccountId>,154 ),155 Value = u128,156 QueryKind = ValueQuery,157 >;158159 #[pallet::hooks]160 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {161 fn on_runtime_upgrade() -> Weight {162 if StorageVersion::get::<Pallet<T>>() < StorageVersion::new(1) {163 <TokenData<T>>::translate_values::<ItemDataVersion1, _>(|v| {164 Some(<ItemDataVersion2>::from(v))165 })166 }167168 0169 }170 }171}172173pub struct RefungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);174impl<T: Config> RefungibleHandle<T> {175 pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {176 Self(inner)177 }178 pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {179 self.0180 }181}182impl<T: Config> Deref for RefungibleHandle<T> {183 type Target = pallet_common::CollectionHandle<T>;184185 fn deref(&self) -> &Self::Target {186 &self.0187 }188}189190impl<T: Config> Pallet<T> {191 pub fn total_supply(collection: &RefungibleHandle<T>) -> u32 {192 <TokensMinted<T>>::get(collection.id) - <TokensBurnt<T>>::get(collection.id)193 }194 pub fn token_exists(collection: &RefungibleHandle<T>, token: TokenId) -> bool {195 <TotalSupply<T>>::contains_key((collection.id, token))196 }197}198199// unchecked calls skips any permission checks200impl<T: Config> Pallet<T> {201 pub fn init_collection(202 owner: T::CrossAccountId,203 data: CreateCollectionData<T::AccountId>,204 ) -> Result<CollectionId, DispatchError> {205 <PalletCommon<T>>::init_collection(owner, data, false)206 }207 pub fn destroy_collection(208 collection: RefungibleHandle<T>,209 sender: &T::CrossAccountId,210 ) -> DispatchResult {211 let id = collection.id;212213 if Self::collection_has_tokens(id) {214 return Err(<CommonError<T>>::CantDestroyNotEmptyCollection.into());215 }216217 // =========218219 PalletCommon::destroy_collection(collection.0, sender)?;220221 <TokensMinted<T>>::remove(id);222 <TokensBurnt<T>>::remove(id);223 <TokenData<T>>::remove_prefix((id,), None);224 <TotalSupply<T>>::remove_prefix((id,), None);225 <Balance<T>>::remove_prefix((id,), None);226 <Allowance<T>>::remove_prefix((id,), None);227 <Owned<T>>::remove_prefix((id,), None);228 <AccountBalance<T>>::remove_prefix((id,), None);229 Ok(())230 }231232 fn collection_has_tokens(collection_id: CollectionId) -> bool {233 <TokenData<T>>::iter_prefix((collection_id,))234 .next()235 .is_some()236 }237238 pub fn burn_token(collection: &RefungibleHandle<T>, token_id: TokenId) -> DispatchResult {239 let burnt = <TokensBurnt<T>>::get(collection.id)240 .checked_add(1)241 .ok_or(ArithmeticError::Overflow)?;242243 <TokensBurnt<T>>::insert(collection.id, burnt);244 <TokenData<T>>::remove((collection.id, token_id));245 <TotalSupply<T>>::remove((collection.id, token_id));246 <Balance<T>>::remove_prefix((collection.id, token_id), None);247 <Allowance<T>>::remove_prefix((collection.id, token_id), None);248 // TODO: ERC721 transfer event249 Ok(())250 }251252 pub fn burn(253 collection: &RefungibleHandle<T>,254 owner: &T::CrossAccountId,255 token: TokenId,256 amount: u128,257 ) -> DispatchResult {258 let total_supply = <TotalSupply<T>>::get((collection.id, token))259 .checked_sub(amount)260 .ok_or(<CommonError<T>>::TokenValueTooLow)?;261262 // This was probally last owner of this token?263 if total_supply == 0 {264 // Ensure user actually owns this amount265 ensure!(266 <Balance<T>>::get((collection.id, token, owner)) == amount,267 <CommonError<T>>::TokenValueTooLow268 );269 let account_balance = <AccountBalance<T>>::get((collection.id, owner))270 .checked_sub(1)271 // Should not occur272 .ok_or(ArithmeticError::Underflow)?;273274 // =========275276 <Owned<T>>::remove((collection.id, owner, token));277 <PalletStructure<T>>::unnest_if_nested(owner, collection.id, token);278 <AccountBalance<T>>::insert((collection.id, owner), account_balance);279 Self::burn_token(collection, token)?;280 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(281 collection.id,282 token,283 owner.clone(),284 amount,285 ));286 return Ok(());287 }288289 let balance = <Balance<T>>::get((collection.id, token, owner))290 .checked_sub(amount)291 .ok_or(<CommonError<T>>::TokenValueTooLow)?;292 let account_balance = if balance == 0 {293 <AccountBalance<T>>::get((collection.id, owner))294 .checked_sub(1)295 // Should not occur296 .ok_or(ArithmeticError::Underflow)?297 } else {298 0299 };300301 // =========302303 if balance == 0 {304 <Owned<T>>::remove((collection.id, owner, token));305 <PalletStructure<T>>::unnest_if_nested(owner, collection.id, token);306 <Balance<T>>::remove((collection.id, token, owner));307 <AccountBalance<T>>::insert((collection.id, owner), account_balance);308 } else {309 <Balance<T>>::insert((collection.id, token, owner), balance);310 }311 <TotalSupply<T>>::insert((collection.id, token), total_supply);312 // TODO: ERC20 transfer event313 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(314 collection.id,315 token,316 owner.clone(),317 amount,318 ));319 Ok(())320 }321322 pub fn transfer(323 collection: &RefungibleHandle<T>,324 from: &T::CrossAccountId,325 to: &T::CrossAccountId,326 token: TokenId,327 amount: u128,328 nesting_budget: &dyn Budget,329 ) -> DispatchResult {330 ensure!(331 collection.limits.transfers_enabled(),332 <CommonError<T>>::TransferNotAllowed333 );334335 if collection.permissions.access() == AccessMode::AllowList {336 collection.check_allowlist(from)?;337 collection.check_allowlist(to)?;338 }339 <PalletCommon<T>>::ensure_correct_receiver(to)?;340341 let balance_from = <Balance<T>>::get((collection.id, token, from))342 .checked_sub(amount)343 .ok_or(<CommonError<T>>::TokenValueTooLow)?;344 let mut create_target = false;345 let from_to_differ = from != to;346 let balance_to = if from != to {347 let old_balance = <Balance<T>>::get((collection.id, token, to));348 if old_balance == 0 {349 create_target = true;350 }351 Some(352 old_balance353 .checked_add(amount)354 .ok_or(ArithmeticError::Overflow)?,355 )356 } else {357 None358 };359360 let account_balance_from = if balance_from == 0 {361 Some(362 <AccountBalance<T>>::get((collection.id, from))363 .checked_sub(1)364 // Should not occur365 .ok_or(ArithmeticError::Underflow)?,366 )367 } else {368 None369 };370 // Account data is created in token, AccountBalance should be increased371 // But only if from != to as we shouldn't check overflow in this case372 let account_balance_to = if create_target && from_to_differ {373 let account_balance_to = <AccountBalance<T>>::get((collection.id, to))374 .checked_add(1)375 .ok_or(ArithmeticError::Overflow)?;376 ensure!(377 account_balance_to < collection.limits.account_token_ownership_limit(),378 <CommonError<T>>::AccountTokenLimitExceeded,379 );380381 Some(account_balance_to)382 } else {383 None384 };385386 // =========387388 <PalletStructure<T>>::nest_if_sent_to_token(389 from.clone(),390 to,391 collection.id,392 token,393 nesting_budget,394 )?;395396 if let Some(balance_to) = balance_to {397 // from != to398 if balance_from == 0 {399 <Balance<T>>::remove((collection.id, token, from));400 <PalletStructure<T>>::unnest_if_nested(from, collection.id, token);401 } else {402 <Balance<T>>::insert((collection.id, token, from), balance_from);403 }404 <Balance<T>>::insert((collection.id, token, to), balance_to);405 if let Some(account_balance_from) = account_balance_from {406 <AccountBalance<T>>::insert((collection.id, from), account_balance_from);407 <Owned<T>>::remove((collection.id, from, token));408 }409 if let Some(account_balance_to) = account_balance_to {410 <AccountBalance<T>>::insert((collection.id, to), account_balance_to);411 <Owned<T>>::insert((collection.id, to, token), true);412 }413 }414415 // TODO: ERC20 transfer event416 <PalletCommon<T>>::deposit_event(CommonEvent::Transfer(417 collection.id,418 token,419 from.clone(),420 to.clone(),421 amount,422 ));423 Ok(())424 }425426 pub fn create_multiple_items(427 collection: &RefungibleHandle<T>,428 sender: &T::CrossAccountId,429 data: Vec<CreateRefungibleExData<T::CrossAccountId>>,430 nesting_budget: &dyn Budget,431 ) -> DispatchResult {432 if !collection.is_owner_or_admin(sender) {433 ensure!(434 collection.permissions.mint_mode(),435 <CommonError<T>>::PublicMintingNotAllowed436 );437 collection.check_allowlist(sender)?;438439 for item in data.iter() {440 for user in item.users.keys() {441 collection.check_allowlist(user)?;442 }443 }444 }445446 for item in data.iter() {447 for (owner, _) in item.users.iter() {448 <PalletCommon<T>>::ensure_correct_receiver(owner)?;449 }450 }451452 // Total pieces per tokens453 let totals = data454 .iter()455 .map(|data| {456 Ok(data457 .users458 .iter()459 .map(|u| u.1)460 .try_fold(0u128, |acc, v| acc.checked_add(*v))461 .ok_or(ArithmeticError::Overflow)?)462 })463 .collect::<Result<Vec<_>, DispatchError>>()?;464 for total in &totals {465 ensure!(466 *total <= MAX_REFUNGIBLE_PIECES,467 <Error<T>>::WrongRefungiblePieces468 );469 }470471 let first_token_id = <TokensMinted<T>>::get(collection.id);472 let tokens_minted = first_token_id473 .checked_add(data.len() as u32)474 .ok_or(ArithmeticError::Overflow)?;475 ensure!(476 tokens_minted < collection.limits.token_limit(),477 <CommonError<T>>::CollectionTokenLimitExceeded478 );479480 let mut balances = BTreeMap::new();481 for data in &data {482 for owner in data.users.keys() {483 let balance = balances484 .entry(owner)485 .or_insert_with(|| <AccountBalance<T>>::get((collection.id, owner)));486 *balance = balance.checked_add(1).ok_or(ArithmeticError::Overflow)?;487488 ensure!(489 *balance <= collection.limits.account_token_ownership_limit(),490 <CommonError<T>>::AccountTokenLimitExceeded,491 );492 }493 }494495 for (i, token) in data.iter().enumerate() {496 let token_id = TokenId(first_token_id + i as u32 + 1);497 for (to, _) in token.users.iter() {498 <PalletStructure<T>>::check_nesting(499 sender.clone(),500 to,501 collection.id,502 token_id,503 nesting_budget,504 )?;505 }506 }507508 // =========509510 <TokensMinted<T>>::insert(collection.id, tokens_minted);511 for (account, balance) in balances {512 <AccountBalance<T>>::insert((collection.id, account), balance);513 }514 for (i, token) in data.into_iter().enumerate() {515 let token_id = first_token_id + i as u32 + 1;516 <TotalSupply<T>>::insert((collection.id, token_id), totals[i]);517518 <TokenData<T>>::insert(519 (collection.id, token_id),520 ItemData {521 const_data: token.const_data,522 },523 );524525 for (user, amount) in token.users.into_iter() {526 if amount == 0 {527 continue;528 }529 <Balance<T>>::insert((collection.id, token_id, &user), amount);530 <Owned<T>>::insert((collection.id, &user, TokenId(token_id)), true);531 <PalletStructure<T>>::nest_if_sent_to_token_unchecked(532 &user,533 collection.id,534 TokenId(token_id),535 );536537 // TODO: ERC20 transfer event538 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(539 collection.id,540 TokenId(token_id),541 user,542 amount,543 ));544 }545 }546 Ok(())547 }548549 pub fn set_allowance_unchecked(550 collection: &RefungibleHandle<T>,551 sender: &T::CrossAccountId,552 spender: &T::CrossAccountId,553 token: TokenId,554 amount: u128,555 ) {556 if amount == 0 {557 <Allowance<T>>::remove((collection.id, token, sender, spender));558 } else {559 <Allowance<T>>::insert((collection.id, token, sender, spender), amount);560 }561 // TODO: ERC20 approval event562 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(563 collection.id,564 token,565 sender.clone(),566 spender.clone(),567 amount,568 ))569 }570571 pub fn set_allowance(572 collection: &RefungibleHandle<T>,573 sender: &T::CrossAccountId,574 spender: &T::CrossAccountId,575 token: TokenId,576 amount: u128,577 ) -> DispatchResult {578 if collection.permissions.access() == AccessMode::AllowList {579 collection.check_allowlist(sender)?;580 collection.check_allowlist(spender)?;581 }582583 <PalletCommon<T>>::ensure_correct_receiver(spender)?;584585 if <Balance<T>>::get((collection.id, token, sender)) < amount {586 ensure!(587 collection.ignores_owned_amount(sender) && Self::token_exists(collection, token),588 <CommonError<T>>::CantApproveMoreThanOwned589 );590 }591592 // =========593594 Self::set_allowance_unchecked(collection, sender, spender, token, amount);595 Ok(())596 }597598 /// Returns allowance, which should be set after transaction599 fn check_allowed(600 collection: &RefungibleHandle<T>,601 spender: &T::CrossAccountId,602 from: &T::CrossAccountId,603 token: TokenId,604 amount: u128,605 nesting_budget: &dyn Budget,606 ) -> Result<Option<u128>, DispatchError> {607 if spender.conv_eq(from) {608 return Ok(None);609 }610 if collection.permissions.access() == AccessMode::AllowList {611 // `from`, `to` checked in [`transfer`]612 collection.check_allowlist(spender)?;613 }614 if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {615 // TODO: should collection owner be allowed to perform this transfer?616 ensure!(617 <PalletStructure<T>>::check_indirectly_owned(618 spender.clone(),619 source.0,620 source.1,621 None,622 nesting_budget623 )?,624 <CommonError<T>>::ApprovedValueTooLow,625 );626 return Ok(None);627 }628 let allowance =629 <Allowance<T>>::get((collection.id, token, from, &spender)).checked_sub(amount);630 if allowance.is_none() {631 ensure!(632 collection.ignores_allowance(spender),633 <CommonError<T>>::ApprovedValueTooLow634 );635 }636 Ok(allowance)637 }638639 pub fn transfer_from(640 collection: &RefungibleHandle<T>,641 spender: &T::CrossAccountId,642 from: &T::CrossAccountId,643 to: &T::CrossAccountId,644 token: TokenId,645 amount: u128,646 nesting_budget: &dyn Budget,647 ) -> DispatchResult {648 let allowance =649 Self::check_allowed(collection, spender, from, token, amount, nesting_budget)?;650651 // =========652653 Self::transfer(collection, from, to, token, amount, nesting_budget)?;654 if let Some(allowance) = allowance {655 Self::set_allowance_unchecked(collection, from, spender, token, allowance);656 }657 Ok(())658 }659660 pub fn burn_from(661 collection: &RefungibleHandle<T>,662 spender: &T::CrossAccountId,663 from: &T::CrossAccountId,664 token: TokenId,665 amount: u128,666 nesting_budget: &dyn Budget,667 ) -> DispatchResult {668 let allowance =669 Self::check_allowed(collection, spender, from, token, amount, nesting_budget)?;670671 // =========672673 Self::burn(collection, from, token, amount)?;674 if let Some(allowance) = allowance {675 Self::set_allowance_unchecked(collection, from, spender, token, allowance);676 }677 Ok(())678 }679680 /// Delegated to `create_multiple_items`681 pub fn create_item(682 collection: &RefungibleHandle<T>,683 sender: &T::CrossAccountId,684 data: CreateRefungibleExData<T::CrossAccountId>,685 nesting_budget: &dyn Budget,686 ) -> DispatchResult {687 Self::create_multiple_items(collection, sender, vec![data], nesting_budget)688 }689690 pub fn repartition(691 collection: &RefungibleHandle<T>,692 owner: &T::CrossAccountId,693 token: TokenId,694 amount: u128,695 ) -> DispatchResult {696 ensure!(697 amount <= MAX_REFUNGIBLE_PIECES,698 <Error<T>>::WrongRefungiblePieces699 );700 ensure!(amount > 0, <CommonError<T>>::TokenValueTooLow);701 // Ensure user owns all pieces702 let total_supply = <TotalSupply<T>>::get((collection.id, token));703 let balance = <Balance<T>>::get((collection.id, token, owner));704 ensure!(705 total_supply == balance,706 <Error<T>>::RepartitionWhileNotOwningAllPieces707 );708709 <Balance<T>>::insert((collection.id, token, owner), amount);710 <TotalSupply<T>>::insert((collection.id, token), amount);711 Ok(())712 }713}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use frame_support::{ensure, BoundedVec};20use up_data_structs::{21 AccessMode, CollectionId, CustomDataLimit, MAX_REFUNGIBLE_PIECES, TokenId,22 CreateCollectionData, CreateRefungibleExData, mapping::TokenAddressMapping, budget::Budget,23};24use pallet_evm::account::CrossAccountId;25use pallet_common::{Error as CommonError, Event as CommonEvent, Pallet as PalletCommon};26use pallet_structure::Pallet as PalletStructure;27use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};28use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};29use core::ops::Deref;30use codec::{Encode, Decode, MaxEncodedLen};31use scale_info::TypeInfo;3233pub use pallet::*;34#[cfg(feature = "runtime-benchmarks")]35pub mod benchmarking;36pub mod common;37pub mod erc;38pub mod weights;39pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;4041#[struct_versioning::versioned(version = 2, upper)]42#[derive(Encode, Decode, Default, TypeInfo, MaxEncodedLen)]43pub struct ItemData {44 pub const_data: BoundedVec<u8, CustomDataLimit>,4546 #[version(..2)]47 pub variable_data: BoundedVec<u8, CustomDataLimit>,48}4950#[frame_support::pallet]51pub mod pallet {52 use super::*;53 use frame_support::{54 Blake2_128, Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key,55 traits::StorageVersion,56 };57 use frame_system::pallet_prelude::*;58 use up_data_structs::{CollectionId, TokenId};59 use super::weights::WeightInfo;6061 #[pallet::error]62 pub enum Error<T> {63 /// Not Refungible item data used to mint in Refungible collection.64 NotRefungibleDataUsedToMintFungibleCollectionToken,65 /// Maximum refungibility exceeded66 WrongRefungiblePieces,67 /// Refungible token can't be repartitioned by user who isn't owns all pieces68 RepartitionWhileNotOwningAllPieces,69 /// Refungible token can't nest other tokens70 RefungibleDisallowsNesting,71 /// Setting item properties is not allowed72 SettingPropertiesNotAllowed,73 }7475 #[pallet::config]76 pub trait Config:77 frame_system::Config + pallet_common::Config + pallet_structure::Config78 {79 type WeightInfo: WeightInfo;80 }8182 const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);8384 #[pallet::pallet]85 #[pallet::storage_version(STORAGE_VERSION)]86 #[pallet::generate_store(pub(super) trait Store)]87 pub struct Pallet<T>(_);8889 #[pallet::storage]90 pub type TokensMinted<T: Config> =91 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;92 #[pallet::storage]93 pub type TokensBurnt<T: Config> =94 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;9596 #[pallet::storage]97 pub type TokenData<T: Config> = StorageNMap<98 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),99 Value = ItemData,100 QueryKind = ValueQuery,101 >;102103 #[pallet::storage]104 pub type TotalSupply<T: Config> = StorageNMap<105 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),106 Value = u128,107 QueryKind = ValueQuery,108 >;109110 /// Used to enumerate tokens owned by account111 #[pallet::storage]112 pub type Owned<T: Config> = StorageNMap<113 Key = (114 Key<Twox64Concat, CollectionId>,115 Key<Blake2_128Concat, T::CrossAccountId>,116 Key<Twox64Concat, TokenId>,117 ),118 Value = bool,119 QueryKind = ValueQuery,120 >;121122 #[pallet::storage]123 pub type AccountBalance<T: Config> = StorageNMap<124 Key = (125 Key<Twox64Concat, CollectionId>,126 // Owner127 Key<Blake2_128Concat, T::CrossAccountId>,128 ),129 Value = u32,130 QueryKind = ValueQuery,131 >;132133 #[pallet::storage]134 pub type Balance<T: Config> = StorageNMap<135 Key = (136 Key<Twox64Concat, CollectionId>,137 Key<Twox64Concat, TokenId>,138 // Owner139 Key<Blake2_128Concat, T::CrossAccountId>,140 ),141 Value = u128,142 QueryKind = ValueQuery,143 >;144145 #[pallet::storage]146 pub type Allowance<T: Config> = StorageNMap<147 Key = (148 Key<Twox64Concat, CollectionId>,149 Key<Twox64Concat, TokenId>,150 // Owner151 Key<Blake2_128, T::CrossAccountId>,152 // Spender153 Key<Blake2_128Concat, T::CrossAccountId>,154 ),155 Value = u128,156 QueryKind = ValueQuery,157 >;158159 #[pallet::hooks]160 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {161 fn on_runtime_upgrade() -> Weight {162 StorageVersion::new(1).put::<Pallet<T>>();163164 0165 }166 }167}168169pub struct RefungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);170impl<T: Config> RefungibleHandle<T> {171 pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {172 Self(inner)173 }174 pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {175 self.0176 }177}178impl<T: Config> Deref for RefungibleHandle<T> {179 type Target = pallet_common::CollectionHandle<T>;180181 fn deref(&self) -> &Self::Target {182 &self.0183 }184}185186impl<T: Config> Pallet<T> {187 pub fn total_supply(collection: &RefungibleHandle<T>) -> u32 {188 <TokensMinted<T>>::get(collection.id) - <TokensBurnt<T>>::get(collection.id)189 }190 pub fn token_exists(collection: &RefungibleHandle<T>, token: TokenId) -> bool {191 <TotalSupply<T>>::contains_key((collection.id, token))192 }193}194195// unchecked calls skips any permission checks196impl<T: Config> Pallet<T> {197 pub fn init_collection(198 owner: T::CrossAccountId,199 data: CreateCollectionData<T::AccountId>,200 ) -> Result<CollectionId, DispatchError> {201 <PalletCommon<T>>::init_collection(owner, data, false)202 }203 pub fn destroy_collection(204 collection: RefungibleHandle<T>,205 sender: &T::CrossAccountId,206 ) -> DispatchResult {207 let id = collection.id;208209 if Self::collection_has_tokens(id) {210 return Err(<CommonError<T>>::CantDestroyNotEmptyCollection.into());211 }212213 // =========214215 PalletCommon::destroy_collection(collection.0, sender)?;216217 <TokensMinted<T>>::remove(id);218 <TokensBurnt<T>>::remove(id);219 <TokenData<T>>::remove_prefix((id,), None);220 <TotalSupply<T>>::remove_prefix((id,), None);221 <Balance<T>>::remove_prefix((id,), None);222 <Allowance<T>>::remove_prefix((id,), None);223 <Owned<T>>::remove_prefix((id,), None);224 <AccountBalance<T>>::remove_prefix((id,), None);225 Ok(())226 }227228 fn collection_has_tokens(collection_id: CollectionId) -> bool {229 <TokenData<T>>::iter_prefix((collection_id,))230 .next()231 .is_some()232 }233234 pub fn burn_token(collection: &RefungibleHandle<T>, token_id: TokenId) -> DispatchResult {235 let burnt = <TokensBurnt<T>>::get(collection.id)236 .checked_add(1)237 .ok_or(ArithmeticError::Overflow)?;238239 <TokensBurnt<T>>::insert(collection.id, burnt);240 <TokenData<T>>::remove((collection.id, token_id));241 <TotalSupply<T>>::remove((collection.id, token_id));242 <Balance<T>>::remove_prefix((collection.id, token_id), None);243 <Allowance<T>>::remove_prefix((collection.id, token_id), None);244 // TODO: ERC721 transfer event245 Ok(())246 }247248 pub fn burn(249 collection: &RefungibleHandle<T>,250 owner: &T::CrossAccountId,251 token: TokenId,252 amount: u128,253 ) -> DispatchResult {254 let total_supply = <TotalSupply<T>>::get((collection.id, token))255 .checked_sub(amount)256 .ok_or(<CommonError<T>>::TokenValueTooLow)?;257258 // This was probally last owner of this token?259 if total_supply == 0 {260 // Ensure user actually owns this amount261 ensure!(262 <Balance<T>>::get((collection.id, token, owner)) == amount,263 <CommonError<T>>::TokenValueTooLow264 );265 let account_balance = <AccountBalance<T>>::get((collection.id, owner))266 .checked_sub(1)267 // Should not occur268 .ok_or(ArithmeticError::Underflow)?;269270 // =========271272 <Owned<T>>::remove((collection.id, owner, token));273 <PalletStructure<T>>::unnest_if_nested(owner, collection.id, token);274 <AccountBalance<T>>::insert((collection.id, owner), account_balance);275 Self::burn_token(collection, token)?;276 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(277 collection.id,278 token,279 owner.clone(),280 amount,281 ));282 return Ok(());283 }284285 let balance = <Balance<T>>::get((collection.id, token, owner))286 .checked_sub(amount)287 .ok_or(<CommonError<T>>::TokenValueTooLow)?;288 let account_balance = if balance == 0 {289 <AccountBalance<T>>::get((collection.id, owner))290 .checked_sub(1)291 // Should not occur292 .ok_or(ArithmeticError::Underflow)?293 } else {294 0295 };296297 // =========298299 if balance == 0 {300 <Owned<T>>::remove((collection.id, owner, token));301 <PalletStructure<T>>::unnest_if_nested(owner, collection.id, token);302 <Balance<T>>::remove((collection.id, token, owner));303 <AccountBalance<T>>::insert((collection.id, owner), account_balance);304 } else {305 <Balance<T>>::insert((collection.id, token, owner), balance);306 }307 <TotalSupply<T>>::insert((collection.id, token), total_supply);308 // TODO: ERC20 transfer event309 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(310 collection.id,311 token,312 owner.clone(),313 amount,314 ));315 Ok(())316 }317318 pub fn transfer(319 collection: &RefungibleHandle<T>,320 from: &T::CrossAccountId,321 to: &T::CrossAccountId,322 token: TokenId,323 amount: u128,324 nesting_budget: &dyn Budget,325 ) -> DispatchResult {326 ensure!(327 collection.limits.transfers_enabled(),328 <CommonError<T>>::TransferNotAllowed329 );330331 if collection.permissions.access() == AccessMode::AllowList {332 collection.check_allowlist(from)?;333 collection.check_allowlist(to)?;334 }335 <PalletCommon<T>>::ensure_correct_receiver(to)?;336337 let balance_from = <Balance<T>>::get((collection.id, token, from))338 .checked_sub(amount)339 .ok_or(<CommonError<T>>::TokenValueTooLow)?;340 let mut create_target = false;341 let from_to_differ = from != to;342 let balance_to = if from != to {343 let old_balance = <Balance<T>>::get((collection.id, token, to));344 if old_balance == 0 {345 create_target = true;346 }347 Some(348 old_balance349 .checked_add(amount)350 .ok_or(ArithmeticError::Overflow)?,351 )352 } else {353 None354 };355356 let account_balance_from = if balance_from == 0 {357 Some(358 <AccountBalance<T>>::get((collection.id, from))359 .checked_sub(1)360 // Should not occur361 .ok_or(ArithmeticError::Underflow)?,362 )363 } else {364 None365 };366 // Account data is created in token, AccountBalance should be increased367 // But only if from != to as we shouldn't check overflow in this case368 let account_balance_to = if create_target && from_to_differ {369 let account_balance_to = <AccountBalance<T>>::get((collection.id, to))370 .checked_add(1)371 .ok_or(ArithmeticError::Overflow)?;372 ensure!(373 account_balance_to < collection.limits.account_token_ownership_limit(),374 <CommonError<T>>::AccountTokenLimitExceeded,375 );376377 Some(account_balance_to)378 } else {379 None380 };381382 // =========383384 <PalletStructure<T>>::nest_if_sent_to_token(385 from.clone(),386 to,387 collection.id,388 token,389 nesting_budget,390 )?;391392 if let Some(balance_to) = balance_to {393 // from != to394 if balance_from == 0 {395 <Balance<T>>::remove((collection.id, token, from));396 <PalletStructure<T>>::unnest_if_nested(from, collection.id, token);397 } else {398 <Balance<T>>::insert((collection.id, token, from), balance_from);399 }400 <Balance<T>>::insert((collection.id, token, to), balance_to);401 if let Some(account_balance_from) = account_balance_from {402 <AccountBalance<T>>::insert((collection.id, from), account_balance_from);403 <Owned<T>>::remove((collection.id, from, token));404 }405 if let Some(account_balance_to) = account_balance_to {406 <AccountBalance<T>>::insert((collection.id, to), account_balance_to);407 <Owned<T>>::insert((collection.id, to, token), true);408 }409 }410411 // TODO: ERC20 transfer event412 <PalletCommon<T>>::deposit_event(CommonEvent::Transfer(413 collection.id,414 token,415 from.clone(),416 to.clone(),417 amount,418 ));419 Ok(())420 }421422 pub fn create_multiple_items(423 collection: &RefungibleHandle<T>,424 sender: &T::CrossAccountId,425 data: Vec<CreateRefungibleExData<T::CrossAccountId>>,426 nesting_budget: &dyn Budget,427 ) -> DispatchResult {428 if !collection.is_owner_or_admin(sender) {429 ensure!(430 collection.permissions.mint_mode(),431 <CommonError<T>>::PublicMintingNotAllowed432 );433 collection.check_allowlist(sender)?;434435 for item in data.iter() {436 for user in item.users.keys() {437 collection.check_allowlist(user)?;438 }439 }440 }441442 for item in data.iter() {443 for (owner, _) in item.users.iter() {444 <PalletCommon<T>>::ensure_correct_receiver(owner)?;445 }446 }447448 // Total pieces per tokens449 let totals = data450 .iter()451 .map(|data| {452 Ok(data453 .users454 .iter()455 .map(|u| u.1)456 .try_fold(0u128, |acc, v| acc.checked_add(*v))457 .ok_or(ArithmeticError::Overflow)?)458 })459 .collect::<Result<Vec<_>, DispatchError>>()?;460 for total in &totals {461 ensure!(462 *total <= MAX_REFUNGIBLE_PIECES,463 <Error<T>>::WrongRefungiblePieces464 );465 }466467 let first_token_id = <TokensMinted<T>>::get(collection.id);468 let tokens_minted = first_token_id469 .checked_add(data.len() as u32)470 .ok_or(ArithmeticError::Overflow)?;471 ensure!(472 tokens_minted < collection.limits.token_limit(),473 <CommonError<T>>::CollectionTokenLimitExceeded474 );475476 let mut balances = BTreeMap::new();477 for data in &data {478 for owner in data.users.keys() {479 let balance = balances480 .entry(owner)481 .or_insert_with(|| <AccountBalance<T>>::get((collection.id, owner)));482 *balance = balance.checked_add(1).ok_or(ArithmeticError::Overflow)?;483484 ensure!(485 *balance <= collection.limits.account_token_ownership_limit(),486 <CommonError<T>>::AccountTokenLimitExceeded,487 );488 }489 }490491 for (i, token) in data.iter().enumerate() {492 let token_id = TokenId(first_token_id + i as u32 + 1);493 for (to, _) in token.users.iter() {494 <PalletStructure<T>>::check_nesting(495 sender.clone(),496 to,497 collection.id,498 token_id,499 nesting_budget,500 )?;501 }502 }503504 // =========505506 <TokensMinted<T>>::insert(collection.id, tokens_minted);507 for (account, balance) in balances {508 <AccountBalance<T>>::insert((collection.id, account), balance);509 }510 for (i, token) in data.into_iter().enumerate() {511 let token_id = first_token_id + i as u32 + 1;512 <TotalSupply<T>>::insert((collection.id, token_id), totals[i]);513514 <TokenData<T>>::insert(515 (collection.id, token_id),516 ItemData {517 const_data: token.const_data,518 },519 );520521 for (user, amount) in token.users.into_iter() {522 if amount == 0 {523 continue;524 }525 <Balance<T>>::insert((collection.id, token_id, &user), amount);526 <Owned<T>>::insert((collection.id, &user, TokenId(token_id)), true);527 <PalletStructure<T>>::nest_if_sent_to_token_unchecked(528 &user,529 collection.id,530 TokenId(token_id),531 );532533 // TODO: ERC20 transfer event534 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(535 collection.id,536 TokenId(token_id),537 user,538 amount,539 ));540 }541 }542 Ok(())543 }544545 pub fn set_allowance_unchecked(546 collection: &RefungibleHandle<T>,547 sender: &T::CrossAccountId,548 spender: &T::CrossAccountId,549 token: TokenId,550 amount: u128,551 ) {552 if amount == 0 {553 <Allowance<T>>::remove((collection.id, token, sender, spender));554 } else {555 <Allowance<T>>::insert((collection.id, token, sender, spender), amount);556 }557 // TODO: ERC20 approval event558 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(559 collection.id,560 token,561 sender.clone(),562 spender.clone(),563 amount,564 ))565 }566567 pub fn set_allowance(568 collection: &RefungibleHandle<T>,569 sender: &T::CrossAccountId,570 spender: &T::CrossAccountId,571 token: TokenId,572 amount: u128,573 ) -> DispatchResult {574 if collection.permissions.access() == AccessMode::AllowList {575 collection.check_allowlist(sender)?;576 collection.check_allowlist(spender)?;577 }578579 <PalletCommon<T>>::ensure_correct_receiver(spender)?;580581 if <Balance<T>>::get((collection.id, token, sender)) < amount {582 ensure!(583 collection.ignores_owned_amount(sender) && Self::token_exists(collection, token),584 <CommonError<T>>::CantApproveMoreThanOwned585 );586 }587588 // =========589590 Self::set_allowance_unchecked(collection, sender, spender, token, amount);591 Ok(())592 }593594 /// Returns allowance, which should be set after transaction595 fn check_allowed(596 collection: &RefungibleHandle<T>,597 spender: &T::CrossAccountId,598 from: &T::CrossAccountId,599 token: TokenId,600 amount: u128,601 nesting_budget: &dyn Budget,602 ) -> Result<Option<u128>, DispatchError> {603 if spender.conv_eq(from) {604 return Ok(None);605 }606 if collection.permissions.access() == AccessMode::AllowList {607 // `from`, `to` checked in [`transfer`]608 collection.check_allowlist(spender)?;609 }610 if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {611 // TODO: should collection owner be allowed to perform this transfer?612 ensure!(613 <PalletStructure<T>>::check_indirectly_owned(614 spender.clone(),615 source.0,616 source.1,617 None,618 nesting_budget619 )?,620 <CommonError<T>>::ApprovedValueTooLow,621 );622 return Ok(None);623 }624 let allowance =625 <Allowance<T>>::get((collection.id, token, from, &spender)).checked_sub(amount);626 if allowance.is_none() {627 ensure!(628 collection.ignores_allowance(spender),629 <CommonError<T>>::ApprovedValueTooLow630 );631 }632 Ok(allowance)633 }634635 pub fn transfer_from(636 collection: &RefungibleHandle<T>,637 spender: &T::CrossAccountId,638 from: &T::CrossAccountId,639 to: &T::CrossAccountId,640 token: TokenId,641 amount: u128,642 nesting_budget: &dyn Budget,643 ) -> DispatchResult {644 let allowance =645 Self::check_allowed(collection, spender, from, token, amount, nesting_budget)?;646647 // =========648649 Self::transfer(collection, from, to, token, amount, nesting_budget)?;650 if let Some(allowance) = allowance {651 Self::set_allowance_unchecked(collection, from, spender, token, allowance);652 }653 Ok(())654 }655656 pub fn burn_from(657 collection: &RefungibleHandle<T>,658 spender: &T::CrossAccountId,659 from: &T::CrossAccountId,660 token: TokenId,661 amount: u128,662 nesting_budget: &dyn Budget,663 ) -> DispatchResult {664 let allowance =665 Self::check_allowed(collection, spender, from, token, amount, nesting_budget)?;666667 // =========668669 Self::burn(collection, from, token, amount)?;670 if let Some(allowance) = allowance {671 Self::set_allowance_unchecked(collection, from, spender, token, allowance);672 }673 Ok(())674 }675676 /// Delegated to `create_multiple_items`677 pub fn create_item(678 collection: &RefungibleHandle<T>,679 sender: &T::CrossAccountId,680 data: CreateRefungibleExData<T::CrossAccountId>,681 nesting_budget: &dyn Budget,682 ) -> DispatchResult {683 Self::create_multiple_items(collection, sender, vec![data], nesting_budget)684 }685686 pub fn repartition(687 collection: &RefungibleHandle<T>,688 owner: &T::CrossAccountId,689 token: TokenId,690 amount: u128,691 ) -> DispatchResult {692 ensure!(693 amount <= MAX_REFUNGIBLE_PIECES,694 <Error<T>>::WrongRefungiblePieces695 );696 ensure!(amount > 0, <CommonError<T>>::TokenValueTooLow);697 // Ensure user owns all pieces698 let total_supply = <TotalSupply<T>>::get((collection.id, token));699 let balance = <Balance<T>>::get((collection.id, token, owner));700 ensure!(701 total_supply == balance,702 <Error<T>>::RepartitionWhileNotOwningAllPieces703 );704705 <Balance<T>>::insert((collection.id, token, owner), amount);706 <TotalSupply<T>>::insert((collection.id, token), amount);707 Ok(())708 }709}runtime/opal/src/lib.rsdiffbeforeafterboth--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -192,7 +192,7 @@
spec_name: create_runtime_str!(RUNTIME_NAME),
impl_name: create_runtime_str!(RUNTIME_NAME),
authoring_version: 1,
- spec_version: 924010,
+ spec_version: 924011,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
runtime/quartz/src/lib.rsdiffbeforeafterboth--- a/runtime/quartz/src/lib.rs
+++ b/runtime/quartz/src/lib.rs
@@ -191,7 +191,7 @@
spec_name: create_runtime_str!(RUNTIME_NAME),
impl_name: create_runtime_str!(RUNTIME_NAME),
authoring_version: 1,
- spec_version: 924010,
+ spec_version: 924011,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
runtime/unique/src/lib.rsdiffbeforeafterboth--- a/runtime/unique/src/lib.rs
+++ b/runtime/unique/src/lib.rs
@@ -190,7 +190,7 @@
spec_name: create_runtime_str!(RUNTIME_NAME),
impl_name: create_runtime_str!(RUNTIME_NAME),
authoring_version: 1,
- spec_version: 924010,
+ spec_version: 924011,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,