difftreelog
fix property keys are optional in RPC
in: master
7 files changed
client/rpc/src/lib.rsdiffbeforeafterboth--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -76,7 +76,7 @@
fn collection_properties(
&self,
collection: CollectionId,
- keys: Vec<String>,
+ keys: Option<Vec<String>>,
at: Option<BlockHash>,
) -> Result<Vec<Property>>;
@@ -85,7 +85,7 @@
&self,
collection: CollectionId,
token_id: TokenId,
- properties: Vec<String>,
+ keys: Option<Vec<String>>,
at: Option<BlockHash>,
) -> Result<Vec<Property>>;
@@ -93,7 +93,7 @@
fn property_permissions(
&self,
collection: CollectionId,
- keys: Vec<String>,
+ keys: Option<Vec<String>>,
at: Option<BlockHash>,
) -> Result<Vec<PropertyKeyPermission>>;
@@ -102,7 +102,7 @@
&self,
collection: CollectionId,
token_id: TokenId,
- keys: Vec<String>,
+ keys: Option<Vec<String>>,
at: Option<BlockHash>,
) -> Result<TokenData<CrossAccountId>>;
@@ -277,7 +277,7 @@
collection: CollectionId,
#[map(|keys| string_keys_to_bytes_keys(keys))]
- keys: Vec<String>
+ keys: Option<Vec<String>>
) -> Vec<Property>);
pass_method!(token_properties(
@@ -285,14 +285,14 @@
token_id: TokenId,
#[map(|keys| string_keys_to_bytes_keys(keys))]
- properties: Vec<String>
+ keys: Option<Vec<String>>
) -> Vec<Property>);
pass_method!(property_permissions(
collection: CollectionId,
#[map(|keys| string_keys_to_bytes_keys(keys))]
- keys: Vec<String>
+ keys: Option<Vec<String>>
) -> Vec<PropertyKeyPermission>);
pass_method!(token_data(
@@ -300,7 +300,7 @@
token_id: TokenId,
#[map(|keys| string_keys_to_bytes_keys(keys))]
- keys: Vec<String>,
+ keys: Option<Vec<String>>,
) -> TokenData<CrossAccountId>);
pass_method!(total_supply(collection: CollectionId) -> u32);
@@ -318,6 +318,8 @@
pass_method!(effective_collection_limits(collection_id: CollectionId) -> Option<CollectionLimits>);
}
-fn string_keys_to_bytes_keys(keys: Vec<String>) -> Vec<Vec<u8>> {
- keys.into_iter().map(|key| key.into_bytes()).collect()
+fn string_keys_to_bytes_keys(keys: Option<Vec<String>>) -> Option<Vec<Vec<u8>>> {
+ keys.map(|keys| {
+ keys.into_iter().map(|key| key.into_bytes()).collect()
+ })
}
pallets/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)
pallets/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()
}
pallets/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 {
pallets/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()
}
primitives/rpc/src/lib.rsdiffbeforeafterboth43 fn topmost_token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>>;43 fn topmost_token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>>;44 fn const_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>>;44 fn const_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>>;454546 fn collection_properties(collection: CollectionId, properties: Vec<Vec<u8>>) -> Result<Vec<Property>>;46 fn collection_properties(collection: CollectionId, properties: Option<Vec<Vec<u8>>>) -> Result<Vec<Property>>;474748 fn token_properties(48 fn token_properties(49 collection: CollectionId,49 collection: CollectionId,50 token_id: TokenId,50 token_id: TokenId,51 properties: Vec<Vec<u8>>51 properties: Option<Vec<Vec<u8>>>52 ) -> Result<Vec<Property>>;52 ) -> Result<Vec<Property>>;535354 fn property_permissions(54 fn property_permissions(55 collection: CollectionId,55 collection: CollectionId,56 properties: Vec<Vec<u8>>56 properties: Option<Vec<Vec<u8>>>57 ) -> Result<Vec<PropertyKeyPermission>>;57 ) -> Result<Vec<PropertyKeyPermission>>;585859 fn token_data(collection: CollectionId, token_id: TokenId, keys: Vec<Vec<u8>>) -> Result<TokenData<CrossAccountId>>;59 fn token_data(60 collection: CollectionId,61 token_id: TokenId,62 keys: Option<Vec<Vec<u8>>>63 ) -> Result<TokenData<CrossAccountId>>;606461 fn total_supply(collection: CollectionId) -> Result<u32>;65 fn total_supply(collection: CollectionId) -> Result<u32>;runtime/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)?,