-
Notifications
You must be signed in to change notification settings - Fork 23
/
main.cpp
402 lines (398 loc) · 18 KB
/
main.cpp
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
#include "stdio.h"
#include "structs.h"
#include "global.h"
#include "argparser.h"
#include "walletUtils.h"
#include "nodeUtils.h"
#include "assetUtil.h"
#include "keyUtils.h"
#include "sanityCheck.h"
#include "SCUtils.h"
#include "quottery.h"
#include "qutil.h"
#include "qx.h"
#include "proposal.h"
int run(int argc, char* argv[])
{
parseArgument(argc, argv);
switch (g_cmd){
case SHOW_KEYS:
sanityCheckSeed(g_seed);
printWalletInfo(g_seed);
break;
case GET_CURRENT_TICK:
sanityCheckNode(g_nodeIp, g_nodePort);
printTickInfoFromNode(g_nodeIp, g_nodePort);
break;
case GET_SYSTEM_INFO:
sanityCheckNode(g_nodeIp, g_nodePort);
printSystemInfoFromNode(g_nodeIp, g_nodePort);
break;
case GET_BALANCE:
sanityCheckIdentity(g_requestedIdentity);
sanityCheckNode(g_nodeIp, g_nodePort);
printBalance(g_requestedIdentity, g_nodeIp, g_nodePort);
break;
case GET_ASSET:
sanityCheckIdentity(g_requestedIdentity);
sanityCheckNode(g_nodeIp, g_nodePort);
printOwnedAsset(g_nodeIp, g_nodePort, g_requestedIdentity);
printPossessionAsset(g_nodeIp, g_nodePort, g_requestedIdentity);
break;
case SEND_COIN:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
sanityCheckIdentity(g_targetIdentity);
sanityCheckTxAmount(g_TxAmount);
makeStandardTransaction(g_nodeIp, g_nodePort, g_seed, g_targetIdentity, g_TxAmount, g_offsetScheduledTick, g_waitUntilFinish);
break;
case SEND_COIN_IN_TICK:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
sanityCheckIdentity(g_targetIdentity);
sanityCheckTxAmount(g_TxAmount);
makeStandardTransactionInTick(g_nodeIp, g_nodePort, g_seed, g_targetIdentity, g_TxAmount, g_TxTick, g_waitUntilFinish);
break;
case SEND_CUSTOM_TX:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
sanityCheckTxType(g_TxType);
sanityCheckIdentity(g_targetIdentity);
sanityCheckTxAmount(g_TxAmount);
sanityCheckExtraDataSize(g_txExtraDataSize);
makeCustomTransaction(g_nodeIp, g_nodePort, g_seed, g_targetIdentity,
g_TxType, g_TxAmount, g_txExtraDataSize,
g_txExtraData, g_offsetScheduledTick);
break;
case GET_TX_INFO:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckTxHash(g_requestedTxId);
getTxInfo(g_nodeIp, g_nodePort, g_requestedTxId);
break;
case CHECK_TX_ON_TICK:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckTxHash(g_requestedTxId);
checkTxOnTick(g_nodeIp, g_nodePort, g_requestedTxId, g_requestedTickNumber);
break;
case SEND_RAW_PACKET:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckRawPacketSize(g_rawPacketSize);
sendRawPacket(g_nodeIp, g_nodePort, g_rawPacketSize, g_rawPacket);
break;
case GET_TICK_DATA:
sanityCheckNode(g_nodeIp, g_nodePort);
getTickDataToFile(g_nodeIp, g_nodePort, g_requestedTickNumber, g_requestedFileName);
break;
case GET_QUORUM_TICK:
sanityCheckNode(g_nodeIp, g_nodePort);
getQuorumTick(g_nodeIp, g_nodePort, g_requestedTickNumber, g_requestedFileName);
break;
case READ_TICK_DATA:
sanityFileExist(g_requestedFileName);
sanityFileExist(g_requestedFileName2);
printTickDataFromFile(g_requestedFileName, g_requestedFileName2);
break;
case CHECK_TX_ON_FILE:
sanityFileExist(g_requestedFileName);
sanityCheckTxHash(g_requestedTxId);
checkTxOnFile(g_requestedTxId, g_requestedFileName);
break;
case PUBLISH_PROPOSAL:
printf("On development. Come back later\n");
break;
case VOTE_PROPOSAL:
printf("On development. Come back later\n");
break;
case QX_ISSUE_ASSET:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
sanityCheckNumberOfUnit(g_qx_issue_asset_number_of_unit);
sanityCheckValidString(g_qx_issue_asset_name);
sanityCheckValidString(g_qx_issue_unit_of_measurement);
sanityCheckNumberOfDecimal(g_qx_issue_asset_num_decimal);
qxIssueAsset(g_nodeIp, g_nodePort, g_seed,
g_qx_issue_asset_name,
g_qx_issue_unit_of_measurement,
g_qx_issue_asset_number_of_unit,
g_qx_issue_asset_num_decimal,
g_offsetScheduledTick);
break;
case QX_TRANSFER_ASSET:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
sanityCheckNumberOfUnit(g_qx_asset_transfer_amount);
sanityCheckValidString(g_qx_asset_transfer_asset_name);
sanityCheckValidString(g_qx_asset_transfer_issuer_in_hex);
sanityCheckIdentity(g_qx_asset_transfer_new_owner_identity);
qxTransferAsset(g_nodeIp, g_nodePort, g_seed,
g_qx_asset_transfer_asset_name,
g_qx_asset_transfer_issuer_in_hex,
g_qx_asset_transfer_new_owner_identity,
g_qx_asset_transfer_amount,
g_offsetScheduledTick);
break;
case QX_ORDER:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
sanityCheckValidString(g_qx_command_1);
sanityCheckValidString(g_qx_command_2);
if (strcmp(g_qx_command_1, "add") == 0){
if (strcmp(g_qx_command_2, "bid") == 0){
qxAddToBidOrder(g_nodeIp, g_nodePort, g_seed, g_qx_asset_name, g_qx_issuer, g_qx_price, g_qx_number_of_share, g_offsetScheduledTick);
} else if (strcmp(g_qx_command_2, "ask") == 0){
qxAddToAskOrder(g_nodeIp, g_nodePort, g_seed, g_qx_asset_name, g_qx_issuer, g_qx_price, g_qx_number_of_share, g_offsetScheduledTick);
}
} else if (strcmp(g_qx_command_1, "remove") == 0){
if (strcmp(g_qx_command_2, "bid") == 0){
qxRemoveToBidOrder(g_nodeIp, g_nodePort, g_seed, g_qx_asset_name, g_qx_issuer, g_qx_price, g_qx_number_of_share, g_offsetScheduledTick);
} else if (strcmp(g_qx_command_2, "ask") == 0){
qxRemoveToAskOrder(g_nodeIp, g_nodePort, g_seed, g_qx_asset_name, g_qx_issuer, g_qx_price, g_qx_number_of_share, g_offsetScheduledTick);
}
}
break;
case QX_GET_ORDER:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckValidString(g_qx_command_1);
sanityCheckValidString(g_qx_command_2);
if (strcmp(g_qx_command_1, "entity") == 0){
if (strcmp(g_qx_command_2, "bid") == 0){
qxGetEntityBidOrder(g_nodeIp, g_nodePort, g_qx_issuer, g_qx_offset);
} else if (strcmp(g_qx_command_2, "ask") == 0){
qxGetEntityAskOrder(g_nodeIp, g_nodePort, g_qx_issuer, g_qx_offset);
}
} else if (strcmp(g_qx_command_1, "asset") == 0){
if (strcmp(g_qx_command_2, "bid") == 0){
qxGetAssetBidOrder(g_nodeIp, g_nodePort, g_qx_asset_name, g_qx_issuer, g_qx_offset);
} else if (strcmp(g_qx_command_2, "ask") == 0){
qxGetAssetAskOrder(g_nodeIp, g_nodePort, g_qx_asset_name, g_qx_issuer, g_qx_offset);
}
}
break;
case GET_COMP_LIST:
sanityCheckNode(g_nodeIp, g_nodePort);
getComputorListToFile(g_nodeIp, g_nodePort, g_requestedFileName);
break;
case GET_NODE_IP_LIST:
sanityCheckNode(g_nodeIp, g_nodePort);
getNodeIpList(g_nodeIp, g_nodePort);
break;
case GET_LOG_FROM_NODE:
sanityCheckNode(g_nodeIp, g_nodePort);
getLogFromNode(g_nodeIp, g_nodePort, g_get_log_passcode);
break;
case UPLOAD_FILE:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
uploadFile(g_nodeIp, g_nodePort, g_file_path, g_seed, g_offsetScheduledTick);
break;
case DOWNLOAD_FILE:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
downloadFile(g_nodeIp, g_nodePort, g_requestedTxId, g_file_path);
break;
case DUMP_SPECTRUM_FILE:
sanityFileExist(g_dump_binary_file_input);
sanityCheckValidString(g_dump_binary_file_output);
dumpSpectrumToCSV(g_dump_binary_file_input, g_dump_binary_file_output);
break;
case DUMP_UNIVERSE_FILE:
sanityFileExist(g_dump_binary_file_input);
sanityCheckValidString(g_dump_binary_file_output);
dumpUniverseToCSV(g_dump_binary_file_input, g_dump_binary_file_output);
break;
case DUMP_CONTRACT_FILE:
sanityFileExist(g_dump_binary_file_input);
sanityCheckValidString(g_dump_binary_file_output);
dumpContractToCSV(g_dump_binary_file_input, g_dump_binary_contract_id, g_dump_binary_file_output);
break;
case PRINT_QX_FEE:
sanityCheckNode(g_nodeIp, g_nodePort);
printQxFee(g_nodeIp, g_nodePort);
break;
case MAKE_IPO_BID:
sanityCheckNode(g_nodeIp, g_nodePort);
makeIPOBid(g_nodeIp, g_nodePort, g_seed, g_ipo_contract_index, g_make_ipo_bid_price_per_share, g_make_ipo_bid_number_of_share, g_offsetScheduledTick);
break;
case GET_IPO_STATUS:
sanityCheckNode(g_nodeIp, g_nodePort);
printIPOStatus(g_nodeIp, g_nodePort, g_ipo_contract_index);
break;
case QUOTTERY_ISSUE_BET:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
quotteryIssueBet(g_nodeIp, g_nodePort, g_seed, g_offsetScheduledTick);
break;
case QUOTTERY_GET_BET_INFO:
sanityCheckNode(g_nodeIp, g_nodePort);
quotteryPrintBetInfo(g_nodeIp, g_nodePort, g_quottery_bet_id);
break;
case QUOTTERY_JOIN_BET:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
quotteryJoinBet(g_nodeIp, g_nodePort, g_seed, g_quottery_bet_id, g_quottery_number_bet_slot, g_quottery_amount_per_bet_slot, g_quottery_picked_option, g_offsetScheduledTick);
break;
case QUOTTERY_GET_BET_DETAIL:
sanityCheckNode(g_nodeIp, g_nodePort);
quotteryPrintBetOptionDetail(g_nodeIp, g_nodePort, g_quottery_bet_id, g_quottery_option_id);
break;
case QUOTTERY_GET_ACTIVE_BET:
sanityCheckNode(g_nodeIp, g_nodePort);
quotteryPrintActiveBet(g_nodeIp, g_nodePort);
break;
case QUOTTERY_GET_ACTIVE_BET_BY_CREATOR:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckIdentity(g_quottery_creator_id);
quotteryPrintActiveBetByCreator(g_nodeIp, g_nodePort, g_quottery_creator_id);
break;
case QUOTTERY_GET_BASIC_INFO:
sanityCheckNode(g_nodeIp, g_nodePort);
quotteryPrintBasicInfo(g_nodeIp, g_nodePort);
break;
case QUOTTERY_PUBLISH_RESULT:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
quotteryPublishResult(g_nodeIp, g_nodePort, g_seed, g_quottery_bet_id, g_quottery_option_id, g_offsetScheduledTick);
break;
case QUOTTERY_CANCEL_BET:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
quotteryCancelBet(g_nodeIp, g_nodePort, g_seed, g_quottery_bet_id, g_offsetScheduledTick);
break;
case TOOGLE_MAIN_AUX:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
sanityCheckMainAuxStatus(g_toogle_main_aux_0);
sanityCheckMainAuxStatus(g_toogle_main_aux_1);
toogleMainAux(g_nodeIp, g_nodePort, g_seed, g_requestedSpecialCommand, g_toogle_main_aux_0, g_toogle_main_aux_1);
break;
case SET_SOLUTION_THRESHOLD:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
checkValidEpoch(g_set_solution_threshold_epoch);
checkValidSolutionThreshold(g_set_solution_threshold_value);
setSolutionThreshold(g_nodeIp, g_nodePort, g_seed,
g_requestedSpecialCommand, g_set_solution_threshold_epoch, g_set_solution_threshold_value);
break;
case SEND_SPECIAL_COMMAND:
case REFRESH_PEER_LIST:
case FORCE_NEXT_TICK:
case REISSUE_VOTE:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
sanityCheckSpecialCommand(g_requestedSpecialCommand);
sendSpecialCommand(g_nodeIp, g_nodePort, g_seed, g_requestedSpecialCommand);
break;
case GET_MINING_SCORE_RANKING:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
sanityCheckSpecialCommand(g_requestedSpecialCommand);
sendSpecialCommandGetMiningScoreRanking(g_nodeIp, g_nodePort, g_seed, g_requestedSpecialCommand);
break;
case GET_VOTE_COUNTER_TX:
sanityCheckNode(g_nodeIp, g_nodePort);
getVoteCounterTransaction(g_nodeIp, g_nodePort, g_requestedTickNumber, g_requestedFileName);
break;
case SYNC_TIME:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
syncTime(g_nodeIp, g_nodePort, g_seed);
break;
case QUTIL_SEND_TO_MANY_V1:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
sanityFileExist(g_qutil_sendtomanyv1_payout_list_file);
qutilSendToManyV1(g_nodeIp, g_nodePort, g_seed, g_qutil_sendtomanyv1_payout_list_file, g_offsetScheduledTick);
break;
case QUTIL_BURN_QUBIC:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
qutilBurnQubic(g_nodeIp, g_nodePort, g_seed, g_TxAmount, g_offsetScheduledTick);
break;
case GQMPROP_SET_PROPOSAL:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
gqmpropSetProposal(g_nodeIp, g_nodePort, g_seed, g_proposalString, g_offsetScheduledTick, g_force);
break;
case GQMPROP_CLEAR_PROPOSAL:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
gqmpropClearProposal(g_nodeIp, g_nodePort, g_seed, g_offsetScheduledTick);
break;
case GQMPROP_GET_PROPOSALS:
sanityCheckNode(g_nodeIp, g_nodePort);
gqmpropGetProposals(g_nodeIp, g_nodePort, g_proposalString);
break;
case GQMPROP_VOTE:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
gqmpropVote(g_nodeIp, g_nodePort, g_seed, g_proposalString, g_voteValueString, g_offsetScheduledTick, g_force);
break;
case GQMPROP_GET_VOTE:
sanityCheckNode(g_nodeIp, g_nodePort);
if (g_requestedIdentity)
sanityCheckIdentity(g_requestedIdentity);
else
sanityCheckSeed(g_seed);
gqmpropGetVote(g_nodeIp, g_nodePort, g_proposalString, g_requestedIdentity, g_seed);
break;
case GQMPROP_GET_VOTING_RESULTS:
sanityCheckNode(g_nodeIp, g_nodePort);
gqmpropGetVotingResults(g_nodeIp, g_nodePort, g_proposalString);
break;
case GQMPROP_GET_REV_DONATION:
sanityCheckNode(g_nodeIp, g_nodePort);
gqmpropGetRevenueDonationTable(g_nodeIp, g_nodePort);
break;
case CCF_SET_PROPOSAL:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
ccfSetProposal(g_nodeIp, g_nodePort, g_seed, g_proposalString, g_offsetScheduledTick, g_force);
break;
case CCF_CLEAR_PROPOSAL:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
ccfClearProposal(g_nodeIp, g_nodePort, g_seed, g_offsetScheduledTick);
break;
case CCF_GET_PROPOSALS:
sanityCheckNode(g_nodeIp, g_nodePort);
ccfGetProposals(g_nodeIp, g_nodePort, g_proposalString);
break;
case CCF_VOTE:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
ccfVote(g_nodeIp, g_nodePort, g_seed, g_proposalString, g_voteValueString, g_offsetScheduledTick, g_force);
break;
case CCF_GET_VOTE:
sanityCheckNode(g_nodeIp, g_nodePort);
if (g_requestedIdentity)
sanityCheckIdentity(g_requestedIdentity);
else
sanityCheckSeed(g_seed);
ccfGetVote(g_nodeIp, g_nodePort, g_proposalString, g_requestedIdentity, g_seed);
break;
case CCF_GET_VOTING_RESULTS:
sanityCheckNode(g_nodeIp, g_nodePort);
ccfGetVotingResults(g_nodeIp, g_nodePort, g_proposalString);
break;
case CCF_GET_LATEST_TRANSFERS:
sanityCheckNode(g_nodeIp, g_nodePort);
ccfGetLatestTransfers(g_nodeIp, g_nodePort);
break;
default:
printf("Unexpected command!\n");
break;
}
return 0;
}
int main(int argc, char* argv[])
{
try
{
return run(argc, argv);
}
catch (std::exception & ex)
{
printf("%s\n", ex.what());
return -1;
}
}