pub struct NonFungibleToken {
pub owner_id: AccountId,
pub extra_storage_in_bytes_per_token: StorageUsage,
pub owner_by_id: TreeMap<TokenId, AccountId>,
pub token_metadata_by_id: Option<LookupMap<TokenId, TokenMetadata>>,
pub tokens_per_owner: Option<LookupMap<AccountId, UnorderedSet<TokenId>>>,
pub approvals_by_id: Option<LookupMap<TokenId, HashMap<AccountId, u64>>>,
pub next_approval_id_by_id: Option<LookupMap<TokenId, u64>>,
}
Expand description
Implementation of the non-fungible token standard. Allows to include NEP-171 compatible token to any contract. There are next traits that any contract may implement: - NonFungibleTokenCore – interface with nft_transfer methods. NonFungibleToken provides methods for it. - NonFungibleTokenApproval – interface with nft_approve methods. NonFungibleToken provides methods for it. - NonFungibleTokenEnumeration – interface for getting lists of tokens. NonFungibleToken provides methods for it. - NonFungibleTokenMetadata – return metadata for the token in NEP-177, up to contract to implement.
For example usage, see examples/non-fungible-token/src/lib.rs.
Fields§
§owner_id: AccountId
§extra_storage_in_bytes_per_token: StorageUsage
§owner_by_id: TreeMap<TokenId, AccountId>
§token_metadata_by_id: Option<LookupMap<TokenId, TokenMetadata>>
§tokens_per_owner: Option<LookupMap<AccountId, UnorderedSet<TokenId>>>
§approvals_by_id: Option<LookupMap<TokenId, HashMap<AccountId, u64>>>
§next_approval_id_by_id: Option<LookupMap<TokenId, u64>>
Implementations§
Source§impl NonFungibleToken
impl NonFungibleToken
pub fn new<Q, R, S, T>( owner_by_id_prefix: Q, owner_id: AccountId, token_metadata_prefix: Option<R>, enumeration_prefix: Option<S>, approval_prefix: Option<T>, ) -> Self
Sourcepub fn internal_transfer_unguarded(
&mut self,
token_id: &TokenId,
from: &AccountId,
to: &AccountId,
)
pub fn internal_transfer_unguarded( &mut self, token_id: &TokenId, from: &AccountId, to: &AccountId, )
Transfer token_id from from
to to
Do not perform any safety checks or do any logging
Sourcepub fn internal_transfer(
&mut self,
sender_id: &AccountId,
receiver_id: &AccountId,
token_id: &TokenId,
approval_id: Option<u64>,
memo: Option<String>,
) -> (AccountId, Option<HashMap<AccountId, u64>>)
pub fn internal_transfer( &mut self, sender_id: &AccountId, receiver_id: &AccountId, token_id: &TokenId, approval_id: Option<u64>, memo: Option<String>, ) -> (AccountId, Option<HashMap<AccountId, u64>>)
Transfer from current owner to receiver_id, checking that sender is allowed to transfer. Clear approvals, if approval extension being used. Return previous owner and approvals.
Sourcepub fn mint(
&mut self,
token_id: TokenId,
token_owner_id: AccountId,
token_metadata: Option<TokenMetadata>,
) -> Token
👎Deprecated since 4.0.0: mint is deprecated, please use internal_mint instead.
pub fn mint( &mut self, token_id: TokenId, token_owner_id: AccountId, token_metadata: Option<TokenMetadata>, ) -> Token
Mint a new token. Not part of official standard, but needed in most situations.
Consuming contract expected to wrap this with an nft_mint
function.
Requirements:
- Caller must be the
owner_id
set during contract initialization. - Caller of the method must attach a deposit of 1 yoctoⓃ for security purposes.
- If contract is using Metadata extension (by having provided
metadata_prefix
during contract initialization),token_metadata
must be given. - token_id must be unique
Returns the newly minted token
Sourcepub fn internal_mint(
&mut self,
token_id: TokenId,
token_owner_id: AccountId,
token_metadata: Option<TokenMetadata>,
) -> Token
pub fn internal_mint( &mut self, token_id: TokenId, token_owner_id: AccountId, token_metadata: Option<TokenMetadata>, ) -> Token
Mint a new token without checking:
- Whether the caller id is equal to the
owner_id
- Assumes there will be a refund to the predecessor after covering the storage costs
Returns the newly minted token and emits the mint event
Sourcepub fn internal_mint_with_refund(
&mut self,
token_id: TokenId,
token_owner_id: AccountId,
token_metadata: Option<TokenMetadata>,
refund_id: Option<AccountId>,
) -> Token
pub fn internal_mint_with_refund( &mut self, token_id: TokenId, token_owner_id: AccountId, token_metadata: Option<TokenMetadata>, refund_id: Option<AccountId>, ) -> Token
Mint a new token without checking:
- Whether the caller id is equal to the
owner_id
refund_id
will transfer the left over balance after storage costs are calculated to the provided account. Typically the account will be the owner. IfNone
, will not refund. This is useful for delaying refunding until multiple tokens have been minted.
Returns the newly minted token and does not emit the mint event. This allows minting multiple before emitting.
Trait Implementations§
Source§impl BorshDeserialize for NonFungibleToken
impl BorshDeserialize for NonFungibleToken
fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>
Source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl BorshSchema for NonFungibleToken
impl BorshSchema for NonFungibleToken
Source§fn declaration() -> Declaration
fn declaration() -> Declaration
Source§fn add_definitions_recursively(
definitions: &mut BTreeMap<Declaration, Definition>,
)
fn add_definitions_recursively( definitions: &mut BTreeMap<Declaration, Definition>, )
Source§impl BorshSerialize for NonFungibleToken
impl BorshSerialize for NonFungibleToken
Source§impl NonFungibleTokenApproval for NonFungibleToken
impl NonFungibleTokenApproval for NonFungibleToken
Source§fn nft_approve(
&mut self,
token_id: TokenId,
account_id: AccountId,
msg: Option<String>,
) -> Option<Promise>
fn nft_approve( &mut self, token_id: TokenId, account_id: AccountId, msg: Option<String>, ) -> Option<Promise>
Source§fn nft_revoke(&mut self, token_id: TokenId, account_id: AccountId)
fn nft_revoke(&mut self, token_id: TokenId, account_id: AccountId)
Source§fn nft_revoke_all(&mut self, token_id: TokenId)
fn nft_revoke_all(&mut self, token_id: TokenId)
Source§impl NonFungibleTokenCore for NonFungibleToken
impl NonFungibleTokenCore for NonFungibleToken
Source§fn nft_transfer(
&mut self,
receiver_id: AccountId,
token_id: TokenId,
approval_id: Option<u64>,
memo: Option<String>,
)
fn nft_transfer( &mut self, receiver_id: AccountId, token_id: TokenId, approval_id: Option<u64>, memo: Option<String>, )
Source§fn nft_transfer_call(
&mut self,
receiver_id: AccountId,
token_id: TokenId,
approval_id: Option<u64>,
memo: Option<String>,
msg: String,
) -> PromiseOrValue<bool>
fn nft_transfer_call( &mut self, receiver_id: AccountId, token_id: TokenId, approval_id: Option<u64>, memo: Option<String>, msg: String, ) -> PromiseOrValue<bool>
nft_resolve_transfer
. Read more