git.delta.rocks / unique-network / refs/commits / 17ea847df73f

difftreelog

feat add mint_bulk_cross

Grigoriy Simonov2023-09-22parent: #9a3d9a7.patch.diff
in: master

15 files changed

modifiedpallets/common/src/eth.rsdiffbeforeafterboth
632 }632 }
633}633}
634
635/// Token minting parameters
636#[derive(AbiCoder, Default, Debug)]
637pub struct MintTokenData {
638 /// Minted token owner
639 pub owner: CrossAddress,
640 /// Minted token properties
641 pub properties: Vec<Property>,
642}
634643
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
981 Ok(true)981 Ok(true)
982 }982 }
983
984 /// @notice Function to mint a token.
985 /// @param data Array of pairs of token owner and token's properties for minted token
986 #[weight(<SelfWeightOf<T>>::create_multiple_items(data.len() as u32) + <SelfWeightOf<T>>::set_token_properties(data.len() as u32))]
987 fn mint_bulk_cross(&mut self, caller: Caller, data: Vec<eth::MintTokenData>) -> Result<bool> {
988 let caller = T::CrossAccountId::from_eth(caller);
989 let budget = self
990 .recorder
991 .weight_calls_budget(<StructureWeight<T>>::find_parent());
992
993 let mut create_nft_data = Vec::with_capacity(data.len());
994 for eth::MintTokenData { owner, properties } in data {
995 let owner = owner.into_sub_cross_account::<T>()?;
996 create_nft_data.push(CreateItemData::<T> {
997 properties: properties
998 .into_iter()
999 .map(|property| property.try_into())
1000 .collect::<Result<Vec<_>>>()?
1001 .try_into()
1002 .map_err(|_| "too many properties")?,
1003 owner,
1004 });
1005 }
1006
1007 <Pallet<T>>::create_multiple_items(self, &caller, create_nft_data, &budget)
1008 .map_err(dispatch_to_evm::<T>)?;
1009 Ok(true)
1010 }
9831011
984 /// @notice Function to mint multiple tokens with the given tokenUris.1012 /// @notice Function to mint multiple tokens with the given tokenUris.
985 /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive1013 /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
800}800}
801801
802/// @title Unique extensions for ERC721.802/// @title Unique extensions for ERC721.
803/// @dev the ERC-165 identifier for this interface is 0x307b061a803/// @dev the ERC-165 identifier for this interface is 0x9b397d16
804contract ERC721UniqueExtensions is Dummy, ERC165 {804contract ERC721UniqueExtensions is Dummy, ERC165 {
805 /// @notice A descriptive name for a collection of NFTs in this contract805 /// @notice A descriptive name for a collection of NFTs in this contract
806 /// @dev EVM selector for this function is: 0x06fdde03,806 /// @dev EVM selector for this function is: 0x06fdde03,
997 // return false;997 // return false;
998 // }998 // }
999
1000 /// @notice Function to mint a token.
1001 /// @param data Array of pairs of token owner and token's properties for minted token
1002 /// @dev EVM selector for this function is: 0xab427b0c,
1003 /// or in textual repr: mintBulkCross(((address,uint256),(string,bytes)[])[])
1004 function mintBulkCross(MintTokenData[] memory data) public returns (bool) {
1005 require(false, stub_error);
1006 data;
1007 dummy = 0;
1008 return false;
1009 }
9991010
1000 // /// @notice Function to mint multiple tokens with the given tokenUris.1011 // /// @notice Function to mint multiple tokens with the given tokenUris.
1001 // /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive1012 // /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
1044 string uri;1055 string uri;
1045}1056}
1057
1058struct MintTokenData {
1059 CrossAddress owner;
1060 Property[] properties;
1061}
10461062
1047/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension1063/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
1048/// @dev See https://eips.ethereum.org/EIPS/eip-7211064/// @dev See https://eips.ethereum.org/EIPS/eip-721
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
1021 Ok(true)1021 Ok(true)
1022 }1022 }
1023
1024 /// @notice Function to mint a token.
1025 /// @param tokenProperties Properties of minted token
1026 #[weight(<SelfWeightOf<T>>::create_multiple_items(token_properties.len() as u32) + <SelfWeightOf<T>>::set_token_properties(token_properties.len() as u32))]
1027 fn mint_bulk_cross(
1028 &mut self,
1029 caller: Caller,
1030 token_properties: Vec<eth::MintTokenData>,
1031 ) -> Result<bool> {
1032 let caller = T::CrossAccountId::from_eth(caller);
1033 let budget = self
1034 .recorder
1035 .weight_calls_budget(<StructureWeight<T>>::find_parent());
1036
1037 let mut create_rft_data = Vec::with_capacity(token_properties.len());
1038 for eth::MintTokenData { owner, properties } in token_properties {
1039 let owner = owner.into_sub_cross_account::<T>()?;
1040 let users: BoundedBTreeMap<_, _, _> = [(owner, 1)]
1041 .into_iter()
1042 .collect::<BTreeMap<_, _>>()
1043 .try_into()
1044 .map_err(|_| "too many users")?;
1045 create_rft_data.push(CreateItemData::<T> {
1046 properties: properties
1047 .into_iter()
1048 .map(|property| property.try_into())
1049 .collect::<Result<Vec<_>>>()?
1050 .try_into()
1051 .map_err(|_| "too many properties")?,
1052 users,
1053 });
1054 }
1055
1056 <Pallet<T>>::create_multiple_items(self, &caller, create_rft_data, &budget)
1057 .map_err(dispatch_to_evm::<T>)?;
1058 Ok(true)
1059 }
10231060
1024 /// @notice Function to mint multiple tokens with the given tokenUris.1061 /// @notice Function to mint multiple tokens with the given tokenUris.
1025 /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive1062 /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
modifiedpallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth
800}800}
801801
802/// @title Unique extensions for ERC721.802/// @title Unique extensions for ERC721.
803/// @dev the ERC-165 identifier for this interface is 0x95c0f66c803/// @dev the ERC-165 identifier for this interface is 0x3e828d60
804contract ERC721UniqueExtensions is Dummy, ERC165 {804contract ERC721UniqueExtensions is Dummy, ERC165 {
805 /// @notice A descriptive name for a collection of NFTs in this contract805 /// @notice A descriptive name for a collection of NFTs in this contract
806 /// @dev EVM selector for this function is: 0x06fdde03,806 /// @dev EVM selector for this function is: 0x06fdde03,
986 // return false;986 // return false;
987 // }987 // }
988
989 /// @notice Function to mint a token.
990 /// @param tokenProperties Properties of minted token
991 /// @dev EVM selector for this function is: 0xab427b0c,
992 /// or in textual repr: mintBulkCross(((address,uint256),(string,bytes)[])[])
993 function mintBulkCross(MintTokenData[] memory tokenProperties) public returns (bool) {
994 require(false, stub_error);
995 tokenProperties;
996 dummy = 0;
997 return false;
998 }
988999
989 // /// @notice Function to mint multiple tokens with the given tokenUris.1000 // /// @notice Function to mint multiple tokens with the given tokenUris.
990 // /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive1001 // /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
1045 string uri;1056 string uri;
1046}1057}
1058
1059struct MintTokenData {
1060 CrossAddress owner;
1061 Property[] properties;
1062}
10471063
1048/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension1064/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
1049/// @dev See https://eips.ethereum.org/EIPS/eip-7211065/// @dev See https://eips.ethereum.org/EIPS/eip-721
modifiedpallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth
25}25}
2626
27/// @title Contract, which allows users to operate with collections27/// @title Contract, which allows users to operate with collections
28/// @dev the ERC-165 identifier for this interface is 0x4135fff128/// @dev the ERC-165 identifier for this interface is 0x94e5af0d
29contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {29contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
30 /// Create a collection30 /// Create a collection
31 /// @return address Address of the newly created collection31 /// @return address Address of the newly created collection
32 /// @dev EVM selector for this function is: 0xa765ee5b,32 /// @dev EVM selector for this function is: 0x72b5bea7,
33 /// or in textual repr: createCollection(((address,uint256),string,string,string,uint8,uint8,(string,bytes)[],(string,(uint8,bool)[])[],(address,uint256)[],(bool,bool,address[]),(uint8,uint256)[],uint8))33 /// or in textual repr: createCollection((string,string,string,uint8,uint8,(string,bytes)[],(string,(uint8,bool)[])[],(address,uint256)[],(bool,bool,address[]),(uint8,uint256)[],(address,uint256),uint8))
34 function createCollection(CreateCollectionData memory data) public payable returns (address) {34 function createCollection(CreateCollectionData memory data) public payable returns (address) {
35 require(false, stub_error);35 require(false, stub_error);
36 data;36 data;
170170
171/// Collection properties171/// Collection properties
172struct CreateCollectionData {172struct CreateCollectionData {
173 /// Collection sponsor
174 CrossAddress pending_sponsor;
175 /// Collection name173 /// Collection name
176 string name;174 string name;
177 /// Collection description175 /// Collection description
192 CollectionNestingAndPermission nesting_settings;190 CollectionNestingAndPermission nesting_settings;
193 /// Collection limits191 /// Collection limits
194 CollectionLimitValue[] limits;192 CollectionLimitValue[] limits;
193 /// Collection sponsor
194 CrossAddress pending_sponsor;
195 /// Extra collection flags195 /// Extra collection flags
196 CollectionFlags flags;196 CollectionFlags flags;
197}197}
198198
199/// Cross account struct
200type CollectionFlags is uint8;199type CollectionFlags is uint8;
201200
202library CollectionFlagsLib {201library CollectionFlagsLib {
207 /// External collections can't be managed using `unique` api206 /// External collections can't be managed using `unique` api
208 CollectionFlags constant externalField = CollectionFlags.wrap(1);207 CollectionFlags constant externalField = CollectionFlags.wrap(1);
209208
210 /// Reserved bits209 /// Reserved flags
211 function reservedField(uint8 value) public pure returns (CollectionFlags) {210 function reservedField(uint8 value) public pure returns (CollectionFlags) {
212 require(value < 1 << 5, "out of bound value");211 require(value < 1 << 5, "out of bound value");
213 return CollectionFlags.wrap(value << 1);212 return CollectionFlags.wrap(value << 1);
214 }213 }
215}214}
215
216/// Cross account struct
217struct CrossAddress {
218 address eth;
219 uint256 sub;
220}
216221
217/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.222/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
218struct CollectionLimitValue {223struct CollectionLimitValue {
252 address[] restricted;257 address[] restricted;
253}258}
254
255/// Cross account struct
256struct CrossAddress {
257 address eth;
258 uint256 sub;
259}
260259
261/// Ethereum representation of Token Property Permissions.260/// Ethereum representation of Token Property Permissions.
262struct TokenPropertyPermission {261struct TokenPropertyPermission {
292291
293/// Type of tokens in collection292/// Type of tokens in collection
294enum CollectionMode {293enum CollectionMode {
294 /// Nonfungible
295 Nonfungible,
295 /// Fungible296 /// Fungible
296 Fungible,297 Fungible,
297 /// Nonfungible
298 Nonfungible,
299 /// Refungible298 /// Refungible
300 Refungible299 Refungible
301}300}
modifiedruntime/common/ethereum/sponsoring/refungible.rsdiffbeforeafterboth
242 BurnFrom { .. }242 BurnFrom { .. }
243 | BurnFromCross { .. }243 | BurnFromCross { .. }
244 | MintBulk { .. }244 | MintBulk { .. }
245 | MintBulkCross { .. }
245 | MintBulkWithTokenUri { .. } => None,246 | MintBulkWithTokenUri { .. } => None,
246247
247 MintCross { .. } => withdraw_create_item::<T>(248 MintCross { .. } => withdraw_create_item::<T>(
modifiedtests/src/eth/abi/nonFungible.jsondiffbeforeafterboth
465 "stateMutability": "nonpayable",465 "stateMutability": "nonpayable",
466 "type": "function"466 "type": "function"
467 },467 },
468 {
469 "inputs": [
470 {
471 "components": [
472 {
473 "components": [
474 { "internalType": "address", "name": "eth", "type": "address" },
475 { "internalType": "uint256", "name": "sub", "type": "uint256" }
476 ],
477 "internalType": "struct CrossAddress",
478 "name": "owner",
479 "type": "tuple"
480 },
481 {
482 "components": [
483 { "internalType": "string", "name": "key", "type": "string" },
484 { "internalType": "bytes", "name": "value", "type": "bytes" }
485 ],
486 "internalType": "struct Property[]",
487 "name": "properties",
488 "type": "tuple[]"
489 }
490 ],
491 "internalType": "struct MintTokenData[]",
492 "name": "data",
493 "type": "tuple[]"
494 }
495 ],
496 "name": "mintBulkCross",
497 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
498 "stateMutability": "nonpayable",
499 "type": "function"
500 },
468 {501 {
469 "inputs": [502 "inputs": [
470 {503 {
modifiedtests/src/eth/abi/reFungible.jsondiffbeforeafterboth
447 "stateMutability": "nonpayable",447 "stateMutability": "nonpayable",
448 "type": "function"448 "type": "function"
449 },449 },
450 {
451 "inputs": [
452 {
453 "components": [
454 {
455 "components": [
456 { "internalType": "address", "name": "eth", "type": "address" },
457 { "internalType": "uint256", "name": "sub", "type": "uint256" }
458 ],
459 "internalType": "struct CrossAddress",
460 "name": "owner",
461 "type": "tuple"
462 },
463 {
464 "components": [
465 { "internalType": "string", "name": "key", "type": "string" },
466 { "internalType": "bytes", "name": "value", "type": "bytes" }
467 ],
468 "internalType": "struct Property[]",
469 "name": "properties",
470 "type": "tuple[]"
471 }
472 ],
473 "internalType": "struct MintTokenData[]",
474 "name": "tokenProperties",
475 "type": "tuple[]"
476 }
477 ],
478 "name": "mintBulkCross",
479 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
480 "stateMutability": "nonpayable",
481 "type": "function"
482 },
450 {483 {
451 "inputs": [484 "inputs": [
452 {485 {
modifiedtests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth
20}20}
2121
22/// @title Contract, which allows users to operate with collections22/// @title Contract, which allows users to operate with collections
23/// @dev the ERC-165 identifier for this interface is 0x4135fff123/// @dev the ERC-165 identifier for this interface is 0x94e5af0d
24interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {24interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
25 /// Create a collection25 /// Create a collection
26 /// @return address Address of the newly created collection26 /// @return address Address of the newly created collection
27 /// @dev EVM selector for this function is: 0xa765ee5b,27 /// @dev EVM selector for this function is: 0x72b5bea7,
28 /// or in textual repr: createCollection(((address,uint256),string,string,string,uint8,uint8,(string,bytes)[],(string,(uint8,bool)[])[],(address,uint256)[],(bool,bool,address[]),(uint8,uint256)[],uint8))28 /// or in textual repr: createCollection((string,string,string,uint8,uint8,(string,bytes)[],(string,(uint8,bool)[])[],(address,uint256)[],(bool,bool,address[]),(uint8,uint256)[],(address,uint256),uint8))
29 function createCollection(CreateCollectionData memory data) external payable returns (address);29 function createCollection(CreateCollectionData memory data) external payable returns (address);
3030
31 /// Create an NFT collection31 /// Create an NFT collection
103103
104/// Collection properties104/// Collection properties
105struct CreateCollectionData {105struct CreateCollectionData {
106 /// Collection sponsor
107 CrossAddress pending_sponsor;
108 /// Collection name106 /// Collection name
109 string name;107 string name;
110 /// Collection description108 /// Collection description
125 CollectionNestingAndPermission nesting_settings;123 CollectionNestingAndPermission nesting_settings;
126 /// Collection limits124 /// Collection limits
127 CollectionLimitValue[] limits;125 CollectionLimitValue[] limits;
126 /// Collection sponsor
127 CrossAddress pending_sponsor;
128 /// Extra collection flags128 /// Extra collection flags
129 CollectionFlags flags;129 CollectionFlags flags;
130}130}
131131
132/// Cross account struct
133type CollectionFlags is uint8;132type CollectionFlags is uint8;
134133
135library CollectionFlagsLib {134library CollectionFlagsLib {
140 /// External collections can't be managed using `unique` api139 /// External collections can't be managed using `unique` api
141 CollectionFlags constant externalField = CollectionFlags.wrap(1);140 CollectionFlags constant externalField = CollectionFlags.wrap(1);
142141
143 /// Reserved bits142 /// Reserved flags
144 function reservedField(uint8 value) public pure returns (CollectionFlags) {143 function reservedField(uint8 value) public pure returns (CollectionFlags) {
145 require(value < 1 << 5, "out of bound value");144 require(value < 1 << 5, "out of bound value");
146 return CollectionFlags.wrap(value << 1);145 return CollectionFlags.wrap(value << 1);
147 }146 }
148}147}
148
149/// Cross account struct
150struct CrossAddress {
151 address eth;
152 uint256 sub;
153}
149154
150/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.155/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
151struct CollectionLimitValue {156struct CollectionLimitValue {
185 address[] restricted;190 address[] restricted;
186}191}
187
188/// Cross account struct
189struct CrossAddress {
190 address eth;
191 uint256 sub;
192}
193192
194/// Ethereum representation of Token Property Permissions.193/// Ethereum representation of Token Property Permissions.
195struct TokenPropertyPermission {194struct TokenPropertyPermission {
225224
226/// Type of tokens in collection225/// Type of tokens in collection
227enum CollectionMode {226enum CollectionMode {
227 /// Nonfungible
228 Nonfungible,
228 /// Fungible229 /// Fungible
229 Fungible,230 Fungible,
230 /// Nonfungible
231 Nonfungible,
232 /// Refungible231 /// Refungible
233 Refungible232 Refungible
234}233}
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
551}551}
552552
553/// @title Unique extensions for ERC721.553/// @title Unique extensions for ERC721.
554/// @dev the ERC-165 identifier for this interface is 0x307b061a554/// @dev the ERC-165 identifier for this interface is 0x9b397d16
555interface ERC721UniqueExtensions is Dummy, ERC165 {555interface ERC721UniqueExtensions is Dummy, ERC165 {
556 /// @notice A descriptive name for a collection of NFTs in this contract556 /// @notice A descriptive name for a collection of NFTs in this contract
557 /// @dev EVM selector for this function is: 0x06fdde03,557 /// @dev EVM selector for this function is: 0x06fdde03,
674 // /// or in textual repr: mintBulk(address,uint256[])674 // /// or in textual repr: mintBulk(address,uint256[])
675 // function mintBulk(address to, uint256[] memory tokenIds) external returns (bool);675 // function mintBulk(address to, uint256[] memory tokenIds) external returns (bool);
676
677 /// @notice Function to mint a token.
678 /// @param data Array of pairs of token owner and token's properties for minted token
679 /// @dev EVM selector for this function is: 0xab427b0c,
680 /// or in textual repr: mintBulkCross(((address,uint256),(string,bytes)[])[])
681 function mintBulkCross(MintTokenData[] memory data) external returns (bool);
676682
677 // /// @notice Function to mint multiple tokens with the given tokenUris.683 // /// @notice Function to mint multiple tokens with the given tokenUris.
678 // /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive684 // /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
705 string uri;711 string uri;
706}712}
713
714struct MintTokenData {
715 CrossAddress owner;
716 Property[] properties;
717}
707718
708/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension719/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
709/// @dev See https://eips.ethereum.org/EIPS/eip-721720/// @dev See https://eips.ethereum.org/EIPS/eip-721
modifiedtests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth
551}551}
552552
553/// @title Unique extensions for ERC721.553/// @title Unique extensions for ERC721.
554/// @dev the ERC-165 identifier for this interface is 0x95c0f66c554/// @dev the ERC-165 identifier for this interface is 0x3e828d60
555interface ERC721UniqueExtensions is Dummy, ERC165 {555interface ERC721UniqueExtensions is Dummy, ERC165 {
556 /// @notice A descriptive name for a collection of NFTs in this contract556 /// @notice A descriptive name for a collection of NFTs in this contract
557 /// @dev EVM selector for this function is: 0x06fdde03,557 /// @dev EVM selector for this function is: 0x06fdde03,
668 // /// or in textual repr: mintBulk(address,uint256[])668 // /// or in textual repr: mintBulk(address,uint256[])
669 // function mintBulk(address to, uint256[] memory tokenIds) external returns (bool);669 // function mintBulk(address to, uint256[] memory tokenIds) external returns (bool);
670
671 /// @notice Function to mint a token.
672 /// @param tokenProperties Properties of minted token
673 /// @dev EVM selector for this function is: 0xab427b0c,
674 /// or in textual repr: mintBulkCross(((address,uint256),(string,bytes)[])[])
675 function mintBulkCross(MintTokenData[] memory tokenProperties) external returns (bool);
670676
671 // /// @notice Function to mint multiple tokens with the given tokenUris.677 // /// @notice Function to mint multiple tokens with the given tokenUris.
672 // /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive678 // /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
706 string uri;712 string uri;
707}713}
714
715struct MintTokenData {
716 CrossAddress owner;
717 Property[] properties;
718}
708719
709/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension720/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
710/// @dev See https://eips.ethereum.org/EIPS/eip-721721/// @dev See https://eips.ethereum.org/EIPS/eip-721