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
use parity_scale_codec::{Decode, Encode};
use scale_info::prelude::vec::Vec;
#[cfg(not(feature = "std"))]
type String = Vec<u8>;
#[derive(Encode, Decode, Copy, Clone, PartialEq, Debug, Eq, scale_info::TypeInfo)]
pub enum CodeType {
Shards,
Wire,
}
#[derive(Encode, Decode, Copy, Clone, PartialEq, Debug, Eq, scale_info::TypeInfo)]
pub enum VariableType {
None,
Any,
Enum(u32, u32),
Bool,
Int,
Int2,
Int3,
Int4,
Int8,
Int16,
Float,
Float2,
Float3,
Float4,
Color,
Bytes,
String,
Image,
Seq,
Table,
Object(u32, u32),
Audio,
}
#[derive(Encode, Decode, Clone, PartialEq, Debug, Eq, scale_info::TypeInfo)]
pub struct CodeInfo {
pub kind: CodeType,
pub requires: Vec<(String, VariableType)>,
pub exposes: Vec<(String, VariableType)>,
pub inputs: Vec<VariableType>,
pub output: VariableType,
}
#[derive(Encode, Decode, Clone, PartialEq, Debug, Eq, scale_info::TypeInfo)]
pub enum TraitInfo {
SingleType(VariableType),
MultipleTypes(Vec<VariableType>),
Code(CodeInfo),
}
pub type Traits = Vec<(String, TraitInfo)>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn encode_decode_simple_1() {
let mut trait1 = vec![("int1".to_string(), TraitInfo::SingleType(VariableType::Int))];
trait1.dedup_by(|a, b| a.0.to_lowercase() == b.0.to_lowercase());
trait1.sort_by(|a, b| a.0.to_lowercase().cmp(&b.0.to_lowercase()));
let e_trait1 = trait1.encode();
let d_trait1 = Traits::decode(&mut e_trait1.as_slice()).unwrap();
assert!(trait1 == d_trait1);
}
}