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

difftreelog

fix property keys are optional in RPC

Daniel Shiposha2022-05-19parent: #0391082.patch.diff
in: master

7 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
76 fn collection_properties(76 fn collection_properties(
77 &self,77 &self,
78 collection: CollectionId,78 collection: CollectionId,
79 keys: Vec<String>,79 keys: Option<Vec<String>>,
80 at: Option<BlockHash>,80 at: Option<BlockHash>,
81 ) -> Result<Vec<Property>>;81 ) -> Result<Vec<Property>>;
8282
85 &self,85 &self,
86 collection: CollectionId,86 collection: CollectionId,
87 token_id: TokenId,87 token_id: TokenId,
88 properties: Vec<String>,88 keys: Option<Vec<String>>,
89 at: Option<BlockHash>,89 at: Option<BlockHash>,
90 ) -> Result<Vec<Property>>;90 ) -> Result<Vec<Property>>;
9191
92 #[rpc(name = "unique_propertyPermissions")]92 #[rpc(name = "unique_propertyPermissions")]
93 fn property_permissions(93 fn property_permissions(
94 &self,94 &self,
95 collection: CollectionId,95 collection: CollectionId,
96 keys: Vec<String>,96 keys: Option<Vec<String>>,
97 at: Option<BlockHash>,97 at: Option<BlockHash>,
98 ) -> Result<Vec<PropertyKeyPermission>>;98 ) -> Result<Vec<PropertyKeyPermission>>;
9999
102 &self,102 &self,
103 collection: CollectionId,103 collection: CollectionId,
104 token_id: TokenId,104 token_id: TokenId,
105 keys: Vec<String>,105 keys: Option<Vec<String>>,
106 at: Option<BlockHash>,106 at: Option<BlockHash>,
107 ) -> Result<TokenData<CrossAccountId>>;107 ) -> Result<TokenData<CrossAccountId>>;
108108
277 collection: CollectionId,277 collection: CollectionId,
278278
279 #[map(|keys| string_keys_to_bytes_keys(keys))]279 #[map(|keys| string_keys_to_bytes_keys(keys))]
280 keys: Vec<String>280 keys: Option<Vec<String>>
281 ) -> Vec<Property>);281 ) -> Vec<Property>);
282282
283 pass_method!(token_properties(283 pass_method!(token_properties(
284 collection: CollectionId,284 collection: CollectionId,
285 token_id: TokenId,285 token_id: TokenId,
286286
287 #[map(|keys| string_keys_to_bytes_keys(keys))]287 #[map(|keys| string_keys_to_bytes_keys(keys))]
288 properties: Vec<String>288 keys: Option<Vec<String>>
289 ) -> Vec<Property>);289 ) -> Vec<Property>);
290290
291 pass_method!(property_permissions(291 pass_method!(property_permissions(
292 collection: CollectionId,292 collection: CollectionId,
293293
294 #[map(|keys| string_keys_to_bytes_keys(keys))]294 #[map(|keys| string_keys_to_bytes_keys(keys))]
295 keys: Vec<String>295 keys: Option<Vec<String>>
296 ) -> Vec<PropertyKeyPermission>);296 ) -> Vec<PropertyKeyPermission>);
297297
298 pass_method!(token_data(298 pass_method!(token_data(
299 collection: CollectionId,299 collection: CollectionId,
300 token_id: TokenId,300 token_id: TokenId,
301301
302 #[map(|keys| string_keys_to_bytes_keys(keys))]302 #[map(|keys| string_keys_to_bytes_keys(keys))]
303 keys: Vec<String>,303 keys: Option<Vec<String>>,
304 ) -> TokenData<CrossAccountId>);304 ) -> TokenData<CrossAccountId>);
305305
306 pass_method!(total_supply(collection: CollectionId) -> u32);306 pass_method!(total_supply(collection: CollectionId) -> u32);
318 pass_method!(effective_collection_limits(collection_id: CollectionId) -> Option<CollectionLimits>);318 pass_method!(effective_collection_limits(collection_id: CollectionId) -> Option<CollectionLimits>);
319}319}
320320
321fn string_keys_to_bytes_keys(keys: Vec<String>) -> Vec<Vec<u8>> {321fn string_keys_to_bytes_keys(keys: Option<Vec<String>>) -> Option<Vec<Vec<u8>>> {
322 keys.map(|keys| {
322 keys.into_iter().map(|key| key.into_bytes()).collect()323 keys.into_iter().map(|key| key.into_bytes()).collect()
323}324 })
325}
324326
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -845,31 +845,39 @@
 
 	pub fn filter_collection_properties(
 		collection_id: CollectionId,
-		keys: Vec<PropertyKey>,
+		keys: Option<Vec<PropertyKey>>,
 	) -> Result<Vec<Property>, DispatchError> {
 		let properties = Self::collection_properties(collection_id);
 
-		let properties = keys
-			.into_iter()
+		let properties = keys.map(|keys| {
+			keys.into_iter()
 			.filter_map(|key| {
 				properties.get(&key).map(|value| Property {
 					key,
 					value: value.clone(),
 				})
 			})
-			.collect();
+			.collect()
+		}).unwrap_or(
+			properties.iter()
+				.map(|(key, value)| Property {
+					key: key.clone(),
+					value: value.clone(),
+				})
+				.collect()
+		);
 
 		Ok(properties)
 	}
 
 	pub fn filter_property_permissions(
 		collection_id: CollectionId,
-		keys: Vec<PropertyKey>,
+		keys: Option<Vec<PropertyKey>>,
 	) -> Result<Vec<PropertyKeyPermission>, DispatchError> {
 		let permissions = Self::property_permissions(collection_id);
 
-		let key_permissions = keys
-			.into_iter()
+		let key_permissions = keys.map(|keys| {
+			keys.into_iter()
 			.filter_map(|key| {
 				permissions
 					.get(&key)
@@ -878,7 +886,15 @@
 						permission: permission.clone(),
 					})
 			})
-			.collect();
+			.collect()
+		}).unwrap_or(
+			permissions.iter()
+				.map(|(key, permission)| PropertyKeyPermission {
+					key: key.clone(),
+					permission: permission.clone(),
+				})
+				.collect()
+		);
 
 		Ok(key_permissions)
 	}
