-
Notifications
You must be signed in to change notification settings - Fork 23
/
qxStruct.h
264 lines (228 loc) · 6.34 KB
/
qxStruct.h
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#pragma once
struct IssueAsset_input
{
uint64_t name;
int64_t numberOfUnits;
uint64_t unitOfMeasurement;
char numberOfDecimalPlaces;
};
struct AssetAskOrders_input
{
uint8_t issuer[32];
uint64_t assetName;
uint64_t offset;
};
struct AssetAskOrders_output
{
struct Order
{
uint8_t entity[32];
long long price;
long long numberOfShares;
};
Order orders[256];
};
struct AssetBidOrders_input
{
uint8_t issuer[32];
uint64_t assetName;
uint64_t offset;
};
struct AssetBidOrders_output
{
struct Order
{
uint8_t entity[32];
long long price;
long long numberOfShares;
};
Order orders[256];
};
struct EntityAskOrders_input
{
uint8_t entity[32];
uint64_t offset;
};
struct EntityAskOrders_output
{
struct Order
{
uint8_t issuer[32];
uint64_t assetName;
long long price;
long long numberOfShares;
};
Order orders[256];
};
struct EntityBidOrders_input
{
uint8_t entity[32];
uint64_t offset;
};
struct EntityBidOrders_output
{
struct Order
{
uint8_t issuer[32];
uint64_t assetName;
long long price;
long long numberOfShares;
};
Order orders[256];
};
struct qxGetAssetOrder_input{
uint8_t issuer[32];
uint64_t assetName;
uint64_t offset;
};
static_assert(sizeof(qxGetAssetOrder_input) == sizeof(AssetAskOrders_input), "wrong implementation");
static_assert(sizeof(qxGetAssetOrder_input) == sizeof(AssetBidOrders_input), "wrong implementation");
struct qxGetAssetOrder_output{
struct Order
{
uint8_t entity[32];
long long price;
long long numberOfShares;
};
Order orders[256];
};
static_assert(sizeof(qxGetAssetOrder_output) == sizeof(AssetAskOrders_output), "wrong implementation");
static_assert(sizeof(qxGetAssetOrder_output) == sizeof(AssetBidOrders_output), "wrong implementation");
struct qxGetEntityOrder_input{
uint8_t entity[32];
uint64_t offset;
};
static_assert(sizeof(qxGetEntityOrder_input) == sizeof(EntityAskOrders_input), "wrong implementation");
static_assert(sizeof(qxGetEntityOrder_input) == sizeof(EntityBidOrders_input), "wrong implementation");
struct qxGetEntityOrder_output{
struct Order
{
uint8_t issuer[32];
uint64_t assetName;
long long price;
long long numberOfShares;
};
Order orders[256];
};
static_assert(sizeof(qxGetEntityOrder_output) == sizeof(EntityAskOrders_output), "wrong implementation");
static_assert(sizeof(qxGetEntityOrder_output) == sizeof(EntityBidOrders_output), "wrong implementation");
struct TransferAssetOwnershipAndPossession_input
{
uint8_t issuer[32];
uint8_t newOwnerAndPossessor[32];
unsigned long long assetName;
long long numberOfUnits;
};
struct AddToAskOrder_input
{
uint8_t issuer[32];
uint64_t assetName;
long long price;
long long numberOfShares;
};
struct AddToAskOrder_output
{
long long addedNumberOfShares;
};
struct AddToBidOrder_input
{
uint8_t issuer[32];
uint64_t assetName;
long long price;
long long numberOfShares;
};
struct AddToBidOrder_output
{
long long addedNumberOfShares;
};
struct RemoveFromAskOrder_input
{
uint8_t issuer[32];
uint64_t assetName;
long long price;
long long numberOfShares;
};
struct RemoveFromAskOrder_output
{
long long removedNumberOfShares;
};
struct RemoveFromBidOrder_input
{
uint8_t issuer[32];
uint64_t assetName;
long long price;
long long numberOfShares;
};
struct RemoveFromBidOrder_output
{
long long removedNumberOfShares;
};
struct qxOrderAction_input{
uint8_t issuer[32];
uint64_t assetName;
long long price;
long long numberOfShares;
};
static_assert(sizeof(qxOrderAction_input) == sizeof(RemoveFromBidOrder_input), "wrong implementation");
static_assert(sizeof(qxOrderAction_input) == sizeof(RemoveFromAskOrder_input), "wrong implementation");
static_assert(sizeof(qxOrderAction_input) == sizeof(AddToBidOrder_input), "wrong implementation");
static_assert(sizeof(qxOrderAction_input) == sizeof(AddToAskOrder_input), "wrong implementation");
struct QX : ContractBase
{
uint64_t _earnedAmount;
uint64_t _distributedAmount;
uint64_t _burnedAmount;
uint32_t _assetIssuanceFee; // Amount of qus
uint32_t _transferFee; // Amount of qus
uint32_t _tradeFee; // Number of billionths
struct _AssetOrder
{
uint8_t entity[32];
int64_t numberOfShares;
};
collection<_AssetOrder, 2097152 * X_MULTIPLIER> _assetOrders;
static_assert(sizeof(_assetOrders) == 302514192, "The size of the _assetOrders must be the same with core.");
struct _EntityOrder
{
uint8_t issuer[32];
uint64_t assetName;
int64_t numberOfShares;
};
collection<_EntityOrder, 2097152 * X_MULTIPLIER> _entityOrders;
static_assert(sizeof(_entityOrders) == 319291408, "The size of the _entityOrders must be the same with core.");
// Belows are used for replicate exactly QX struct in core.
// TODO: change to "locals" variables and remove from state? -> every func/proc can define struct of "locals" that is passed as an argument (stored on stack structure per processor)
int64_t _elementIndex, _elementIndex2;
uint8_t _issuerAndAssetName[32];
_AssetOrder _assetOrder;
_EntityOrder _entityOrder;
int64_t _price;
int64_t _fee;
AssetAskOrders_output::Order _assetAskOrder;
AssetBidOrders_output::Order _assetBidOrder;
EntityAskOrders_output::Order _entityAskOrder;
EntityBidOrders_output::Order _entityBidOrder;
struct _TradeMessage
{
uint32_t _contractIndex;
uint32_t _type;
uint8_t issuer[32];
uint64_t assetName;
int64_t price;
int64_t numberOfShares;
char _terminator;
} _tradeMessage;
struct _NumberOfReservedShares_input
{
uint8_t issuer[32];
uint64_t assetName;
} _numberOfReservedShares_input;
struct _NumberOfReservedShares_output
{
int64_t numberOfShares;
} _numberOfReservedShares_output;
};
// Match size between cli and core struct. may be changed in the future
static constexpr uint64_t QX_STATE_SIZE = 621806120ULL;
static_assert(sizeof(QX) == QX_STATE_SIZE, "Size of QX must match with core's QX");
//ContractDescription qxContractDescriptions = {"QX", 66, 10000, sizeof(QX)};