git.delta.rocks / unique-network / refs/commits / 4375a2d3ddf0

difftreelog

CORE-412 Add create_refungible_collection method

Trubnikov Sergey2022-06-14parent: #e5c8c50.patch.diff
in: master

5 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6649,6 +6649,7 @@
  "pallet-evm",
  "pallet-evm-coder-substrate",
  "pallet-nonfungible",
+ "pallet-refungible",
  "parity-scale-codec 3.1.5",
  "scale-info",
  "serde",
modifiedpallets/unique/Cargo.tomldiffbeforeafterboth
--- a/pallets/unique/Cargo.toml
+++ b/pallets/unique/Cargo.toml
@@ -103,3 +103,4 @@
 evm-coder = { default-features = false, path = '../../crates/evm-coder' }
 pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }
 pallet-nonfungible = { default-features = false, path = '../../pallets/nonfungible' }
+pallet-refungible = { default-features = false, path = '../../pallets/refungible' }
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -210,6 +210,24 @@
 		Ok(address)
 	}
 
+	#[weight(<SelfWeightOf<T>>::create_collection())]
+	fn create_refungible_collection(
+		&self,
+		caller: caller,
+		name: string,
+		description: string,
+		token_prefix: string,
+	) -> Result<address> {
+		let (caller, name, description, token_prefix) =
+			convert_data::<T>(caller, name, description, token_prefix)?;
+		let data = make_data::<T>(name, description, token_prefix)?;
+		let collection_id = <pallet_refungible::Pallet<T>>::init_collection(caller.clone(), data)
+			.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
+
+		let address = pallet_common::eth::collection_id_to_address(collection_id);
+		Ok(address)
+	}
+
 	/// Check if a collection exists
 	/// @param collection_address Address of the collection in question
 	/// @return bool Does the collection exist?
@@ -225,7 +243,9 @@
 
 /// Implements [`OnMethodCall`], which delegates call to [`EvmCollectionHelpers`]
 pub struct CollectionHelpersOnMethodCall<T: Config>(PhantomData<*const T>);
-impl<T: Config + pallet_nonfungible::Config> OnMethodCall<T> for CollectionHelpersOnMethodCall<T> {
+impl<T: Config + pallet_nonfungible::Config + pallet_refungible::Config> OnMethodCall<T>
+	for CollectionHelpersOnMethodCall<T>
+{
 	fn is_reserved(contract: &sp_core::H160) -> bool {
 		contract == &T::ContractAddress::get()
 	}
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -298,9 +298,9 @@
 	pub mode: CollectionMode,
 	#[version(..2)]
 	pub access: AccessMode,
-	pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,
-	pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,
-	pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,
+	pub name: CollectionName,
+	pub description: CollectionDescription,
+	pub token_prefix: CollectionTokenPrefix,
 
 	#[version(..2)]
 	pub mint_mode: bool,
@@ -354,9 +354,9 @@
 	#[derivative(Default(value = "CollectionMode::NFT"))]
 	pub mode: CollectionMode,
 	pub access: Option<AccessMode>,
-	pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,
-	pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,
-	pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,
+	pub name: CollectionName,
+	pub description: CollectionDescription,
+	pub token_prefix: CollectionTokenPrefix,
 	pub pending_sponsor: Option<AccountId>,
 	pub limits: Option<CollectionLimits>,
 	pub permissions: Option<CollectionPermissions>,
modifiedtests/src/eth/createCollection.test.tsdiffbeforeafterboth
27 getCollectionAddressFromResult,27 getCollectionAddressFromResult,
28} from './util/helpers';28} from './util/helpers';
2929
30describe('Create collection from EVM', () => {30describe.only('Create collection from EVM', () => {
31 // itWeb3('Create collection', async ({api, web3, privateKeyWrapper}) => {31 itWeb3('Create collection', async ({api, web3, privateKeyWrapper}) => {
32 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);32 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
33 // const collectionHelper = evmCollectionHelpers(web3, owner);33 const collectionHelper = evmCollectionHelpers(web3, owner);
34 // const collectionName = 'CollectionEVM';34 const collectionName = 'CollectionEVM';
35 // const description = 'Some description';35 const description = 'Some description';
36 // const tokenPrefix = 'token prefix';36 const tokenPrefix = 'token prefix';
37 37
38 // const collectionCountBefore = await getCreatedCollectionCount(api);38 const collectionCountBefore = await getCreatedCollectionCount(api);
39 // const result = await collectionHelper.methods39 const result = await collectionHelper.methods
40 // .createNonfungibleCollection(collectionName, description, tokenPrefix)40 .createNonfungibleCollection(collectionName, description, tokenPrefix)
41 // .send();41 .send();
42 // const collectionCountAfter = await getCreatedCollectionCount(api);42 const collectionCountAfter = await getCreatedCollectionCount(api);
43 43
44 // const {collectionId, collection} = await getCollectionAddressFromResult(api, result);44 const {collectionId, collection} = await getCollectionAddressFromResult(api, result);
45 // expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);45 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);
46 // expect(collectionId).to.be.eq(collectionCountAfter);46 expect(collectionId).to.be.eq(collectionCountAfter);
47 // expect(collection.name.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(collectionName);47 expect(collection.name.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(collectionName);
48 // expect(collection.description.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(description);48 expect(collection.description.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(description);
49 // expect(collection.tokenPrefix.toHuman()).to.be.eq(tokenPrefix);49 expect(collection.tokenPrefix.toHuman()).to.be.eq(tokenPrefix);
50 // });50 });
5151
52 // itWeb3('Check collection address exist', async ({api, web3, privateKeyWrapper}) => {52 itWeb3('Check collection address exist', async ({api, web3, privateKeyWrapper}) => {
53 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);53 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
54 // const collectionHelpers = evmCollectionHelpers(web3, owner);54 const collectionHelpers = evmCollectionHelpers(web3, owner);
55 55
56 // const expectedCollectionId = await getCreatedCollectionCount(api) + 1;56 const expectedCollectionId = await getCreatedCollectionCount(api) + 1;
57 // const expectedCollectionAddress = collectionIdToAddress(expectedCollectionId);57 const expectedCollectionAddress = collectionIdToAddress(expectedCollectionId);
58 // expect(await collectionHelpers.methods58 expect(await collectionHelpers.methods
59 // .isCollectionExist(expectedCollectionAddress)59 .isCollectionExist(expectedCollectionAddress)
60 // .call()).to.be.false;60 .call()).to.be.false;
6161
62 // await collectionHelpers.methods62 await collectionHelpers.methods
63 // .createNonfungibleCollection('A', 'A', 'A')63 .createNonfungibleCollection('A', 'A', 'A')
64 // .send();64 .send();
65 65
66 // expect(await collectionHelpers.methods66 expect(await collectionHelpers.methods
67 // .isCollectionExist(expectedCollectionAddress)67 .isCollectionExist(expectedCollectionAddress)
68 // .call()).to.be.true;68 .call()).to.be.true;
69 // });69 });
70 70
71 itWeb3('Set sponsorship', async ({api, web3, privateKeyWrapper}) => {71 itWeb3('Set sponsorship', async ({api, web3, privateKeyWrapper}) => {
72 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);72 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);