git.delta.rocks / unique-network / refs/commits / 424362fb52a4

difftreelog

Merge pull request #683 from UniqueNetwork/fix/collection-rpc-runtime-versioning

Yaroslav Bolyukin2022-10-26parents: #778aa39 #6fd4079.patch.diff
in: master

3 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -557,7 +557,10 @@
 	pass_method!(allowlist(collection: CollectionId) -> Vec<CrossAccountId>, unique_api);
 	pass_method!(allowed(collection: CollectionId, user: CrossAccountId) -> bool, unique_api);
 	pass_method!(last_token_id(collection: CollectionId) -> TokenId, unique_api);
-	pass_method!(collection_by_id(collection: CollectionId) -> Option<RpcCollection<AccountId>>, unique_api);
+	pass_method!(
+		collection_by_id(collection: CollectionId) -> Option<RpcCollection<AccountId>>, unique_api;
+		changed_in 3, collection_by_id_before_version_3(collection) => |value| value.map(|coll| coll.into())
+	);
 	pass_method!(collection_stats() -> CollectionStats, unique_api);
 	pass_method!(next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Option<u64>, unique_api);
 	pass_method!(effective_collection_limits(collection_id: CollectionId) -> Option<CollectionLimits>, unique_api);
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -447,6 +447,7 @@
 }
 
 /// Collection parameters, used in RPC calls (see [`Collection`] for the storage version).
+#[struct_versioning::versioned(version = 2, upper)]
 #[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]
 #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
 pub struct RpcCollection<AccountId> {
@@ -484,6 +485,7 @@
 	pub read_only: bool,
 
 	/// Extra collection flags
+	#[version(2.., upper(RpcCollectionFlags {foreign: false, erc721metadata: false}))]
 	pub flags: RpcCollectionFlags,
 }
 
modifiedprimitives/rpc/src/lib.rsdiffbeforeafterboth
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,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}