Crates.io | pallet-commodities |
lib.rs | pallet-commodities |
version | 1.0.0 |
source | src |
created_at | 2020-08-13 23:37:15.285683 |
updated_at | 2020-09-29 22:23:10.660344 |
description | A unique asset (NFT) interface and a Substrate FRAME implementation optimized for commodity assets. |
homepage | https://github.com/danforbes/pallet-nft |
repository | https://github.com/danforbes/pallet-nft |
max_upload_size | |
id | 276382 |
size | 34,488 |
This is a FRAME pallet that defines and implements an interface for managing a set of non-fungible tokens (NFTs). Assets have an owner and can be created, destroyed and transferred.
This package defines a public trait (Rust interface) for working with NFTs: the UniqueAssets
trait.
UniqueAssets
TraitThis trait is generic with respect to a type that is used to identify asset owners - the AccountId
type. Assets with
equivalent attributes (as defined by the AssetInfo
type) must have equal AssetId
s and assets with different
AssetId
s must not have equivalent attributes.
AssetId
: a URI for an assetAssetInfo
: a set of attributes that uniquely describes an assetAssetLimit
: the maximum number of assets, expressed as an unsigned 128-bit integer, that may exist in this set at
onceUserAssetLimit
: the maximum number of assets, expressed as an unsigned 64-bit integer, that any single account may
own from this set at oncetotal() -> u128
: returns the total number of assets in this set of assetsburned() -> u128
: returns the total number of assets from this set that have been burnedtotal_for_account(AccountId) -> u64
: returns the total number of asset from this set that are owned by a given
accountassets_for_account(AccountId) -> Vec<(AssetId, AssetInfo)>
: returns the list of assets from this set that are owned
by a given accountowner_of(AssetId) -> AccountId
: returns the ID of the account that owns the given asset from this setmint(AccountId, AssetInfo) -> Result<AssetID, DispatchError>
: use the given attributes to create a new unique asset
that belongs to this set and assign ownership of it to the given account
burn(AssetId) -> DispatchResult
: destroy the given asset
transfer(AccountId, AssetId) -> DispatchResult
: transfer ownership of the given asset from this set from its current
owner to a given target account
The reference implementation defined in this project is referred to as a "commodity" - a unique asset that is designed for frequent trading. In order to optimize for this use case, sorted lists of assets are stored per owner. Although maintaining a sorted list is trivial with Rust vectors, which implement a binary search API that can be used for sorted insertion, it introduces significant overhead when an asset is created because the entire list must be decoded from the backing trie in order to insert the new asset in the correct spot. Maintaining a sorted asset list is desireable for the commodity use case, however, because it allows assets to be efficiently located when destroying or transferring them. An alternative implementation, the Keepsake pallet, is in the works :rocket:
Refer to the mock runtime and provided tests to see the NFT implementation in action.
In order to help develop this pallet, it is being consumed by a test project - a work-in-progress update to the original Substratekitties tutorial.
This project was inspired by works such as the following:
Thanks to the following people who helped me overcome my relatively limited understanding of Rust.
This project was forked from the Substrate DevHub Pallet Template.