git.delta.rocks / unique-network / refs/commits / 6be1bb56d5e4

difftreelog

feat split large fields out of Collection

Yaroslav Bolyukin2022-04-07parent: #3db55eb.patch.diff
in: master

7 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
before · client/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/>.1617use std::sync::Arc;1819use codec::Decode;20use jsonrpc_core::{Error as RpcError, ErrorCode, Result};21use jsonrpc_derive::rpc;22use up_data_structs::{Collection, CollectionId, CollectionStats, CollectionLimits, TokenId};23use sp_api::{BlockId, BlockT, ProvideRuntimeApi, ApiExt};24use sp_blockchain::HeaderBackend;25use up_rpc::UniqueApi as UniqueRuntimeApi;2627#[rpc]28pub trait UniqueApi<BlockHash, CrossAccountId, AccountId> {29	#[rpc(name = "unique_accountTokens")]30	fn account_tokens(31		&self,32		collection: CollectionId,33		account: CrossAccountId,34		at: Option<BlockHash>,35	) -> Result<Vec<TokenId>>;36	#[rpc(name = "unique_tokenExists")]37	fn token_exists(38		&self,39		collection: CollectionId,40		token: TokenId,41		at: Option<BlockHash>,42	) -> Result<bool>;4344	#[rpc(name = "unique_tokenOwner")]45	fn token_owner(46		&self,47		collection: CollectionId,48		token: TokenId,49		at: Option<BlockHash>,50	) -> Result<Option<CrossAccountId>>;51	#[rpc(name = "unique_constMetadata")]52	fn const_metadata(53		&self,54		collection: CollectionId,55		token: TokenId,56		at: Option<BlockHash>,57	) -> Result<Vec<u8>>;58	#[rpc(name = "unique_variableMetadata")]59	fn variable_metadata(60		&self,61		collection: CollectionId,62		token: TokenId,63		at: Option<BlockHash>,64	) -> Result<Vec<u8>>;6566	#[rpc(name = "unique_collectionTokens")]67	fn collection_tokens(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<u32>;68	#[rpc(name = "unique_accountBalance")]69	fn account_balance(70		&self,71		collection: CollectionId,72		account: CrossAccountId,73		at: Option<BlockHash>,74	) -> Result<u32>;75	#[rpc(name = "unique_balance")]76	fn balance(77		&self,78		collection: CollectionId,79		account: CrossAccountId,80		token: TokenId,81		at: Option<BlockHash>,82	) -> Result<String>;83	#[rpc(name = "unique_allowance")]84	fn allowance(85		&self,86		collection: CollectionId,87		sender: CrossAccountId,88		spender: CrossAccountId,89		token: TokenId,90		at: Option<BlockHash>,91	) -> Result<String>;9293	#[rpc(name = "unique_adminlist")]94	fn adminlist(95		&self,96		collection: CollectionId,97		at: Option<BlockHash>,98	) -> Result<Vec<CrossAccountId>>;99	#[rpc(name = "unique_allowlist")]100	fn allowlist(101		&self,102		collection: CollectionId,103		at: Option<BlockHash>,104	) -> Result<Vec<CrossAccountId>>;105	#[rpc(name = "unique_allowed")]106	fn allowed(107		&self,108		collection: CollectionId,109		user: CrossAccountId,110		at: Option<BlockHash>,111	) -> Result<bool>;112	#[rpc(name = "unique_lastTokenId")]113	fn last_token_id(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<TokenId>;114	#[rpc(name = "unique_collectionById")]115	fn collection_by_id(116		&self,117		collection: CollectionId,118		at: Option<BlockHash>,119	) -> Result<Option<Collection<AccountId>>>;120	#[rpc(name = "unique_collectionStats")]121	fn collection_stats(&self, at: Option<BlockHash>) -> Result<CollectionStats>;122123	#[rpc(name = "unique_nextSponsored")]124	fn next_sponsored(125		&self,126		collection: CollectionId,127		account: CrossAccountId,128		token: TokenId,129		at: Option<BlockHash>,130	) -> Result<Option<u64>>;131	#[rpc(name = "unique_effectiveCollectionLimits")]132	fn effective_collection_limits(133		&self,134		collection_id: CollectionId,135		at: Option<BlockHash>,136	) -> Result<Option<CollectionLimits>>;137}138139pub struct Unique<C, P> {140	client: Arc<C>,141	_marker: std::marker::PhantomData<P>,142}143144impl<C, P> Unique<C, P> {145	pub fn new(client: Arc<C>) -> Self {146		Self {147			client,148			_marker: Default::default(),149		}150	}151}152153pub enum Error {154	RuntimeError,155}156157impl From<Error> for i64 {158	fn from(e: Error) -> i64 {159		match e {160			Error::RuntimeError => 1,161		}162	}163}164165macro_rules! pass_method {166	(167		$method_name:ident($($name:ident: $ty:ty),* $(,)?) -> $result:ty $(=> $mapper:expr)?168		$(; changed_in $ver:expr, $changed_method_name:ident ($($changed_name:expr), * $(,)?) => $fixer:expr)*169	) => {170		fn $method_name(171			&self,172			$(173				$name: $ty,174			)*175			at: Option<<Block as BlockT>::Hash>,176		) -> Result<$result> {177			let api = self.client.runtime_api();178			let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash));179			let _api_version = if let Ok(Some(api_version)) =180				api.api_version::<dyn UniqueRuntimeApi<Block, CrossAccountId, AccountId>>(&at)181			{182				api_version183			} else {184				// unreachable for our runtime185				return Err(RpcError {186					code: ErrorCode::InvalidParams,187					message: "Api is not available".into(),188					data: None,189				})190			};191192			let result = $(if _api_version < $ver {193				api.$changed_method_name(&at, $($changed_name),*).map(|r| r.map($fixer))194			} else)*195			{ api.$method_name(&at, $($name),*) };196197			let result = result.map_err(|e| RpcError {198				code: ErrorCode::ServerError(Error::RuntimeError.into()),199				message: "Unable to query".into(),200				data: Some(format!("{:?}", e).into()),201			})?;202			result.map_err(|e| RpcError {203				code: ErrorCode::InvalidParams,204				message: "Runtime returned error".into(),205				data: Some(format!("{:?}", e).into()),206			})$(.map($mapper))?207		}208	};209}210211#[allow(deprecated)]212impl<C, Block, CrossAccountId, AccountId>213	UniqueApi<<Block as BlockT>::Hash, CrossAccountId, AccountId> for Unique<C, Block>214where215	Block: BlockT,216	AccountId: Decode,217	C: 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,218	C::Api: UniqueRuntimeApi<Block, CrossAccountId, AccountId>,219	CrossAccountId: pallet_evm::account::CrossAccountId<AccountId>,220{221	pass_method!(account_tokens(collection: CollectionId, account: CrossAccountId) -> Vec<TokenId>);222	pass_method!(token_exists(collection: CollectionId, token: TokenId) -> bool);223	pass_method!(224		token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>;225		changed_in 2, token_owner_before_version_2(collection, token) => |u| Some(u)226	);227	pass_method!(const_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);228	pass_method!(variable_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);229	pass_method!(collection_tokens(collection: CollectionId) -> u32);230	pass_method!(account_balance(collection: CollectionId, account: CrossAccountId) -> u32);231	pass_method!(balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> String => |v| v.to_string());232	pass_method!(allowance(collection: CollectionId, sender: CrossAccountId, spender: CrossAccountId, token: TokenId) -> String => |v| v.to_string());233234	pass_method!(adminlist(collection: CollectionId) -> Vec<CrossAccountId>);235	pass_method!(allowlist(collection: CollectionId) -> Vec<CrossAccountId>);236	pass_method!(allowed(collection: CollectionId, user: CrossAccountId) -> bool);237	pass_method!(last_token_id(collection: CollectionId) -> TokenId);238	pass_method!(collection_by_id(collection: CollectionId) -> Option<Collection<AccountId>>);239	pass_method!(collection_stats() -> CollectionStats);240	pass_method!(next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Option<u64>);241	pass_method!(effective_collection_limits(collection_id: CollectionId) -> Option<CollectionLimits>);242}
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -29,11 +29,11 @@
 };
 use pallet_evm::GasWeightMapping;
 use up_data_structs::{
-	COLLECTION_NUMBER_LIMIT, Collection, CollectionId, CreateItemData, MAX_TOKEN_PREFIX_LENGTH,
+	COLLECTION_NUMBER_LIMIT, Collection, RpcCollection, CollectionId, CreateItemData, MAX_TOKEN_PREFIX_LENGTH,
 	COLLECTION_ADMINS_LIMIT, MetaUpdatePermission, TokenId, CollectionStats, MAX_TOKEN_OWNERSHIP,
 	CollectionMode, NFT_SPONSOR_TRANSFER_TIMEOUT, FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
 	REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, MAX_SPONSOR_TIMEOUT, CUSTOM_DATA_LIMIT, CollectionLimits,
-	CustomDataLimit, CreateCollectionData, SponsorshipState, CreateItemExData, SponsoringRateLimit, budget::Budget,
+	CustomDataLimit, CreateCollectionData, SponsorshipState, CreateItemExData, SponsoringRateLimit, budget::Budget, COLLECTION_FIELD_LIMIT, CollectionField,
 };
 pub use pallet::*;
 use sp_core::H160;
