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.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>;
runtime/common/src/runtime_apis.rsdiffbeforeafterboth353536 fn collection_properties(36 fn collection_properties(37 collection: CollectionId,37 collection: CollectionId,38 keys: Vec<Vec<u8>>38 keys: Option<Vec<Vec<u8>>>39 ) -> Result<Vec<Property>, DispatchError> {39 ) -> Result<Vec<Property>, DispatchError> {40 let keys = pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)?;40 let keys = keys.map(41 |keys| pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)42 ).transpose()?;414342 pallet_common::Pallet::<Runtime>::filter_collection_properties(collection, keys)44 pallet_common::Pallet::<Runtime>::filter_collection_properties(collection, keys)43 }45 }444645 fn token_properties(47 fn token_properties(46 collection: CollectionId,48 collection: CollectionId,47 token_id: TokenId,49 token_id: TokenId,48 keys: Vec<Vec<u8>>50 keys: Option<Vec<Vec<u8>>>49 ) -> Result<Vec<Property>, DispatchError> {51 ) -> Result<Vec<Property>, DispatchError> {50 let keys = pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)?;52 let keys = keys.map(53 |keys| pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)54 ).transpose()?;5551 dispatch_unique_runtime!(collection.token_properties(token_id, keys))56 dispatch_unique_runtime!(collection.token_properties(token_id, keys))52 }57 }535854 fn property_permissions(59 fn property_permissions(55 collection: CollectionId,60 collection: CollectionId,56 keys: Vec<Vec<u8>>61 keys: Option<Vec<Vec<u8>>>57 ) -> Result<Vec<PropertyKeyPermission>, DispatchError> {62 ) -> Result<Vec<PropertyKeyPermission>, DispatchError> {58 let keys = pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)?;63 let keys = keys.map(64 |keys| pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)65 ).transpose()?;596660 pallet_common::Pallet::<Runtime>::filter_property_permissions(collection, keys)67 pallet_common::Pallet::<Runtime>::filter_property_permissions(collection, keys)61 }68 }626963 fn token_data(70 fn token_data(64 collection: CollectionId,71 collection: CollectionId,65 token_id: TokenId,72 token_id: TokenId,66 keys: Vec<Vec<u8>>73 keys: Option<Vec<Vec<u8>>>67 ) -> Result<TokenData<CrossAccountId>, DispatchError> {74 ) -> Result<TokenData<CrossAccountId>, DispatchError> {68 let token_data = TokenData {75 let token_data = TokenData {69 const_data: Self::const_metadata(collection, token_id)?,76 const_data: Self::const_metadata(collection, token_id)?,