Skip to content

Commit a794d0e

Browse files
jsidorenkoshawntabriziParity Bot
authored andcommitted
Use 'Items' and 'Collections' in uniques pallet (paritytech#11389)
* Rename class to collection * Use "assets collection" instead of "asset collection" * Rename 'instance' to 'asset' * Change "asset `collection`" to "`collection`" * A bit more clean up * Rename Asset to Item * Add a storage hack * Typos * fix compile * fmt * Fix * cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark pallet --chain=dev --steps=50 --repeat=20 --pallet=pallet_uniques --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/uniques/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Update frame/uniques/src/lib.rs * cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark pallet --chain=dev --steps=50 --repeat=20 --pallet=pallet_uniques --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/uniques/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Change 'items collection' to 'collection' * Apply suggestions Co-authored-by: Shawn Tabrizi <[email protected]> Co-authored-by: Parity Bot <[email protected]>
1 parent 8169b3c commit a794d0e

File tree

13 files changed

+1120
-1082
lines changed

13 files changed

+1120
-1082
lines changed

bin/node/runtime/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,12 +1414,12 @@ parameter_types! {
14141414

14151415
impl pallet_uniques::Config for Runtime {
14161416
type Event = Event;
1417-
type ClassId = u32;
1418-
type InstanceId = u32;
1417+
type CollectionId = u32;
1418+
type ItemId = u32;
14191419
type Currency = Balances;
14201420
type ForceOrigin = frame_system::EnsureRoot<AccountId>;
1421-
type ClassDeposit = ClassDeposit;
1422-
type InstanceDeposit = InstanceDeposit;
1421+
type CollectionDeposit = ClassDeposit;
1422+
type ItemDeposit = InstanceDeposit;
14231423
type MetadataDepositBase = MetadataDepositBase;
14241424
type AttributeDepositBase = MetadataDepositBase;
14251425
type DepositPerByte = MetadataDepositPerByte;

frame/support/src/traits/tokens/misc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,16 @@ pub trait BalanceConversion<InBalance, AssetId, OutBalance> {
182182

183183
/// Trait to handle asset locking mechanism to ensure interactions with the asset can be implemented
184184
/// downstream to extend logic of Uniques current functionality.
185-
pub trait Locker<ClassId, InstanceId> {
185+
pub trait Locker<CollectionId, ItemId> {
186186
/// Check if the asset should be locked and prevent interactions with the asset from executing.
187-
fn is_locked(class: ClassId, instance: InstanceId) -> bool;
187+
fn is_locked(collection: CollectionId, item: ItemId) -> bool;
188188
}
189189

190-
impl<ClassId, InstanceId> Locker<ClassId, InstanceId> for () {
190+
impl<CollectionId, ItemId> Locker<CollectionId, ItemId> for () {
191191
// Default will be false if not implemented downstream.
192192
// Note: The logic check in this function must be constant time and consistent for benchmarks
193193
// to work.
194-
fn is_locked(_class: ClassId, _instance: InstanceId) -> bool {
194+
fn is_locked(_collection: CollectionId, _item: ItemId) -> bool {
195195
false
196196
}
197197
}

frame/support/src/traits/tokens/nonfungible.rs

Lines changed: 61 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
// See the License for the specific language governing permissions and
1616
// limitations under the License.
1717

18-
//! Traits for dealing with a single non-fungible asset class.
18+
//! Traits for dealing with a single non-fungible collection of items.
1919
//!
20-
//! This assumes a single level namespace identified by `Inspect::InstanceId`, and could
20+
//! This assumes a single level namespace identified by `Inspect::ItemId`, and could
2121
//! reasonably be implemented by pallets which wants to expose a single collection of NFT-like
2222
//! objects.
2323
//!
@@ -30,167 +30,164 @@ use codec::{Decode, Encode};
3030
use sp_runtime::TokenError;
3131
use sp_std::prelude::*;
3232

33-
/// Trait for providing an interface to a read-only NFT-like set of asset instances.
33+
/// Trait for providing an interface to a read-only NFT-like set of items.
3434
pub trait Inspect<AccountId> {
35-
/// Type for identifying an asset instance.
36-
type InstanceId;
35+
/// Type for identifying an item.
36+
type ItemId;
3737

38-
/// Returns the owner of asset `instance`, or `None` if the asset doesn't exist or has no
38+
/// Returns the owner of `item`, or `None` if the item doesn't exist or has no
3939
/// owner.
40-
fn owner(instance: &Self::InstanceId) -> Option<AccountId>;
40+
fn owner(item: &Self::ItemId) -> Option<AccountId>;
4141

42-
/// Returns the attribute value of `instance` corresponding to `key`.
42+
/// Returns the attribute value of `item` corresponding to `key`.
4343
///
4444
/// By default this is `None`; no attributes are defined.
45-
fn attribute(_instance: &Self::InstanceId, _key: &[u8]) -> Option<Vec<u8>> {
45+
fn attribute(_item: &Self::ItemId, _key: &[u8]) -> Option<Vec<u8>> {
4646
None
4747
}
4848

49-
/// Returns the strongly-typed attribute value of `instance` corresponding to `key`.
49+
/// Returns the strongly-typed attribute value of `item` corresponding to `key`.
5050
///
5151
/// By default this just attempts to use `attribute`.
52-
fn typed_attribute<K: Encode, V: Decode>(instance: &Self::InstanceId, key: &K) -> Option<V> {
53-
key.using_encoded(|d| Self::attribute(instance, d))
52+
fn typed_attribute<K: Encode, V: Decode>(item: &Self::ItemId, key: &K) -> Option<V> {
53+
key.using_encoded(|d| Self::attribute(item, d))
5454
.and_then(|v| V::decode(&mut &v[..]).ok())
5555
}
5656

57-
/// Returns `true` if the asset `instance` may be transferred.
57+
/// Returns `true` if the `item` may be transferred.
5858
///
59-
/// Default implementation is that all assets are transferable.
60-
fn can_transfer(_instance: &Self::InstanceId) -> bool {
59+
/// Default implementation is that all items are transferable.
60+
fn can_transfer(_item: &Self::ItemId) -> bool {
6161
true
6262
}
6363
}
6464

65-
/// Interface for enumerating assets in existence or owned by a given account over a collection
65+
/// Interface for enumerating items in existence or owned by a given account over a collection
6666
/// of NFTs.
6767
pub trait InspectEnumerable<AccountId>: Inspect<AccountId> {
68-
/// Returns an iterator of the instances of an asset `class` in existence.
69-
fn instances() -> Box<dyn Iterator<Item = Self::InstanceId>>;
68+
/// Returns an iterator of the items within a `collection` in existence.
69+
fn items() -> Box<dyn Iterator<Item = Self::ItemId>>;
7070

71-
/// Returns an iterator of the asset instances of all classes owned by `who`.
72-
fn owned(who: &AccountId) -> Box<dyn Iterator<Item = Self::InstanceId>>;
71+
/// Returns an iterator of the items of all collections owned by `who`.
72+
fn owned(who: &AccountId) -> Box<dyn Iterator<Item = Self::ItemId>>;
7373
}
7474

75-
/// Trait for providing an interface for NFT-like assets which may be minted, burned and/or have
75+
/// Trait for providing an interface for NFT-like items which may be minted, burned and/or have
7676
/// attributes set on them.
7777
pub trait Mutate<AccountId>: Inspect<AccountId> {
78-
/// Mint some asset `instance` to be owned by `who`.
78+
/// Mint some `item` to be owned by `who`.
7979
///
8080
/// By default, this is not a supported operation.
81-
fn mint_into(_instance: &Self::InstanceId, _who: &AccountId) -> DispatchResult {
81+
fn mint_into(_item: &Self::ItemId, _who: &AccountId) -> DispatchResult {
8282
Err(TokenError::Unsupported.into())
8383
}
8484

85-
/// Burn some asset `instance`.
85+
/// Burn some `item`.
8686
///
8787
/// By default, this is not a supported operation.
88-
fn burn(
89-
_instance: &Self::InstanceId,
90-
_maybe_check_owner: Option<&AccountId>,
91-
) -> DispatchResult {
88+
fn burn(_item: &Self::ItemId, _maybe_check_owner: Option<&AccountId>) -> DispatchResult {
9289
Err(TokenError::Unsupported.into())
9390
}
9491

95-
/// Set attribute `value` of asset `instance`'s `key`.
92+
/// Set attribute `value` of `item`'s `key`.
9693
///
9794
/// By default, this is not a supported operation.
98-
fn set_attribute(_instance: &Self::InstanceId, _key: &[u8], _value: &[u8]) -> DispatchResult {
95+
fn set_attribute(_item: &Self::ItemId, _key: &[u8], _value: &[u8]) -> DispatchResult {
9996
Err(TokenError::Unsupported.into())
10097
}
10198

102-
/// Attempt to set the strongly-typed attribute `value` of `instance`'s `key`.
99+
/// Attempt to set the strongly-typed attribute `value` of `item`'s `key`.
103100
///
104101
/// By default this just attempts to use `set_attribute`.
105102
fn set_typed_attribute<K: Encode, V: Encode>(
106-
instance: &Self::InstanceId,
103+
item: &Self::ItemId,
107104
key: &K,
108105
value: &V,
109106
) -> DispatchResult {
110-
key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(instance, k, v)))
107+
key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(item, k, v)))
111108
}
112109
}
113110

114-
/// Trait for providing a non-fungible set of assets which can only be transferred.
111+
/// Trait for providing a non-fungible set of items which can only be transferred.
115112
pub trait Transfer<AccountId>: Inspect<AccountId> {
116-
/// Transfer asset `instance` into `destination` account.
117-
fn transfer(instance: &Self::InstanceId, destination: &AccountId) -> DispatchResult;
113+
/// Transfer `item` into `destination` account.
114+
fn transfer(item: &Self::ItemId, destination: &AccountId) -> DispatchResult;
118115
}
119116

120117
/// Convert a `fungibles` trait implementation into a `fungible` trait implementation by identifying
121118
/// a single item.
122119
pub struct ItemOf<
123120
F: nonfungibles::Inspect<AccountId>,
124-
A: Get<<F as nonfungibles::Inspect<AccountId>>::ClassId>,
121+
A: Get<<F as nonfungibles::Inspect<AccountId>>::CollectionId>,
125122
AccountId,
126123
>(sp_std::marker::PhantomData<(F, A, AccountId)>);
127124

128125
impl<
129126
F: nonfungibles::Inspect<AccountId>,
130-
A: Get<<F as nonfungibles::Inspect<AccountId>>::ClassId>,
127+
A: Get<<F as nonfungibles::Inspect<AccountId>>::CollectionId>,
131128
AccountId,
132129
> Inspect<AccountId> for ItemOf<F, A, AccountId>
133130
{
134-
type InstanceId = <F as nonfungibles::Inspect<AccountId>>::InstanceId;
135-
fn owner(instance: &Self::InstanceId) -> Option<AccountId> {
136-
<F as nonfungibles::Inspect<AccountId>>::owner(&A::get(), instance)
131+
type ItemId = <F as nonfungibles::Inspect<AccountId>>::ItemId;
132+
fn owner(item: &Self::ItemId) -> Option<AccountId> {
133+
<F as nonfungibles::Inspect<AccountId>>::owner(&A::get(), item)
137134
}
138-
fn attribute(instance: &Self::InstanceId, key: &[u8]) -> Option<Vec<u8>> {
139-
<F as nonfungibles::Inspect<AccountId>>::attribute(&A::get(), instance, key)
135+
fn attribute(item: &Self::ItemId, key: &[u8]) -> Option<Vec<u8>> {
136+
<F as nonfungibles::Inspect<AccountId>>::attribute(&A::get(), item, key)
140137
}
141-
fn typed_attribute<K: Encode, V: Decode>(instance: &Self::InstanceId, key: &K) -> Option<V> {
142-
<F as nonfungibles::Inspect<AccountId>>::typed_attribute(&A::get(), instance, key)
138+
fn typed_attribute<K: Encode, V: Decode>(item: &Self::ItemId, key: &K) -> Option<V> {
139+
<F as nonfungibles::Inspect<AccountId>>::typed_attribute(&A::get(), item, key)
143140
}
144-
fn can_transfer(instance: &Self::InstanceId) -> bool {
145-
<F as nonfungibles::Inspect<AccountId>>::can_transfer(&A::get(), instance)
141+
fn can_transfer(item: &Self::ItemId) -> bool {
142+
<F as nonfungibles::Inspect<AccountId>>::can_transfer(&A::get(), item)
146143
}
147144
}
148145

149146
impl<
150147
F: nonfungibles::InspectEnumerable<AccountId>,
151-
A: Get<<F as nonfungibles::Inspect<AccountId>>::ClassId>,
148+
A: Get<<F as nonfungibles::Inspect<AccountId>>::CollectionId>,
152149
AccountId,
153150
> InspectEnumerable<AccountId> for ItemOf<F, A, AccountId>
154151
{
155-
fn instances() -> Box<dyn Iterator<Item = Self::InstanceId>> {
156-
<F as nonfungibles::InspectEnumerable<AccountId>>::instances(&A::get())
152+
fn items() -> Box<dyn Iterator<Item = Self::ItemId>> {
153+
<F as nonfungibles::InspectEnumerable<AccountId>>::items(&A::get())
157154
}
158-
fn owned(who: &AccountId) -> Box<dyn Iterator<Item = Self::InstanceId>> {
159-
<F as nonfungibles::InspectEnumerable<AccountId>>::owned_in_class(&A::get(), who)
155+
fn owned(who: &AccountId) -> Box<dyn Iterator<Item = Self::ItemId>> {
156+
<F as nonfungibles::InspectEnumerable<AccountId>>::owned_in_collection(&A::get(), who)
160157
}
161158
}
162159

163160
impl<
164161
F: nonfungibles::Mutate<AccountId>,
165-
A: Get<<F as nonfungibles::Inspect<AccountId>>::ClassId>,
162+
A: Get<<F as nonfungibles::Inspect<AccountId>>::CollectionId>,
166163
AccountId,
167164
> Mutate<AccountId> for ItemOf<F, A, AccountId>
168165
{
169-
fn mint_into(instance: &Self::InstanceId, who: &AccountId) -> DispatchResult {
170-
<F as nonfungibles::Mutate<AccountId>>::mint_into(&A::get(), instance, who)
166+
fn mint_into(item: &Self::ItemId, who: &AccountId) -> DispatchResult {
167+
<F as nonfungibles::Mutate<AccountId>>::mint_into(&A::get(), item, who)
171168
}
172-
fn burn(instance: &Self::InstanceId, maybe_check_owner: Option<&AccountId>) -> DispatchResult {
173-
<F as nonfungibles::Mutate<AccountId>>::burn(&A::get(), instance, maybe_check_owner)
169+
fn burn(item: &Self::ItemId, maybe_check_owner: Option<&AccountId>) -> DispatchResult {
170+
<F as nonfungibles::Mutate<AccountId>>::burn(&A::get(), item, maybe_check_owner)
174171
}
175-
fn set_attribute(instance: &Self::InstanceId, key: &[u8], value: &[u8]) -> DispatchResult {
176-
<F as nonfungibles::Mutate<AccountId>>::set_attribute(&A::get(), instance, key, value)
172+
fn set_attribute(item: &Self::ItemId, key: &[u8], value: &[u8]) -> DispatchResult {
173+
<F as nonfungibles::Mutate<AccountId>>::set_attribute(&A::get(), item, key, value)
177174
}
178175
fn set_typed_attribute<K: Encode, V: Encode>(
179-
instance: &Self::InstanceId,
176+
item: &Self::ItemId,
180177
key: &K,
181178
value: &V,
182179
) -> DispatchResult {
183-
<F as nonfungibles::Mutate<AccountId>>::set_typed_attribute(&A::get(), instance, key, value)
180+
<F as nonfungibles::Mutate<AccountId>>::set_typed_attribute(&A::get(), item, key, value)
184181
}
185182
}
186183

187184
impl<
188185
F: nonfungibles::Transfer<AccountId>,
189-
A: Get<<F as nonfungibles::Inspect<AccountId>>::ClassId>,
186+
A: Get<<F as nonfungibles::Inspect<AccountId>>::CollectionId>,
190187
AccountId,
191188
> Transfer<AccountId> for ItemOf<F, A, AccountId>
192189
{
193-
fn transfer(instance: &Self::InstanceId, destination: &AccountId) -> DispatchResult {
194-
<F as nonfungibles::Transfer<AccountId>>::transfer(&A::get(), instance, destination)
190+
fn transfer(item: &Self::ItemId, destination: &AccountId) -> DispatchResult {
191+
<F as nonfungibles::Transfer<AccountId>>::transfer(&A::get(), item, destination)
195192
}
196193
}

0 commit comments

Comments
 (0)