@@ -1148,7 +1164,7 @@
 
 	fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId>;
 	fn const_metadata(&self, token: TokenId) -> Vec<u8>;
-	fn token_properties(&self, token_id: TokenId, keys: Vec<PropertyKey>) -> Vec<Property>;
+	fn token_properties(&self, token_id: TokenId, keys: Option<Vec<PropertyKey>>) -> Vec<Property>;
 	/// Amount of unique collection tokens
 	fn total_supply(&self) -> u32;
 	/// Amount of different tokens account has (Applicable to nonfungible/refungible)
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -319,7 +319,7 @@
 		Vec::new()
 	}
 
-	fn token_properties(&self, _token_id: TokenId, _keys: Vec<PropertyKey>) -> Vec<Property> {
+	fn token_properties(&self, _token_id: TokenId, _keys: Option<Vec<PropertyKey>>) -> Vec<Property> {
 		Vec::new()
 	}
 
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -362,10 +362,11 @@
 			.into_inner()
 	}
 
-	fn token_properties(&self, token_id: TokenId, keys: Vec<PropertyKey>) -> Vec<Property> {
+	fn token_properties(&self, token_id: TokenId, keys: Option<Vec<PropertyKey>>) -> Vec<Property> {
 		let properties = <Pallet<T>>::token_properties((self.id, token_id));
 
-		keys.into_iter()
+		keys.map(|keys| {
+			keys.into_iter()
 			.filter_map(|key| {
 				properties.get(&key).map(|value| Property {
 					key,
@@ -373,6 +374,13 @@
 				})
 			})
 			.collect()
+		}).unwrap_or(
+			properties.iter().map(|(key, value)| Property {
+				key: key.clone(),
+				value: value.clone(),
+			})
+			.collect()
+		)
 	}
 
 	fn total_supply(&self) -> u32 {
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -340,7 +340,7 @@
 			.into_inner()
 	}
 
-	fn token_properties(&self, _token_id: TokenId, _keys: Vec<PropertyKey>) -> Vec<Property> {
+	fn token_properties(&self, _token_id: TokenId, _keys: Option<Vec<PropertyKey>>) -> Vec<Property> {
 		Vec::new()
 	}
 
modifiedprimitives/rpc/src/lib.rsdiffbeforeafterboth
--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -43,20 +43,24 @@
 		fn topmost_token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>>;
 		fn const_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>>;
 
-		fn collection_properties(collection: CollectionId, properties: Vec<Vec<u8>>) -> Result<Vec<Property>>;
+		fn collection_properties(collection: CollectionId, properties: Option<Vec<Vec<u8>>>) -> Result<Vec<Property>>;
 
 		fn token_properties(
 			collection: CollectionId,
 			token_id: TokenId,
-			properties: Vec<Vec<u8>>
+			properties: Option<Vec<Vec<u8>>>
 		) -> Result<Vec<Property>>;
 
 		fn property_permissions(
 			collection: CollectionId,
-			properties: Vec<Vec<u8>>
+			properties: Option<Vec<Vec<u8>>>
 		) -> Result<Vec<PropertyKeyPermission>>;
 
-		fn token_data(collection: CollectionId, token_id: TokenId, keys: Vec<Vec<u8>>) -> Result<TokenData<CrossAccountId>>;
+		fn token_data(
+			collection: CollectionId,
+			token_id: TokenId,
+			keys: Option<Vec<Vec<u8>>>
+		) -> Result<TokenData<CrossAccountId>>;
 
 		fn total_supply(collection: CollectionId) -> Result<u32>;
 		fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32>;
modifiedruntime/common/src/runtime_apis.rsdiffbeforeafterboth
--- a/runtime/common/src/runtime_apis.rs
+++ b/runtime/common/src/runtime_apis.rs
@@ -35,9 +35,11 @@
 
                 fn collection_properties(
                     collection: CollectionId,
-                    keys: Vec<Vec<u8>>
+                    keys: Option<Vec<Vec<u8>>>
                 ) -> Result<Vec<Property>, DispatchError> {
-                    let keys = pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)?;
+                    let keys = keys.map(
+                        |keys| pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)
+                    ).transpose()?;
 
                     pallet_common::Pallet::<Runtime>::filter_collection_properties(collection, keys)
                 }
