forked from Cardinal-Cryptography/PSP34
-
Notifications
You must be signed in to change notification settings - Fork 0
/
traits.rs
124 lines (111 loc) · 3.92 KB
/
traits.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use ink::{
prelude::vec::Vec,
primitives::AccountId,
};
use crate::data::Id;
use crate::errors::PSP34Error;
#[ink::trait_definition]
pub trait PSP34 {
/// Returns the collection `Id` of the NFT token.
///
/// This can represents the relationship between tokens/contracts/pallets.
#[ink(message)]
fn collection_id(&self) -> Id;
/// Returns the current total supply of the NFT.
#[ink(message)]
fn total_supply(&self) -> u128;
/// Returns the account balance for the specified `owner`.
///
/// This represents the amount of unique tokens the owner has.
#[ink(message)]
fn balance_of(&self, owner: AccountId) -> u32;
/// Returns `true` if the operator is approved by the owner to withdraw `id` token.
///
/// If `id` is `None`, returns `true` if the operator is approved to withdraw all owner's tokens.
#[ink(message)]
fn allowance(&self, owner: AccountId, operator: AccountId, id: Option<Id>) -> bool;
/// Transfer approved or owned token from caller.
///
/// On success a `Transfer` event is emitted.
///
/// # Errors
///
/// Returns `TokenNotExists` error if `id` does not exist.
///
/// Returns `NotApproved` error if `from` doesn't have allowance for transferring.
///
/// Returns `SafeTransferCheckFailed` error if `to` doesn't accept transfer.
#[ink(message)]
fn transfer(&mut self, to: AccountId, id: Id, data: Vec<u8>) -> Result<(), PSP34Error>;
/// Approves `operator` to withdraw the `id` token from the caller's account.
/// If `id` is `None` approves or disapproves the operator for all tokens of the caller.
///
/// An `Approval` event is emitted.
///
/// # Errors
///
/// Returns `SelfApprove` error if it is self approve.
///
/// Returns `NotApproved` error if caller is not owner of `id`.
#[ink(message)]
fn approve(
&mut self,
operator: AccountId,
id: Option<Id>,
approved: bool,
) -> Result<(), PSP34Error>;
/// Returns the owner of the token if any.
#[ink(message)]
fn owner_of(&self, id: Id) -> Option<AccountId>;
}
#[ink::trait_definition]
pub trait PSP34Metadata {
/// Returns the attribute of `id` for the given `key`.
///
/// If `id` is a collection id of the token, it returns attributes for collection.
#[ink(message)]
fn get_attribute(&self, id: Id, key: Vec<u8>) -> Option<Vec<u8>>;
}
#[ink::trait_definition]
pub trait PSP34Mintable {
/// Mints a token to the sender's account.
///
/// # Events
///
/// On success a `Transfer` event is emitted with `None` sender.
///
/// # Errors
///
/// Reverts with `TokenExists`` if token id is already in the library.
///
/// Reverts with `Custom (max supply exceeded)` if the incremented by 1 total
/// supply exceeds maximal value of `u128` type.
#[ink(message)]
fn mint(&mut self, id: Id) -> Result<(), PSP34Error>;
}
#[ink::trait_definition]
pub trait PSP34Burnable {
/// Burns token from the selected account.
///
/// # Events
///
/// On success a `Transfer` event is emitted with `None` recipient.
///
/// # Errors
///
/// Reverts with `TokenExists` if token id is already in the library.
#[ink(message)]
fn burn(&mut self, account: AccountId, id: Id) -> Result<(), PSP34Error>;
}
#[cfg(feature = "enumerable")]
#[ink::trait_definition]
pub trait PSP34Enumerable {
/// Returns a token `Id` owned by `owner` at a given `index` of its token list.
/// Use along with `balance_of` to enumerate all of ``owner``'s tokens.
#[ink(message)]
fn owners_token_by_index(&self, owner: AccountId, index: u128) -> Result<Id, PSP34Error>;
/// Returns a token `Id` at a given `index` of all the tokens stored by the contract.
/// Use along with `total_supply` to enumerate all tokens.
#[ink(message)]
fn token_by_index(&self, index: u128) -> Result<Id, PSP34Error>;
}