@@ -352,6 +352,9 @@
 		OnlyOwnerAllowedToNest,
 		/// Only tokens from specific collections may nest tokens under this
 		SourceCollectionIsNotAllowedToNest,
+
+		/// Tried to store more data than allowed in collection field
+		CollectionFieldSizeExceeded,
 	}
 
 	#[pallet::storage]
@@ -369,6 +372,17 @@
 		QueryKind = OptionQuery,
 	>;
 
+	/// Large variable-size collection fields are extracted here
+	#[pallet::storage]
+	pub type CollectionData<T> = StorageNMap<
+		Key = (
+			Key<Twox64Concat, CollectionId>,
+			Key<Twox64Concat, CollectionField>,
+		),
+		Value = BoundedVec<u8, ConstU32<COLLECTION_FIELD_LIMIT>>,
+		QueryKind = ValueQuery,
+	>;
+
 	#[pallet::storage]
 	pub type AdminAmount<T> = StorageMap<
 		Hasher = Blake2_128Concat,
@@ -409,7 +423,26 @@
 		fn on_runtime_upgrade() -> Weight {
 			if StorageVersion::get::<Pallet<T>>() < StorageVersion::new(1) {
 				use up_data_structs::{CollectionVersion1, CollectionVersion2};
-				<CollectionById<T>>::translate_values::<CollectionVersion1<T::AccountId>, _>(|v| {
+				<CollectionById<T>>::translate::<CollectionVersion1<T::AccountId>, _>(|id, v| {
+					Self::set_field_raw(
+						id,
+						CollectionField::OffchainSchema,
+						v.offchain_schema.clone().into_inner(),
+					)
+					.expect("data has lower bounds than field");
+					Self::set_field_raw(
+						id,
+						CollectionField::VariableOnChainSchema,
+						v.variable_on_chain_schema.clone().into_inner(),
+					)
+					.expect("data has lower bounds than field");
+					Self::set_field_raw(
+						id,
+						CollectionField::ConstOnChainSchema,
+						v.const_on_chain_schema.clone().into_inner(),
+					)
+					.expect("data has lower bounds than field");
+
 					Some(CollectionVersion2::from(v))
 				});
 			}
@@ -483,6 +516,50 @@
 
 		Some(effective_limits)
 	}
+
+	pub fn rpc_collection(collection: CollectionId) -> Option<RpcCollection<T::AccountId>> {
+		let Collection {
+			name,
+			description,
+			owner,
+			mode,
+			access,
+			token_prefix,
+			mint_mode,
+			schema_version,
+			sponsorship,
+			limits,
+			meta_update_permission,
+		} = <CollectionById<T>>::get(collection)?;
+		Some(RpcCollection {
+			name: name.into_inner(),
+			description: description.into_inner(),
+			owner,
+			mode,
+			access,
+			token_prefix: token_prefix.into_inner(),
+			mint_mode,
+			schema_version,
+			sponsorship,
+			limits,
+			meta_update_permission,
+			offchain_schema: <CollectionData<T>>::get((
+				collection,
+				CollectionField::OffchainSchema,
+			))
+			.into_inner(),
+			const_on_chain_schema: <CollectionData<T>>::get((
+				collection,
+				CollectionField::ConstOnChainSchema,
+			))
+			.into_inner(),
+			variable_on_chain_schema: <CollectionData<T>>::get((
+				collection,
+				CollectionField::VariableOnChainSchema,
+			))
+			.into_inner(),
+		})
+	}
 }
 
 impl<T: Config> Pallet<T> {
@@ -520,14 +597,11 @@
 			access: data.access.unwrap_or_default(),
 			description: data.description,
 			token_prefix: data.token_prefix,
-			offchain_schema: data.offchain_schema,
 			schema_version: data.schema_version.unwrap_or_default(),
 			sponsorship: data
 				.pending_sponsor
 				.map(SponsorshipState::Unconfirmed)
 				.unwrap_or_default(),
-			variable_on_chain_schema: data.variable_on_chain_schema,
-			const_on_chain_schema: data.const_on_chain_schema,
 			limits: data
 				.limits
 				.map(|limits| Self::clamp_limits(data.mode.clone(), &Default::default(), limits))
@@ -557,6 +631,24 @@
 		<CreatedCollectionCount<T>>::put(created_count);
 		<Pallet<T>>::deposit_event(Event::CollectionCreated(id, data.mode.id(), owner.clone()));
 		<CollectionById<T>>::insert(id, collection);
+		Self::set_field_raw(
+			id,
+			CollectionField::OffchainSchema,
+			data.offchain_schema.into_inner(),
+		)
+		.expect("data has lower bounds than field");
+		Self::set_field_raw(
+			id,
+			CollectionField::VariableOnChainSchema,
+			data.variable_on_chain_schema.into_inner(),
+		)
+		.expect("data has lower bounds than field");
+		Self::set_field_raw(
+			id,
+			CollectionField::ConstOnChainSchema,
+			data.const_on_chain_schema.into_inner(),
+		)
+		.expect("data has lower bounds than field");
 		Ok(id)
 	}
 
@@ -579,6 +671,7 @@
 
 		<DestroyedCollectionCount<T>>::put(destroyed_collections);
 		<CollectionById<T>>::remove(collection.id);
+		<CollectionData<T>>::remove_prefix((collection.id,), None);
 		<AdminAmount<T>>::remove(collection.id);
 		<IsAdmin<T>>::remove_prefix((collection.id,), None);
 		<Allowlist<T>>::remove_prefix((collection.id,), None);
@@ -587,6 +680,35 @@
 		Ok(())
 	}
 
