NFT

Struct NFT 

Source
pub struct NFT<'st, S, BS>
where S: Syscalls, BS: Blockstore,
{ /* private fields */ }
Expand description

A helper handle for NFTState that injects services into the state-level operations.

Implementations§

Source§

impl<'st, S, BS> NFT<'st, S, BS>
where S: Syscalls, BS: Blockstore,

Source

pub fn wrap(runtime: ActorRuntime<S, BS>, state: &'st mut NFTState) -> Self

Wrap an instance of the state-tree in a handle for higher-level operations.

Source

pub fn flush(&mut self) -> Result<Cid>

Flush state and return Cid for root.

Source

pub fn load_replace(&mut self, cid: &Cid) -> Result<NFTState>

Loads a fresh copy of the state from a blockstore from a given cid, replacing existing state.

The old state is returned for convenience but can be safely dropped.

Source

pub fn transaction<F, Res>(&mut self, f: F) -> Result<Res>
where F: FnOnce(&mut NFTState, &ActorRuntime<S, BS>) -> Result<Res>,

Opens an atomic transaction on TokenState which allows a closure to make multiple modifications to the state tree.

If errors are returned by any intermediate state method, it is recommended to abort the entire transaction by propagating the error. If state-level errors are explicitly handled, it is necessary to reload from the blockstore any passed-in owner HAMT or token AMT to ensure partial writes are dropped.

If the closure returns an error, the transaction is dropped atomically and no change is observed on token state.

Source

pub fn check_invariants(&self) -> Result<StateSummary, Vec<StateInvariantError>>

Check the underlying state for consistency errors.

Source§

impl<S, BS> NFT<'_, S, BS>
where S: Syscalls, BS: Blockstore,

Source

pub fn total_supply(&self) -> u64

Return the total number of NFTs in circulation from this collection.

Source

pub fn balance_of(&self, address: &Address) -> Result<u64>

Return the number of NFTs held by a particular address.

Source

pub fn owner_of(&self, token_id: TokenID) -> Result<ActorID>

Return the owner of an NFT.

Source

pub fn metadata(&self, token_id: TokenID) -> Result<String>

Return the metadata for an NFT.

Source

pub fn mint( &mut self, operator: &Address, initial_owner: &Address, metadata_array: Vec<String>, operator_data: RawBytes, token_data: RawBytes, ) -> Result<ReceiverHook<MintIntermediate>>

Create new NFTs belonging to the initial_owner. The mint method is not standardised as part of the actor’s interface but this is a useful method at the library level to generate new tokens that will maintain the necessary state invariants.

For each string in metadata_array, a new NFT will be minted with the given metadata.

Returns a MintIntermediate that can be used to construct return data.

Source

pub fn mint_return( &mut self, intermediate: MintIntermediate, prior_state_cid: Cid, ) -> Result<MintReturn>

Constructs MintReturn data from a MintIntermediate handle.

Creates an up-to-date view of the actor state where necessary to generate the values prior_state_cid is the CID of the state prior to hook call.

Source

pub fn burn(&mut self, owner: &Address, token_ids: &[TokenID]) -> Result<u64>

Burn a set of NFTs as the owner and returns the resulting balance.

A burnt TokenID can never be minted again.

Source

pub fn burn_from( &mut self, owner: &Address, operator: &Address, token_ids: &[TokenID], ) -> Result<u64>

Burn a set of NFTs as an operator and returns the resulting balance.

A burnt TokenID can never be minted again.

Source

pub fn approve( &mut self, caller: &Address, operator: &Address, token_ids: &[TokenID], ) -> Result<()>

Approve an operator to transfer or burn a single NFT.

  • caller may be an account-level operator or owner of the NFT.
  • operator is the new address to become an approved operator.
Source

pub fn revoke( &mut self, caller: &Address, operator: &Address, token_ids: &[TokenID], ) -> Result<()>

Revoke the approval of an operator to transfer a particular NFT.

  • caller may be an account-level operator or owner of the NFT.
  • operator is the address whose approval is being revoked.
Source

pub fn approve_for_owner( &mut self, owner: &Address, operator: &Address, ) -> Result<()>

Approve an operator to transfer or burn on behalf of the account.

  • owner must be the address that called this method.
  • operator is the new address to become an approved operator.
Source

pub fn revoke_for_all( &mut self, owner: &Address, operator: &Address, ) -> Result<()>

Revoke the approval of an operator to transfer on behalf of the caller.

  • owner must be the address that called this method.
  • operator is the address whose approval is being revoked.
Source

pub fn transfer( &mut self, owner: &Address, recipient: &Address, token_ids: &[TokenID], operator_data: RawBytes, token_data: RawBytes, ) -> Result<ReceiverHook<TransferIntermediate>>

Transfers a token owned by the caller.

Source

pub fn transfer_return( &mut self, intermediate: TransferIntermediate, prior_state_cid: Cid, ) -> Result<TransferReturn>

Constructs TransferReturn data from a TransferIntermediate.

Creates an up-to-date view of the actor state where necessary to generate the values prior_state_cid is the CID of the state prior to hook call.

Source

pub fn transfer_from( &mut self, owner: &Address, operator: &Address, recipient: &Address, token_ids: &[TokenID], operator_data: RawBytes, token_data: RawBytes, ) -> Result<ReceiverHook<TransferIntermediate>>

Transfers a token that the caller is an operator for.

Source

pub fn transfer_from_return( &mut self, intermediate: TransferIntermediate, prior_state_cid: Cid, ) -> Result<TransferReturn>

Constructs TransferReturn data from a TransferIntermediate.

Creates an up-to-date view of the actor state where necessary to generate the values prior_state_cid is the CID of the state prior to hook call.

Source

pub fn list_tokens( &self, cursor: RawBytes, limit: u64, ) -> Result<ListTokensReturn>

Enumerates a page of TokenIDs.

Source

pub fn list_owned_tokens( &self, owner: &Address, cursor: RawBytes, limit: u64, ) -> Result<ListTokensReturn>

Enumerates a page of TokenIDs. owned by a specific address.

Source

pub fn list_token_operators( &self, token_id: TokenID, cursor: RawBytes, limit: u64, ) -> Result<ListTokenOperatorsReturn>

Returns all the operators approved by an owner for a token.

Source

pub fn list_operator_tokens( &self, operator: &Address, cursor: RawBytes, limit: u64, ) -> Result<ListOperatorTokensReturn>

Enumerates tokens for which an account is an operator for an owner.

Source

pub fn list_account_operators( &self, owner: &Address, cursor: RawBytes, limit: u64, ) -> Result<ListAccountOperatorsReturn>

Returns all the account-level operators approved by an owner.

Source

pub fn reload_if_changed( &mut self, expected_cid: Cid, ) -> Result<Option<NFTState>>

Reloads the state if the current root cid has diverged (i.e. during re-entrant receiver hooks) from the last known expected cid.

Returns the current in-blockstore state if the root cid has changed else RawBytes::default().

Auto Trait Implementations§

§

impl<'st, S, BS> Freeze for NFT<'st, S, BS>
where S: Freeze, BS: Freeze,

§

impl<'st, S, BS> RefUnwindSafe for NFT<'st, S, BS>

§

impl<'st, S, BS> Send for NFT<'st, S, BS>
where S: Send, BS: Send,

§

impl<'st, S, BS> Sync for NFT<'st, S, BS>
where S: Sync, BS: Sync,

§

impl<'st, S, BS> Unpin for NFT<'st, S, BS>
where S: Unpin, BS: Unpin,

§

impl<'st, S, BS> !UnwindSafe for NFT<'st, S, BS>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.