git.delta.rocks / unique-network / refs/commits / ba2c7d200136

difftreelog

fix runtime api versioning for TokenData

Yaroslav Bolyukin2022-10-28parent: #835d378.patch.diff
in: master

3 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -545,13 +545,16 @@
 		keys: Option<Vec<String>>
 	) -> Vec<PropertyKeyPermission>, unique_api);
 
-	pass_method!(token_data(
-		collection: CollectionId,
-		token_id: TokenId,
+	pass_method!(
+		token_data(
+			collection: CollectionId,
+			token_id: TokenId,
 
-		#[map(|keys| string_keys_to_bytes_keys(keys))]
-		keys: Option<Vec<String>>,
-	) -> TokenData<CrossAccountId>, unique_api);
+			#[map(|keys| string_keys_to_bytes_keys(keys))]
+			keys: Option<Vec<String>>,
+		) -> TokenData<CrossAccountId>, unique_api;
+		changed_in 3, token_data_before_version_3(collection, token_id, string_keys_to_bytes_keys(keys)) => |value| value.into()
+	);
 
 	pass_method!(adminlist(collection: CollectionId) -> Vec<CrossAccountId>, unique_api);
 	pass_method!(allowlist(collection: CollectionId) -> Vec<CrossAccountId>, unique_api);
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -221,6 +221,7 @@
 }
 
 /// Token data.
+#[struct_versioning::versioned(version = 2, upper)]
 #[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]
 #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
 pub struct TokenData<CrossAccountId> {
@@ -231,6 +232,7 @@
 	pub owner: Option<CrossAccountId>,
 
 	/// Token pieces.
+	#[version(2.., upper(0))]
 	pub pieces: u128,
 }
 
