git.delta.rocks / unique-network / refs/commits / 7e74e9a0b0c6

difftreelog

feat sponsored approvals

Yaroslav Bolyukin2021-11-18parent: #4a3d839.patch.diff
in: master

2 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -147,7 +147,11 @@
 
 		/// Variable metadata sponsoring
 		/// Collection id (controlled?2), token id (controlled?2)
-		pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber> = None;
+		pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;
+		/// Approval sponsoring
+		pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;
+		pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;
+		pub RefungibleApproveBasket get(fn refungible_approve_basket): nmap hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;
 	}
 }
 
@@ -252,6 +256,9 @@
 			<ReFungibleTransferBasket<T>>::remove_prefix(collection_id, None);
 
 			<VariableMetaDataBasket<T>>::remove_prefix(collection_id, None);
+			<NftApproveBasket<T>>::remove_prefix(collection_id, None);
+			<FungibleApproveBasket<T>>::remove_prefix(collection_id, None);
+			<RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);
 
 			Ok(())
 		}
@@ -592,7 +599,15 @@
 		pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
 
-			dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))
+			let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;
+			if value == 1 {
+				<NftTransferBasket<T>>::remove(collection_id, item_id);
+				<NftApproveBasket<T>>::remove(collection_id, item_id);
+			}
+			// Those maps should be cleared only if token disappears completly, need to move this part of logic to pallets?
+			// <FungibleApproveBasket<T>>::remove(collection_id, sender.as_sub());
+			// <RefungibleApproveBasket<T>>::remove((collection_id, item_id, sender.as_sub()));
+			Ok(post_info)
 		}
 
 		/// Destroys a concrete instance of NFT on behalf of the owner
modifiedprimitives/nft/src/lib.rsdiffbeforeafterboth
54pub const FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;54pub const FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;
55pub const REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;55pub const REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;
56
57pub const SPONSOR_APPROVE_TIMEOUT: u32 = 5;
5658
57// Schema limits59// Schema limits
58pub const OFFCHAIN_SCHEMA_LIMIT: u32 = 1024;60pub const OFFCHAIN_SCHEMA_LIMIT: u32 = 1024;
259261
260 // Timeouts for item types in passed blocks262 // Timeouts for item types in passed blocks
261 pub sponsor_transfer_timeout: Option<u32>,263 pub sponsor_transfer_timeout: Option<u32>,
264 pub sponsor_approve_timeout: Option<u32>,
262 pub owner_can_transfer: Option<bool>,265 pub owner_can_transfer: Option<bool>,
263 pub owner_can_destroy: Option<bool>,266 pub owner_can_destroy: Option<bool>,
264 pub transfers_enabled: Option<bool>,267 pub transfers_enabled: Option<bool>,
285 .unwrap_or(default)288 .unwrap_or(default)
286 .min(MAX_SPONSOR_TIMEOUT)289 .min(MAX_SPONSOR_TIMEOUT)
287 }290 }
291 pub fn sponsor_approve_timeout(&self) -> u32 {
292 self.sponsor_approve_timeout
293 .unwrap_or(SPONSOR_APPROVE_TIMEOUT)
294 .min(MAX_SPONSOR_TIMEOUT)
295 }
288 pub fn owner_can_transfer(&self) -> bool {296 pub fn owner_can_transfer(&self) -> bool {
289 self.owner_can_transfer.unwrap_or(true)297 self.owner_can_transfer.unwrap_or(true)
290 }298 }