difftreelog
CORE-410 Setup properties at creation items
in: master
4 files changed
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -140,6 +140,7 @@
out.insert(to.clone(), data.pieces);
out.try_into().expect("limit > 0")
},
+ properties: data.properties,
}),
_ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),
}
pallets/refungible/src/lib.rsdiffbeforeafterboth878788#![cfg_attr(not(feature = "std"), no_std)]88#![cfg_attr(not(feature = "std"), no_std)]898990use frame_support::{ensure, BoundedVec, transactional};90use frame_support::{ensure, BoundedVec, transactional, storage::with_transaction};91use up_data_structs::{91use up_data_structs::{92 AccessMode, CollectionId, CustomDataLimit, MAX_REFUNGIBLE_PIECES, TokenId,92 AccessMode, CollectionId, CustomDataLimit, MAX_REFUNGIBLE_PIECES, TokenId,93 CreateCollectionData, CreateRefungibleExData, mapping::TokenAddressMapping, budget::Budget,93 CreateCollectionData, CreateRefungibleExData, mapping::TokenAddressMapping, budget::Budget,96use pallet_evm::account::CrossAccountId;96use pallet_evm::account::CrossAccountId;97use pallet_common::{Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, CommonCollectionOperations as _};97use pallet_common::{Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, CommonCollectionOperations as _};98use pallet_structure::Pallet as PalletStructure;98use pallet_structure::Pallet as PalletStructure;99use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};99use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};100use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};100use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};101use core::ops::Deref;101use core::ops::Deref;102use codec::{Encode, Decode, MaxEncodedLen};102use codec::{Encode, Decode, MaxEncodedLen};804804805 // =========805 // =========806807 with_transaction(|| {808 for (i, data) in data.iter().enumerate() {809 let token_id = first_token_id + i as u32 + 1;810 <TotalSupply<T>>::insert((collection.id, token_id), totals[i]);811812 <TokenData<T>>::insert(813 (collection.id, token_id),814 ItemData {815 const_data: data.const_data.clone(),816 },817 );818819 for (user, amount) in data.users.iter() {820 if *amount == 0 {821 continue;822 }823 <Balance<T>>::insert((collection.id, token_id, &user), amount);824 <Owned<T>>::insert((collection.id, &user, TokenId(token_id)), true);825 <PalletStructure<T>>::nest_if_sent_to_token_unchecked(826 user,827 collection.id,828 TokenId(token_id),829 );830 }831832 if let Err(e) = Self::set_token_properties(833 collection,834 sender,835 TokenId(token_id),836 data.properties.clone().into_inner(),837 true,838 ) {839 return TransactionOutcome::Rollback(Err(e));840 }841 }842 TransactionOutcome::Commit(Ok(()))843 })?;806844807 <TokensMinted<T>>::insert(collection.id, tokens_minted);845 <TokensMinted<T>>::insert(collection.id, tokens_minted);846808 for (account, balance) in balances {847 for (account, balance) in balances {809 <AccountBalance<T>>::insert((collection.id, account), balance);848 <AccountBalance<T>>::insert((collection.id, account), balance);810 }849 }850811 for (i, token) in data.into_iter().enumerate() {851 for (i, token) in data.into_iter().enumerate() {812 let token_id = first_token_id + i as u32 + 1;852 let token_id = first_token_id + i as u32 + 1;813 <TotalSupply<T>>::insert((collection.id, token_id), totals[i]);814815 <TokenData<T>>::insert(816 (collection.id, token_id),817 ItemData {818 const_data: token.const_data,819 },820 );821853822 for (user, amount) in token.users.into_iter() {854 for (user, amount) in token.users.into_iter() {823 if amount == 0 {855 if amount == 0 {824 continue;856 continue;825 }857 } 826 <Balance<T>>::insert((collection.id, token_id, &user), amount);827 <Owned<T>>::insert((collection.id, &user, TokenId(token_id)), true);828 <PalletStructure<T>>::nest_if_sent_to_token_unchecked(829 &user,830 collection.id,831 TokenId(token_id),832 );833858834 // TODO: ERC20 transfer event859 // TODO: ERC20 transfer event835 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(860 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -534,7 +534,12 @@
#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]
#[derivative(Debug(format_with = "bounded::vec_debug"))]
pub const_data: BoundedVec<u8, CustomDataLimit>,
+
pub pieces: u128,
+
+ #[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]
+ #[derivative(Debug(format_with = "bounded::vec_debug"))]
+ pub properties: CollectionPropertiesVec,
}
#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]
@@ -568,6 +573,8 @@
pub const_data: BoundedVec<u8, CustomDataLimit>,
#[derivative(Debug(format_with = "bounded::map_debug"))]
pub users: BoundedBTreeMap<CrossAccountId, u128, ConstU32<MAX_ITEMS_PER_BATCH>>,
+ #[derivative(Debug(format_with = "bounded::vec_debug"))]
+ pub properties: CollectionPropertiesVec,
}
#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]
tests/src/createMultipleItems.test.tsdiffbeforeafterboth--- a/tests/src/createMultipleItems.test.ts
+++ b/tests/src/createMultipleItems.test.ts
@@ -376,14 +376,26 @@
// ReFungible
const collectionIdReFungible =
await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const argsReFungible = [
- {ReFungible: ['1'.repeat(2049), 10]},
- {ReFungible: ['2'.repeat(2049), 10]},
- {ReFungible: ['3'.repeat(2049), 10]},
- ];
- const createMultipleItemsTxFungible = api.tx.unique
- .createMultipleItems(collectionIdReFungible, normalizeAccountId(alice.address), argsReFungible);
- await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTxFungible)).to.be.rejected;
+ {
+ const argsReFungible = [
+ {ReFungible: ['1'.repeat(2049), 10, []]},
+ {ReFungible: ['2'.repeat(2049), 10, []]},
+ {ReFungible: ['3'.repeat(2049), 10, []]},
+ ];
+ const createMultipleItemsTxFungible = api.tx.unique
+ .createMultipleItems(collectionIdReFungible, normalizeAccountId(alice.address), argsReFungible);
+ await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTxFungible)).to.be.rejected;
+ }
+ {
+ const argsReFungible = [
+ {ReFungible: {properties: [{key: 'key', value: 'A'.repeat(32769)}]}},
+ {ReFungible: {properties: [{key: 'key', value: 'B'.repeat(32769)}]}},
+ {ReFungible: {properties: [{key: 'key', value: 'C'.repeat(32769)}]}},
+ ];
+ const createMultipleItemsTxFungible = api.tx.unique
+ .createMultipleItems(collectionIdReFungible, normalizeAccountId(alice.address), argsReFungible);
+ await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTxFungible)).to.be.rejected;
+ }
});
});