+	fn set_field_raw(
+		collection_id: CollectionId,
+		field: CollectionField,
+		value: Vec<u8>,
+	) -> DispatchResult {
+		if !value.is_empty() {
+			<CollectionData<T>>::insert(
+				(collection_id, field),
+				BoundedVec::try_from(value).map_err(|_| <Error<T>>::CollectionFieldSizeExceeded)?,
+			)
+		} else {
+			<CollectionData<T>>::remove((collection_id, field));
+		}
+		Ok(())
+	}
+
+	pub fn set_field(
+		collection: &CollectionHandle<T>,
+		sender: &T::CrossAccountId,
+		field: CollectionField,
+		value: Vec<u8>,
+	) -> DispatchResult {
+		collection.check_is_owner_or_admin(sender)?;
+
+		// =========
+
+		Self::set_field_raw(collection.id, field, value)
+	}
+
 	pub fn toggle_allowlist(
 		collection: &CollectionHandle<T>,
 		sender: &T::CrossAccountId,
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -43,7 +43,7 @@
 	MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
 	AccessMode, CreateItemData, CollectionLimits, CollectionId, CollectionMode, TokenId,
 	SchemaVersion, SponsorshipState, MetaUpdatePermission, CreateCollectionData, CustomDataLimit,
-	CreateItemExData, budget,
+	CreateItemExData, budget, CollectionField,
 };
 use pallet_evm::account::CrossAccountId;
 use pallet_common::{
@@ -1004,16 +1004,16 @@
 			schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,
 		) -> DispatchResult {
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
-			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
-			target_collection.check_is_owner_or_admin(&sender)?;
+			let collection = <CollectionHandle<T>>::try_get(collection_id)?;
+
+			// =========
 
-			target_collection.offchain_schema = schema;
+			<PalletCommon<T>>::set_field(&collection, &sender, CollectionField::OffchainSchema, schema.into_inner())?;
 
 			<Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(
 				collection_id
 			));
