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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
mod error;
pub use error::*;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet};
pub use struct_tag::*;
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct IDLPackage {
pub name: String,
pub modules: BTreeMap<ModuleIdData, IDLModule>,
pub aliases: BTreeMap<String, AccountAddressData>,
pub dependencies: BTreeMap<ModuleIdData, IDLModule>,
pub errors: IDLErrorMapping,
pub structs: Vec<IDLStruct>,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
pub struct IDLStructType {
pub name: StructTagData,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub ty_args: Vec<IDLType>,
}
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct IDLModule {
pub module_id: ModuleIdData,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub doc: Option<String>,
pub functions: Vec<IDLScriptFunction>,
pub structs: Vec<IDLStruct>,
pub errors: BTreeMap<u64, IDLError>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum IDLType {
Bool,
U8,
U64,
U128,
Address,
Signer,
TypeParam(u16),
Tuple(Vec<IDLType>),
Vector(Box<IDLType>),
Struct(IDLStructType),
}
#[repr(u8)]
#[derive(
Debug, Clone, Eq, Copy, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize, JsonSchema,
)]
#[serde(rename_all = "snake_case")]
pub enum IDLAbility {
Copy = 0x1,
Drop = 0x2,
Store = 0x4,
Key = 0x8,
}
fn is_false(b: impl std::borrow::Borrow<bool>) -> bool {
!b.borrow()
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema)]
pub struct IDLTypeParam {
pub name: String,
#[serde(default, skip_serializing_if = "is_false")]
pub is_phantom: bool,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema)]
pub struct IDLStruct {
pub name: StructTagData,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub doc: Option<String>,
pub fields: Vec<IDLField>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub type_params: Vec<IDLTypeParam>,
pub abilities: BTreeSet<IDLAbility>,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema)]
pub struct IDLField {
pub name: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub doc: Option<String>,
pub ty: IDLType,
}
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct IDLArgument {
pub name: String,
pub ty: IDLType,
}
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct IDLScriptFunction {
pub name: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub doc: Option<String>,
pub ty_args: Vec<String>,
pub args: Vec<IDLArgument>,
}