forked from qubic/qubic-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnostromo.cpp
More file actions
1459 lines (1290 loc) · 52.2 KB
/
nostromo.cpp
File metadata and controls
1459 lines (1290 loc) · 52.2 KB
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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <cstdint>
#include <cstring>
#include <stdexcept>
#include <cinttypes>
#include "structs.h"
#include "wallet_utils.h"
#include "key_utils.h"
#include "asset_utils.h"
#include "connection.h"
#include "logger.h"
#include "node_utils.h"
#include "k12_and_key_utils.h"
#include "nostromo.h"
#define NOSTROMO_CONTRACT_INDEX 14
// NOSTROMO FUNCTIONS
#define NOSTROMO_TYPE_GET_STATS 1
#define NOSTROMO_TYPE_GET_TIER_LEVEL_BY_USER 2
#define NOSTROMO_TYPE_GET_USER_VOTE_STATUS 3
#define NOSTROMO_TYPE_CHECK_TOKEN_CREATABILITY 4
#define NOSTROMO_TYPE_GET_NUMBER_OF_INVESTED_AND_CLAIMED_PROJECTS 5
#define NOSTROMO_TYPE_GET_PROJECT_BY_INDEX 6
#define NOSTROMO_TYPE_GET_FUNDRAISING_BY_INDEX 7
#define NOSTROMO_TYPE_GET_PROJECT_INDEX_LIST_BY_CREATOR 8
#define NOSTROMO_TYPE_GET_INFO_USER_INVESTED 9
#define NOSTROMO_TYPE_GET_MAX_CLAIM_AMOUNT 10
// NOSTROMO PROCEDURES
#define NOSTROMO_TYPE_REGISTER_IN_TIER 1
#define NOSTROMO_TYPE_LOGOUT_FROM_TIER 2
#define NOSTROMO_TYPE_CREATE_PROJECT 3
#define NOSTROMO_TYPE_VOTE_IN_PROJECT 4
#define NOSTROMO_TYPE_CREATE_FUNDRAISING 5
#define NOSTROMO_TYPE_INVEST_IN_FUNDRAISING 6
#define NOSTROMO_TYPE_CLAIM_TOKEN 7
#define NOSTROMO_TYPE_UPGRADE_TIER 8
#define NOSTROMO_TRANSFER_SHARE_MANAGEMENT_RIGHTS 9
constexpr uint32_t NOSTROMO_CREATE_PROJECT_FEE = 100000000;
constexpr uint64_t NOSTROMO_TIER_FACEHUGGER_STAKE_AMOUNT = 20000000ULL;
constexpr uint64_t NOSTROMO_TIER_CHESTBURST_STAKE_AMOUNT = 100000000ULL;
constexpr uint64_t NOSTROMO_TIER_DOG_STAKE_AMOUNT = 200000000ULL;
constexpr uint64_t NOSTROMO_TIER_XENOMORPH_STAKE_AMOUNT = 800000000ULL;
constexpr uint64_t NOSTROMO_TIER_WARRIOR_STAKE_AMOUNT = 3200000000ULL;
constexpr uint64_t NOSTROMO_QX_TOKEN_ISSUANCE_FEE = 1000000000ULL;
constexpr uint32_t NOSTROMO_SHARE_MANAGEMENT_TRANSFER_FEE = 100;
constexpr uint32_t NOSTROMO_MAX_NUMBER_PROJECT = 262144;
inline static uint32_t GetYear(uint32_t data)
{
return ((data >> 26) + 24);
}
inline static uint32_t GetMonth(uint32_t data)
{
return ((data >> 22) & 0b1111);
}
inline static uint32_t GetDay(uint32_t data)
{
return ((data >> 17) & 0b11111);
}
inline static uint32_t GetHour(uint32_t data)
{
return ((data >> 12) & 0b11111);
}
inline static uint32_t GetMinute(uint32_t data)
{
return ((data >> 6) & 0b111111);
}
inline static uint32_t GetSecond(uint32_t data)
{
return (data & 0b111111);
}
struct registerInTier_input
{
uint32_t tierLevel;
};
struct registerInTier_output
{
uint32_t tierLevel;
};
struct logoutFromTier_input
{
};
struct logoutFromTier_output
{
bool result;
};
struct createProject_input
{
uint64_t tokenName;
uint64_t supply;
uint32_t startYear;
uint32_t startMonth;
uint32_t startDay;
uint32_t startHour;
uint32_t endYear;
uint32_t endMonth;
uint32_t endDay;
uint32_t endHour;
};
struct createProject_output
{
uint32_t indexOfProject;
};
struct voteInProject_input
{
uint32_t indexOfProject;
bool decision;
};
struct voteInProject_output
{
};
struct createFundraising_input
{
uint64_t tokenPrice;
uint64_t soldAmount;
uint64_t requiredFunds;
uint32_t indexOfProject;
uint32_t firstPhaseStartYear;
uint32_t firstPhaseStartMonth;
uint32_t firstPhaseStartDay;
uint32_t firstPhaseStartHour;
uint32_t firstPhaseEndYear;
uint32_t firstPhaseEndMonth;
uint32_t firstPhaseEndDay;
uint32_t firstPhaseEndHour;
uint32_t secondPhaseStartYear;
uint32_t secondPhaseStartMonth;
uint32_t secondPhaseStartDay;
uint32_t secondPhaseStartHour;
uint32_t secondPhaseEndYear;
uint32_t secondPhaseEndMonth;
uint32_t secondPhaseEndDay;
uint32_t secondPhaseEndHour;
uint32_t thirdPhaseStartYear;
uint32_t thirdPhaseStartMonth;
uint32_t thirdPhaseStartDay;
uint32_t thirdPhaseStartHour;
uint32_t thirdPhaseEndYear;
uint32_t thirdPhaseEndMonth;
uint32_t thirdPhaseEndDay;
uint32_t thirdPhaseEndHour;
uint32_t listingStartYear;
uint32_t listingStartMonth;
uint32_t listingStartDay;
uint32_t listingStartHour;
uint32_t cliffEndYear;
uint32_t cliffEndMonth;
uint32_t cliffEndDay;
uint32_t cliffEndHour;
uint32_t vestingEndYear;
uint32_t vestingEndMonth;
uint32_t vestingEndDay;
uint32_t vestingEndHour;
uint8_t threshold;
uint8_t TGE;
uint8_t stepOfVesting;
};
struct createFundraising_output
{
};
struct investInProject_input
{
uint32_t indexOfFundraising;
};
struct investInProject_output
{
};
struct claimToken_input
{
uint64_t amount;
uint32_t indexOfFundraising;
};
struct claimToken_output
{
};
struct upgradeTier_input
{
uint32_t newTierLevel;
};
struct upgradeTier_output
{
};
struct Asset
{
uint8_t issuer[32];
uint64_t assetName;
};
struct nostromoTransferShareManagementRights_input
{
Asset asset;
int64_t numberOfShares;
uint32_t newManagingContractIndex;
};
struct nostromoTransferShareManagementRights_output
{
int64_t transferredNumberOfShares;
};
void registerInTier(const char* nodeIp, int nodePort,
const char* seed,
uint32_t scheduledTickOffset,
uint32_t tierLevel)
{
if (tierLevel < 1 || tierLevel > 5)
{
printf("TierLevel should be the number between 1 ~ 5!\n");
return ;
}
auto qc = make_qc(nodeIp, nodePort);
uint8_t privateKey[32] = {0};
uint8_t sourcePublicKey[32] = {0};
uint8_t destPublicKey[32] = {0};
uint8_t subseed[32] = {0};
uint8_t digest[32] = {0};
uint8_t signature[64] = {0};
char publicIdentity[128] = {0};
char txHash[128] = {0};
getSubseedFromSeed((uint8_t*)seed, subseed);
getPrivateKeyFromSubSeed(subseed, privateKey);
getPublicKeyFromPrivateKey(privateKey, sourcePublicKey);
const bool isLowerCase = false;
getIdentityFromPublicKey(sourcePublicKey, publicIdentity, isLowerCase);
((uint64_t*)destPublicKey)[0] = NOSTROMO_CONTRACT_INDEX;
((uint64_t*)destPublicKey)[1] = 0;
((uint64_t*)destPublicKey)[2] = 0;
((uint64_t*)destPublicKey)[3] = 0;
#pragma pack(push, 1)
struct {
RequestResponseHeader header;
Transaction transaction;
registerInTier_input input;
unsigned char signature[64];
} packet;
#pragma pack(pop)
packet.input.tierLevel = tierLevel;
switch (tierLevel)
{
case 1:
packet.transaction.amount = NOSTROMO_TIER_FACEHUGGER_STAKE_AMOUNT;
break;
case 2:
packet.transaction.amount = NOSTROMO_TIER_CHESTBURST_STAKE_AMOUNT;
break;
case 3:
packet.transaction.amount = NOSTROMO_TIER_DOG_STAKE_AMOUNT;
break;
case 4:
packet.transaction.amount = NOSTROMO_TIER_XENOMORPH_STAKE_AMOUNT;
break;
case 5:
packet.transaction.amount = NOSTROMO_TIER_WARRIOR_STAKE_AMOUNT;
break;
default:
break;
}
memcpy(packet.transaction.sourcePublicKey, sourcePublicKey, 32);
memcpy(packet.transaction.destinationPublicKey, destPublicKey, 32);
uint32_t currentTick = getTickNumberFromNode(qc);
packet.transaction.tick = currentTick + scheduledTickOffset;
packet.transaction.inputType = NOSTROMO_TYPE_REGISTER_IN_TIER;
packet.transaction.inputSize = sizeof(registerInTier_input);
KangarooTwelve((unsigned char*)&packet.transaction,
sizeof(packet.transaction) + sizeof(registerInTier_input),
digest,
32);
sign(subseed, sourcePublicKey, digest, signature);
memcpy(packet.signature, signature, 64);
packet.header.setSize(sizeof(packet));
packet.header.zeroDejavu();
packet.header.setType(BROADCAST_TRANSACTION);
qc->sendData((uint8_t *) &packet, packet.header.size());
KangarooTwelve((unsigned char*)&packet.transaction,
sizeof(packet.transaction) + sizeof(registerInTier_input) + SIGNATURE_SIZE,
digest,
32); // recompute digest for txhash
getTxHashFromDigest(digest, txHash);
LOG("registerInTier tx has been sent!\n");
printReceipt(packet.transaction, txHash, nullptr);
LOG("run ./qubic-cli [...] -checktxontick %u %s\n", currentTick + scheduledTickOffset, txHash);
LOG("to check your tx confirmation status\n");
}
void logoutFromTier(const char* nodeIp, int nodePort,
const char* seed,
uint32_t scheduledTickOffset)
{
auto qc = make_qc(nodeIp, nodePort);
uint8_t privateKey[32] = {0};
uint8_t sourcePublicKey[32] = {0};
uint8_t destPublicKey[32] = {0};
uint8_t subseed[32] = {0};
uint8_t digest[32] = {0};
uint8_t signature[64] = {0};
char publicIdentity[128] = {0};
char txHash[128] = {0};
getSubseedFromSeed((uint8_t*)seed, subseed);
getPrivateKeyFromSubSeed(subseed, privateKey);
getPublicKeyFromPrivateKey(privateKey, sourcePublicKey);
const bool isLowerCase = false;
getIdentityFromPublicKey(sourcePublicKey, publicIdentity, isLowerCase);
((uint64_t*)destPublicKey)[0] = NOSTROMO_CONTRACT_INDEX;
((uint64_t*)destPublicKey)[1] = 0;
((uint64_t*)destPublicKey)[2] = 0;
((uint64_t*)destPublicKey)[3] = 0;
#pragma pack(push, 1)
struct {
RequestResponseHeader header;
Transaction transaction;
logoutFromTier_input input;
unsigned char signature[64];
} packet;
#pragma pack(pop)
packet.transaction.amount = 0;
memcpy(packet.transaction.sourcePublicKey, sourcePublicKey, 32);
memcpy(packet.transaction.destinationPublicKey, destPublicKey, 32);
uint32_t currentTick = getTickNumberFromNode(qc);
packet.transaction.tick = currentTick + scheduledTickOffset;
packet.transaction.inputType = NOSTROMO_TYPE_LOGOUT_FROM_TIER;
packet.transaction.inputSize = sizeof(logoutFromTier_input);
KangarooTwelve((unsigned char*)&packet.transaction,
sizeof(packet.transaction) + sizeof(logoutFromTier_input),
digest,
32);
sign(subseed, sourcePublicKey, digest, signature);
memcpy(packet.signature, signature, 64);
packet.header.setSize(sizeof(packet));
packet.header.zeroDejavu();
packet.header.setType(BROADCAST_TRANSACTION);
qc->sendData((uint8_t *) &packet, packet.header.size());
KangarooTwelve((unsigned char*)&packet.transaction,
sizeof(packet.transaction) + sizeof(logoutFromTier_input) + SIGNATURE_SIZE,
digest,
32); // recompute digest for txhash
getTxHashFromDigest(digest, txHash);
LOG("logoutFromTier tx has been sent!\n");
printReceipt(packet.transaction, txHash, nullptr);
LOG("run ./qubic-cli [...] -checktxontick %u %s\n", currentTick + scheduledTickOffset, txHash);
LOG("to check your tx confirmation status\n");
}
void createProject(const char* nodeIp, int nodePort,
const char* seed,
uint32_t scheduledTickOffset,
const char* tokenName,
uint64_t supply,
uint32_t startYear,
uint32_t startMonth,
uint32_t startDay,
uint32_t startHour,
uint32_t endYear,
uint32_t endMonth,
uint32_t endDay,
uint32_t endHour)
{
auto qc = make_qc(nodeIp, nodePort);
char assetNameS1[8] = {0};
memcpy(assetNameS1, tokenName, strlen(tokenName));
uint8_t privateKey[32] = {0};
uint8_t sourcePublicKey[32] = {0};
uint8_t destPublicKey[32] = {0};
uint8_t subseed[32] = {0};
uint8_t digest[32] = {0};
uint8_t signature[64] = {0};
char publicIdentity[128] = {0};
char txHash[128] = {0};
getSubseedFromSeed((uint8_t*)seed, subseed);
getPrivateKeyFromSubSeed(subseed, privateKey);
getPublicKeyFromPrivateKey(privateKey, sourcePublicKey);
const bool isLowerCase = false;
getIdentityFromPublicKey(sourcePublicKey, publicIdentity, isLowerCase);
((uint64_t*)destPublicKey)[0] = NOSTROMO_CONTRACT_INDEX;
((uint64_t*)destPublicKey)[1] = 0;
((uint64_t*)destPublicKey)[2] = 0;
((uint64_t*)destPublicKey)[3] = 0;
#pragma pack(push, 1)
struct {
RequestResponseHeader header;
Transaction transaction;
createProject_input input;
unsigned char signature[64];
} packet;
#pragma pack(pop)
memcpy(&packet.input.tokenName, assetNameS1, 8);
packet.input.supply = supply;
packet.input.startYear = startYear - 2000;
packet.input.startMonth = startMonth;
packet.input.startDay = startDay;
packet.input.startHour = startHour;
packet.input.endYear = endYear - 2000;
packet.input.endMonth = endMonth;
packet.input.endDay = endDay;
packet.input.endHour = endHour;
packet.transaction.amount = NOSTROMO_CREATE_PROJECT_FEE;
memcpy(packet.transaction.sourcePublicKey, sourcePublicKey, 32);
memcpy(packet.transaction.destinationPublicKey, destPublicKey, 32);
uint32_t currentTick = getTickNumberFromNode(qc);
packet.transaction.tick = currentTick + scheduledTickOffset;
packet.transaction.inputType = NOSTROMO_TYPE_CREATE_PROJECT;
packet.transaction.inputSize = sizeof(createProject_input);
KangarooTwelve((unsigned char*)&packet.transaction,
sizeof(packet.transaction) + sizeof(createProject_input),
digest,
32);
sign(subseed, sourcePublicKey, digest, signature);
memcpy(packet.signature, signature, 64);
packet.header.setSize(sizeof(packet));
packet.header.zeroDejavu();
packet.header.setType(BROADCAST_TRANSACTION);
qc->sendData((uint8_t *) &packet, packet.header.size());
KangarooTwelve((unsigned char*)&packet.transaction,
sizeof(packet.transaction) + sizeof(createProject_input) + SIGNATURE_SIZE,
digest,
32); // recompute digest for txhash
getTxHashFromDigest(digest, txHash);
LOG("createProject tx has been sent!\n");
printReceipt(packet.transaction, txHash, nullptr);
LOG("run ./qubic-cli [...] -checktxontick %u %s\n", currentTick + scheduledTickOffset, txHash);
LOG("to check your tx confirmation status\n");
}
void voteInProject(const char* nodeIp, int nodePort,
const char* seed,
uint32_t scheduledTickOffset,
uint32_t indexOfProject,
bool decision)
{
auto qc = make_qc(nodeIp, nodePort);
uint8_t privateKey[32] = {0};
uint8_t sourcePublicKey[32] = {0};
uint8_t destPublicKey[32] = {0};
uint8_t subseed[32] = {0};
uint8_t digest[32] = {0};
uint8_t signature[64] = {0};
char publicIdentity[128] = {0};
char txHash[128] = {0};
getSubseedFromSeed((uint8_t*)seed, subseed);
getPrivateKeyFromSubSeed(subseed, privateKey);
getPublicKeyFromPrivateKey(privateKey, sourcePublicKey);
const bool isLowerCase = false;
getIdentityFromPublicKey(sourcePublicKey, publicIdentity, isLowerCase);
((uint64_t*)destPublicKey)[0] = NOSTROMO_CONTRACT_INDEX;
((uint64_t*)destPublicKey)[1] = 0;
((uint64_t*)destPublicKey)[2] = 0;
((uint64_t*)destPublicKey)[3] = 0;
#pragma pack(push, 1)
struct {
RequestResponseHeader header;
Transaction transaction;
voteInProject_input input;
unsigned char signature[64];
} packet;
#pragma pack(pop)
packet.input.decision = decision;
packet.input.indexOfProject = indexOfProject;
packet.transaction.amount = 0;
memcpy(packet.transaction.sourcePublicKey, sourcePublicKey, 32);
memcpy(packet.transaction.destinationPublicKey, destPublicKey, 32);
uint32_t currentTick = getTickNumberFromNode(qc);
packet.transaction.tick = currentTick + scheduledTickOffset;
packet.transaction.inputType = NOSTROMO_TYPE_VOTE_IN_PROJECT;
packet.transaction.inputSize = sizeof(voteInProject_input);
KangarooTwelve((unsigned char*)&packet.transaction,
sizeof(packet.transaction) + sizeof(voteInProject_input),
digest,
32);
sign(subseed, sourcePublicKey, digest, signature);
memcpy(packet.signature, signature, 64);
packet.header.setSize(sizeof(packet));
packet.header.zeroDejavu();
packet.header.setType(BROADCAST_TRANSACTION);
qc->sendData((uint8_t *) &packet, packet.header.size());
KangarooTwelve((unsigned char*)&packet.transaction,
sizeof(packet.transaction) + sizeof(voteInProject_input) + SIGNATURE_SIZE,
digest,
32); // recompute digest for txhash
getTxHashFromDigest(digest, txHash);
LOG("voteInProject tx has been sent!\n");
printReceipt(packet.transaction, txHash, nullptr);
LOG("run ./qubic-cli [...] -checktxontick %u %s\n", currentTick + scheduledTickOffset, txHash);
LOG("to check your tx confirmation status\n");
}
void createFundraising(const char* nodeIp, int nodePort,
const char* seed,
uint32_t scheduledTickOffset,
uint64_t tokenPrice,
uint64_t soldAmount,
uint64_t requiredFunds,
uint32_t indexOfProject,
uint32_t firstPhaseStartYear,
uint32_t firstPhaseStartMonth,
uint32_t firstPhaseStartDay,
uint32_t firstPhaseStartHour,
uint32_t firstPhaseEndYear,
uint32_t firstPhaseEndMonth,
uint32_t firstPhaseEndDay,
uint32_t firstPhaseEndHour,
uint32_t secondPhaseStartYear,
uint32_t secondPhaseStartMonth,
uint32_t secondPhaseStartDay,
uint32_t secondPhaseStartHour,
uint32_t secondPhaseEndYear,
uint32_t secondPhaseEndMonth,
uint32_t secondPhaseEndDay,
uint32_t secondPhaseEndHour,
uint32_t thirdPhaseStartYear,
uint32_t thirdPhaseStartMonth,
uint32_t thirdPhaseStartDay,
uint32_t thirdPhaseStartHour,
uint32_t thirdPhaseEndYear,
uint32_t thirdPhaseEndMonth,
uint32_t thirdPhaseEndDay,
uint32_t thirdPhaseEndHour,
uint32_t listingStartYear,
uint32_t listingStartMonth,
uint32_t listingStartDay,
uint32_t listingStartHour,
uint32_t cliffEndYear,
uint32_t cliffEndMonth,
uint32_t cliffEndDay,
uint32_t cliffEndHour,
uint32_t vestingEndYear,
uint32_t vestingEndMonth,
uint32_t vestingEndDay,
uint32_t vestingEndHour,
uint8_t threshold,
uint8_t TGE,
uint8_t stepOfVesting)
{
auto qc = make_qc(nodeIp, nodePort);
uint8_t privateKey[32] = {0};
uint8_t sourcePublicKey[32] = {0};
uint8_t destPublicKey[32] = {0};
uint8_t subseed[32] = {0};
uint8_t digest[32] = {0};
uint8_t signature[64] = {0};
char publicIdentity[128] = {0};
char txHash[128] = {0};
getSubseedFromSeed((uint8_t*)seed, subseed);
getPrivateKeyFromSubSeed(subseed, privateKey);
getPublicKeyFromPrivateKey(privateKey, sourcePublicKey);
const bool isLowerCase = false;
getIdentityFromPublicKey(sourcePublicKey, publicIdentity, isLowerCase);
((uint64_t*)destPublicKey)[0] = NOSTROMO_CONTRACT_INDEX;
((uint64_t*)destPublicKey)[1] = 0;
((uint64_t*)destPublicKey)[2] = 0;
((uint64_t*)destPublicKey)[3] = 0;
#pragma pack(push, 1)
struct {
RequestResponseHeader header;
Transaction transaction;
createFundraising_input input;
unsigned char signature[64];
} packet;
#pragma pack(pop)
packet.input.tokenPrice = tokenPrice;
packet.input.soldAmount = soldAmount;
packet.input.requiredFunds = requiredFunds;
packet.input.indexOfProject = indexOfProject;
packet.input.firstPhaseStartYear = firstPhaseStartYear - 2000;
packet.input.firstPhaseStartMonth = firstPhaseStartMonth;
packet.input.firstPhaseStartDay = firstPhaseStartDay;
packet.input.firstPhaseStartHour = firstPhaseStartHour;
packet.input.firstPhaseEndYear = firstPhaseEndYear - 2000;
packet.input.firstPhaseEndMonth = firstPhaseEndMonth;
packet.input.firstPhaseEndDay = firstPhaseEndDay;
packet.input.firstPhaseEndHour = firstPhaseEndHour;
packet.input.secondPhaseStartYear = secondPhaseStartYear - 2000;
packet.input.secondPhaseStartMonth = secondPhaseStartMonth;
packet.input.secondPhaseStartDay = secondPhaseStartDay;
packet.input.secondPhaseStartHour = secondPhaseStartHour;
packet.input.secondPhaseEndYear = secondPhaseEndYear - 2000;
packet.input.secondPhaseEndMonth = secondPhaseEndMonth;
packet.input.secondPhaseEndDay = secondPhaseEndDay;
packet.input.secondPhaseEndHour = secondPhaseEndHour;
packet.input.thirdPhaseStartYear = thirdPhaseStartYear - 2000;
packet.input.thirdPhaseStartMonth = thirdPhaseStartMonth;
packet.input.thirdPhaseStartDay = thirdPhaseStartDay;
packet.input.thirdPhaseStartHour = thirdPhaseStartHour;
packet.input.thirdPhaseEndYear = thirdPhaseEndYear - 2000;
packet.input.thirdPhaseEndMonth = thirdPhaseEndMonth;
packet.input.thirdPhaseEndDay = thirdPhaseEndDay;
packet.input.thirdPhaseEndHour = thirdPhaseEndHour;
packet.input.listingStartYear = listingStartYear - 2000;
packet.input.listingStartMonth = listingStartMonth;
packet.input.listingStartDay = listingStartDay;
packet.input.listingStartHour = listingStartHour;
packet.input.cliffEndYear = cliffEndYear - 2000;
packet.input.cliffEndMonth = cliffEndMonth;
packet.input.cliffEndDay = cliffEndDay;
packet.input.cliffEndHour = cliffEndHour;
packet.input.vestingEndYear = vestingEndYear - 2000;
packet.input.vestingEndMonth = vestingEndMonth;
packet.input.vestingEndDay = vestingEndDay;
packet.input.vestingEndHour = vestingEndHour;
packet.input.threshold = threshold;
packet.input.TGE = TGE;
packet.input.stepOfVesting = stepOfVesting;
packet.transaction.amount = NOSTROMO_QX_TOKEN_ISSUANCE_FEE;
memcpy(packet.transaction.sourcePublicKey, sourcePublicKey, 32);
memcpy(packet.transaction.destinationPublicKey, destPublicKey, 32);
uint32_t currentTick = getTickNumberFromNode(qc);
packet.transaction.tick = currentTick + scheduledTickOffset;
packet.transaction.inputType = NOSTROMO_TYPE_CREATE_FUNDRAISING;
packet.transaction.inputSize = sizeof(createFundraising_input);
KangarooTwelve((unsigned char*)&packet.transaction,
sizeof(packet.transaction) + sizeof(createFundraising_input),
digest,
32);
sign(subseed, sourcePublicKey, digest, signature);
memcpy(packet.signature, signature, 64);
packet.header.setSize(sizeof(packet));
packet.header.zeroDejavu();
packet.header.setType(BROADCAST_TRANSACTION);
qc->sendData((uint8_t *) &packet, packet.header.size());
KangarooTwelve((unsigned char*)&packet.transaction,
sizeof(packet.transaction) + sizeof(createFundraising_input) + SIGNATURE_SIZE,
digest,
32); // recompute digest for txhash
getTxHashFromDigest(digest, txHash);
LOG("createFundraising tx has been sent!\n");
printReceipt(packet.transaction, txHash, nullptr);
LOG("run ./qubic-cli [...] -checktxontick %u %s\n", currentTick + scheduledTickOffset, txHash);
LOG("to check your tx confirmation status\n");
}
void investInProject(const char* nodeIp, int nodePort,
const char* seed,
uint32_t scheduledTickOffset,
uint32_t indexOfFundraising, uint64_t amount)
{
auto qc = make_qc(nodeIp, nodePort);
uint8_t privateKey[32] = {0};
uint8_t sourcePublicKey[32] = {0};
uint8_t destPublicKey[32] = {0};
uint8_t subseed[32] = {0};
uint8_t digest[32] = {0};
uint8_t signature[64] = {0};
char publicIdentity[128] = {0};
char txHash[128] = {0};
getSubseedFromSeed((uint8_t*)seed, subseed);
getPrivateKeyFromSubSeed(subseed, privateKey);
getPublicKeyFromPrivateKey(privateKey, sourcePublicKey);
const bool isLowerCase = false;
getIdentityFromPublicKey(sourcePublicKey, publicIdentity, isLowerCase);
((uint64_t*)destPublicKey)[0] = NOSTROMO_CONTRACT_INDEX;
((uint64_t*)destPublicKey)[1] = 0;
((uint64_t*)destPublicKey)[2] = 0;
((uint64_t*)destPublicKey)[3] = 0;
#pragma pack(push, 1)
struct {
RequestResponseHeader header;
Transaction transaction;
investInProject_input input;
unsigned char signature[64];
} packet;
#pragma pack(pop)
packet.input.indexOfFundraising = indexOfFundraising;
packet.transaction.amount = amount;
memcpy(packet.transaction.sourcePublicKey, sourcePublicKey, 32);
memcpy(packet.transaction.destinationPublicKey, destPublicKey, 32);
uint32_t currentTick = getTickNumberFromNode(qc);
packet.transaction.tick = currentTick + scheduledTickOffset;
packet.transaction.inputType = NOSTROMO_TYPE_INVEST_IN_FUNDRAISING;
packet.transaction.inputSize = sizeof(investInProject_input);
KangarooTwelve((unsigned char*)&packet.transaction,
sizeof(packet.transaction) + sizeof(investInProject_input),
digest,
32);
sign(subseed, sourcePublicKey, digest, signature);
memcpy(packet.signature, signature, 64);
packet.header.setSize(sizeof(packet));
packet.header.zeroDejavu();
packet.header.setType(BROADCAST_TRANSACTION);
qc->sendData((uint8_t *) &packet, packet.header.size());
KangarooTwelve((unsigned char*)&packet.transaction,
sizeof(packet.transaction) + sizeof(investInProject_input) + SIGNATURE_SIZE,
digest,
32); // recompute digest for txhash
getTxHashFromDigest(digest, txHash);
LOG("investInProject tx has been sent!\n");
printReceipt(packet.transaction, txHash, nullptr);
LOG("run ./qubic-cli [...] -checktxontick %u %s\n", currentTick + scheduledTickOffset, txHash);
LOG("to check your tx confirmation status\n");
}
void claimToken(const char* nodeIp, int nodePort,
const char* seed,
uint32_t scheduledTickOffset,
uint64_t amount,
uint32_t indexOfFundraising)
{
auto qc = make_qc(nodeIp, nodePort);
uint8_t privateKey[32] = {0};
uint8_t sourcePublicKey[32] = {0};
uint8_t destPublicKey[32] = {0};
uint8_t subseed[32] = {0};
uint8_t digest[32] = {0};
uint8_t signature[64] = {0};
char publicIdentity[128] = {0};
char txHash[128] = {0};
getSubseedFromSeed((uint8_t*)seed, subseed);
getPrivateKeyFromSubSeed(subseed, privateKey);
getPublicKeyFromPrivateKey(privateKey, sourcePublicKey);
const bool isLowerCase = false;
getIdentityFromPublicKey(sourcePublicKey, publicIdentity, isLowerCase);
((uint64_t*)destPublicKey)[0] = NOSTROMO_CONTRACT_INDEX;
((uint64_t*)destPublicKey)[1] = 0;
((uint64_t*)destPublicKey)[2] = 0;
((uint64_t*)destPublicKey)[3] = 0;
#pragma pack(push, 1)
struct {
RequestResponseHeader header;
Transaction transaction;
claimToken_input input;
unsigned char signature[64];
} packet;
#pragma pack(pop)
packet.input.amount = amount;
packet.input.indexOfFundraising = indexOfFundraising;
packet.transaction.amount = 0;
memcpy(packet.transaction.sourcePublicKey, sourcePublicKey, 32);
memcpy(packet.transaction.destinationPublicKey, destPublicKey, 32);
uint32_t currentTick = getTickNumberFromNode(qc);
packet.transaction.tick = currentTick + scheduledTickOffset;
packet.transaction.inputType = NOSTROMO_TYPE_CLAIM_TOKEN;
packet.transaction.inputSize = sizeof(claimToken_input);
KangarooTwelve((unsigned char*)&packet.transaction,
sizeof(packet.transaction) + sizeof(claimToken_input),
digest,
32);
sign(subseed, sourcePublicKey, digest, signature);
memcpy(packet.signature, signature, 64);
packet.header.setSize(sizeof(packet));
packet.header.zeroDejavu();
packet.header.setType(BROADCAST_TRANSACTION);
qc->sendData((uint8_t *) &packet, packet.header.size());
KangarooTwelve((unsigned char*)&packet.transaction,
sizeof(packet.transaction) + sizeof(claimToken_input) + SIGNATURE_SIZE,
digest,
32); // recompute digest for txhash
getTxHashFromDigest(digest, txHash);
LOG("claimToken tx has been sent!\n");
printReceipt(packet.transaction, txHash, nullptr);
LOG("run ./qubic-cli [...] -checktxontick %u %s\n", currentTick + scheduledTickOffset, txHash);
LOG("to check your tx confirmation status\n");
}
void upgradeTierLevel(const char* nodeIp, int nodePort,
const char* seed,
uint32_t scheduledTickOffset,
uint32_t tierLevel)
{
if (tierLevel < 2 || tierLevel > 5)
{
printf("Wrong Tierlevel for upgrading!\n");
return ;
}
auto qc = make_qc(nodeIp, nodePort);
uint8_t privateKey[32] = {0};
uint8_t sourcePublicKey[32] = {0};
uint8_t destPublicKey[32] = {0};
uint8_t subseed[32] = {0};
uint8_t digest[32] = {0};
uint8_t signature[64] = {0};
char publicIdentity[128] = {0};
char txHash[128] = {0};
getSubseedFromSeed((uint8_t*)seed, subseed);
getPrivateKeyFromSubSeed(subseed, privateKey);
getPublicKeyFromPrivateKey(privateKey, sourcePublicKey);
const bool isLowerCase = false;
getIdentityFromPublicKey(sourcePublicKey, publicIdentity, isLowerCase);
((uint64_t*)destPublicKey)[0] = NOSTROMO_CONTRACT_INDEX;
((uint64_t*)destPublicKey)[1] = 0;
((uint64_t*)destPublicKey)[2] = 0;
((uint64_t*)destPublicKey)[3] = 0;
#pragma pack(push, 1)
struct {
RequestResponseHeader header;
Transaction transaction;
upgradeTier_input input;
unsigned char signature[64];
} packet;
#pragma pack(pop)
packet.input.newTierLevel = tierLevel;
switch (tierLevel)
{
case 2:
packet.transaction.amount = NOSTROMO_TIER_CHESTBURST_STAKE_AMOUNT - NOSTROMO_TIER_FACEHUGGER_STAKE_AMOUNT;
break;
case 3:
packet.transaction.amount = NOSTROMO_TIER_DOG_STAKE_AMOUNT - NOSTROMO_TIER_CHESTBURST_STAKE_AMOUNT;
break;
case 4:
packet.transaction.amount = NOSTROMO_TIER_XENOMORPH_STAKE_AMOUNT - NOSTROMO_TIER_DOG_STAKE_AMOUNT;
break;
case 5:
packet.transaction.amount = NOSTROMO_TIER_WARRIOR_STAKE_AMOUNT - NOSTROMO_TIER_XENOMORPH_STAKE_AMOUNT;
break;
default:
break;
}
memcpy(packet.transaction.sourcePublicKey, sourcePublicKey, 32);
memcpy(packet.transaction.destinationPublicKey, destPublicKey, 32);
uint32_t currentTick = getTickNumberFromNode(qc);
packet.transaction.tick = currentTick + scheduledTickOffset;
packet.transaction.inputType = NOSTROMO_TYPE_UPGRADE_TIER;
packet.transaction.inputSize = sizeof(upgradeTier_input);
KangarooTwelve((unsigned char*)&packet.transaction,
sizeof(packet.transaction) + sizeof(upgradeTier_input),
digest,
32);
sign(subseed, sourcePublicKey, digest, signature);
memcpy(packet.signature, signature, 64);
packet.header.setSize(sizeof(packet));
packet.header.zeroDejavu();
packet.header.setType(BROADCAST_TRANSACTION);
qc->sendData((uint8_t *) &packet, packet.header.size());
KangarooTwelve((unsigned char*)&packet.transaction,
sizeof(packet.transaction) + sizeof(upgradeTier_input) + SIGNATURE_SIZE,
digest,
32); // recompute digest for txhash
getTxHashFromDigest(digest, txHash);
LOG("upgradeTierLevel tx has been sent!\n");
printReceipt(packet.transaction, txHash, nullptr);
LOG("run ./qubic-cli [...] -checktxontick %u %s\n", currentTick + scheduledTickOffset, txHash);
LOG("to check your tx confirmation status\n");
}
void nostromoTransferShareManagementRights(const char* nodeIp, int nodePort,
const char* seed,
uint32_t scheduledTickOffset,
const char* issuer,
const char* assetName,
int64_t numberOfShares,
uint32_t newManagingContractIndex)
{
auto qc = make_qc(nodeIp, nodePort);
uint8_t pubKey[32] = {0};
char assetNameS1[8] = {0};
memcpy(assetNameS1, assetName, strlen(assetName));
getPublicKeyFromIdentity(issuer, pubKey);
uint8_t privateKey[32] = {0};
uint8_t sourcePublicKey[32] = {0};
uint8_t destPublicKey[32] = {0};
uint8_t subseed[32] = {0};
uint8_t digest[32] = {0};
uint8_t signature[64] = {0};
char publicIdentity[128] = {0};
char txHash[128] = {0};
getSubseedFromSeed((uint8_t*)seed, subseed);
getPrivateKeyFromSubSeed(subseed, privateKey);
getPublicKeyFromPrivateKey(privateKey, sourcePublicKey);
const bool isLowerCase = false;
getIdentityFromPublicKey(sourcePublicKey, publicIdentity, isLowerCase);
((uint64_t*)destPublicKey)[0] = NOSTROMO_CONTRACT_INDEX;
((uint64_t*)destPublicKey)[1] = 0;
((uint64_t*)destPublicKey)[2] = 0;
((uint64_t*)destPublicKey)[3] = 0;
#pragma pack(push, 1)
struct {
RequestResponseHeader header;
Transaction transaction;
nostromoTransferShareManagementRights_input input;
unsigned char signature[64];
} packet;
#pragma pack(pop)
memcpy(&packet.input.asset.assetName, assetNameS1, 8);
memcpy(packet.input.asset.issuer, pubKey, 32);
packet.input.newManagingContractIndex = newManagingContractIndex;
packet.input.numberOfShares = numberOfShares;
packet.transaction.amount = NOSTROMO_SHARE_MANAGEMENT_TRANSFER_FEE;
memcpy(packet.transaction.sourcePublicKey, sourcePublicKey, 32);
memcpy(packet.transaction.destinationPublicKey, destPublicKey, 32);
uint32_t currentTick = getTickNumberFromNode(qc);
packet.transaction.tick = currentTick + scheduledTickOffset;
packet.transaction.inputType = NOSTROMO_TRANSFER_SHARE_MANAGEMENT_RIGHTS;
packet.transaction.inputSize = sizeof(nostromoTransferShareManagementRights_input);
KangarooTwelve((unsigned char*)&packet.transaction,
sizeof(packet.transaction) + sizeof(nostromoTransferShareManagementRights_input),
digest,
32);
sign(subseed, sourcePublicKey, digest, signature);
memcpy(packet.signature, signature, 64);
packet.header.setSize(sizeof(packet));
packet.header.zeroDejavu();
packet.header.setType(BROADCAST_TRANSACTION);
qc->sendData((uint8_t *) &packet, packet.header.size());
KangarooTwelve((unsigned char*)&packet.transaction,
sizeof(packet.transaction) + sizeof(nostromoTransferShareManagementRights_input) + SIGNATURE_SIZE,
digest,
32); // recompute digest for txhash
getTxHashFromDigest(digest, txHash);
LOG("nostromoTransferShareManagementRights tx has been sent!\n");
printReceipt(packet.transaction, txHash, nullptr);
LOG("run ./qubic-cli [...] -checktxontick %u %s\n", currentTick + scheduledTickOffset, txHash);
LOG("to check your tx confirmation status\n");
}
void getStats(const char* nodeIp, int nodePort)
{
auto qc = make_qc(nodeIp, nodePort);
#pragma pack(push, 1)
struct {
RequestResponseHeader header;
RequestContractFunction rcf;
} packet;