git.delta.rocks / unique-network / refs/commits / 26c4de6147e8

difftreelog

doc: Add general documentation.

Trubnikov Sergey2022-07-22parent: #2232fc1.patch.diff
in: master

1 file changed

modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
55pub mod mapping;55pub mod mapping;
56mod migration;56mod migration;
5757
58/// Maximum of decimal points.
58pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;59pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;
60
61/// Maximum pieces for refungible token.
59pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;62pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;
60pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;63pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;
6164
65/// Maximum tokens for user.
62pub const MAX_TOKEN_OWNERSHIP: u32 = if cfg!(not(feature = "limit-testing")) {66pub const MAX_TOKEN_OWNERSHIP: u32 = if cfg!(not(feature = "limit-testing")) {
63 100_00067 100_000
64} else {68} else {
65 1069 10
66};70};
71
72/// Maximum for collections can be created.
67pub const COLLECTION_NUMBER_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {73pub const COLLECTION_NUMBER_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {
68 100_00074 100_000
69} else {75} else {
70 1076 10
71};77};
78
79/// Maximum for various custom data of token.
72pub const CUSTOM_DATA_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {80pub const CUSTOM_DATA_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {
73 204881 2048
74} else {82} else {
113/// create_many call121/// create_many call
114pub const MAX_ITEMS_PER_BATCH: u32 = 200;122pub const MAX_ITEMS_PER_BATCH: u32 = 200;
115123
124/// Used for limit bounded types of token custom data.
116pub type CustomDataLimit = ConstU32<CUSTOM_DATA_LIMIT>;125pub type CustomDataLimit = ConstU32<CUSTOM_DATA_LIMIT>;
117126
127/// Collection id.
118#[derive(128#[derive(
119 Encode,129 Encode,
120 Decode,130 Decode,
134impl EncodeLike<u32> for CollectionId {}144impl EncodeLike<u32> for CollectionId {}
135impl EncodeLike<CollectionId> for u32 {}145impl EncodeLike<CollectionId> for u32 {}
136146
147/// Token id
137#[derive(148#[derive(
138 Encode,149 Encode,
139 Decode,150 Decode,
154impl EncodeLike<TokenId> for u32 {}165impl EncodeLike<TokenId> for u32 {}
155166
156impl TokenId {167impl TokenId {
168 /// Try to get next token id.
169 ///
170 /// If next id cause overflow, then [`ArithmeticError::Overflow`] returned.
157 pub fn try_next(self) -> Result<TokenId, ArithmeticError> {171 pub fn try_next(self) -> Result<TokenId, ArithmeticError> {
158 self.0172 self.0
159 .checked_add(1)173 .checked_add(1)
184 pub pieces: u128,198 pub pieces: u128,
185}199}
186200
201// TODO: unused type
187pub struct OverflowError;202pub struct OverflowError;
188impl From<OverflowError> for &'static str {203impl From<OverflowError> for &'static str {
189 fn from(_: OverflowError) -> Self {204 fn from(_: OverflowError) -> Self {
190 "overflow occured"205 "overflow occured"
191 }206 }
192}207}
193208
209/// Alias for decimal points type.
194pub type DecimalPoints = u8;210pub type DecimalPoints = u8;
195211
212/// Collection mode.
213///
214/// Collection can represent various types of tokens.
215/// Each collection can contain only one type of tokens at a time.
216/// This type helps to understand which tokens the collection contains.
196#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]217#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]
197#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]218#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
198pub enum CollectionMode {219pub enum CollectionMode {
220 /// Non fungible tokens.
199 NFT,221 NFT,
222 /// Fungible tokens.
200 Fungible(DecimalPoints),223 Fungible(DecimalPoints),
224 /// Refungible tokens.
201 ReFungible,225 ReFungible,
202}226}
203227
204impl CollectionMode {228impl CollectionMode {
229 /// Get collection mod as number.
205 pub fn id(&self) -> u8 {230 pub fn id(&self) -> u8 {
206 match self {231 match self {
207 CollectionMode::NFT => 1,232 CollectionMode::NFT => 1,
211 }236 }
212}237}
213238
239// TODO: unused trait
214pub trait SponsoringResolve<AccountId, Call> {240pub trait SponsoringResolve<AccountId, Call> {
215 fn resolve(who: &AccountId, call: &Call) -> Option<AccountId>;241 fn resolve(who: &AccountId, call: &Call) -> Option<AccountId>;
216}242}
217243
244/// Access mode for token.
218#[derive(Encode, Decode, Eq, Debug, Clone, Copy, PartialEq, TypeInfo, MaxEncodedLen)]245#[derive(Encode, Decode, Eq, Debug, Clone, Copy, PartialEq, TypeInfo, MaxEncodedLen)]
219#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]246#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
220pub enum AccessMode {247pub enum AccessMode {
248 /// Access grant for owner and admins. Used as default.
221 Normal,249 Normal,
250 /// Like a [`Normal`](AccessMode::Normal) but also users in allow list.
222 AllowList,251 AllowList,
223}252}
224impl Default for AccessMode {253impl Default for AccessMode {
227 }256 }
228}257}
229258
259// TODO: remove in future.
230#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]260#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]
231#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]261#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
232pub enum SchemaVersion {262pub enum SchemaVersion {
239 }269 }
240}270}
241271
272// TODO: unused type
242#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, TypeInfo)]273#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, TypeInfo)]
243#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]274#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
244pub struct Ownership<AccountId> {275pub struct Ownership<AccountId> {
245 pub owner: AccountId,276 pub owner: AccountId,
246 pub fraction: u128,277 pub fraction: u128,
247}278}
248279
280/// The state of collection sponsorship.
249#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]281#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]
250#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]282#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
251pub enum SponsorshipState<AccountId> {283pub enum SponsorshipState<AccountId> {
252 /// The fees are applied to the transaction sender284 /// The fees are applied to the transaction sender.
253 Disabled,285 Disabled,
254 /// Pending confirmation from a sponsor-to-be286 /// The sponsor is under consideration. Until the sponsor gives his consent,
287 /// the fee will still be charged to sender.
255 Unconfirmed(AccountId),288 Unconfirmed(AccountId),
256 /// Transactions are sponsored by specified account289 /// Transactions are sponsored by specified account.
257 Confirmed(AccountId),290 Confirmed(AccountId),
258}291}
259292
260impl<AccountId> SponsorshipState<AccountId> {293impl<AccountId> SponsorshipState<AccountId> {
261 /// Get the acting sponsor account, if present294 /// Get a sponsor of the collection who has confirmed his status.
262 pub fn sponsor(&self) -> Option<&AccountId> {295 pub fn sponsor(&self) -> Option<&AccountId> {
263 match self {296 match self {
264 Self::Confirmed(sponsor) => Some(sponsor),297 Self::Confirmed(sponsor) => Some(sponsor),
265 _ => None,298 _ => None,
266 }299 }
267 }300 }
268301
269 /// Get the sponsor account currently pending confirmation, if present302 /// Get a sponsor of the collection who has pending or confirmed status.
270 pub fn pending_sponsor(&self) -> Option<&AccountId> {303 pub fn pending_sponsor(&self) -> Option<&AccountId> {
271 match self {304 match self {
272 Self::Unconfirmed(sponsor) | Self::Confirmed(sponsor) => Some(sponsor),305 Self::Unconfirmed(sponsor) | Self::Confirmed(sponsor) => Some(sponsor),
273 _ => None,306 _ => None,
274 }307 }
275 }308 }
276309
277 /// Is sponsorship set and acting310 /// Whether the sponsorship is confirmed.
278 pub fn confirmed(&self) -> bool {311 pub fn confirmed(&self) -> bool {
279 matches!(self, Self::Confirmed(_))312 matches!(self, Self::Confirmed(_))
280 }313 }
290pub type CollectionDescription = BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>;323pub type CollectionDescription = BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>;
291pub type CollectionTokenPrefix = BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>;324pub type CollectionTokenPrefix = BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>;
292325
326/// Base structure for represent collection.
327///
328/// Used to provide basic functionality for all types of collections.
329///
330/// #### Note
293/// Collection parameters, used in storage (see [`RpcCollection`] for the RPC version).331/// Collection parameters, used in storage (see [`RpcCollection`] for the RPC version).
294#[struct_versioning::versioned(version = 2, upper)]332#[struct_versioning::versioned(version = 2, upper)]
295#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)]333#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)]
296pub struct Collection<AccountId> {334pub struct Collection<AccountId> {
335 /// Collection owner account.
297 pub owner: AccountId,336 pub owner: AccountId,
337
338 /// Collection mode.
298 pub mode: CollectionMode,339 pub mode: CollectionMode,
340
341 /// Access mode.
299 #[version(..2)]342 #[version(..2)]
300 pub access: AccessMode,343 pub access: AccessMode,
344
345 /// Collection name.
301 pub name: CollectionName,346 pub name: CollectionName,
347
348 /// Collection description.
302 pub description: CollectionDescription,349 pub description: CollectionDescription,
350
351 /// Token prefix.
303 pub token_prefix: CollectionTokenPrefix,352 pub token_prefix: CollectionTokenPrefix,
304353
305 #[version(..2)]354 #[version(..2)]
311 #[version(..2)]360 #[version(..2)]
312 pub schema_version: SchemaVersion,361 pub schema_version: SchemaVersion,
362
363 /// The state of sponsorship of the collection.
313 pub sponsorship: SponsorshipState<AccountId>,364 pub sponsorship: SponsorshipState<AccountId>,
314365
366 /// Collection limits.
315 pub limits: CollectionLimits,367 pub limits: CollectionLimits,
316368
369 /// Collection permissions.
317 #[version(2.., upper(Default::default()))]370 #[version(2.., upper(Default::default()))]
318 pub permissions: CollectionPermissions,371 pub permissions: CollectionPermissions,
319372
335#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]388#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]
336#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]389#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
337pub struct RpcCollection<AccountId> {390pub struct RpcCollection<AccountId> {
391 /// Collection owner account.
338 pub owner: AccountId,392 pub owner: AccountId,
393
394 /// Collection mode.
339 pub mode: CollectionMode,395 pub mode: CollectionMode,
396
397 /// Collection name.
340 pub name: Vec<u16>,398 pub name: Vec<u16>,
399
400 /// Collection description.
341 pub description: Vec<u16>,401 pub description: Vec<u16>,
402
403 /// Token prefix.
342 pub token_prefix: Vec<u8>,404 pub token_prefix: Vec<u8>,
405
406 /// The state of sponsorship of the collection.
343 pub sponsorship: SponsorshipState<AccountId>,407 pub sponsorship: SponsorshipState<AccountId>,
408
409 /// Collection limits.
344 pub limits: CollectionLimits,410 pub limits: CollectionLimits,
411
412 /// Collection permissions.
345 pub permissions: CollectionPermissions,413 pub permissions: CollectionPermissions,
414
415 /// Token property permissions.
346 pub token_property_permissions: Vec<PropertyKeyPermission>,416 pub token_property_permissions: Vec<PropertyKeyPermission>,
417
418 /// Collection properties.
347 pub properties: Vec<Property>,419 pub properties: Vec<Property>,
420
421 /// Is collection read only.
348 pub read_only: bool,422 pub read_only: bool,
349}423}
350424
425/// Data used for create collection.
426///
427/// All fields are wrapped in [`Option`], where `None` means chain default.
351#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, Derivative, MaxEncodedLen)]428#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, Derivative, MaxEncodedLen)]
352#[derivative(Debug, Default(bound = ""))]429#[derivative(Debug, Default(bound = ""))]
353pub struct CreateCollectionData<AccountId> {430pub struct CreateCollectionData<AccountId> {
431 /// Collection mode.
354 #[derivative(Default(value = "CollectionMode::NFT"))]432 #[derivative(Default(value = "CollectionMode::NFT"))]
355 pub mode: CollectionMode,433 pub mode: CollectionMode,
434
435 /// Access mode.
356 pub access: Option<AccessMode>,436 pub access: Option<AccessMode>,
437
438 /// Collection name.
357 pub name: CollectionName,439 pub name: CollectionName,
440
441 /// Collection description.
358 pub description: CollectionDescription,442 pub description: CollectionDescription,
443
444 /// Token prefix.
359 pub token_prefix: CollectionTokenPrefix,445 pub token_prefix: CollectionTokenPrefix,
446
447 /// Pending collection sponsor.
360 pub pending_sponsor: Option<AccountId>,448 pub pending_sponsor: Option<AccountId>,
449
450 /// Collection limits.
361 pub limits: Option<CollectionLimits>,451 pub limits: Option<CollectionLimits>,
452
453 /// Collection permissions.
362 pub permissions: Option<CollectionPermissions>,454 pub permissions: Option<CollectionPermissions>,
455
456 /// Token property permissions.
363 pub token_property_permissions: CollectionPropertiesPermissionsVec,457 pub token_property_permissions: CollectionPropertiesPermissionsVec,
458
459 /// Collection properties.
364 pub properties: CollectionPropertiesVec,460 pub properties: CollectionPropertiesVec,
365}461}
366462
463/// Bounded vector of properties permissions. Max length is [`MAX_PROPERTIES_PER_ITEM`].
464// TODO: maybe rename to PropertiesPermissionsVec
367pub type CollectionPropertiesPermissionsVec =465pub type CollectionPropertiesPermissionsVec =
368 BoundedVec<PropertyKeyPermission, ConstU32<MAX_PROPERTIES_PER_ITEM>>;466 BoundedVec<PropertyKeyPermission, ConstU32<MAX_PROPERTIES_PER_ITEM>>;
369467
468/// Bounded vector of properties. Max length is [`MAX_PROPERTIES_PER_ITEM`].
370pub type CollectionPropertiesVec = BoundedVec<Property, ConstU32<MAX_PROPERTIES_PER_ITEM>>;469pub type CollectionPropertiesVec = BoundedVec<Property, ConstU32<MAX_PROPERTIES_PER_ITEM>>;
371470
372/// Limits and restrictions of a collection.471/// Limits and restrictions of a collection.
373/// All fields are wrapped in `Option`s, where None means chain default.
374///472///
375/// todo:doc links to chain defaults473/// All fields are wrapped in [`Option`], where `None` means chain default.
474///
475/// Update with `pallet_common::Pallet::clamp_limits`.
376// IMPORTANT: When adding/removing fields from this struct - don't forget to also476// IMPORTANT: When adding/removing fields from this struct - don't forget to also
377// update clamp_limits() in pallet-common.477// TODO: move `pallet_common::Pallet::clamp_limits() in pallet-common.` into `impl CollectionLimits`.
378#[derive(Encode, Decode, Debug, Default, Clone, PartialEq, TypeInfo, MaxEncodedLen)]478#[derive(Encode, Decode, Debug, Default, Clone, PartialEq, TypeInfo, MaxEncodedLen)]
379#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]479#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
380pub struct CollectionLimits {480pub struct CollectionLimits {
381 /// Maximum number of owned tokens per account. Chain default: [`ACCOUNT_TOKEN_OWNERSHIP_LIMIT`]481 /// How many tokens can a user have on one account.
482 /// * Default - [`ACCOUNT_TOKEN_OWNERSHIP_LIMIT`].
483 /// * Limit - [`MAX_TOKEN_OWNERSHIP`].
382 pub account_token_ownership_limit: Option<u32>,484 pub account_token_ownership_limit: Option<u32>,
485
383 /// Maximum size of data in bytes of a sponsored transaction. Chain default: [`CUSTOM_DATA_LIMIT`]486 /// Maximum size of data in bytes of a sponsored transaction.
487 /// * Default - [`CUSTOM_DATA_LIMIT`].
384 pub sponsored_data_size: Option<u32>,488 pub sponsored_data_size: Option<u32>,
385489
386 /// FIXME should we delete this or repurpose it?490 /// FIXME should we delete this or repurpose it?