NFTState

Struct NFTState 

Source
pub struct NFTState {
    pub token_data: Cid,
    pub owner_data: Cid,
    pub next_token: TokenID,
    pub total_supply: u64,
}
Expand description

NFT state IPLD structure.

Fields§

§token_data: Cid

Amt<TokenId, TokenData> encodes information per token - ownership, operators, metadata etc.

§owner_data: Cid

Hamt<ActorID, OwnerData> index for faster lookup of data often queried by owner.

§next_token: TokenID

The next available token id for minting.

§total_supply: u64

The number of minted tokens less the number of burned tokens.

Implementations§

Source§

impl NFTState

Source

pub fn new<BS: Blockstore>(store: &BS) -> Result<Self, StateError>

Create a new NFT state-tree, without committing it (the root Cid) to a blockstore.

Source

pub fn load<BS: Blockstore>(store: &BS, root: &Cid) -> Result<Self, StateError>

Source

pub fn save<BS: Blockstore>(&self, store: &BS) -> Result<Cid, StateError>

Source

pub fn get_token_data_amt<'bs, BS: Blockstore>( &self, store: &'bs BS, ) -> Result<Amt<TokenData, &'bs BS>, StateError>

Source

pub fn get_owner_data_hamt<'bs, BS: Blockstore>( &self, store: &'bs BS, ) -> Result<Hamt<&'bs BS, OwnerData, BytesKey>, StateError>

Source

pub fn get_token_amt_for_cursor<'bs, BS: Blockstore>( &self, store: &'bs BS, cursor: &Option<Cursor>, ) -> Result<Amt<TokenData, &'bs BS>, StateError>

Retrieves the token data amt, asserting that the cursor is valid for the current state. If the root cid has changed since the cursor was created, the data has mutated and the cursor is invalid.

Source§

impl NFTState

Source

pub fn mint_tokens<BS: Blockstore>( &mut self, bs: &BS, initial_owner: ActorID, metadatas: Vec<String>, ) -> Result<MintIntermediate, StateError>

Mint a new token to the specified address.

Source

pub fn get_balance<BS: Blockstore>( &self, bs: &BS, owner: ActorID, ) -> Result<u64, StateError>

Get the number of tokens owned by a particular address.

Source

pub fn approve_for_tokens<F, BS: Blockstore>( &mut self, bs: &BS, operator: ActorID, token_ids: &[TokenID], approve_predicate: F, ) -> Result<(), StateError>

Approves an operator to transfer a set of specified tokens.

The caller should own the tokens or an account-level operator on the owner of the tokens.

Source

pub fn revoke_for_tokens<F, BS: Blockstore>( &mut self, bs: &BS, operator: ActorID, token_ids: &[TokenID], revoke_predicate: F, ) -> Result<(), StateError>

Revokes an operator’s permission to transfer the specified tokens.

The caller should own the tokens or be an account-level operator on the owner of the tokens.

Source

pub fn approve_for_owner<BS: Blockstore>( &mut self, bs: &BS, owner: ActorID, operator: ActorID, ) -> Result<(), StateError>

Approves an operator to transfer tokens on behalf of the owner.

The operator becomes authorized at account level, meaning all tokens owned by the account can be transferred, approved or burned by the operator, including future tokens owned by the account.

The caller should be the owning account.

Source

pub fn revoke_for_all<BS: Blockstore>( &mut self, bs: &BS, owner: ActorID, operator: ActorID, ) -> Result<(), StateError>

Revokes an operator’s authorization to transfer tokens on behalf of the owner account.

The caller should be the owner of the account.

Source

pub fn burn_tokens<F, BS: Blockstore>( &mut self, bs: &BS, owner: ActorID, token_ids: &[TokenID], burn_predicate: F, ) -> Result<u64, StateError>

Burns a set of tokens, removing them from circulation and deleting associated metadata.

If any of the token_ids cannot be burned (e.g. non-existent, already burned), the entire transaction should fail atomically.

The tokens must all be owned by the same owner.

Returns the new balance of the owner if all tokens were burned successfully.

Source

pub fn transfer<F, BS: Blockstore>( &mut self, bs: &BS, token_ids: &[TokenID], owner: ActorID, receiver: ActorID, transfer_predicate: &F, ) -> Result<TransferIntermediate, StateError>

