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: CidAmt<TokenId, TokenData> encodes information per token - ownership, operators, metadata
etc.
owner_data: CidHamt<ActorID, OwnerData> index for faster lookup of data often queried by owner.
next_token: TokenIDThe next available token id for minting.
total_supply: u64The number of minted tokens less the number of burned tokens.
Implementations§
Source§impl NFTState
impl NFTState
Sourcepub fn new<BS: Blockstore>(store: &BS) -> Result<Self, StateError>
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.
pub fn load<BS: Blockstore>(store: &BS, root: &Cid) -> Result<Self, StateError>
pub fn save<BS: Blockstore>(&self, store: &BS) -> Result<Cid, StateError>
pub fn get_token_data_amt<'bs, BS: Blockstore>( &self, store: &'bs BS, ) -> Result<Amt<TokenData, &'bs BS>, StateError>
pub fn get_owner_data_hamt<'bs, BS: Blockstore>( &self, store: &'bs BS, ) -> Result<Hamt<&'bs BS, OwnerData, BytesKey>, StateError>
Sourcepub fn get_token_amt_for_cursor<'bs, BS: Blockstore>(
&self,
store: &'bs BS,
cursor: &Option<Cursor>,
) -> Result<Amt<TokenData, &'bs BS>, StateError>
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
impl NFTState
Sourcepub fn mint_tokens<BS: Blockstore>(
&mut self,
bs: &BS,
initial_owner: ActorID,
metadatas: Vec<String>,
) -> Result<MintIntermediate, StateError>
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.
Sourcepub fn get_balance<BS: Blockstore>(
&self,
bs: &BS,
owner: ActorID,
) -> Result<u64, StateError>
pub fn get_balance<BS: Blockstore>( &self, bs: &BS, owner: ActorID, ) -> Result<u64, StateError>
Get the number of tokens owned by a particular address.
Sourcepub fn approve_for_tokens<F, BS: Blockstore>(
&mut self,
bs: &BS,
operator: ActorID,
token_ids: &[TokenID],
approve_predicate: F,
) -> Result<(), StateError>
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.
Sourcepub fn revoke_for_tokens<F, BS: Blockstore>(
&mut self,
bs: &BS,
operator: ActorID,
token_ids: &[TokenID],
revoke_predicate: F,
) -> Result<(), StateError>
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.
Sourcepub fn approve_for_owner<BS: Blockstore>(
&mut self,
bs: &BS,
owner: ActorID,
operator: ActorID,
) -> Result<(), StateError>
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.
Sourcepub fn revoke_for_all<BS: Blockstore>(
&mut self,
bs: &BS,
owner: ActorID,
operator: ActorID,
) -> Result<(), StateError>
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.
Sourcepub fn burn_tokens<F, BS: Blockstore>(
&mut self,
bs: &BS,
owner: ActorID,
token_ids: &[TokenID],
burn_predicate: F,
) -> Result<u64, StateError>
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.
Sourcepub fn transfer<F, BS: Blockstore>(
&mut self,
bs: &BS,
token_ids: &[TokenID],
owner: ActorID,
receiver: ActorID,
transfer_predicate: &F,
) -> Result<TransferIntermediate, StateError>
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.
Sourcepub fn is_account_operator<BS: Blockstore>(
owner_map: &Hamt<&BS, OwnerData>,
owner: ActorID,
operator: ActorID,
) -> Result<bool, StateError>
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.
Sourcepub fn assert_can_approve_token(
token_data: &TokenData,
actor: ActorID,
token_id: TokenID,
) -> Result<(), StateError>
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.
Sourcepub fn assert_token_level_approval(
token_data: &TokenData,
token_id: TokenID,
operator: ActorID,
) -> Result<(), StateError>
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.
Sourcepub fn assert_owns_token(
token_data: &TokenData,
token_id: TokenID,
actor: ActorID,
) -> Result<(), StateError>
pub fn assert_owns_token( token_data: &TokenData, token_id: TokenID, actor: ActorID, ) -> Result<(), StateError>
Asserts that a given account owns the specified token.
Sourcepub fn mint_return<BS: Blockstore>(
&self,
bs: &BS,
intermediate: MintIntermediate,
) -> Result<MintReturn, StateError>
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.
Sourcepub fn transfer_return<BS: Blockstore>(
&self,
bs: &BS,
intermediate: TransferIntermediate,
) -> Result<TransferReturn, StateError>
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.
Sourcepub fn get_metadata<BS: Blockstore>(
&self,
bs: &BS,
token_id: TokenID,
) -> Result<String, StateError>
pub fn get_metadata<BS: Blockstore>( &self, bs: &BS, token_id: TokenID, ) -> Result<String, StateError>
Get the metadata for a token.
Sourcepub fn get_owner<BS: Blockstore>(
&self,
bs: &BS,
token_id: TokenID,
) -> Result<ActorID, StateError>
pub fn get_owner<BS: Blockstore>( &self, bs: &BS, token_id: TokenID, ) -> Result<ActorID, StateError>
Get the owner of a token.
Sourcepub fn list_tokens<BS: Blockstore>(
&self,
bs: &BS,
cursor: Option<Cursor>,
limit: u64,
) -> Result<(TokenSet, Option<Cursor>), StateError>
pub fn list_tokens<BS: Blockstore>( &self, bs: &BS, cursor: Option<Cursor>, limit: u64, ) -> Result<(TokenSet, Option<Cursor>), StateError>
List all the minted tokens.
Sourcepub fn list_owned_tokens<BS: Blockstore>(
&self,
bs: &BS,
owner: ActorID,
cursor: Option<Cursor>,
limit: u64,
) -> Result<(TokenSet, Option<Cursor>), StateError>
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.
Sourcepub fn list_token_operators<BS: Blockstore>(
&self,
bs: &BS,
token_id: TokenID,
cursor: Option<Cursor>,
limit: u64,
) -> Result<(ActorIDSet, Option<Cursor>), StateError>
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.
Sourcepub fn list_operator_tokens<BS: Blockstore>(
&self,
bs: &BS,
operator: ActorID,
cursor: Option<Cursor>,
limit: u64,
) -> Result<(TokenSet, Option<Cursor>), StateError>
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.
Sourcepub fn list_account_operators<BS: Blockstore>(
&self,
bs: &BS,
actor_id: ActorID,
cursor: Option<Cursor>,
limit: u64,
) -> Result<(ActorIDSet, Option<Cursor>), StateError>
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
impl NFTState
Sourcepub fn check_invariants<BS: Blockstore>(
&self,
bs: &BS,
) -> (StateSummary, Vec<StateInvariantError>)
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<'de> Deserialize<'de> for NFTState
impl<'de> Deserialize<'de> for NFTState
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for NFTState
impl StructuralPartialEq for NFTState
Auto Trait Implementations§
impl Freeze for NFTState
impl RefUnwindSafe for NFTState
impl Send for NFTState
impl Sync for NFTState
impl Unpin for NFTState
impl UnwindSafe for NFTState
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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