git.delta.rocks / unique-network / refs/commits / 6bf51e4b62d4

difftreelog

feat remove collection with metadata creation

Yaroslav Bolyukin2022-10-14parent: #503c92c.patch.diff
in: master

1 file changed

modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
59 name: string,59 name: string,
60 description: string,60 description: string,
61 token_prefix: string,61 token_prefix: string,
62 base_uri: string,
63) -> Result<(62) -> Result<(
64 T::CrossAccountId,63 T::CrossAccountId,
65 CollectionName,64 CollectionName,
66 CollectionDescription,65 CollectionDescription,
67 CollectionTokenPrefix,66 CollectionTokenPrefix,
68 PropertyValue,
69)> {67)> {
70 let caller = T::CrossAccountId::from_eth(caller);68 let caller = T::CrossAccountId::from_eth(caller);
71 let name = name69 let name = name
83 let token_prefix = token_prefix.into_bytes().try_into().map_err(|_| {81 let token_prefix = token_prefix.into_bytes().try_into().map_err(|_| {
84 error_field_too_long(stringify!(token_prefix), CollectionTokenPrefix::bound())82 error_field_too_long(stringify!(token_prefix), CollectionTokenPrefix::bound())
85 })?;83 })?;
86 let base_uri_value = base_uri
87 .into_bytes()
88 .try_into()
89 .map_err(|_| error_field_too_long(stringify!(token_prefix), PropertyValue::bound()))?;
90 Ok((caller, name, description, token_prefix, base_uri_value))84 Ok((caller, name, description, token_prefix))
91}85}
92
93fn default_url_pkp() -> up_data_structs::PropertyKeyPermission {
94 up_data_structs::PropertyKeyPermission {
95 key: key::url(),
96 permission: up_data_structs::PropertyPermission {
97 mutable: true,
98 collection_admin: true,
99 token_owner: false,
100 },
101 }
102}
103fn default_suffix_pkp() -> up_data_structs::PropertyKeyPermission {
104 up_data_structs::PropertyKeyPermission {
105 key: key::suffix(),
106 permission: up_data_structs::PropertyPermission {
107 mutable: true,
108 collection_admin: true,
109 token_owner: false,
110 },
111 }
112}
113fn make_data<T: Config>(
114 name: CollectionName,
115 mode: CollectionMode,
116 description: CollectionDescription,
117 token_prefix: CollectionTokenPrefix,
118 base_uri_value: PropertyValue,
119 add_properties: bool,
120) -> Result<CreateCollectionData<T::AccountId>> {
121 let token_property_permissions = if add_properties {
122 vec![default_url_pkp(), default_suffix_pkp()]
123 .try_into()
124 .map_err(|e| Error::Revert(format!("{:?}", e)))?
125 } else {
126 up_data_structs::CollectionPropertiesPermissionsVec::default()
127 };
128 let properties = if add_properties && !base_uri_value.is_empty() {
129 vec![up_data_structs::Property {
130 key: key::base_uri(),
131 value: base_uri_value,
132 }]
133 .try_into()
134 .expect("limit >= 1")
135 } else {
136 up_data_structs::CollectionPropertiesVec::default()
137 };
138
139 let data = CreateCollectionData {
140 name,
141 mode,
142 description,
143 token_prefix,
144 token_property_permissions,
145 properties,
146 ..Default::default()
147 };
148 Ok(data)
149}
15086
151fn create_refungible_collection_internal<87fn create_refungible_collection_internal<
152 T: Config + pallet_nonfungible::Config + pallet_refungible::Config,88 T: Config + pallet_nonfungible::Config + pallet_refungible::Config,
156 name: string,92 name: string,
157 description: string,93 description: string,
158 token_prefix: string,94 token_prefix: string,
159 base_uri: string,
160 add_properties: bool,
161) -> Result<address> {95) -> Result<address> {
162 let (caller, name, description, token_prefix, base_uri_value) =96 let (caller, name, description, token_prefix) =
163 convert_data::<T>(caller, name, description, token_prefix, base_uri)?;97 convert_data::<T>(caller, name, description, token_prefix)?;
164 let data = make_data::<T>(98 let data = CreateCollectionData {
165 name,99 name,
166 CollectionMode::ReFungible,100 mode: CollectionMode::ReFungible,
167 description,101 description,
168 token_prefix,102 token_prefix,
169 base_uri_value,103 ..Default::default()
170 add_properties,
171 )?;104 };
172 check_sent_amount_equals_collection_creation_price::<T>(value)?;105 check_sent_amount_equals_collection_creation_price::<T>(value)?;
173 let collection_helpers_address =106 let collection_helpers_address =
174 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());107 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
177 caller.clone(),110 caller.clone(),
178 collection_helpers_address,111 collection_helpers_address,
179 data,112 data,
180 CollectionFlags {
181 erc721metadata: add_properties,
182 ..Default::default()113 Default::default(),
183 },
184 )114 )
185 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;115 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
186 let address = pallet_common::eth::collection_id_to_address(collection_id);116 let address = pallet_common::eth::collection_id_to_address(collection_id);
224 description: string,154 description: string,
225 token_prefix: string,155 token_prefix: string,
226 ) -> Result<address> {156 ) -> Result<address> {
227 let (caller, name, description, token_prefix, _base_uri_value) =157 let (caller, name, description, token_prefix) =
228 convert_data::<T>(caller, name, description, token_prefix, "".into())?;158 convert_data::<T>(caller, name, description, token_prefix)?;
229 let data = make_data::<T>(159 let data = CreateCollectionData {
230 name,160 name,
231 CollectionMode::NFT,161 mode: CollectionMode::NFT,
232 description,162 description,
233 token_prefix,163 token_prefix,
234 Default::default(),164 ..Default::default()
235 false,
236 )?;165 };
237 check_sent_amount_equals_collection_creation_price::<T>(value)?;166 check_sent_amount_equals_collection_creation_price::<T>(value)?;
238 let collection_helpers_address =167 let collection_helpers_address =
239 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());168 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
266 self.create_nft_collection(caller, value, name, description, token_prefix)195 self.create_nft_collection(caller, value, name, description, token_prefix)
267 }196 }
268
269 #[weight(<SelfWeightOf<T>>::create_collection())]
270 #[solidity(rename_selector = "createERC721MetadataCompatibleNFTCollection")]
271 fn create_nonfungible_collection_with_properties(
272 &mut self,
273 caller: caller,
274 value: value,
275 name: string,
276 description: string,
277 token_prefix: string,
278 base_uri: string,
279 ) -> Result<address> {
280 let (caller, name, description, token_prefix, base_uri_value) =
281 convert_data::<T>(caller, name, description, token_prefix, base_uri)?;
282 let data = make_data::<T>(
283 name,
284 CollectionMode::NFT,
285 description,
286 token_prefix,
287 base_uri_value,
288 true,
289 )?;
290 check_sent_amount_equals_collection_creation_price::<T>(value)?;
291 let collection_helpers_address =
292 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
293 let collection_id = T::CollectionDispatch::create(
294 caller,
295 collection_helpers_address,
296 data,
297 CollectionFlags {
298 erc721metadata: true,
299 ..Default::default()
300 },
301 )
302 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
303
304 let address = pallet_common::eth::collection_id_to_address(collection_id);
305 Ok(address)
306 }
307197
308 #[weight(<SelfWeightOf<T>>::create_collection())]198 #[weight(<SelfWeightOf<T>>::create_collection())]
309 #[solidity(rename_selector = "createRFTCollection")]199 #[solidity(rename_selector = "createRFTCollection")]
320 value,
321 name,
322 description,
323 token_prefix,
324 Default::default(),
325 false,
326 )
327 }209 }
328
329 #[weight(<SelfWeightOf<T>>::create_collection())]
330 #[solidity(rename_selector = "createERC721MetadataCompatibleRFTCollection")]
331 fn create_refungible_collection_with_properties(
332 &mut self,
333 caller: caller,
334 value: value,
335 name: string,
336 description: string,
337 token_prefix: string,
338 base_uri: string,
339 ) -> Result<address> {
340 create_refungible_collection_internal::<T>(
341 caller,
342 value,
343 name,
344 description,
345 token_prefix,
346 base_uri,
347 true,
348 )
349 }
350210
351 #[solidity(rename_selector = "makeCollectionERC721MetadataCompatible")]211 #[solidity(rename_selector = "makeCollectionERC721MetadataCompatible")]
352 fn make_collection_metadata_compatible(212 fn make_collection_metadata_compatible(
381 let all_permissions = <pallet_common::CollectionPropertyPermissions<T>>::get(collection.id);241 let all_permissions = <pallet_common::CollectionPropertyPermissions<T>>::get(collection.id);
382 if all_permissions.get(&key::url()).is_none() {242 if all_permissions.get(&key::url()).is_none() {
383 self.recorder().consume_sstore()?;243 self.recorder().consume_sstore()?;
384 <PalletCommon<T>>::set_property_permission(&collection, &caller, default_url_pkp())244 <PalletCommon<T>>::set_property_permission(
245 &collection,
246 &caller,
247 up_data_structs::PropertyKeyPermission {
248 key: key::url(),
249 permission: up_data_structs::PropertyPermission {
250 mutable: true,
251 collection_admin: true,
252 token_owner: false,
253 },
254 },
255 )
385 .map_err(dispatch_to_evm::<T>)?;256 .map_err(dispatch_to_evm::<T>)?;
386 }257 }
387 if all_permissions.get(&key::suffix()).is_none() {258 if all_permissions.get(&key::suffix()).is_none() {
388 self.recorder().consume_sstore()?;259 self.recorder().consume_sstore()?;
389 <PalletCommon<T>>::set_property_permission(&collection, &caller, default_suffix_pkp())260 <PalletCommon<T>>::set_property_permission(
261 &collection,
262 &caller,
263 up_data_structs::PropertyKeyPermission {
264 key: key::suffix(),
265 permission: up_data_structs::PropertyPermission {
266 mutable: true,
267 collection_admin: true,
268 token_owner: false,
269 },
270 },
271 )
390 .map_err(dispatch_to_evm::<T>)?;272 .map_err(dispatch_to_evm::<T>)?;
391 }273 }