Struct frc53_nft::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<'st, S, BS> NFT<'st, 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 usefuly 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> RefUnwindSafe for NFT<'st, S, BS>

§

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

§

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

§

impl<'st, S, BS> Unpin for NFT<'st, S, BS>
where BS: Unpin, S: 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.

§

impl<T> References<RawCodec> for T

§

fn references<R, E>(_c: RawCodec, _r: &mut R, _set: &mut E) -> Result<(), Error>
where R: Read, E: Extend<Cid<64>>,

Scrape the references from an impl Read. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.