forked from qubic/qubic-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs.h
499 lines (439 loc) · 10.5 KB
/
structs.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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
#pragma once
#include "defines.h"
#include "utils.h"
enum COMMAND
{
SHOW_KEYS = 0,
GET_CURRENT_TICK = 1,
GET_BALANCE = 2,
GET_ASSET = 3,
SEND_COIN = 4,
SEND_CUSTOM_TX = 5,
SEND_SPECIAL_COMMAND = 6,
SEND_RAW_PACKET = 7,
PUBLISH_PROPOSAL = 8,
VOTE_PROPOSAL = 9,
GET_QUORUM_TICK = 10,
GET_TICK_DATA=11,
READ_TICK_DATA=12,
CHECK_TX_ON_TICK=13,
CHECK_TX_ON_FILE=14,
GET_COMP_LIST=15,
QX_ISSUE_ASSET = 16,
QX_TRANSFER_ASSET = 17,
GET_NODE_IP_LIST=18,
GET_LOG_FROM_NODE = 19,
DUMP_SPECTRUM_FILE = 20,
DUMP_UNIVERSE_FILE = 21,
PRINT_QX_FEE =22,
MAKE_IPO_BID=23,
GET_IPO_STATUS=24,
QUOTTERY_ISSUE_BET=25,
QUOTTERY_JOIN_BET=26,
QUOTTERY_GET_BET_INFO=27,
QUOTTERY_GET_BET_DETAIL=28,
QUOTTERY_GET_ACTIVE_BET=29,
QUOTTERY_GET_ACTIVE_BET_BY_CREATOR=30,
QUOTTERY_GET_BET_FEE=31,
QUOTTERY_PUBLISH_RESULT=32,
QUOTTERY_CANCEL_BET=33,
TOOGLE_MAIN_AUX = 34,
SET_SOLUTION_THRESHOLD=35,
REFRESH_PEER_LIST=36,
FORCE_NEXT_TICK=37,
REISSUE_VOTE=38,
QUTIL_SEND_TO_MANY_V1=39,
TOTAL_COMMAND = 40,
SYNC_TIME = 41,
GET_SYSTEM_INFO = 42,
QX_ORDER=43,
QX_GET_ORDER=44,
};
struct RequestResponseHeader {
private:
uint8_t _size[3];
uint8_t _type;
unsigned int _dejavu;
public:
inline unsigned int size() {
if (((*((unsigned int*)_size)) & 0xFFFFFF)==0) return INT32_MAX; // size is never zero, zero means broken packets
return (*((unsigned int*)_size)) & 0xFFFFFF;
}
inline void setSize(unsigned int size) {
_size[0] = (uint8_t)size;
_size[1] = (uint8_t)(size >> 8);
_size[2] = (uint8_t)(size >> 16);
}
inline bool isDejavuZero()
{
return !_dejavu;
}
inline void zeroDejavu()
{
_dejavu = 0;
}
inline void randomizeDejavu()
{
rand32(&_dejavu);
if (!_dejavu)
{
_dejavu = 1;
}
}
inline uint8_t type()
{
return _type;
}
inline void setType(const uint8_t type)
{
_type = type;
}
};
typedef struct
{
unsigned char publicKey[32];
} RequestedEntity;
struct Tick
{
unsigned short computorIndex;
unsigned short epoch;
unsigned int tick;
unsigned short millisecond;
unsigned char second;
unsigned char minute;
unsigned char hour;
unsigned char day;
unsigned char month;
unsigned char year;
unsigned long long prevResourceTestingDigest;
unsigned long long saltedResourceTestingDigest;
uint8_t prevSpectrumDigest[32];
uint8_t prevUniverseDigest[32];
uint8_t prevComputerDigest[32];
uint8_t saltedSpectrumDigest[32];
uint8_t saltedUniverseDigest[32];
uint8_t saltedComputerDigest[32];
uint8_t transactionDigest[32];
uint8_t expectedNextTickTransactionDigest[32];
unsigned char signature[SIGNATURE_SIZE];
static constexpr unsigned char type()
{
return 3;
}
};
struct Entity
{
unsigned char publicKey[32];
long long incomingAmount, outgoingAmount;
unsigned int numberOfIncomingTransfers, numberOfOutgoingTransfers;
unsigned int latestIncomingTransferTick, latestOutgoingTransferTick;
};
typedef struct
{
Entity entity;
unsigned int tick;
int spectrumIndex;
unsigned char siblings[SPECTRUM_DEPTH][32];
} RespondedEntity;
typedef struct
{
unsigned char sourcePublicKey[32];
unsigned char destinationPublicKey[32];
long long amount;
unsigned int tick;
unsigned short inputType;
unsigned short inputSize;
} Transaction;
typedef struct
{
unsigned short tickDuration;
unsigned short epoch;
unsigned int tick;
unsigned short numberOfAlignedVotes;
unsigned short numberOfMisalignedVotes;
unsigned int initialTick;
} CurrentTickInfo;
typedef struct
{
short version;
unsigned short epoch;
unsigned int tick;
unsigned int initialTick;
unsigned int latestCreatedTick;
unsigned short initialMillisecond;
unsigned char initialSecond;
unsigned char initialMinute;
unsigned char initialHour;
unsigned char initialDay;
unsigned char initialMonth;
unsigned char initialYear;
unsigned int numberOfEntities;
unsigned int numberOfTransactions;
uint8_t randomMiningSeed[32];
} CurrentSystemInfo;
typedef struct
{
unsigned short computorIndex;
unsigned short epoch;
unsigned int tick;
unsigned short millisecond;
unsigned char second;
unsigned char minute;
unsigned char hour;
unsigned char day;
unsigned char month;
unsigned char year;
union
{
struct
{
unsigned char uriSize;
unsigned char uri[255];
} proposal;
struct
{
unsigned char zero;
unsigned char votes[(676 * 3 + 7) / 8];
unsigned char quasiRandomNumber;
} ballot;
} varStruct;
unsigned char timelock[32];
unsigned char transactionDigests[NUMBER_OF_TRANSACTIONS_PER_TICK][32];
long long contractFees[1024];
unsigned char signature[SIGNATURE_SIZE];
} TickData;
typedef struct
{
unsigned int tick;
} RequestedTickData;
typedef struct
{
RequestedTickData requestedTickData;
enum {
type = 16,
};
} RequestTickData;
typedef struct
{
unsigned int tick;
unsigned char voteFlags[(676 + 7) / 8];
enum {
type = 14,
};
} RequestedQuorumTick;
typedef struct
{
unsigned int tick;
unsigned char transactionFlags[NUMBER_OF_TRANSACTIONS_PER_TICK / 8];
} RequestedTickTransactions;
typedef struct
{
uint8_t sig[SIGNATURE_SIZE];
} SignatureStruct;
typedef struct
{
char hash[60];
} TxhashStruct;
typedef struct
{
std::vector<uint8_t> vecU8;
} extraDataStruct;
struct SpecialCommand
{
unsigned long long everIncreasingNonceAndCommandType;
static constexpr unsigned char type()
{
return 255;
}
};
#define EMPTY 0
#define ISSUANCE 1
#define OWNERSHIP 2
#define POSSESSION 3
struct Asset
{
union
{
struct
{
unsigned char publicKey[32];
unsigned char type;
char name[7]; // Capital letters + digits
char numberOfDecimalPlaces;
char unitOfMeasurement[7]; // Powers of the corresponding SI base units going in alphabetical order
} issuance;
struct
{
unsigned char publicKey[32];
unsigned char type;
char padding[1];
unsigned short managingContractIndex;
unsigned int issuanceIndex;
long long numberOfUnits;
} ownership;
struct
{
unsigned char publicKey[32];
unsigned char type;
char padding[1];
unsigned short managingContractIndex;
unsigned int ownershipIndex;
long long numberOfUnits;
} possession;
} varStruct;
};
typedef struct
{
unsigned char publicKey[32];
} RequestIssuedAssets;
typedef struct
{
Asset asset;
unsigned int tick;
// TODO: Add siblings
} RespondIssuedAssets;
typedef struct
{
unsigned char publicKey[32];
} RequestOwnedAssets;
typedef struct
{
Asset asset;
Asset issuanceAsset;
unsigned int tick;
// TODO: Add siblings
} RespondOwnedAssets;
typedef struct
{
unsigned char publicKey[32];
} RequestPossessedAssets;
typedef struct
{
Asset asset;
Asset ownershipAsset;
Asset issuanceAsset;
unsigned int tick;
// TODO: Add siblings
} RespondPossessedAssets;
typedef struct
{
// TODO: Padding
unsigned short epoch;
unsigned char publicKeys[NUMBER_OF_COMPUTORS][32];
unsigned char signature[SIGNATURE_SIZE];
} Computors;
typedef struct
{
Computors computors;
} BroadcastComputors;
typedef struct
{
unsigned char peers[4][4];
} ExchangePublicPeers;
struct RequestLog // Fetches log
{
unsigned long long passcode[4];
static constexpr unsigned char type()
{
return 44;
}
};
struct RespondLog // Returns buffered log; clears the buffer; make sure you fetch log quickly enough, if the buffer is overflown log stops being written into it till the node restart
{
// Variable-size log;
static constexpr unsigned char type()
{
return 45;
}
};
struct RequestContractFunction // Invokes contract function
{
unsigned int contractIndex;
unsigned short inputType;
unsigned short inputSize;
// Variable-size input
static constexpr unsigned char type()
{
return 42;
}
};
struct RespondContractFunction // Returns result of contract function invocation
{
// Variable-size output; the size must be 0 if the invocation has failed for whatever reason (e.g. no a function registered for [inputType], or the function has timed out)
static constexpr unsigned char type()
{
return 43;
}
};
struct QxFees_output
{
uint32_t assetIssuanceFee; // Amount of qus
uint32_t transferFee; // Amount of qus
uint32_t tradeFee; // Number of billionths
};
struct GetSendToManyV1Fee_output
{
long long fee; // Number of billionths
static constexpr unsigned char type()
{
return 43;
}
};
struct ContractIPOBid
{
long long price;
unsigned short quantity;
};
#define REQUEST_CONTRACT_IPO 33
typedef struct
{
unsigned int contractIndex;
} RequestContractIPO;
#define RESPOND_CONTRACT_IPO 34
typedef struct
{
unsigned int contractIndex;
unsigned int tick;
uint8_t publicKeys[NUMBER_OF_COMPUTORS][32];
long long prices[NUMBER_OF_COMPUTORS];
} RespondContractIPO;
struct SpecialCommandToggleMainModeResquestAndResponse
{
unsigned long long everIncreasingNonceAndCommandType;
unsigned char mainModeFlag;
unsigned char padding[7];
static constexpr unsigned char type()
{
return 255;
}
};
struct SpecialCommandSetSolutionThresholdResquestAndResponse
{
unsigned long long everIncreasingNonceAndCommandType;
unsigned int epoch;
int threshold;
static constexpr unsigned char type()
{
return 255;
}
};
struct UtcTime
{
unsigned short year; // 1900 - 9999
unsigned char month; // 1 - 12
unsigned char day; // 1 - 31
unsigned char hour; // 0 - 23
unsigned char minute; // 0 - 59
unsigned char second; // 0 - 59
unsigned char pad1;
unsigned int nanosecond; // 0 - 999,999,999
};
struct SpecialCommandSendTime
{
unsigned long long everIncreasingNonceAndCommandType;
UtcTime utcTime;
static constexpr unsigned char type()
{
return 255;
}
};