-
-			target_collection.save()
+			Ok(())
 		}
 
 		/// Set const on-chain data schema.
@@ -1036,16 +1036,16 @@
 			schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>
 		) -> DispatchResult {
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
-			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
-			target_collection.check_is_owner_or_admin(&sender)?;
+			let collection = <CollectionHandle<T>>::try_get(collection_id)?;
+
+			// =========
 
-			target_collection.const_on_chain_schema = schema;
+			<PalletCommon<T>>::set_field(&collection, &sender, CollectionField::ConstOnChainSchema, schema.into_inner())?;
 
 			<Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(
 				collection_id
 			));
-
-			target_collection.save()
+			Ok(())
 		}
 
 		/// Set variable on-chain data schema.
@@ -1068,16 +1068,16 @@
 			schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>
 		) -> DispatchResult {
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
-			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
-			target_collection.check_is_owner_or_admin(&sender)?;
+			let collection = <CollectionHandle<T>>::try_get(collection_id)?;
+
+			// =========
 
-			target_collection.variable_on_chain_schema = schema;
+			<PalletCommon<T>>::set_field(&collection, &sender, CollectionField::VariableOnChainSchema, schema.into_inner())?;
 
 			<Pallet<T>>::deposit_event(Event::<T>::VariableOnChainSchemaSet(
 				collection_id
 			));
-
-			target_collection.save()
+			Ok(())
 		}
 
 		#[weight = <SelfWeightOf<T>>::set_collection_limits()]
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -78,6 +78,9 @@
 pub const VARIABLE_ON_CHAIN_SCHEMA_LIMIT: u32 = 8192;
 pub const CONST_ON_CHAIN_SCHEMA_LIMIT: u32 = 32768;
 
