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

difftreelog

fix versioning of the RpcCollection

Grigoriy Simonov2023-04-07parent: #f7fea33.patch.diff
in: master

3 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -353,7 +353,7 @@
 			};
 
 			let result = $(if _api_version < $ver {
-				api.$changed_method_name(at, $($changed_name),*).map(|r| r.map($fixer))
+				api.$changed_method_name(at, $($changed_name),*).map(|r| r.and_then($fixer))
 			} else)*
 			{ api.$method_name(at, $($((|$map_arg: $ty| $map))? ($name)),*) };
 
@@ -440,7 +440,7 @@
 			#[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()
+		changed_in 3, token_data_before_version_3(collection, token_id, string_keys_to_bytes_keys(keys)) => |value| Ok(value.into())
 	);
 
 	pass_method!(adminlist(collection: CollectionId) -> Vec<CrossAccountId>, unique_api);
@@ -449,7 +449,22 @@
 	pass_method!(last_token_id(collection: CollectionId) -> TokenId, 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())
+		changed_in 3, collection_by_id_before_version_3(collection) => |value| {
+			use codec::IoReader;
+			use up_data_structs::RpcCollectionVersion1;
+			use up_data_structs::CollectionVersion1;
+			use sp_runtime::DispatchError;
+
+			if let Some(bytes) = value {
+				let mut reader = IoReader(bytes.as_slice());
+				Ok(Some(RpcCollection::<AccountId>::decode(&mut reader)
+				.or_else(|_| RpcCollectionVersion1::<AccountId>::decode(&mut reader).map(|col| col.into()))
+				.or_else(|_| CollectionVersion1::<AccountId>::decode(&mut reader).map(|col| col.into()))
+				.map_err(|_| DispatchError::Other("API Error: UniqueApi_collection_by_id"))?))
+			} else {
+				Ok(None)
+			}
+		}
 	);
 	pass_method!(collection_stats() -> CollectionStats, unique_api);
 	pass_method!(next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Option<u64>, unique_api);
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -479,6 +479,46 @@
 	pub flags: RpcCollectionFlags,
 }
 
+impl<AccountId> From<CollectionVersion1<AccountId>> for RpcCollection<AccountId> {
+	fn from(value: CollectionVersion1<AccountId>) -> Self {
+		let CollectionVersion1 {
+			name,
+			description,
+			owner,
+			mode,
+			access,
+			token_prefix,
+			mint_mode,
+			sponsorship,
+			limits,
+			..
+		} = value;
+
+		RpcCollection {
+			name: name.into_inner(),
+			description: description.into_inner(),
+			owner,
+			mode,
+			token_prefix: token_prefix.into_inner(),
+			sponsorship,
+			limits,
+			permissions: CollectionPermissions {
+				access: Some(access),
+				mint_mode: Some(mint_mode),
+				nesting: None,
+			},
+			token_property_permissions: Vec::default(),
+			properties: Vec::default(),
+			read_only: true,
+
+			flags: RpcCollectionFlags {
+				foreign: false,
+				erc721metadata: false,
+			},
+		}
+	}
+}
+
 /// Data used for create collection.
 ///
 /// All fields are wrapped in [`Option`], where `None` means chain default.
@@ -1376,3 +1416,155 @@
 
 pub type CollectionProperties = Properties<MAX_COLLECTION_PROPERTIES_SIZE>;
 pub type TokenProperties = Properties<MAX_TOKEN_PROPERTIES_SIZE>;