modifiedprimitives/rpc/src/lib.rsdiffbeforeafterboth
before · primitives/rpc/src/lib.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819extern crate alloc;2021use up_data_structs::{22	CollectionId, TokenId, RpcCollection, CollectionStats, CollectionLimits, Property,23	PropertyKeyPermission, TokenData, TokenChild, RpcCollectionVersion1,24};2526use sp_std::vec::Vec;27use codec::Decode;28use sp_runtime::DispatchError;2930type Result<T> = core::result::Result<T, DispatchError>;3132sp_api::decl_runtime_apis! {33	#[api_version(3)]34	/// Trait for generate rpc.35	pub trait UniqueApi<CrossAccountId, AccountId> where36		AccountId: Decode,37		CrossAccountId: pallet_evm::account::CrossAccountId<AccountId>,38	{39		/// Get number of tokens in collection owned by account.40		fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>>;4142		/// Number of existing tokens in collection.43		fn collection_tokens(collection: CollectionId) -> Result<Vec<TokenId>>;4445		/// Check token exist.46		fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool>;4748		/// Get token owner.49		fn token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>>;5051		/// Get real owner of nested token.52		fn topmost_token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>>;5354		/// Get nested tokens for the specified item.55		fn token_children(collection: CollectionId, token: TokenId) -> Result<Vec<TokenChild>>;5657		/// Get collection properties.58		fn collection_properties(collection: CollectionId, properties: Option<Vec<Vec<u8>>>) -> Result<Vec<Property>>;5960		/// Get token properties.61		fn token_properties(62			collection: CollectionId,63			token_id: TokenId,64			properties: Option<Vec<Vec<u8>>>65		) -> Result<Vec<Property>>;6667		/// Get permissions for token properties.68		fn property_permissions(69			collection: CollectionId,70			properties: Option<Vec<Vec<u8>>>71		) -> Result<Vec<PropertyKeyPermission>>;7273		/// Get token data.74		fn token_data(75			collection: CollectionId,76			token_id: TokenId,77			keys: Option<Vec<Vec<u8>>>78		) -> Result<TokenData<CrossAccountId>>;7980		/// Total number of tokens in collection.81		fn total_supply(collection: CollectionId) -> Result<u32>;8283		/// Get account balance for collection (sum of tokens pieces).84		fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32>;8586		/// Get account balance for specified token.87		fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128>;8889		/// Amount of token pieces allowed to spend from granded account.90		fn allowance(91			collection: CollectionId,92			sender: CrossAccountId,93			spender: CrossAccountId,94			token: TokenId,95		) -> Result<u128>;9697		/// Get list of collection admins.98		fn adminlist(collection: CollectionId) -> Result<Vec<CrossAccountId>>;99100		/// Get list of users that allowet to mint tikens in collection.101		fn allowlist(collection: CollectionId) -> Result<Vec<CrossAccountId>>;102103		/// Check that user is in allowed list (see [`allowlist`]).104		fn allowed(collection: CollectionId, user: CrossAccountId) -> Result<bool>;105106		/// Last minted token id.107		fn last_token_id(collection: CollectionId) -> Result<TokenId>;108109		/// Get collection by id.110		fn collection_by_id(collection: CollectionId) -> Result<Option<RpcCollection<AccountId>>>;111112		#[changed_in(3)]113		fn collection_by_id(collection: CollectionId) -> Result<Option<RpcCollectionVersion1<AccountId>>>;114115		/// Get collection stats.116		fn collection_stats() -> Result<CollectionStats>;117118		/// Get the number of blocks through which sponsorship will be available.119		fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>>;120121		/// Get effective colletion limits.122		fn effective_collection_limits(collection_id: CollectionId) -> Result<Option<CollectionLimits>>;123124		/// Get total pieces of token.125		fn total_pieces(collection_id: CollectionId, token_id: TokenId) -> Result<Option<u128>>;126127		fn token_owners(collection: CollectionId, token: TokenId) -> Result<Vec<CrossAccountId>>;128	}129}
after · primitives/rpc/src/lib.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819extern crate alloc;2021use up_data_structs::{22	CollectionId, TokenId, RpcCollection, CollectionStats, CollectionLimits, Property,23	PropertyKeyPermission, TokenData, TokenChild, RpcCollectionVersion1, TokenDataVersion1,24};2526use sp_std::vec::Vec;27use codec::Decode;28use sp_runtime::DispatchError;2930type Result<T> = core::result::Result<T, DispatchError>;3132sp_api::decl_runtime_apis! {33	#[api_version(3)]34	/// Trait for generate rpc.35	pub trait UniqueApi<CrossAccountId, AccountId> where36		AccountId: Decode,37		CrossAccountId: pallet_evm::account::CrossAccountId<AccountId>,38	{39		/// Get number of tokens in collection owned by account.40		fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>>;4142		/// Number of existing tokens in collection.43		fn collection_tokens(collection: CollectionId) -> Result<Vec<TokenId>>;4445		/// Check token exist.46		fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool>;4748		/// Get token owner.49		fn token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>>;5051		/// Get real owner of nested token.52		fn topmost_token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>>;5354		/// Get nested tokens for the specified item.55		fn token_children(collection: CollectionId, token: TokenId) -> Result<Vec<TokenChild>>;5657		/// Get collection properties.58		fn collection_properties(collection: CollectionId, properties: Option<Vec<Vec<u8>>>) -> Result<Vec<Property>>;5960		/// Get token properties.61		fn token_properties(62			collection: CollectionId,63			token_id: TokenId,64			properties: Option<Vec<Vec<u8>>>65		) -> Result<Vec<Property>>;6667		/// Get permissions for token properties.68		fn property_permissions(69			collection: CollectionId,70			properties: Option<Vec<Vec<u8>>>71		) -> Result<Vec<PropertyKeyPermission>>;7273		/// Get token data.74		fn token_data(75			collection: CollectionId,76			token_id: TokenId,77			keys: Option<Vec<Vec<u8>>>78		) -> Result<TokenData<CrossAccountId>>;7980		#[changed_in(3)]81		fn token_data(82			collection: CollectionId,83			token_id: TokenId,84			keys: Option<Vec<Vec<u8>>>85		) -> Result<TokenDataVersion1<CrossAccountId>>;8687		/// Total number of tokens in collection.88		fn total_supply(collection: CollectionId) -> Result<u32>;8990		/// Get account balance for collection (sum of tokens pieces).91		fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32>;9293		/// Get account balance for specified token.94		fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128>;9596		/// Amount of token pieces allowed to spend from granded account.97		fn allowance(98			collection: CollectionId,99			sender: CrossAccountId,100			spender: CrossAccountId,101			token: TokenId,102		) -> Result<u128>;103104		/// Get list of collection admins.105		fn adminlist(collection: CollectionId) -> Result<Vec<CrossAccountId>>;106107		/// Get list of users that allowet to mint tikens in collection.108		fn allowlist(collection: CollectionId) -> Result<Vec<CrossAccountId>>;109110		/// Check that user is in allowed list (see [`allowlist`]).111		fn allowed(collection: CollectionId, user: CrossAccountId) -> Result<bool>;112113		/// Last minted token id.114		fn last_token_id(collection: CollectionId) -> Result<TokenId>;115116		/// Get collection by id.117		fn collection_by_id(collection: CollectionId) -> Result<Option<RpcCollection<AccountId>>>;118119		#[changed_in(3)]120		fn collection_by_id(collection: CollectionId) -> Result<Option<RpcCollectionVersion1<AccountId>>>;121122		/// Get collection stats.123		fn collection_stats() -> Result<CollectionStats>;124125		/// Get the number of blocks through which sponsorship will be available.126		fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>>;127128		/// Get effective colletion limits.129		fn effective_collection_limits(collection_id: CollectionId) -> Result<Option<CollectionLimits>>;130131		/// Get total pieces of token.132		fn total_pieces(collection_id: CollectionId, token_id: TokenId) -> Result<Option<u128>>;133134		fn token_owners(collection: CollectionId, token: TokenId) -> Result<Vec<CrossAccountId>>;135	}136}