Struct near_contract_standards::non_fungible_token::NonFungibleToken [−][src]
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
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 where
Q: IntoStorageKey,
R: IntoStorageKey,
S: IntoStorageKey,
T: IntoStorageKey,
pub 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
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.
pub 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 is deprecated, please use internal_mint instead.
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
pub 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
Trait Implementations
impl BorshDeserialize for NonFungibleToken where
AccountId: BorshDeserialize,
StorageUsage: BorshDeserialize,
TreeMap<TokenId, AccountId>: BorshDeserialize,
Option<LookupMap<TokenId, TokenMetadata>>: BorshDeserialize,
Option<LookupMap<AccountId, UnorderedSet<TokenId>>>: BorshDeserialize,
Option<LookupMap<TokenId, HashMap<AccountId, u64>>>: BorshDeserialize,
Option<LookupMap<TokenId, u64>>: BorshDeserialize,
impl BorshDeserialize for NonFungibleToken where
AccountId: BorshDeserialize,
StorageUsage: BorshDeserialize,
TreeMap<TokenId, AccountId>: BorshDeserialize,
Option<LookupMap<TokenId, TokenMetadata>>: BorshDeserialize,
Option<LookupMap<AccountId, UnorderedSet<TokenId>>>: BorshDeserialize,
Option<LookupMap<TokenId, HashMap<AccountId, u64>>>: BorshDeserialize,
Option<LookupMap<TokenId, u64>>: BorshDeserialize,
Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes. Read more
Whether Self is u8.
NOTE: Vec<u8>
is the most common use-case for serialization and deserialization, it’s
worth handling it as a special case to improve performance.
It’s a workaround for specific Vec<u8>
implementation versus generic Vec<T>
implementation. See https://github.com/rust-lang/rfcs/pull/1210 for details. Read more
impl BorshSerialize for NonFungibleToken where
AccountId: BorshSerialize,
StorageUsage: BorshSerialize,
TreeMap<TokenId, AccountId>: BorshSerialize,
Option<LookupMap<TokenId, TokenMetadata>>: BorshSerialize,
Option<LookupMap<AccountId, UnorderedSet<TokenId>>>: BorshSerialize,
Option<LookupMap<TokenId, HashMap<AccountId, u64>>>: BorshSerialize,
Option<LookupMap<TokenId, u64>>: BorshSerialize,
impl BorshSerialize for NonFungibleToken where
AccountId: BorshSerialize,
StorageUsage: BorshSerialize,
TreeMap<TokenId, AccountId>: BorshSerialize,
Option<LookupMap<TokenId, TokenMetadata>>: BorshSerialize,
Option<LookupMap<AccountId, UnorderedSet<TokenId>>>: BorshSerialize,
Option<LookupMap<TokenId, HashMap<AccountId, u64>>>: BorshSerialize,
Option<LookupMap<TokenId, u64>>: BorshSerialize,
Serialize this instance into a vector of bytes.
Whether Self is u8.
NOTE: Vec<u8>
is the most common use-case for serialization and deserialization, it’s
worth handling it as a special case to improve performance.
It’s a workaround for specific Vec<u8>
implementation versus generic Vec<T>
implementation. See https://github.com/rust-lang/rfcs/pull/1210 for details. Read more