difftreelog
CORE-412 Add create_refungible_collection method
in: master
5 files changed
Cargo.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",
pallets/unique/Cargo.tomldiffbeforeafterboth1################################################################################2# Package34[package]5authors = ['Unique Network <support@uniquenetwork.io>']6description = 'Unique Pallet'7edition = '2021'8homepage = 'https://unique.network'9license = 'GPLv3'10name = 'pallet-unique'11repository = 'https://github.com/UniqueNetwork/unique-chain'12version = '0.1.0'1314[package.metadata.docs.rs]15targets = ['x86_64-unknown-linux-gnu']1617[features]18default = ['std']19runtime-benchmarks = ['frame-benchmarking', 'pallet-common/runtime-benchmarks']20std = [21 'codec/std',22 'serde/std',23 'frame-support/std',24 'frame-system/std',25 'pallet-evm/std',26 'pallet-common/std',27 'up-data-structs/std',28 'sp-std/std',29 'sp-runtime/std',30 'frame-benchmarking/std',31 'evm-coder/std',32 'pallet-evm-coder-substrate/std',33 'pallet-nonfungible/std',34]35limit-testing = ["up-data-structs/limit-testing"]3637################################################################################38# Standart Dependencies3940[dependencies.serde]41default-features = false42features = ['derive']43version = '1.0.130'4445[dependencies.ethereum]46version = "0.12.0"47default-features = false4849################################################################################50# Substrate Dependencies5152[dependencies.codec]53default-features = false54features = ['derive']55package = 'parity-scale-codec'56version = '3.1.2'5758[dependencies.frame-benchmarking]59default-features = false60optional = true61git = "https://github.com/paritytech/substrate"62branch = "polkadot-v0.9.24"6364[dependencies.frame-support]65default-features = false66git = "https://github.com/paritytech/substrate"67branch = "polkadot-v0.9.24"6869[dependencies.frame-system]70default-features = false71git = "https://github.com/paritytech/substrate"72branch = "polkadot-v0.9.24"7374[dependencies.sp-std]75default-features = false76git = "https://github.com/paritytech/substrate"77branch = "polkadot-v0.9.24"7879[dependencies.sp-runtime]80default-features = false81git = "https://github.com/paritytech/substrate"82branch = "polkadot-v0.9.24"8384[dependencies.sp-core]85default-features = false86git = "https://github.com/paritytech/substrate"87branch = "polkadot-v0.9.24"8889[dependencies.sp-io]90default-features = false91git = "https://github.com/paritytech/substrate"92branch = "polkadot-v0.9.24"9394################################################################################95# Local Dependencies96[dependencies]97up-data-structs = { default-features = false, path = "../../primitives/data-structs" }98scale-info = { version = "2.0.1", default-features = false, features = [99 "derive",100] }101pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.24" }102pallet-common = { default-features = false, path = "../common" }103evm-coder = { default-features = false, path = '../../crates/evm-coder' }104pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }105pallet-nonfungible = { default-features = false, path = '../../pallets/nonfungible' }1################################################################################2# Package34[package]5authors = ['Unique Network <support@uniquenetwork.io>']6description = 'Unique Pallet'7edition = '2021'8homepage = 'https://unique.network'9license = 'GPLv3'10name = 'pallet-unique'11repository = 'https://github.com/UniqueNetwork/unique-chain'12version = '0.1.0'1314[package.metadata.docs.rs]15targets = ['x86_64-unknown-linux-gnu']1617[features]18default = ['std']19runtime-benchmarks = ['frame-benchmarking', 'pallet-common/runtime-benchmarks']20std = [21 'codec/std',22 'serde/std',23 'frame-support/std',24 'frame-system/std',25 'pallet-evm/std',26 'pallet-common/std',27 'up-data-structs/std',28 'sp-std/std',29 'sp-runtime/std',30 'frame-benchmarking/std',31 'evm-coder/std',32 'pallet-evm-coder-substrate/std',33 'pallet-nonfungible/std',34]35limit-testing = ["up-data-structs/limit-testing"]3637################################################################################38# Standart Dependencies3940[dependencies.serde]41default-features = false42features = ['derive']43version = '1.0.130'4445[dependencies.ethereum]46version = "0.12.0"47default-features = false4849################################################################################50# Substrate Dependencies5152[dependencies.codec]53default-features = false54features = ['derive']55package = 'parity-scale-codec'56version = '3.1.2'5758[dependencies.frame-benchmarking]59default-features = false60optional = true61git = "https://github.com/paritytech/substrate"62branch = "polkadot-v0.9.24"6364[dependencies.frame-support]65default-features = false66git = "https://github.com/paritytech/substrate"67branch = "polkadot-v0.9.24"6869[dependencies.frame-system]70default-features = false71git = "https://github.com/paritytech/substrate"72branch = "polkadot-v0.9.24"7374[dependencies.sp-std]75default-features = false76git = "https://github.com/paritytech/substrate"77branch = "polkadot-v0.9.24"7879[dependencies.sp-runtime]80default-features = false81git = "https://github.com/paritytech/substrate"82branch = "polkadot-v0.9.24"8384[dependencies.sp-core]85default-features = false86git = "https://github.com/paritytech/substrate"87branch = "polkadot-v0.9.24"8889[dependencies.sp-io]90default-features = false91git = "https://github.com/paritytech/substrate"92branch = "polkadot-v0.9.24"9394################################################################################95# Local Dependencies96[dependencies]97up-data-structs = { default-features = false, path = "../../primitives/data-structs" }98scale-info = { version = "2.0.1", default-features = false, features = [99 "derive",100] }101pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.24" }102pallet-common = { default-features = false, path = "../common" }103evm-coder = { default-features = false, path = '../../crates/evm-coder' }104pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }105pallet-nonfungible = { default-features = false, path = '../../pallets/nonfungible' }106pallet-refungible = { default-features = false, path = '../../pallets/refungible' }pallets/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()
}
primitives/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>,
tests/src/eth/createCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createCollection.test.ts
+++ b/tests/src/eth/createCollection.test.ts
@@ -27,46 +27,46 @@
getCollectionAddressFromResult,
} from './util/helpers';
-describe('Create collection from EVM', () => {
- // itWeb3('Create collection', async ({api, web3, privateKeyWrapper}) => {
- // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- // const collectionHelper = evmCollectionHelpers(web3, owner);
- // const collectionName = 'CollectionEVM';
- // const description = 'Some description';
- // const tokenPrefix = 'token prefix';
+describe.only('Create collection from EVM', () => {
+ itWeb3('Create collection', async ({api, web3, privateKeyWrapper}) => {
+ const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ const collectionHelper = evmCollectionHelpers(web3, owner);
+ const collectionName = 'CollectionEVM';
+ const description = 'Some description';
+ const tokenPrefix = 'token prefix';
- // const collectionCountBefore = await getCreatedCollectionCount(api);
- // const result = await collectionHelper.methods
- // .createNonfungibleCollection(collectionName, description, tokenPrefix)
- // .send();
- // const collectionCountAfter = await getCreatedCollectionCount(api);
+ const collectionCountBefore = await getCreatedCollectionCount(api);
+ const result = await collectionHelper.methods
+ .createNonfungibleCollection(collectionName, description, tokenPrefix)
+ .send();
+ const collectionCountAfter = await getCreatedCollectionCount(api);
- // const {collectionId, collection} = await getCollectionAddressFromResult(api, result);
- // expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);
- // expect(collectionId).to.be.eq(collectionCountAfter);
- // expect(collection.name.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(collectionName);
- // expect(collection.description.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(description);
- // expect(collection.tokenPrefix.toHuman()).to.be.eq(tokenPrefix);
- // });
+ const {collectionId, collection} = await getCollectionAddressFromResult(api, result);
+ expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);
+ expect(collectionId).to.be.eq(collectionCountAfter);
+ expect(collection.name.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(collectionName);
+ expect(collection.description.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(description);
+ expect(collection.tokenPrefix.toHuman()).to.be.eq(tokenPrefix);
+ });
- // itWeb3('Check collection address exist', async ({api, web3, privateKeyWrapper}) => {
- // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- // const collectionHelpers = evmCollectionHelpers(web3, owner);
+ itWeb3('Check collection address exist', async ({api, web3, privateKeyWrapper}) => {
+ const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ const collectionHelpers = evmCollectionHelpers(web3, owner);
- // const expectedCollectionId = await getCreatedCollectionCount(api) + 1;
- // const expectedCollectionAddress = collectionIdToAddress(expectedCollectionId);
- // expect(await collectionHelpers.methods
- // .isCollectionExist(expectedCollectionAddress)
- // .call()).to.be.false;
+ const expectedCollectionId = await getCreatedCollectionCount(api) + 1;
+ const expectedCollectionAddress = collectionIdToAddress(expectedCollectionId);
+ expect(await collectionHelpers.methods
+ .isCollectionExist(expectedCollectionAddress)
+ .call()).to.be.false;
- // await collectionHelpers.methods
- // .createNonfungibleCollection('A', 'A', 'A')
- // .send();
+ await collectionHelpers.methods
+ .createNonfungibleCollection('A', 'A', 'A')
+ .send();
- // expect(await collectionHelpers.methods
- // .isCollectionExist(expectedCollectionAddress)
- // .call()).to.be.true;
- // });
+ expect(await collectionHelpers.methods
+ .isCollectionExist(expectedCollectionAddress)
+ .call()).to.be.true;
+ });
itWeb3('Set sponsorship', async ({api, web3, privateKeyWrapper}) => {
const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);