+pub const COLLECTION_FIELD_LIMIT: u32 = CONST_ON_CHAIN_SCHEMA_LIMIT;
+// u32::max is not const: OFFCHAIN_SCHEMA_LIMIT.max(VARIABLE_ON_CHAIN_SCHEMA_LIMIT).max(CONST_ON_CHAIN_SCHEMA_LIMIT);
+
 pub const MAX_COLLECTION_NAME_LENGTH: u32 = 64;
 pub const MAX_COLLECTION_DESCRIPTION_LENGTH: u32 = 256;
 pub const MAX_TOKEN_PREFIX_LENGTH: u32 = 16;
@@ -248,22 +251,21 @@
 	}
 }
 
+/// Used in storage
 #[struct_versioning::versioned(version = 2, upper)]
 #[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)]
-#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
 pub struct Collection<AccountId> {
 	pub owner: AccountId,
 	pub mode: CollectionMode,
 	pub access: AccessMode,
-	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]
 	pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,
-	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]
 	pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,
-	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]
 	pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,
 	pub mint_mode: bool,
-	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]
+
+	#[version(..2)]
 	pub offchain_schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,
+
 	pub schema_version: SchemaVersion,
 	pub sponsorship: SponsorshipState<AccountId>,
 
@@ -272,13 +274,42 @@
 	#[version(2.., upper(limits.into()))]
 	pub limits: CollectionLimitsVersion2,
 