+
+#[cfg(test)]
+mod tests {
+	use super::*;
+	use codec::IoReader;
+
+	#[test]
+	fn rpc_collection_supports_decoding_old_versions() {
+		let encoded_rpc_collection: [u8; 1013] = [
+			0, 1, 250, 241, 137, 120, 188, 29, 94, 210, 193, 237, 186, 22, 203, 241, 52, 248, 167,
+			235, 241, 211, 236, 28, 138, 156, 59, 160, 156, 105, 39, 247, 207, 101, 0, 0, 48, 65,
+			0, 73, 0, 32, 0, 67, 0, 114, 0, 101, 0, 97, 0, 116, 0, 105, 0, 111, 0, 110, 0, 115, 0,
+			252, 65, 0, 32, 0, 112, 0, 105, 0, 101, 0, 99, 0, 101, 0, 32, 0, 111, 0, 102, 0, 32, 0,
+			97, 0, 32, 0, 109, 0, 97, 0, 99, 0, 104, 0, 105, 0, 110, 0, 101, 0, 32, 0, 109, 0, 105,
+			0, 110, 0, 100, 0, 46, 0, 32, 0, 69, 0, 118, 0, 101, 0, 114, 0, 121, 0, 32, 0, 78, 0,
+			70, 0, 84, 0, 32, 0, 105, 0, 115, 0, 32, 0, 109, 0, 97, 0, 100, 0, 101, 0, 32, 0, 101,
+			0, 120, 0, 99, 0, 108, 0, 117, 0, 115, 0, 105, 0, 118, 0, 101, 0, 108, 0, 121, 0, 32,
+			0, 98, 0, 121, 0, 32, 0, 65, 0, 73, 0, 46, 0, 12, 65, 73, 67, 0, 0, 1, 0, 0, 0, 0, 0,
+			0, 0, 0, 0, 0, 17, 1, 123, 34, 99, 111, 108, 108, 101, 99, 116, 105, 111, 110, 67, 111,
+			118, 101, 114, 34, 58, 34, 81, 109, 98, 52, 104, 122, 76, 101, 51, 49, 102, 98, 71, 74,
+			77, 89, 68, 82, 88, 84, 115, 107, 56, 49, 76, 103, 76, 97, 88, 76, 69, 112, 121, 97,
+			122, 102, 66, 85, 103, 111, 110, 118, 49, 118, 84, 85, 34, 125, 125, 11, 123, 34, 110,
+			101, 115, 116, 101, 100, 34, 58, 123, 34, 111, 110, 67, 104, 97, 105, 110, 77, 101,
+			116, 97, 68, 97, 116, 97, 34, 58, 123, 34, 110, 101, 115, 116, 101, 100, 34, 58, 123,
+			34, 78, 70, 84, 77, 101, 116, 97, 34, 58, 123, 34, 102, 105, 101, 108, 100, 115, 34,
+			58, 123, 34, 105, 112, 102, 115, 74, 115, 111, 110, 34, 58, 123, 34, 105, 100, 34, 58,
+			49, 44, 34, 114, 117, 108, 101, 34, 58, 34, 114, 101, 113, 117, 105, 114, 101, 100, 34,
+			44, 34, 116, 121, 112, 101, 34, 58, 34, 115, 116, 114, 105, 110, 103, 34, 125, 44, 34,
+			67, 111, 108, 111, 114, 34, 58, 123, 34, 105, 100, 34, 58, 50, 44, 34, 114, 117, 108,
+			101, 34, 58, 34, 114, 101, 113, 117, 105, 114, 101, 100, 34, 44, 34, 116, 121, 112,
+			101, 34, 58, 34, 67, 111, 108, 111, 114, 34, 125, 44, 34, 73, 110, 116, 101, 110, 115,
+			105, 111, 110, 115, 34, 58, 123, 34, 105, 100, 34, 58, 51, 44, 34, 114, 117, 108, 101,
+			34, 58, 34, 114, 101, 113, 117, 105, 114, 101, 100, 34, 44, 34, 116, 121, 112, 101, 34,
+			58, 34, 73, 110, 116, 101, 110, 115, 105, 111, 110, 115, 34, 125, 44, 34, 77, 111, 111,
+			100, 34, 58, 123, 34, 105, 100, 34, 58, 52, 44, 34, 114, 117, 108, 101, 34, 58, 34,
+			114, 101, 113, 117, 105, 114, 101, 100, 34, 44, 34, 116, 121, 112, 101, 34, 58, 34, 77,
+			111, 111, 100, 34, 125, 125, 125, 44, 34, 67, 111, 108, 111, 114, 34, 58, 123, 34, 111,
+			112, 116, 105, 111, 110, 115, 34, 58, 123, 34, 102, 105, 101, 108, 100, 49, 34, 58, 34,
+			123, 92, 34, 101, 110, 92, 34, 58, 92, 34, 67, 111, 108, 111, 114, 101, 100, 92, 34,
+			125, 34, 44, 34, 102, 105, 101, 108, 100, 50, 34, 58, 34, 123, 92, 34, 101, 110, 92,
+			34, 58, 92, 34, 66, 108, 97, 99, 107, 38, 87, 104, 105, 116, 101, 92, 34, 125, 34, 125,
+			44, 34, 118, 97, 108, 117, 101, 115, 34, 58, 123, 34, 102, 105, 101, 108, 100, 49, 34,
+			58, 48, 44, 34, 102, 105, 101, 108, 100, 50, 34, 58, 49, 125, 125, 44, 34, 73, 110,
+			116, 101, 110, 115, 105, 111, 110, 115, 34, 58, 123, 34, 111, 112, 116, 105, 111, 110,
+			115, 34, 58, 123, 34, 102, 105, 101, 108, 100, 49, 34, 58, 34, 123, 92, 34, 101, 110,
+			92, 34, 58, 92, 34, 101, 118, 105, 108, 92, 34, 125, 34, 44, 34, 102, 105, 101, 108,
+			100, 50, 34, 58, 34, 123, 92, 34, 101, 110, 92, 34, 58, 92, 34, 103, 111, 111, 100, 92,
+			34, 125, 34, 44, 34, 102, 105, 101, 108, 100, 51, 34, 58, 34, 123, 92, 34, 101, 110,
+			92, 34, 58, 92, 34, 110, 101, 117, 116, 114, 97, 108, 92, 34, 125, 34, 125, 44, 34,
+			118, 97, 108, 117, 101, 115, 34, 58, 123, 34, 102, 105, 101, 108, 100, 49, 34, 58, 48,
+			44, 34, 102, 105, 101, 108, 100, 50, 34, 58, 49, 44, 34, 102, 105, 101, 108, 100, 51,
+			34, 58, 50, 125, 125, 44, 34, 77, 111, 111, 100, 34, 58, 123, 34, 111, 112, 116, 105,
+			111, 110, 115, 34, 58, 123, 34, 102, 105, 101, 108, 100, 49, 34, 58, 34, 123, 92, 34,
+			101, 110, 92, 34, 58, 92, 34, 65, 98, 115, 116, 114, 97, 99, 116, 92, 34, 125, 34, 44,
+			34, 102, 105, 101, 108, 100, 50, 34, 58, 34, 123, 92, 34, 101, 110, 92, 34, 58, 92, 34,
+			85, 110, 99, 97, 110, 110, 101, 121, 32, 118, 97, 108, 108, 101, 121, 92, 34, 125, 34,
+			44, 34, 102, 105, 101, 108, 100, 51, 34, 58, 34, 123, 92, 34, 101, 110, 92, 34, 58, 92,
+			34, 83, 117, 114, 114, 101, 97, 108, 105, 115, 116, 92, 34, 125, 34, 125, 44, 34, 118,
+			97, 108, 117, 101, 115, 34, 58, 123, 34, 102, 105, 101, 108, 100, 49, 34, 58, 48, 44,
+			34, 102, 105, 101, 108, 100, 50, 34, 58, 49, 44, 34, 102, 105, 101, 108, 100, 51, 34,
+			58, 50, 125, 125, 125, 125, 125, 125, 0,
+		];
+		let mut bytes = IoReader(encoded_rpc_collection.as_slice());
+		RpcCollectionVersion1::<[u8; 34]>::decode(&mut bytes).unwrap();
+	}
+
+	#[test]
+	fn rpc_collection_supports_decoding_new_versions() {
+		let encoded_rpc_collection: [u8; 1576] = [
+			0, 1, 238, 236, 179, 149, 150, 47, 71, 194, 69, 174, 250, 116, 251, 148, 90, 15, 56,
+			220, 91, 79, 49, 79, 45, 197, 171, 98, 14, 171, 80, 23, 58, 92, 0, 96, 77, 0, 105, 0,
+			110, 0, 116, 0, 70, 0, 101, 0, 115, 0, 116, 0, 32, 0, 83, 0, 121, 0, 109, 0, 109, 0,
+			101, 0, 116, 0, 114, 0, 121, 0, 32, 0, 66, 0, 114, 0, 101, 0, 97, 0, 99, 0, 104, 0,
+			113, 3, 83, 0, 121, 0, 109, 0, 109, 0, 101, 0, 116, 0, 114, 0, 121, 0, 32, 0, 104, 0,
+			97, 0, 115, 0, 32, 0, 115, 0, 111, 0, 109, 0, 101, 0, 116, 0, 104, 0, 105, 0, 110, 0,
+			103, 0, 32, 0, 105, 0, 110, 0, 116, 0, 111, 0, 120, 0, 105, 0, 99, 0, 97, 0, 116, 0,
+			105, 0, 110, 0, 103, 0, 32, 0, 116, 0, 104, 0, 97, 0, 116, 0, 32, 0, 100, 0, 114, 0,
+			97, 0, 119, 0, 115, 0, 32, 0, 121, 0, 111, 0, 117, 0, 32, 0, 105, 0, 110, 0, 46, 0, 10,
+			0, 73, 0, 110, 0, 115, 0, 112, 0, 105, 0, 114, 0, 101, 0, 100, 0, 32, 0, 98, 0, 121, 0,
+			32, 0, 116, 0, 104, 0, 101, 0, 32, 0, 112, 0, 101, 0, 114, 0, 102, 0, 101, 0, 99, 0,
+			116, 0, 105, 0, 111, 0, 110, 0, 32, 0, 111, 0, 102, 0, 32, 0, 116, 0, 104, 0, 101, 0,
+			32, 0, 115, 0, 121, 0, 109, 0, 109, 0, 101, 0, 116, 0, 114, 0, 121, 0, 44, 0, 32, 0,
+			73, 0, 32, 0, 104, 0, 97, 0, 118, 0, 101, 0, 32, 0, 99, 0, 114, 0, 101, 0, 97, 0, 116,
+			0, 101, 0, 100, 0, 32, 0, 115, 0, 121, 0, 109, 0, 109, 0, 101, 0, 116, 0, 114, 0, 105,
+			0, 99, 0, 97, 0, 108, 0, 32, 0, 105, 0, 109, 0, 97, 0, 103, 0, 101, 0, 115, 0, 32, 0,
+			111, 0, 102, 0, 32, 0, 115, 0, 101, 0, 118, 0, 101, 0, 114, 0, 97, 0, 108, 0, 32, 0,
+			118, 0, 101, 0, 114, 0, 116, 0, 105, 0, 99, 0, 101, 0, 115, 0, 44, 0, 32, 0, 98, 0,
+			117, 0, 116, 0, 32, 0, 115, 0, 111, 0, 109, 0, 101, 0, 32, 0, 115, 0, 121, 0, 109, 0,
+			109, 0, 101, 0, 116, 0, 114, 0, 121, 0, 32, 0, 98, 0, 114, 0, 101, 0, 97, 0, 99, 0,
+			104, 0, 101, 0, 115, 0, 32, 0, 97, 0, 110, 0, 100, 0, 32, 0, 99, 0, 111, 0, 108, 0,
+			111, 0, 114, 0, 115, 0, 32, 0, 116, 0, 104, 0, 97, 0, 116, 0, 32, 0, 109, 0, 97, 0,
+			107, 0, 101, 0, 32, 0, 101, 0, 97, 0, 99, 0, 104, 0, 32, 0, 105, 0, 109, 0, 97, 0, 103,
+			0, 101, 0, 32, 0, 85, 0, 78, 0, 73, 0, 81, 0, 85, 0, 69, 0, 46, 0, 12, 83, 121, 66, 0,
+			0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 4, 56, 95, 111, 108, 100, 95, 99,
+			111, 110, 115, 116, 68, 97, 116, 97, 0, 1, 0, 12, 92, 95, 111, 108, 100, 95, 99, 111,
+			110, 115, 116, 79, 110, 67, 104, 97, 105, 110, 83, 99, 104, 101, 109, 97, 97, 13, 123,
+			34, 110, 101, 115, 116, 101, 100, 34, 58, 123, 34, 111, 110, 67, 104, 97, 105, 110, 77,
+			101, 116, 97, 68, 97, 116, 97, 34, 58, 123, 34, 110, 101, 115, 116, 101, 100, 34, 58,
+			123, 34, 78, 70, 84, 77, 101, 116, 97, 34, 58, 123, 34, 102, 105, 101, 108, 100, 115,
+			34, 58, 123, 34, 105, 112, 102, 115, 74, 115, 111, 110, 34, 58, 123, 34, 105, 100, 34,
+			58, 49, 44, 34, 114, 117, 108, 101, 34, 58, 34, 114, 101, 113, 117, 105, 114, 101, 100,
+			34, 44, 34, 116, 121, 112, 101, 34, 58, 34, 115, 116, 114, 105, 110, 103, 34, 125, 44,
+			34, 67, 111, 108, 111, 114, 34, 58, 123, 34, 105, 100, 34, 58, 50, 44, 34, 114, 117,
+			108, 101, 34, 58, 34, 114, 101, 113, 117, 105, 114, 101, 100, 34, 44, 34, 116, 121,
+			112, 101, 34, 58, 34, 67, 111, 108, 111, 114, 34, 125, 44, 34, 83, 121, 109, 109, 101,
+			116, 114, 121, 32, 66, 114, 101, 97, 99, 104, 34, 58, 123, 34, 105, 100, 34, 58, 51,
+			44, 34, 114, 117, 108, 101, 34, 58, 34, 114, 101, 113, 117, 105, 114, 101, 100, 34, 44,
+			34, 116, 121, 112, 101, 34, 58, 34, 83, 121, 109, 109, 101, 116, 114, 121, 32, 66, 114,
+			101, 97, 99, 104, 34, 125, 44, 34, 86, 101, 114, 116, 105, 99, 101, 34, 58, 123, 34,
+			105, 100, 34, 58, 52, 44, 34, 114, 117, 108, 101, 34, 58, 34, 114, 101, 113, 117, 105,
+			114, 101, 100, 34, 44, 34, 116, 121, 112, 101, 34, 58, 34, 86, 101, 114, 116, 105, 99,
+			101, 34, 125, 125, 125, 44, 34, 67, 111, 108, 111, 114, 34, 58, 123, 34, 111, 112, 116,
+			105, 111, 110, 115, 34, 58, 123, 34, 102, 105, 101, 108, 100, 49, 34, 58, 34, 123, 92,
+			34, 101, 110, 92, 34, 58, 92, 34, 49, 32, 32, 32, 92, 34, 125, 34, 44, 34, 102, 105,
+			101, 108, 100, 50, 34, 58, 34, 123, 92, 34, 101, 110, 92, 34, 58, 92, 34, 50, 32, 92,
+			34, 125, 34, 44, 34, 102, 105, 101, 108, 100, 51, 34, 58, 34, 123, 92, 34, 101, 110,
+			92, 34, 58, 92, 34, 51, 92, 34, 125, 34, 125, 44, 34, 118, 97, 108, 117, 101, 115, 34,
+			58, 123, 34, 102, 105, 101, 108, 100, 49, 34, 58, 48, 44, 34, 102, 105, 101, 108, 100,
+			50, 34, 58, 49, 44, 34, 102, 105, 101, 108, 100, 51, 34, 58, 50, 125, 125, 44, 34, 83,
+			121, 109, 109, 101, 116, 114, 121, 32, 66, 114, 101, 97, 99, 104, 34, 58, 123, 34, 111,
+			112, 116, 105, 111, 110, 115, 34, 58, 123, 34, 102, 105, 101, 108, 100, 49, 34, 58, 34,
+			123, 92, 34, 101, 110, 92, 34, 58, 92, 34, 49, 92, 34, 125, 34, 44, 34, 102, 105, 101,
+			108, 100, 50, 34, 58, 34, 123, 92, 34, 101, 110, 92, 34, 58, 92, 34, 50, 92, 34, 125,
+			34, 125, 44, 34, 118, 97, 108, 117, 101, 115, 34, 58, 123, 34, 102, 105, 101, 108, 100,
+			49, 34, 58, 48, 44, 34, 102, 105, 101, 108, 100, 50, 34, 58, 49, 125, 125, 44, 34, 86,
+			101, 114, 116, 105, 99, 101, 34, 58, 123, 34, 111, 112, 116, 105, 111, 110, 115, 34,
+			58, 123, 34, 102, 105, 101, 108, 100, 49, 34, 58, 34, 123, 92, 34, 101, 110, 92, 34,
+			58, 92, 34, 54, 92, 34, 125, 34, 44, 34, 102, 105, 101, 108, 100, 50, 34, 58, 34, 123,
+			92, 34, 101, 110, 92, 34, 58, 92, 34, 55, 92, 34, 125, 34, 44, 34, 102, 105, 101, 108,
+			100, 51, 34, 58, 34, 123, 92, 34, 101, 110, 92, 34, 58, 92, 34, 56, 92, 34, 125, 34,
+			44, 34, 102, 105, 101, 108, 100, 52, 34, 58, 34, 123, 92, 34, 101, 110, 92, 34, 58, 92,
+			34, 57, 92, 34, 125, 34, 44, 34, 102, 105, 101, 108, 100, 53, 34, 58, 34, 123, 92, 34,
+			101, 110, 92, 34, 58, 92, 34, 49, 48, 92, 34, 125, 34, 44, 34, 102, 105, 101, 108, 100,
+			54, 34, 58, 34, 123, 92, 34, 101, 110, 92, 34, 58, 92, 34, 49, 49, 92, 34, 125, 34, 44,
+			34, 102, 105, 101, 108, 100, 55, 34, 58, 34, 123, 92, 34, 101, 110, 92, 34, 58, 92, 34,
+			49, 50, 92, 34, 125, 34, 125, 44, 34, 118, 97, 108, 117, 101, 115, 34, 58, 123, 34,
+			102, 105, 101, 108, 100, 49, 34, 58, 48, 44, 34, 102, 105, 101, 108, 100, 50, 34, 58,
+			49, 44, 34, 102, 105, 101, 108, 100, 51, 34, 58, 50, 44, 34, 102, 105, 101, 108, 100,
+			52, 34, 58, 51, 44, 34, 102, 105, 101, 108, 100, 53, 34, 58, 52, 44, 34, 102, 105, 101,
+			108, 100, 54, 34, 58, 53, 44, 34, 102, 105, 101, 108, 100, 55, 34, 58, 54, 125, 125,
+			125, 125, 125, 125, 72, 95, 111, 108, 100, 95, 115, 99, 104, 101, 109, 97, 86, 101,
+			114, 115, 105, 111, 110, 24, 85, 110, 105, 113, 117, 101, 104, 95, 111, 108, 100, 95,
+			118, 97, 114, 105, 97, 98, 108, 101, 79, 110, 67, 104, 97, 105, 110, 83, 99, 104, 101,
+			109, 97, 17, 1, 123, 34, 99, 111, 108, 108, 101, 99, 116, 105, 111, 110, 67, 111, 118,
+			101, 114, 34, 58, 34, 81, 109, 82, 67, 77, 84, 109, 57, 118, 81, 107, 76, 89, 86, 65,
+			54, 54, 87, 80, 49, 75, 72, 57, 55, 106, 84, 76, 76, 115, 56, 74, 78, 86, 65, 114, 80,
+			66, 52, 56, 98, 106, 87, 84, 75, 74, 110, 34, 125, 0, 0, 0,
+		];
+		let mut bytes = IoReader(encoded_rpc_collection.as_slice());
+		RpcCollection::<[u8; 34]>::decode(&mut bytes).unwrap();
+	}
+}
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, 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>>;135136		/// Get whether an operator is approved by a given owner.137		fn allowance_for_all(collection: CollectionId, owner: CrossAccountId, operator: CrossAccountId) -> Result<bool>;138	}139}
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, 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<Vec<u8>>>;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>>;135136		/// Get whether an operator is approved by a given owner.137		fn allowance_for_all(collection: CollectionId, owner: CrossAccountId, operator: CrossAccountId) -> Result<bool>;138	}139}