forked from stellar/stellar-xdr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Stellar-contract-spec.x
242 lines (211 loc) · 4.85 KB
/
Stellar-contract-spec.x
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
// Copyright 2022 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
// The contract Contractspec XDR is highly experimental, incomplete, and still being
// iterated on. Breaking changes expected.
% #include "xdr/Stellar-types.h"
% #include "xdr/Stellar-contract.h"
namespace stellar
{
const SC_SPEC_DOC_LIMIT = 1024;
enum SCSpecType
{
SC_SPEC_TYPE_VAL = 0,
// Types with no parameters.
SC_SPEC_TYPE_BOOL = 1,
SC_SPEC_TYPE_VOID = 2,
SC_SPEC_TYPE_ERROR = 3,
SC_SPEC_TYPE_U32 = 4,
SC_SPEC_TYPE_I32 = 5,
SC_SPEC_TYPE_U64 = 6,
SC_SPEC_TYPE_I64 = 7,
SC_SPEC_TYPE_TIMEPOINT = 8,
SC_SPEC_TYPE_DURATION = 9,
SC_SPEC_TYPE_U128 = 10,
SC_SPEC_TYPE_I128 = 11,
SC_SPEC_TYPE_U256 = 12,
SC_SPEC_TYPE_I256 = 13,
SC_SPEC_TYPE_BYTES = 14,
SC_SPEC_TYPE_STRING = 16,
SC_SPEC_TYPE_SYMBOL = 17,
SC_SPEC_TYPE_ADDRESS = 19,
// Types with parameters.
SC_SPEC_TYPE_OPTION = 1000,
SC_SPEC_TYPE_RESULT = 1001,
SC_SPEC_TYPE_VEC = 1002,
SC_SPEC_TYPE_MAP = 1004,
SC_SPEC_TYPE_TUPLE = 1005,
SC_SPEC_TYPE_BYTES_N = 1006,
// User defined types.
SC_SPEC_TYPE_UDT = 2000
};
struct SCSpecTypeOption
{
SCSpecTypeDef valueType;
};
struct SCSpecTypeResult
{
SCSpecTypeDef okType;
SCSpecTypeDef errorType;
};
struct SCSpecTypeVec
{
SCSpecTypeDef elementType;
};
struct SCSpecTypeMap
{
SCSpecTypeDef keyType;
SCSpecTypeDef valueType;
};
struct SCSpecTypeTuple
{
SCSpecTypeDef valueTypes<12>;
};
struct SCSpecTypeBytesN
{
uint32 n;
};
struct SCSpecTypeUDT
{
string name<60>;
};
union SCSpecTypeDef switch (SCSpecType type)
{
case SC_SPEC_TYPE_VAL:
case SC_SPEC_TYPE_BOOL:
case SC_SPEC_TYPE_VOID:
case SC_SPEC_TYPE_ERROR:
case SC_SPEC_TYPE_U32:
case SC_SPEC_TYPE_I32:
case SC_SPEC_TYPE_U64:
case SC_SPEC_TYPE_I64:
case SC_SPEC_TYPE_TIMEPOINT:
case SC_SPEC_TYPE_DURATION:
case SC_SPEC_TYPE_U128:
case SC_SPEC_TYPE_I128:
case SC_SPEC_TYPE_U256:
case SC_SPEC_TYPE_I256:
case SC_SPEC_TYPE_BYTES:
case SC_SPEC_TYPE_STRING:
case SC_SPEC_TYPE_SYMBOL:
case SC_SPEC_TYPE_ADDRESS:
void;
case SC_SPEC_TYPE_OPTION:
SCSpecTypeOption option;
case SC_SPEC_TYPE_RESULT:
SCSpecTypeResult result;
case SC_SPEC_TYPE_VEC:
SCSpecTypeVec vec;
case SC_SPEC_TYPE_MAP:
SCSpecTypeMap map;
case SC_SPEC_TYPE_TUPLE:
SCSpecTypeTuple tuple;
case SC_SPEC_TYPE_BYTES_N:
SCSpecTypeBytesN bytesN;
case SC_SPEC_TYPE_UDT:
SCSpecTypeUDT udt;
};
struct SCSpecUDTStructFieldV0
{
string doc<SC_SPEC_DOC_LIMIT>;
string name<30>;
SCSpecTypeDef type;
};
struct SCSpecUDTStructV0
{
string doc<SC_SPEC_DOC_LIMIT>;
string lib<80>;
string name<60>;
SCSpecUDTStructFieldV0 fields<40>;
};
struct SCSpecUDTUnionCaseVoidV0
{
string doc<SC_SPEC_DOC_LIMIT>;
string name<60>;
};
struct SCSpecUDTUnionCaseTupleV0
{
string doc<SC_SPEC_DOC_LIMIT>;
string name<60>;
SCSpecTypeDef type<12>;
};
enum SCSpecUDTUnionCaseV0Kind
{
SC_SPEC_UDT_UNION_CASE_VOID_V0 = 0,
SC_SPEC_UDT_UNION_CASE_TUPLE_V0 = 1
};
union SCSpecUDTUnionCaseV0 switch (SCSpecUDTUnionCaseV0Kind kind)
{
case SC_SPEC_UDT_UNION_CASE_VOID_V0:
SCSpecUDTUnionCaseVoidV0 voidCase;
case SC_SPEC_UDT_UNION_CASE_TUPLE_V0:
SCSpecUDTUnionCaseTupleV0 tupleCase;
};
struct SCSpecUDTUnionV0
{
string doc<SC_SPEC_DOC_LIMIT>;
string lib<80>;
string name<60>;
SCSpecUDTUnionCaseV0 cases<50>;
};
struct SCSpecUDTEnumCaseV0
{
string doc<SC_SPEC_DOC_LIMIT>;
string name<60>;
uint32 value;
};
struct SCSpecUDTEnumV0
{
string doc<SC_SPEC_DOC_LIMIT>;
string lib<80>;
string name<60>;
SCSpecUDTEnumCaseV0 cases<50>;
};
struct SCSpecUDTErrorEnumCaseV0
{
string doc<SC_SPEC_DOC_LIMIT>;
string name<60>;
uint32 value;
};
struct SCSpecUDTErrorEnumV0
{
string doc<SC_SPEC_DOC_LIMIT>;
string lib<80>;
string name<60>;
SCSpecUDTErrorEnumCaseV0 cases<50>;
};
struct SCSpecFunctionInputV0
{
string doc<SC_SPEC_DOC_LIMIT>;
string name<30>;
SCSpecTypeDef type;
};
struct SCSpecFunctionV0
{
string doc<SC_SPEC_DOC_LIMIT>;
SCSymbol name;
SCSpecFunctionInputV0 inputs<10>;
SCSpecTypeDef outputs<1>;
};
enum SCSpecEntryKind
{
SC_SPEC_ENTRY_FUNCTION_V0 = 0,
SC_SPEC_ENTRY_UDT_STRUCT_V0 = 1,
SC_SPEC_ENTRY_UDT_UNION_V0 = 2,
SC_SPEC_ENTRY_UDT_ENUM_V0 = 3,
SC_SPEC_ENTRY_UDT_ERROR_ENUM_V0 = 4
};
union SCSpecEntry switch (SCSpecEntryKind kind)
{
case SC_SPEC_ENTRY_FUNCTION_V0:
SCSpecFunctionV0 functionV0;
case SC_SPEC_ENTRY_UDT_STRUCT_V0:
SCSpecUDTStructV0 udtStructV0;
case SC_SPEC_ENTRY_UDT_UNION_V0:
SCSpecUDTUnionV0 udtUnionV0;
case SC_SPEC_ENTRY_UDT_ENUM_V0:
SCSpecUDTEnumV0 udtEnumV0;
case SC_SPEC_ENTRY_UDT_ERROR_ENUM_V0:
SCSpecUDTErrorEnumV0 udtErrorEnumV0;
};
}