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
#![allow(missing_docs)] use near_sdk::{
borsh::{self, BorshDeserialize, BorshSerialize},
ext_contract,
json_types::Base64VecU8,
};
use serde::{Deserialize, Serialize};
pub const FT_METADATA_SPEC: &str = "ft-1.0.0";
#[derive(BorshDeserialize, BorshSerialize, Deserialize, Serialize, Eq, PartialEq, Clone, Debug)]
pub struct FungibleTokenMetadata {
pub spec: String,
pub name: String,
pub symbol: String,
pub icon: Option<String>,
pub reference: Option<String>,
pub reference_hash: Option<Base64VecU8>,
pub decimals: u8,
}
#[ext_contract(ext_nep148)]
pub trait Nep148 {
fn ft_metadata(&self) -> FungibleTokenMetadata;
}
#[cfg(test)]
mod tests {
use crate::standard::nep148::FungibleTokenMetadata;
use near_sdk::borsh::BorshSerialize;
#[test]
fn borsh_serialization_ignores_cow() {
let m1 = FungibleTokenMetadata {
spec: "spec".into(),
name: "name".into(),
symbol: "symbol".into(),
icon: Some("icon".into()),
reference: Some("reference".into()),
reference_hash: Some(b"reference_hash".to_vec().into()),
decimals: 18,
};
let m2 = FungibleTokenMetadata {
spec: "spec".to_owned(),
name: "name".to_owned(),
symbol: "symbol".to_owned(),
icon: Some("icon".to_owned()),
reference: Some("reference".to_owned()),
reference_hash: Some(b"reference_hash".to_vec().into()),
decimals: 18,
};
assert_eq!(m1, m2);
let m1_serialized = m1.try_to_vec().unwrap();
let m2_serialized = m2.try_to_vec().unwrap();
assert_eq!(m1_serialized, m2_serialized);
}
}