-
Notifications
You must be signed in to change notification settings - Fork 51
/
src7.sw
64 lines (60 loc) · 1.82 KB
/
src7.sw
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
library;
use std::{bytes::Bytes, string::String};
abi SRC7 {
/// Returns metadata for the corresponding `asset` and `key`.
///
/// # Arguments
///
/// * `asset`: [AssetId] - The asset of which to query the metadata.
/// * `key`: [String] - The key to the specific metadata.
///
/// # Returns
///
/// * [Option<Metadata>] - `Some` metadata that corresponds to the `key` or `None`.
///
/// # Examples
///
/// ```sway
/// use src7::{SRC7, Metadata};
/// use std::string::String;
///
/// fn foo(contract_id: ContractId, asset: AssetId) {
/// let contract_abi = abi(SRC7, contract_id);
/// let key = String::from_ascii_str("image");
/// let data = contract_abi.metadata(asset, key);
/// assert(data.is_some());
/// }
/// ```
#[storage(read)]
fn metadata(asset: AssetId, key: String) -> Option<Metadata>;
}
/// Universal return type for metadata.
pub enum Metadata {
// Used when the stored metadata is a `b256`.
B256: b256,
/// Used when the stored metadata is `Bytes`.
Bytes: Bytes,
/// Used when the stored metadata is a `u64`.
Int: u64,
/// Used when the stored metadata is a `String`.
String: String,
}
impl core::ops::Eq for Metadata {
fn eq(self, other: Self) -> bool {
match (self, other) {
(Metadata::B256(bytes1), Metadata::B256(bytes2)) => {
bytes1 == bytes2
},
(Metadata::Bytes(bytes1), Metadata::Bytes(bytes2)) => {
bytes1 == bytes2
},
(Metadata::Int(int1), Metadata::Int(int2)) => {
int1 == int2
},
(Metadata::String(string1), Metadata::String(string2)) => {
string1 == string2
},
_ => false,
}
}
}