difftreelog
feat add mint_bulk_cross
in: master
15 files changed
pallets/common/src/eth.rsdiffbeforeafterboth632 }632 }633}633}634635/// Token minting parameters636#[derive(AbiCoder, Default, Debug)]637pub struct MintTokenData {638 /// Minted token owner639 pub owner: CrossAddress,640 /// Minted token properties641 pub properties: Vec<Property>,642}634643pallets/nonfungible/src/erc.rsdiffbeforeafterboth981 Ok(true)981 Ok(true)982 }982 }983984 /// @notice Function to mint a token.985 /// @param data Array of pairs of token owner and token's properties for minted token986 #[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 = self990 .recorder991 .weight_calls_budget(<StructureWeight<T>>::find_parent());992993 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: properties998 .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 }10061007 <Pallet<T>>::create_multiple_items(self, &caller, create_nft_data, &budget)1008 .map_err(dispatch_to_evm::<T>)?;1009 Ok(true)1010 }9831011984 /// @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 consecutivepallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterbothbinary blob — no preview
pallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth800}800}801801802/// @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 0x9b397d16804contract 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 contract806 /// @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 // }9991000 /// @notice Function to mint a token.1001 /// @param data Array of pairs of token owner and token's properties for minted token1002 /// @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 }99910101000 // /// @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 consecutive1044 string uri;1055 string uri;1045}1056}10571058struct MintTokenData {1059 CrossAddress owner;1060 Property[] properties;1061}104610621047/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension1063/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension1048/// @dev See https://eips.ethereum.org/EIPS/eip-7211064/// @dev See https://eips.ethereum.org/EIPS/eip-721pallets/refungible/src/erc.rsdiffbeforeafterboth1021 Ok(true)1021 Ok(true)1022 }1022 }10231024 /// @notice Function to mint a token.1025 /// @param tokenProperties Properties of minted token1026 #[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 = self1034 .recorder1035 .weight_calls_budget(<StructureWeight<T>>::find_parent());10361037 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: properties1047 .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 }10551056 <Pallet<T>>::create_multiple_items(self, &caller, create_rft_data, &budget)1057 .map_err(dispatch_to_evm::<T>)?;1058 Ok(true)1059 }102310601024 /// @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 consecutivepallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth800}800}801801802/// @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 0x3e828d60804contract 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 contract806 /// @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 // }988989 /// @notice Function to mint a token.990 /// @param tokenProperties Properties of minted token991 /// @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 }988999989 // /// @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 consecutive1045 string uri;1056 string uri;1046}1057}10581059struct MintTokenData {1060 CrossAddress owner;1061 Property[] properties;1062}104710631048/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension1064/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension1049/// @dev See https://eips.ethereum.org/EIPS/eip-7211065/// @dev See https://eips.ethereum.org/EIPS/eip-721pallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth25}25}262627/// @title Contract, which allows users to operate with collections27/// @title Contract, which allows users to operate with collections28/// @dev the ERC-165 identifier for this interface is 0x4135fff128/// @dev the ERC-165 identifier for this interface is 0x94e5af0d29contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {29contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {30 /// Create a collection30 /// Create a collection31 /// @return address Address of the newly created collection31 /// @return address Address of the newly created collection32 /// @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;170170171/// Collection properties171/// Collection properties172struct CreateCollectionData {172struct CreateCollectionData {173 /// Collection sponsor174 CrossAddress pending_sponsor;175 /// Collection name173 /// Collection name176 string name;174 string name;177 /// Collection description175 /// Collection description192 CollectionNestingAndPermission nesting_settings;190 CollectionNestingAndPermission nesting_settings;193 /// Collection limits191 /// Collection limits194 CollectionLimitValue[] limits;192 CollectionLimitValue[] limits;193 /// Collection sponsor194 CrossAddress pending_sponsor;195 /// Extra collection flags195 /// Extra collection flags196 CollectionFlags flags;196 CollectionFlags flags;197}197}198198199/// Cross account struct200type CollectionFlags is uint8;199type CollectionFlags is uint8;201200202library CollectionFlagsLib {201library CollectionFlagsLib {207 /// External collections can't be managed using `unique` api206 /// External collections can't be managed using `unique` api208 CollectionFlags constant externalField = CollectionFlags.wrap(1);207 CollectionFlags constant externalField = CollectionFlags.wrap(1);209208210 /// Reserved bits209 /// Reserved flags211 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}215216/// Cross account struct217struct CrossAddress {218 address eth;219 uint256 sub;220}216221217/// [`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}254255/// Cross account struct256struct CrossAddress {257 address eth;258 uint256 sub;259}260259261/// Ethereum representation of Token Property Permissions.260/// Ethereum representation of Token Property Permissions.262struct TokenPropertyPermission {261struct TokenPropertyPermission {292291293/// Type of tokens in collection292/// Type of tokens in collection294enum CollectionMode {293enum CollectionMode {294 /// Nonfungible295 Nonfungible,295 /// Fungible296 /// Fungible296 Fungible,297 Fungible,297 /// Nonfungible298 Nonfungible,299 /// Refungible298 /// Refungible300 Refungible299 Refungible301}300}runtime/common/ethereum/sponsoring/refungible.rsdiffbeforeafterboth242 BurnFrom { .. }242 BurnFrom { .. }243 | BurnFromCross { .. }243 | BurnFromCross { .. }244 | MintBulk { .. }244 | MintBulk { .. }245 | MintBulkCross { .. }245 | MintBulkWithTokenUri { .. } => None,246 | MintBulkWithTokenUri { .. } => None,246247247 MintCross { .. } => withdraw_create_item::<T>(248 MintCross { .. } => withdraw_create_item::<T>(tests/src/eth/abi/nonFungible.jsondiffbeforeafterboth465 "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 {tests/src/eth/abi/reFungible.jsondiffbeforeafterboth447 "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 {tests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth20}20}212122/// @title Contract, which allows users to operate with collections22/// @title Contract, which allows users to operate with collections23/// @dev the ERC-165 identifier for this interface is 0x4135fff123/// @dev the ERC-165 identifier for this interface is 0x94e5af0d24interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {24interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {25 /// Create a collection25 /// Create a collection26 /// @return address Address of the newly created collection26 /// @return address Address of the newly created collection27 /// @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);303031 /// Create an NFT collection31 /// Create an NFT collection103103104/// Collection properties104/// Collection properties105struct CreateCollectionData {105struct CreateCollectionData {106 /// Collection sponsor107 CrossAddress pending_sponsor;108 /// Collection name106 /// Collection name109 string name;107 string name;110 /// Collection description108 /// Collection description125 CollectionNestingAndPermission nesting_settings;123 CollectionNestingAndPermission nesting_settings;126 /// Collection limits124 /// Collection limits127 CollectionLimitValue[] limits;125 CollectionLimitValue[] limits;126 /// Collection sponsor127 CrossAddress pending_sponsor;128 /// Extra collection flags128 /// Extra collection flags129 CollectionFlags flags;129 CollectionFlags flags;130}130}131131132/// Cross account struct133type CollectionFlags is uint8;132type CollectionFlags is uint8;134133135library CollectionFlagsLib {134library CollectionFlagsLib {140 /// External collections can't be managed using `unique` api139 /// External collections can't be managed using `unique` api141 CollectionFlags constant externalField = CollectionFlags.wrap(1);140 CollectionFlags constant externalField = CollectionFlags.wrap(1);142141143 /// Reserved bits142 /// Reserved flags144 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}148149/// Cross account struct150struct CrossAddress {151 address eth;152 uint256 sub;153}149154150/// [`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}187188/// Cross account struct189struct CrossAddress {190 address eth;191 uint256 sub;192}193192194/// Ethereum representation of Token Property Permissions.193/// Ethereum representation of Token Property Permissions.195struct TokenPropertyPermission {194struct TokenPropertyPermission {225224226/// Type of tokens in collection225/// Type of tokens in collection227enum CollectionMode {226enum CollectionMode {227 /// Nonfungible228 Nonfungible,228 /// Fungible229 /// Fungible229 Fungible,230 Fungible,230 /// Nonfungible231 Nonfungible,232 /// Refungible231 /// Refungible233 Refungible232 Refungible234}233}tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth551}551}552552553/// @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 0x9b397d16555interface 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 contract557 /// @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);676677 /// @notice Function to mint a token.678 /// @param data Array of pairs of token owner and token's properties for minted token679 /// @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);676682677 // /// @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 consecutive705 string uri;711 string uri;706}712}713714struct MintTokenData {715 CrossAddress owner;716 Property[] properties;717}707718708/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension719/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension709/// @dev See https://eips.ethereum.org/EIPS/eip-721720/// @dev See https://eips.ethereum.org/EIPS/eip-721tests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth551}551}552552553/// @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 0x3e828d60555interface 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 contract557 /// @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);670671 /// @notice Function to mint a token.672 /// @param tokenProperties Properties of minted token673 /// @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);670676671 // /// @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 consecutive706 string uri;712 string uri;707}713}714715struct MintTokenData {716 CrossAddress owner;717 Property[] properties;718}708719709/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension720/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension710/// @dev See https://eips.ethereum.org/EIPS/eip-721721/// @dev See https://eips.ethereum.org/EIPS/eip-721