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,
impl<'st, S, BS> NFT<'st, S, BS>where
S: Syscalls,
BS: Blockstore,
Sourcepub fn wrap(runtime: ActorRuntime<S, BS>, state: &'st mut NFTState) -> Self
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.
Sourcepub fn load_replace(&mut self, cid: &Cid) -> Result<NFTState>
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.
Sourcepub fn transaction<F, Res>(&mut self, f: F) -> Result<Res>
pub fn transaction<F, Res>(&mut self, f: F) -> 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.
Sourcepub fn check_invariants(&self) -> Result<StateSummary, Vec<StateInvariantError>>
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,
impl<S, BS> NFT<'_, S, BS>where
S: Syscalls,
BS: Blockstore,
Sourcepub fn total_supply(&self) -> u64
pub fn total_supply(&self) -> u64
Return the total number of NFTs in circulation from this collection.
Sourcepub fn balance_of(&self, address: &Address) -> Result<u64>
pub fn balance_of(&self, address: &Address) -> Result<u64>
Return the number of NFTs held by a particular address.
Sourcepub fn mint(
&mut self,
operator: &Address,
initial_owner: &Address,
metadata_array: Vec<String>,
operator_data: RawBytes,
token_data: RawBytes,
) -> Result<ReceiverHook<MintIntermediate>>
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.
Sourcepub fn mint_return(
&mut self,
intermediate: MintIntermediate,
prior_state_cid: Cid,
) -> Result<MintReturn>
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.
Sourcepub fn burn(&mut self, owner: &Address, token_ids: &[TokenID]) -> Result<u64>
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.
Sourcepub fn burn_from(
&mut self,
owner: &Address,
operator: &Address,
token_ids: &[TokenID],
) -> Result<u64>
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.
Sourcepub fn approve(
&mut self,
caller: &Address,
operator: &Address,
token_ids: &[TokenID],
) -> Result<()>
pub fn approve( &mut self, caller: &Address, operator: &Address, token_ids: &[TokenID], ) -> Result<()>
Approve an operator to transfer or burn a single NFT.
callermay be an account-level operator or owner of the NFT.operatoris the new address to become an approved operator.
Sourcepub fn revoke(
&mut self,
caller: &Address,
operator: &Address,
token_ids: &[TokenID],
) -> Result<()>
pub fn revoke( &mut self, caller: &Address, operator: &Address, token_ids: &[TokenID], ) -> Result<()>
Revoke the approval of an operator to transfer a particular NFT.
callermay be an account-level operator or owner of the NFT.operatoris the address whose approval is being revoked.
Sourcepub fn approve_for_owner(
&mut self,
owner: &Address,
operator: &Address,
) -> Result<()>
pub fn approve_for_owner( &mut self, owner: &Address, operator: &Address, ) -> Result<()>
Approve an operator to transfer or burn on behalf of the account.
ownermust be the address that called this method.operatoris the new address to become an approved operator.
Sourcepub fn revoke_for_all(
&mut self,
owner: &Address,
operator: &Address,
) -> Result<()>
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.
ownermust be the address that called this method.operatoris the address whose approval is being revoked.
Sourcepub fn transfer(
&mut self,
owner: &Address,
recipient: &Address,
token_ids: &[TokenID],
operator_data: RawBytes,
token_data: RawBytes,
) -> Result<ReceiverHook<TransferIntermediate>>
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.
Sourcepub fn transfer_return(
&mut self,
intermediate: TransferIntermediate,
prior_state_cid: Cid,
) -> Result<TransferReturn>
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.
Sourcepub fn transfer_from(
&mut self,
owner: &Address,
operator: &Address,
recipient: &Address,
token_ids: &[TokenID],
operator_data: RawBytes,
token_data: RawBytes,
) -> Result<ReceiverHook<TransferIntermediate>>
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.
Sourcepub fn transfer_from_return(
&mut self,
intermediate: TransferIntermediate,
prior_state_cid: Cid,
) -> Result<TransferReturn>
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.
Sourcepub fn list_tokens(
&self,
cursor: RawBytes,
limit: u64,
) -> Result<ListTokensReturn>
pub fn list_tokens( &self, cursor: RawBytes, limit: u64, ) -> Result<ListTokensReturn>
Enumerates a page of TokenIDs.
Sourcepub fn list_owned_tokens(
&self,
owner: &Address,
cursor: RawBytes,
limit: u64,
) -> Result<ListTokensReturn>
pub fn list_owned_tokens( &self, owner: &Address, cursor: RawBytes, limit: u64, ) -> Result<ListTokensReturn>
Enumerates a page of TokenIDs. owned by a specific address.
Sourcepub fn list_token_operators(
&self,
token_id: TokenID,
cursor: RawBytes,
limit: u64,
) -> Result<ListTokenOperatorsReturn>
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.
Sourcepub fn list_operator_tokens(
&self,
operator: &Address,
cursor: RawBytes,
limit: u64,
) -> Result<ListOperatorTokensReturn>
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.
Sourcepub fn list_account_operators(
&self,
owner: &Address,
cursor: RawBytes,
limit: u64,
) -> Result<ListAccountOperatorsReturn>
pub fn list_account_operators( &self, owner: &Address, cursor: RawBytes, limit: u64, ) -> Result<ListAccountOperatorsReturn>
Returns all the account-level operators approved by an owner.
Sourcepub fn reload_if_changed(
&mut self,
expected_cid: Cid,
) -> Result<Option<NFTState>>
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>
impl<'st, S, BS> RefUnwindSafe for NFT<'st, S, BS>where
S: RefUnwindSafe,
BS: RefUnwindSafe,
impl<'st, S, BS> Send for NFT<'st, S, BS>
impl<'st, S, BS> Sync for NFT<'st, S, BS>
impl<'st, S, BS> Unpin for NFT<'st, S, BS>
impl<'st, S, BS> !UnwindSafe for NFT<'st, S, BS>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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