@@ -45,17 +47,22 @@
                 fn token_properties(
                     collection: CollectionId,
                     token_id: TokenId,
-                    keys: Vec<Vec<u8>>
+                    keys: Option<Vec<Vec<u8>>>
                 ) -> Result<Vec<Property>, DispatchError> {
-                    let keys = pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)?;
+                    let keys = keys.map(
+                        |keys| pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)
+                    ).transpose()?;
+
                     dispatch_unique_runtime!(collection.token_properties(token_id, keys))
                 }
 
                 fn property_permissions(
                     collection: CollectionId,
-                    keys: Vec<Vec<u8>>
+                    keys: Option<Vec<Vec<u8>>>
                 ) -> Result<Vec<PropertyKeyPermission>, DispatchError> {
-                    let keys = pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)?;
+                    let keys = keys.map(
+                        |keys| pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)
+                    ).transpose()?;
 
                     pallet_common::Pallet::<Runtime>::filter_property_permissions(collection, keys)
                 }
@@ -63,7 +70,7 @@
                 fn token_data(
                     collection: CollectionId,
                     token_id: TokenId,
-                    keys: Vec<Vec<u8>>
+                    keys: Option<Vec<Vec<u8>>>
                 ) -> Result<TokenData<CrossAccountId>, DispatchError> {
                     let token_data = TokenData {
                         const_data: Self::const_metadata(collection, token_id)?,