-	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]
+	#[version(..2)]
 	pub variable_on_chain_schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>,
-	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]
+	#[version(..2)]
 	pub const_on_chain_schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>,
+
 	pub meta_update_permission: MetaUpdatePermission,
 }
 
+/// Used in RPC calls
+#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]
+#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
+pub struct RpcCollection<AccountId> {
+	pub owner: AccountId,
+	pub mode: CollectionMode,
+	pub access: AccessMode,
+	pub name: Vec<u16>,
+	pub description: Vec<u16>,
+	pub token_prefix: Vec<u8>,
+	pub mint_mode: bool,
+	pub offchain_schema: Vec<u8>,
+	pub schema_version: SchemaVersion,
+	pub sponsorship: SponsorshipState<AccountId>,
+	pub limits: CollectionLimits,
+	pub variable_on_chain_schema: Vec<u8>,
+	pub const_on_chain_schema: Vec<u8>,
+	pub meta_update_permission: MetaUpdatePermission,
+}
+
+#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)]
+#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
+pub enum CollectionField {
+	VariableOnChainSchema,
+	ConstOnChainSchema,
+	OffchainSchema,
+}
+
 #[derive(Encode, Decode, Clone, PartialEq, TypeInfo, Debug, Derivative, MaxEncodedLen)]
 #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
 #[derivative(Default(bound = ""))]
modifiedprimitives/rpc/src/lib.rsdiffbeforeafterboth
--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -16,7 +16,7 @@
 
 #![cfg_attr(not(feature = "std"), no_std)]
 
-use up_data_structs::{CollectionId, TokenId, Collection, CollectionStats, CollectionLimits};
+use up_data_structs::{CollectionId, TokenId, RpcCollection, Collection, CollectionStats, CollectionLimits};
 use sp_std::vec::Vec;
 use codec::Decode;
 use sp_runtime::DispatchError;
@@ -53,7 +53,7 @@
 		fn allowlist(collection: CollectionId) -> Result<Vec<CrossAccountId>>;
 		fn allowed(collection: CollectionId, user: CrossAccountId) -> Result<bool>;
 		fn last_token_id(collection: CollectionId) -> Result<TokenId>;
-		fn collection_by_id(collection: CollectionId) -> Result<Option<Collection<AccountId>>>;
+		fn collection_by_id(collection: CollectionId) -> Result<Option<RpcCollection<AccountId>>>;
 		fn collection_stats() -> Result<CollectionStats>;
 		fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>>;
 		fn effective_collection_limits(collection_id: CollectionId) -> Result<Option<CollectionLimits>>;
modifiedruntime/common/src/runtime_apis.rsdiffbeforeafterboth
--- a/runtime/common/src/runtime_apis.rs
+++ b/runtime/common/src/runtime_apis.rs
@@ -58,8 +58,8 @@
                 fn last_token_id(collection: CollectionId) -> Result<TokenId, DispatchError> {
                     dispatch_unique_runtime!(collection.last_token_id())
                 }
-                fn collection_by_id(collection: CollectionId) -> Result<Option<Collection<AccountId>>, DispatchError> {
-                    Ok(<pallet_common::CollectionById<Runtime>>::get(collection))
+                fn collection_by_id(collection: CollectionId) -> Result<Option<RpcCollection<AccountId>>, DispatchError> {
+                    Ok(<pallet_common::Pallet<Runtime>>::rpc_collection(collection))
                 }
                 fn collection_stats() -> Result<CollectionStats, DispatchError> {
                     Ok(<pallet_common::Pallet<Runtime>>::collection_stats())
modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -67,7 +67,7 @@
 	},
 };
 use up_data_structs::mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping};
-use up_data_structs::{CollectionId, TokenId, CollectionStats, Collection};
+use up_data_structs::{CollectionId, TokenId, CollectionStats, Collection, RpcCollection};
 // use pallet_contracts::weights::WeightInfo;
 // #[cfg(any(feature = "std", test))]
 use frame_system::{