Transfers a batch of tokens between the owner and receiver.

The predicate is checked for each token to be transferred, and the entire transfer is aborted if the predicate fails. It is the caller’s responsibility to check that the actor using this method is permitted to do so.

Source

pub fn is_account_operator<BS: Blockstore>( owner_map: &Hamt<&BS, OwnerData>, owner: ActorID, operator: ActorID, ) -> Result<bool, StateError>

Checks for account-level approval between owner and operator.

Source

pub fn assert_can_approve_token( token_data: &TokenData, actor: ActorID, token_id: TokenID, ) -> Result<(), StateError>

Asserts that the actor either owns the token or is an account level operator on the owner of the token.

Source

pub fn assert_token_level_approval( token_data: &TokenData, token_id: TokenID, operator: ActorID, ) -> Result<(), StateError>

Asserts that the given operator is permitted authorised for the specified token.

Source

pub fn assert_owns_token( token_data: &TokenData, token_id: TokenID, actor: ActorID, ) -> Result<(), StateError>

Asserts that a given account owns the specified token.

Source

pub fn mint_return<BS: Blockstore>( &self, bs: &BS, intermediate: MintIntermediate, ) -> Result<MintReturn, StateError>

Converts a MintIntermediate to a MintReturn.

This function should be called on a freshly loaded or known-up-to-date state.

Source

pub fn transfer_return<BS: Blockstore>( &self, bs: &BS, intermediate: TransferIntermediate, ) -> Result<TransferReturn, StateError>

Converts a TransferIntermediate to a TransferReturn.

This function should be called on a freshly loaded or known-up-to-date state.

Source

pub fn get_metadata<BS: Blockstore>( &self, bs: &BS, token_id: TokenID, ) -> Result<String, StateError>

Get the metadata for a token.

Source

pub fn get_owner<BS: Blockstore>( &self, bs: &BS, token_id: TokenID, ) -> Result<ActorID, StateError>

Get the owner of a token.

Source

pub fn list_tokens<BS: Blockstore>( &self, bs: &BS, cursor: Option<Cursor>, limit: u64, ) -> Result<(TokenSet, Option<Cursor>), StateError>

List all the minted tokens.

Source

pub fn list_owned_tokens<BS: Blockstore>( &self, bs: &BS, owner: ActorID, cursor: Option<Cursor>, limit: u64, ) -> Result<(TokenSet, Option<Cursor>), StateError>

List the tokens owned by an actor. In the reference implementation this is may be a prohibitievly expensive operation as it involves iterating over the entire token set. Returns a bitfield of the tokens owned by the actor and a cursor to the next page of data.

Source

pub fn list_token_operators<BS: Blockstore>( &self, bs: &BS, token_id: TokenID, cursor: Option<Cursor>, limit: u64, ) -> Result<(ActorIDSet, Option<Cursor>), StateError>

List all the token operators for a given token_id.

Source

pub fn list_operator_tokens<BS: Blockstore>( &self, bs: &BS, operator: ActorID, cursor: Option<Cursor>, limit: u64, ) -> Result<(TokenSet, Option<Cursor>), StateError>

Enumerates tokens for which an account is an operator.

Source

pub fn list_account_operators<BS: Blockstore>( &self, bs: &BS, actor_id: ActorID, cursor: Option<Cursor>, limit: u64, ) -> Result<(ActorIDSet, Option<Cursor>), StateError>

List all the token operators for a given account.

Source§

impl NFTState

Source

pub fn check_invariants<BS: Blockstore>( &self, bs: &BS, ) -> (StateSummary, Vec<StateInvariantError>)

Checks that the state is internally consistent and obeys the specified invariants

Checks that balances in the TokenArray and OwnerMap are consistent. Checks that the total supply is consistent with the number of tokens in the TokenArray. Checks that the OwnerHamt is clear of semantically empty entries. Checks that all bytes keys are valid actor ids.

Returns a state summary that can be used to check application specific invariants and a list of errors that were found.

Trait Implementations§

Source§

impl Clone for NFTState

Source§

fn clone(&self) -> NFTState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NFTState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for NFTState

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for NFTState

Source§

fn eq(&self, other: &NFTState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for NFTState

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for NFTState

Source§

impl StructuralPartialEq for NFTState

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,