-
Notifications
You must be signed in to change notification settings - Fork 241
/
mod.rs
88 lines (83 loc) · 3.17 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
mod enumeration_impl;
use crate::non_fungible_token::token::Token;
use near_sdk::json_types::U128;
use near_sdk::{ext_contract, AccountId};
/// Offers methods helpful in determining account ownership of NFTs and provides a way to page through NFTs per owner, determine total supply, etc.
///
/// # Examples
///
/// ```
/// use std::collections::HashMap;
/// use near_sdk::{PanicOnDefault, AccountId, PromiseOrValue, near, Promise};
/// use near_contract_standards::non_fungible_token::{NonFungibleToken, NonFungibleTokenEnumeration, TokenId, Token};
/// use near_sdk::json_types::U128;
///
/// #[near(contract_state)]
/// #[derive(PanicOnDefault)]
/// pub struct Contract {
/// tokens: NonFungibleToken,
///}
///
/// #[near]
/// impl NonFungibleTokenEnumeration for Contract {
/// fn nft_total_supply(&self) -> U128 {
/// self.tokens.nft_total_supply()
/// }
///
/// fn nft_tokens(&self, from_index: Option<U128>, limit: Option<u64>) -> Vec<Token> {
/// self.tokens.nft_tokens(from_index, limit)
/// }
///
/// fn nft_supply_for_owner(&self, account_id: AccountId) -> U128 {
/// self.tokens.nft_supply_for_owner(account_id)
/// }
///
/// fn nft_tokens_for_owner(&self, account_id: AccountId, from_index: Option<U128>, limit: Option<u64>) -> Vec<Token> {
/// self.tokens.nft_tokens_for_owner(account_id, from_index, limit)
/// }
/// }
/// ```
///
#[ext_contract(ext_nft_enumeration)]
pub trait NonFungibleTokenEnumeration {
/// Returns the total supply of non-fungible tokens as a string representing an
/// unsigned 128-bit integer to avoid JSON number limit of 2^53.
fn nft_total_supply(&self) -> U128;
/// Get a list of all tokens
///
/// Arguments:
/// * `from_index`: a string representing an unsigned 128-bit integer,
/// representing the starting index of tokens to return
/// * `limit`: the maximum number of tokens to return
///
/// Returns an array of Token objects, as described in Core standard
fn nft_tokens(
&self,
from_index: Option<U128>, // default: "0"
limit: Option<u64>, // default: unlimited (could fail due to gas limit)
) -> Vec<Token>;
/// Get number of tokens owned by a given account
///
/// Arguments:
/// * `account_id`: a valid NEAR account
///
/// Returns the number of non-fungible tokens owned by given `account_id` as
/// a string representing the value as an unsigned 128-bit integer to avoid JSON
/// number limit of 2^53.
fn nft_supply_for_owner(&self, account_id: AccountId) -> U128;
/// Get list of all tokens owned by a given account
///
/// Arguments:
/// * `account_id`: a valid NEAR account
/// * `from_index`: a string representing an unsigned 128-bit integer,
/// representing the starting index of tokens to return
/// * `limit`: the maximum number of tokens to return
///
/// Returns a paginated list of all tokens owned by this account
fn nft_tokens_for_owner(
&self,
account_id: AccountId,
from_index: Option<U128>, // default: "0"
limit: Option<u64>, // default: unlimited (could fail due to gas limit)
) -> Vec<Token>;
}