-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcoinbase.cpp
1334 lines (1224 loc) · 49.3 KB
/
coinbase.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
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
// http://www.righto.com/2014/02/bitcoin-mining-hard-way-algorithms.html
// https://en.bitcoin.it/wiki/Merged_mining_specification#Merged_mining_coinbase
#include "stratum.h"
#define TX_VALUE(v, s) ((unsigned int)(v>>s)&0xff)
static void encode_tx_value(char *encoded, json_int_t value)
{
sprintf(encoded, "%02x%02x%02x%02x%02x%02x%02x%02x",
TX_VALUE(value, 0), TX_VALUE(value, 8), TX_VALUE(value, 16), TX_VALUE(value, 24),
TX_VALUE(value, 32), TX_VALUE(value, 40), TX_VALUE(value, 48), TX_VALUE(value, 56));
}
static void p2sh_pack_tx(YAAMP_COIND *coind, char *data, json_int_t amount, char *payee)
{
char evalue[32];
char coinb2_part[256];
char coinb2_len[4];
sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(payee) >> 1) & 0xFF, payee);
sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF);
encode_tx_value(evalue, amount);
strcat(data, evalue);
strcat(data, coinb2_len);
strcat(data, coinb2_part);
}
static void script_pack_tx(YAAMP_COIND *coind, char *data, json_int_t amount, const char *script)
{
char evalue[32];
char coinb2_part[256];
char coinb2_len[4];
encode_tx_value(evalue, amount);
sprintf(coinb2_part, "%s", script);
sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF);
strcat(data, evalue);
strcat(data, coinb2_len);
strcat(data, coinb2_part);
}
static void job_pack_tx(YAAMP_COIND *coind, char *data, json_int_t amount, char *key)
{
int ol = strlen(data);
char evalue[32];
if(coind->p2sh_address && !key) {
p2sh_pack_tx(coind, data, amount, coind->script_pubkey);
return;
}
encode_tx_value(evalue, amount);
sprintf(data+strlen(data), "%s", evalue);
if(coind->pos && !key)
sprintf(data+strlen(data), "2321%sac", coind->pubkey);
else
sprintf(data+strlen(data), "1976a914%s88ac", key? key: coind->script_pubkey);
// debuglog("pack tx %s\n", data+ol);
// debuglog("pack tx %lld\n", amount);
}
void coinbase_aux(YAAMP_JOB_TEMPLATE *templ, char *aux_script)
{
vector<string> hashlist = coind_aux_hashlist(templ->auxs, templ->auxs_size);
while(hashlist.size() > 1)
{
vector<string> l;
for(int i = 0; i < hashlist.size()/2; i++)
{
string s = hashlist[i*2] + hashlist[i*2+1];
char bin[YAAMP_HASHLEN_BIN*2];
char out[YAAMP_HASHLEN_STR];
binlify((unsigned char *)bin, s.c_str());
sha256_double_hash_hex(bin, out, YAAMP_HASHLEN_BIN*2);
l.push_back(out);
}
hashlist = l;
}
char merkle_hash[4*1024];
memset(merkle_hash, 0, 4*1024);
string_be(hashlist[0].c_str(), merkle_hash);
sprintf(aux_script+strlen(aux_script), "fabe6d6d%s%02x00000000000000", merkle_hash, templ->auxs_size);
// debuglog("aux_script is %s\n", aux_script);
}
void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value *json_result)
{
char eheight[32], etime[32];
char entime[32] = { 0 };
char commitment[128] = { 0 };
ser_number(templ->height, eheight);
ser_number(time(NULL), etime);
if(coind->pos) ser_string_be(templ->ntime, entime, 1);
char eversion1[32] = "01000000";
if(coind->txmessage)
strcpy(eversion1, "02000000");
const char *coinbase_payload = json_get_string(json_result, "coinbase_payload");
if(coinbase_payload && strlen(coinbase_payload) > 0)
strcpy(eversion1, "03000500");
char script1[4*1024];
sprintf(script1, "%s%s%s08", eheight, templ->flags, etime);
char script2[32] = "7969696d7000"; // "yiimp\0" in hex ascii
if(!coind->pos && !coind->isaux && templ->auxs_size)
coinbase_aux(templ, script2);
int script_len = strlen(script1)/2 + strlen(script2)/2 + 8;
sprintf(templ->coinb1, "%s%s01"
"0000000000000000000000000000000000000000000000000000000000000000"
"ffffffff%02x%s", eversion1, entime, script_len, script1);
sprintf(templ->coinb2, "%s00000000", script2);
// segwit commitment, if needed
if (templ->has_segwit_txs)
sprintf(commitment, "0000000000000000%02x%s", (int) (strlen(coind->commitment)/2), coind->commitment);
json_int_t available = templ->value;
// sample coins using mandatory dev/foundation fees
if(strcmp(coind->symbol, "EGC") == 0) {
if (coind->charity_percent <= 0)
coind->charity_percent = 2;
if (strlen(coind->charity_address) == 0)
sprintf(coind->charity_address, "EdFwYw4Mo2Zq6CFM2yNJgXvE2DTJxgdBRX");
}
else if(strcmp(coind->symbol, "DYN") == 0)
{
char script_dests[2048] = { 0 };
char script_payee[128] = { 0 };
char payees[3];
int npayees = (templ->has_segwit_txs) ? 2 : 1;
bool dynode_enabled;
dynode_enabled = json_get_bool(json_result, "dynode_payments_enforced");
bool superblocks_enabled = json_get_bool(json_result, "superblocks_enabled");
json_value* superblock = json_get_array(json_result, "superblock");
json_value* dynode;
dynode = json_get_object(json_result, "dynode");
if(!dynode && json_get_bool(json_result, "dynode_payments")) {
coind->oldmasternodes = true;
debuglog("%s is using old dynodes rpc keys\n", coind->symbol);
return;
}
if(superblocks_enabled && superblock) {
for(int i = 0; i < superblock->u.array.length; i++) {
const char *payee = json_get_string(superblock->u.array.values[i], "payee");
json_int_t amount = json_get_int(superblock->u.array.values[i], "amount");
if (payee && amount) {
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
//debuglog("%s superblock found %s %u\n", coind->symbol, payee, amount);
}
}
}
if (dynode_enabled && dynode) {
bool started;
started = json_get_bool(json_result, "dynode_payments_started");
const char *payee = json_get_string(dynode, "payee");
json_int_t amount = json_get_int(dynode, "amount");
if (!payee)
debuglog("coinbase_create failed to get Dynode payee\n");
if (!amount)
debuglog("coinbase_create failed to get Dynode amount\n");
if (!started)
debuglog("coinbase_create failed to get Dynode started\n");
if (payee && amount && started) {
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
//debuglog("%s dynode found %s %u\n", coind->symbol, payee, amount);
}
}
sprintf(payees, "%02x", npayees);
strcat(templ->coinb2, payees);
if (templ->has_segwit_txs) strcat(templ->coinb2, commitment);
strcat(templ->coinb2, script_dests);
job_pack_tx(coind, templ->coinb2, available, NULL);
strcat(templ->coinb2, "00000000"); // locktime
coind->reward = (double)available/100000000*coind->reward_mul;
//debuglog("%s %d dests %s\n", coind->symbol, npayees, script_dests);
return;
}
else if(strcmp(coind->symbol, "IDX") == 0)
{
char script_dests[2048] = { 0 };
char script_payee[128] = { 0 };
char payees[3];
int npayees = (templ->has_segwit_txs) ? 2 : 1;
json_value* indexnode;
indexnode = json_get_object(json_result, "indexnode");
if(!indexnode && json_get_bool(json_result, "indexnode_payments")) {
coind->oldmasternodes = true;
debuglog("%s is using old indexnodes rpc keys\n", coind->symbol);
return;
}
if (indexnode) {
bool started;
started = json_get_bool(json_result, "indexnode_payments_started");
const char *payee = json_get_string(indexnode, "payee");
json_int_t amount = json_get_int(indexnode, "amount");
if (!payee)
debuglog("coinbase_create failed to get Indexnode payee\n");
if (!amount)
debuglog("coinbase_create failed to get Indexnode amount\n");
if (!started)
debuglog("coinbase_create failed to get Indexnode started\n");
if (payee && amount && started) {
npayees++;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
//debuglog("%s indexnode found %s %u\n", coind->symbol, payee, amount);
}
}
sprintf(payees, "%02x", npayees);
strcat(templ->coinb2, payees);
if (templ->has_segwit_txs) strcat(templ->coinb2, commitment);
strcat(templ->coinb2, script_dests);
job_pack_tx(coind, templ->coinb2, available, NULL);
strcat(templ->coinb2, "00000000"); // locktime
coind->reward = (double)available/100000000*coind->reward_mul;
//debuglog("%s %d dests %s\n", coind->symbol, npayees, script_dests);
return;
}
else if(strcmp(coind->symbol, "VGC") == 0)
{
char script_dests[2048] = { 0 };
char script_payee[128] = { 0 };
char payees[3];
int npayees = (templ->has_segwit_txs) ? 2 : 1;
json_value* fivegnode;
fivegnode = json_get_object(json_result, "fivegnode");
if(!fivegnode&& json_get_bool(json_result, "fivegnode_payments")) {
coind->oldmasternodes = true;
debuglog("%s is using old indexnodes rpc keys\n", coind->symbol);
return;
}
if (fivegnode) {
bool started;
started = json_get_bool(json_result, "fivegnode_payments_started");
const char *payee = json_get_string(fivegnode, "payee");
json_int_t amount = json_get_int(fivegnode, "amount");
if (!payee)
//debuglog("coinbase_create failed to get Fivegnode payee\n");
if (!amount)
//debuglog("coinbase_create failed to get Fivegnode amount\n");
if (!started)
//debuglog("coinbase_create failed to get Fivegnode started\n");
if (payee && amount && started) {
npayees++;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
debuglog("%s fivegnode found %s %u\n", coind->symbol, payee, amount);
}
}
sprintf(payees, "%02x", npayees);
strcat(templ->coinb2, payees);
if (templ->has_segwit_txs) strcat(templ->coinb2, commitment);
strcat(templ->coinb2, script_dests);
job_pack_tx(coind, templ->coinb2, available, NULL);
strcat(templ->coinb2, "00000000"); // locktime
coind->reward = (double)available/100000000*coind->reward_mul;
//debuglog("%s %d dests %s\n", coind->symbol, npayees, script_dests);
return;
}
else if(strcmp(coind->symbol, "LTCR") == 0) {
if (coind->charity_percent <= 0)
coind->charity_percent = 10;
if (strlen(coind->charity_address) == 0)
sprintf(coind->charity_address, "BCDrF1hWdKTmrjXXVFTezPjKBmGigmaXg5");
}
else if(strcmp(coind->symbol, "GEEK") == 0) {
if (coind->charity_percent <= 0)
coind->charity_percent = 2.5;
if (strlen(coind->charity_address) == 0)
sprintf(coind->charity_address, "GRpdbSh3Z2FMjJH96CFPK5TzEb47Zg6FFR");
}
else if(strcmp(coind->symbol, "XZC") == 0) {
char script_payee[1024];
bool znode_masternode_enabled = json_get_bool(json_result, "znode_payments_started");
if (znode_masternode_enabled == true) {
json_value* znode_masternode = json_get_object(json_result, "znode");
const char *payee = json_get_string(znode_masternode, "payee");
json_int_t amount = json_get_int(znode_masternode, "amount");
if (payee && amount) {
//debuglog("znode payee: %s\n", payee);
strcat(templ->coinb2, "06");
job_pack_tx(coind, templ->coinb2, available, NULL);
base58_decode(payee, script_payee);
job_pack_tx(coind, templ->coinb2, amount, script_payee);
}
} else {
strcat(templ->coinb2, "06");
job_pack_tx(coind, templ->coinb2, available, NULL);
}
base58_decode("aCAgTPgtYcA4EysU4UKC86EQd5cTtHtCcr", script_payee);
job_pack_tx(coind, templ->coinb2, 1 * 100000000, script_payee);
base58_decode("aHu897ivzmeFuLNB6956X6gyGeVNHUBRgD", script_payee);
job_pack_tx(coind, templ->coinb2, 1 * 100000000, script_payee);
base58_decode("aQ18FBVFtnueucZKeVg4srhmzbpAeb1KoN", script_payee);
job_pack_tx(coind, templ->coinb2, 1 * 100000000, script_payee);
base58_decode("a1HwTdCmQV3NspP2QqCGpehoFpi8NY4Zg3", script_payee);
job_pack_tx(coind, templ->coinb2, 3 * 100000000, script_payee);
base58_decode("a1kCCGddf5pMXSipLVD9hBG2MGGVNaJ15U", script_payee);
job_pack_tx(coind, templ->coinb2, 1 * 100000000, script_payee);
strcat(templ->coinb2, "00000000"); // locktime
coind->reward = (double)available/100000000*coind->reward_mul;
return;
}
else if(strcmp("DCR", coind->rpcencoding) == 0) {
coind->reward_mul = 6; // coinbase value is wrong, reward_mul should be 6
coind->charity_percent = 0;
coind->charity_amount = available;
available *= coind->reward_mul;
if (strlen(coind->charity_address) == 0 && !strcmp(coind->symbol, "DCR"))
sprintf(coind->charity_address, "Dcur2mcGjmENx4DhNqDctW5wJCVyT3Qeqkx");
}
// THIS CODE FOR SMART IS NOT WORKING YET AND NEEDS WORK. BLOCKS GET REJECTED WITH MESSAGE NO FOUNDER REWARDS.
else if (strcmp(coind->symbol, "SMART") == 0) {
char script_payee[512] = { 0 };
char payees[5];
int npayees = (templ->has_segwit_txs) ? 2 : 1;
bool masternode_payments = json_get_bool(json_result, "masternode_payments");
bool masternodes_enabled = json_get_bool(json_result, "enforce_masternode_payments");
if (masternodes_enabled && masternode_payments) {
const char *payee = json_get_string(json_result, "payee");
json_int_t amount = json_get_int(json_result, "payee_amount");
if (payee && amount)
++npayees;
}
//treasury 5000 * (143500/Blockheight) per block
int coinvalue = floor(0.5+((double)(5000 * 143500)/(templ->height +1)));
json_int_t charity_amount = coinvalue * 0.95;
int blockRotation = templ->height - 95 * (templ->height/95);
if (blockRotation >= 0 && blockRotation <= 7) {
sprintf(coind->charity_address, "Siim7T5zMH3he8xxtQzhmHs4CQSuMrCV1M");
}
if (blockRotation >= 8 && blockRotation <= 15) {
sprintf(coind->charity_address, "SW2FbVaBhU1Www855V37auQzGQd8fuLR9x");
}
if (blockRotation >= 16 && blockRotation <= 23) {
sprintf(coind->charity_address, "SPusYr5tUdUyRXevJg7pnCc9Sm4HEzaYZF");
}
if (blockRotation >= 24 && blockRotation <= 38) {
sprintf(coind->charity_address, "SU5bKb35xUV8aHG5dNarWHB3HBVjcCRjYo");
}
if (blockRotation >= 39 && blockRotation <= 94) {
sprintf(coind->charity_address, "SXun9XDHLdBhG4Yd1ueZfLfRpC9kZgwT1b");
}
++npayees;
available -= charity_amount;
base58_decode(coind->charity_address, script_payee);
sprintf(payees, "%02x", npayees);
strcat(templ->coinb2, payees);
if (templ->has_segwit_txs) strcat(templ->coinb2, commitment);
char echarity_amount[32];
encode_tx_value(echarity_amount, charity_amount);
strcat(templ->coinb2, echarity_amount);
char coinb2_part[1024] = { 0 };
char coinb2_len[3] = { 0 };
sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(script_payee) >> 1) & 0xFF, script_payee);
sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF);
strcat(templ->coinb2, coinb2_len);
strcat(templ->coinb2, coinb2_part);
if (masternodes_enabled && masternode_payments) {
//duplicated: revisit ++todo
const char *payee = json_get_string(json_result, "payee");
json_int_t amount = json_get_int(json_result, "payee_amount");
if (payee && amount) {
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, templ->coinb2, amount, script_payee);
}
}
job_pack_tx(coind, templ->coinb2, available, NULL);
strcat(templ->coinb2, "00000000"); // locktime
coind->reward = (double)available / 100000000 * coind->reward_mul;
return;
}
else if(strcmp(coind->symbol, "HXX") == 0) {
char script_payee[1024];
bool znode_masternode_enabled = json_get_bool(json_result, "xnode_payments_started");
if (znode_masternode_enabled == true) {
json_value* znode_masternode = json_get_object(json_result, "xnode");
const char *payee = json_get_string(znode_masternode, "payee");
json_int_t amount = json_get_int(znode_masternode, "amount");
if (payee && amount) {
//debuglog("bznode payee: %s\n", payee);
strcat(templ->coinb2, "06");
job_pack_tx(coind, templ->coinb2, available, NULL);
base58_decode(payee, script_payee);
job_pack_tx(coind, templ->coinb2, amount, script_payee);
}
} else {
strcat(templ->coinb2, "05");
job_pack_tx(coind, templ->coinb2, available, NULL);
}
base58_decode("HE7NSv3jevUAPjwsLGpoYSz9ftzV9S36Xq", script_payee);
job_pack_tx(coind, templ->coinb2, 0.1 * 100000000, script_payee);
base58_decode("HNdzbEtifr2nTd3VBvUWqJLc35ZFXr2EYo", script_payee);
job_pack_tx(coind, templ->coinb2, 0.1 * 100000000, script_payee);
base58_decode("HG1utYiVhkgBNz5ezrVpsjABxmMdVdcQe5", script_payee);
job_pack_tx(coind, templ->coinb2, 0.1 * 100000000, script_payee);
base58_decode("H94j1zMAbWwHWcEq8hUogAMALpVzj34M6Q", script_payee);
job_pack_tx(coind, templ->coinb2, 0.3 * 100000000, script_payee);
strcat(templ->coinb2, "00000000"); // locktime
coind->reward = (double)available/100000000*coind->reward_mul;
return;
}
else if(strcmp(coind->symbol, "BZX") == 0) {
char script_payee[1024];
bool znode_masternode_enabled = json_get_bool(json_result, "bznode_payments_started");
if (znode_masternode_enabled == true) {
json_value* znode_masternode = json_get_object(json_result, "bznode");
const char *payee = json_get_string(znode_masternode, "payee");
json_int_t amount = json_get_int(znode_masternode, "amount");
if (payee && amount) {
//debuglog("bznode payee: %s\n", payee);
strcat(templ->coinb2, "04");
job_pack_tx(coind, templ->coinb2, available, NULL);
base58_decode(payee, script_payee);
job_pack_tx(coind, templ->coinb2, amount, script_payee);
}
} else {
strcat(templ->coinb2, "03");
job_pack_tx(coind, templ->coinb2, available, NULL);
}
base58_decode("XWfdnGbXnBxeegrPJEvnYaNuwf6DXCruMX", script_payee);
job_pack_tx(coind, templ->coinb2, 6.75 * 100000000, script_payee);
base58_decode("XQ4WEZTFP83gVhhLBKavwopz7U84JucR8w", script_payee);
job_pack_tx(coind, templ->coinb2, 2.25 * 100000000, script_payee);
strcat(templ->coinb2, "00000000"); // locktime
coind->reward = (double)available/100000000*coind->reward_mul;
return;
}
else if(strcmp(coind->symbol, "STAK") == 0) {
char script_payee[512] = { 0 };
char payees[4];
int npayees = (templ->has_segwit_txs) ? 2 : 1;
bool masternode_payments = json_get_bool(json_result, "masternode_payments");
bool masternodes_enabled = json_get_bool(json_result, "enforce_masternode_payments");
if (masternodes_enabled && masternode_payments) {
const char *payee = json_get_string(json_result, "payee");
json_int_t amount = json_get_int(json_result, "payee_amount");
if (payee && amount)
++npayees;
}
//treasury 5% @ 10 STAK per block
json_int_t charity_amount = 50000000;
//testnet
//sprintf(coind->charity_address, "93ASJtDuVYVdKXemH9BrtSMscznvsp9stD");
switch (templ->height % 4) {
case 0: sprintf(coind->charity_address, "3K3bPrW5h7DYEMp2RcXawTCXajcm4ZU9Zh");
break;
case 1: sprintf(coind->charity_address, "33Ssxmn3ehVMgyxgegXhpLGSBpubPjLZQ6");
break;
case 2: sprintf(coind->charity_address, "3HFPNAjesiBY5sSVUmuBFnMEGut69R49ca");
break;
case 3: sprintf(coind->charity_address, "37jLjjfUXQU4bdqVzvpUXyzAqPQSmxyByi");
break;
}
++npayees;
available -= charity_amount;
base58_decode(coind->charity_address, script_payee);
sprintf(payees, "%02x", npayees);
strcat(templ->coinb2, payees);
if (templ->has_segwit_txs) strcat(templ->coinb2, commitment);
char echarity_amount[32];
encode_tx_value(echarity_amount, charity_amount);
strcat(templ->coinb2, echarity_amount);
char coinb2_part[1024] = { 0 };
char coinb2_len[3] = { 0 };
sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(script_payee) >> 1) & 0xFF, script_payee);
sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF);
strcat(templ->coinb2, coinb2_len);
strcat(templ->coinb2, coinb2_part);
if (masternodes_enabled && masternode_payments) {
//duplicated: revisit ++todo
const char *payee = json_get_string(json_result, "payee");
json_int_t amount = json_get_int(json_result, "payee_amount");
if (payee && amount) {
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, templ->coinb2, amount, script_payee);
}
}
job_pack_tx(coind, templ->coinb2, available, NULL);
strcat(templ->coinb2, "00000000"); // locktime
coind->reward = (double)available / 100000000 * coind->reward_mul;
return;
}
// 2 txs are required on these coins, one for foundation (dev fees)
if(coind->charity_percent && !coind->hasmasternodes)
{
char script_payee[1024];
char charity_payee[256] = { 0 };
const char *payee = json_get_string(json_result, "payee");
if (payee) snprintf(charity_payee, 255, "%s", payee);
else sprintf(charity_payee, "%s", coind->charity_address);
if (strlen(charity_payee) == 0)
stratumlog("ERROR %s has no charity_address set!\n", coind->name);
base58_decode(charity_payee, script_payee);
json_int_t charity_amount = json_get_int(json_result, "payee_amount");
if (charity_amount <= 0)
charity_amount = (available * coind->charity_percent) / 100;
available -= charity_amount;
coind->charity_amount = charity_amount;
if (templ->has_segwit_txs) {
strcat(templ->coinb2, "03"); // 3 outputs (nulldata + fees + miner)
strcat(templ->coinb2, commitment);
} else {
strcat(templ->coinb2, "02");
}
job_pack_tx(coind, templ->coinb2, available, NULL);
job_pack_tx(coind, templ->coinb2, charity_amount, script_payee);
strcat(templ->coinb2, "00000000"); // locktime
coind->reward = (double)available/100000000*coind->reward_mul;
//debuglog("INFO %s block available %f, charity %f miner %f\n", coind->symbol,
// (double) available/1e8, (double) charity_amount/1e8, coind->reward);
return;
}
else if(coind->charity_amount && !strcmp("DCR", coind->rpcencoding))
{
stratumlog("ERROR %s should not use coinbase (getwork only)!\n", coind->symbol);
coind->reward = (double)available/100000000;
return;
}
// add IFX
if (strcmp(coind->symbol, "IFX") == 0)
{
char payees[4];
int npayees = 1;
char script_dests[4096] = { 0 };
//
json_value* founderreward = json_get_array(json_result, "founderreward");
if (founderreward)
{
const char *payee = json_get_string(founderreward, "founderpayee");
json_int_t amount = json_get_int(founderreward, "amount");
if (payee && amount)
{
char script_payee[128] = { 0 };
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
}
}
json_value* masternode = json_get_object(json_result, "masternode");
bool masternode_enabled = json_get_bool(json_result, "masternode_payments_enforced");
if (masternode_enabled && masternode)
{
bool started = json_get_bool(json_result, "masternode_payments_started");
const char *payee = json_get_string(masternode, "payee");
json_int_t amount = json_get_int(masternode, "amount");
if (started && payee && amount) {
char script_payee[128] = { 0 };
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
}
}
sprintf(payees, "%02x", npayees);
strcat(templ->coinb2, payees);
strcat(templ->coinb2, script_dests);
job_pack_tx(coind, templ->coinb2, available, NULL);
strcat(templ->coinb2, "00000000"); // locktime
coind->reward = (double)available / 100000000 * coind->reward_mul;
return;
}
// add GTM
if (strcmp(coind->symbol, "GTM") == 0)
{
char payees[4];
int npayees = 1;
char script_dests[4096] = { 0 };
//
json_value* founderreward = json_get_array(json_result, "founderreward");
if (founderreward)
{
const char *payee = json_get_string(founderreward, "founderpayee");
json_int_t amount = json_get_int(founderreward, "amount");
if (payee && amount)
{
char script_payee[128] = { 0 };
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
}
}
json_value* masternode = json_get_object(json_result, "masternode");
bool masternode_enabled = json_get_bool(json_result, "masternode_payments_enforced");
if (masternode_enabled && masternode)
{
bool started = json_get_bool(json_result, "masternode_payments_started");
const char *payee = json_get_string(masternode, "payee");
json_int_t amount = json_get_int(masternode, "amount");
if (started && payee && amount) {
char script_payee[128] = { 0 };
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
}
}
sprintf(payees, "%02x", npayees);
strcat(templ->coinb2, payees);
strcat(templ->coinb2, script_dests);
job_pack_tx(coind, templ->coinb2, available, NULL);
strcat(templ->coinb2, "00000000"); // locktime
coind->reward = (double)available / 100000000 * coind->reward_mul;
return;
}
// add AGM
if (strcmp(coind->symbol, "AGM") == 0)
{
char payees[4];
int npayees = 1;
char script_dests[4096] = { 0 };
//
json_value* founderreward = json_get_array(json_result, "founderreward");
if (founderreward)
{
const char *payee = json_get_string(founderreward, "founderpayee");
json_int_t amount = json_get_int(founderreward, "amount");
if (payee && amount)
{
char script_payee[128] = { 0 };
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
}
}
json_value* masternode = json_get_object(json_result, "masternode");
bool masternode_enabled = json_get_bool(json_result, "masternode_payments_enforced");
if (masternode_enabled && masternode)
{
bool started = json_get_bool(json_result, "masternode_payments_started");
const char *payee = json_get_string(masternode, "payee");
json_int_t amount = json_get_int(masternode, "amount");
if (started && payee && amount) {
char script_payee[128] = { 0 };
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
}
}
sprintf(payees, "%02x", npayees);
strcat(templ->coinb2, payees);
strcat(templ->coinb2, script_dests);
job_pack_tx(coind, templ->coinb2, available, NULL);
strcat(templ->coinb2, "00000000"); // locktime
coind->reward = (double)available / 100000000 * coind->reward_mul;
return;
}
// CRDS rename to BCRS
if (strcmp(coind->symbol, "BCRS") == 0)
{
char payees[4];
int npayees = 1;
char script_dests[4096] = { 0 };
json_value* masternode = json_get_object(json_result, "masternode");
bool masternode_started = json_get_bool(json_result, "masternode_payments_started");
if (masternode_started && masternode)
{
const char *payee = json_get_string(masternode, "payee");
json_int_t amount = json_get_int(masternode, "amount");
if (payee && amount) {
char script_payee[128] = { 0 };
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
}
}
json_value* fund_reward = json_get_array(json_result, "fundreward");
if (fund_reward)
{
const char *fund_payee = json_get_string(fund_reward, "payee");
json_int_t fund_amount = json_get_int(fund_reward, "amount");
if (fund_payee && fund_amount)
{
char fund_script_payee[128] = { 0 };
npayees++;
available -= fund_amount;
base58_decode(fund_payee, fund_script_payee);
job_pack_tx(coind, script_dests, fund_amount, fund_script_payee);
}
}
sprintf(payees, "%02x", npayees);
strcat(templ->coinb2, payees);
strcat(templ->coinb2, script_dests);
job_pack_tx(coind, templ->coinb2, available, NULL);
strcat(templ->coinb2, "00000000"); // locktime
coind->reward = (double)available / 100000000 * coind->reward_mul;
return;
}
// add BMN
if (strcmp(coind->symbol, "BMN") == 0)
{
char payees[4];
int npayees = 1;
char script_dests[4096] = { 0 };
//
json_value* founderreward = json_get_array(json_result, "founderreward");
if (founderreward)
{
const char *payee = json_get_string(founderreward, "founderpayee");
json_int_t amount = json_get_int(founderreward, "amount");
if (payee && amount)
{
char script_payee[128] = { 0 };
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
}
}
json_value* masternode = json_get_object(json_result, "masternode");
bool masternode_enabled = json_get_bool(json_result, "masternode_payments_enforced");
if (masternode_enabled && masternode)
{
bool started = json_get_bool(json_result, "masternode_payments_started");
const char *payee = json_get_string(masternode, "payee");
json_int_t amount = json_get_int(masternode, "amount");
if (started && payee && amount) {
char script_payee[128] = { 0 };
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
}
}
sprintf(payees, "%02x", npayees);
strcat(templ->coinb2, payees);
strcat(templ->coinb2, script_dests);
job_pack_tx(coind, templ->coinb2, available, NULL);
strcat(templ->coinb2, "00000000"); // locktime
coind->reward = (double)available / 100000000 * coind->reward_mul;
return;
}
//Add BNODE
if (strcmp(coind->symbol, "BNODE") == 0)
{
char script_dests[4096] = { 0 };
char script_payee[128] = { 0 };
char payees[4];
int npayees = 1;
json_value* evolution = json_get_object(json_result, "evolution");
bool evolution_enabled = json_get_bool(json_result, "evolution_payments_enforced");
bool evolution_started = json_get_bool(json_result, "evolution_payments_started");
if (evolution_enabled && evolution && evolution_started) {
if (json_is_array(evolution)) {
for(int i = 0; i < evolution->u.array.length; i++) {
const char *payee = json_get_string(evolution->u.array.values[i], "payee");
const char *script = json_get_string(evolution->u.array.values[i], "script");
json_int_t amount = json_get_int(evolution->u.array.values[i], "amount");
if (!amount) continue;
if (script) {
npayees++;
available -= amount;
script_pack_tx(coind, script_dests, amount, script);
} else if (payee) {
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
//debuglog("%s evolution %s %u\n", coind->symbol, payee, amount);
}
}
} else {
const char *payee = json_get_string(evolution, "payee");
json_int_t amount = json_get_int(evolution, "amount");
if (payee && amount) {
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
}
}
}
json_value* masternode = json_get_object(json_result, "masternode");
bool started = json_get_bool(json_result, "masternode_payments_started");
if (masternode && started) {
if (json_is_array(masternode)) {
for(int i = 0; i < masternode->u.array.length; i++) {
const char *payee = json_get_string(masternode->u.array.values[i], "payee");
const char *script = json_get_string(masternode->u.array.values[i], "script");
json_int_t amount = json_get_int(masternode->u.array.values[i], "amount");
if (!amount) continue;
if (script) {
npayees++;
available -= amount;
script_pack_tx(coind, script_dests, amount, script);
} else if (payee) {
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
//debuglog("%s masternode %s %u\n", coind->symbol, payee, amount);
}
}
} else {
const char *payee = json_get_string(masternode, "payee");
json_int_t amount = json_get_int(masternode, "amount");
if (payee && amount) {
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
}
}
}
sprintf(payees, "%02x", npayees);
strcat(templ->coinb2, payees);
strcat(templ->coinb2, script_dests);
job_pack_tx(coind, templ->coinb2, available, NULL);
strcat(templ->coinb2, "00000000"); // locktime
coind->reward = (double)available / 100000000 * coind->reward_mul;
return;
}
//add GLT
else if(strcmp(coind->symbol, "GLT") == 0)
{
char script_dests[2048] = { 0 };
char script_payee[128] = { 0 };
char script_treasury[128] = { 0 };
char payees[4];
int npayees = 1;
bool masternode_enabled = json_get_bool(json_result, "masternode_payments_enforced");
json_value* masternode = json_get_object(json_result, "masternode");
json_value* treasury = json_get_object(json_result, "treasury");
bool treasury_enabled = true;
if(treasury_enabled && treasury) {
const char *scriptPubKey = json_get_string(treasury, "scriptPubKey");
json_int_t amount = json_get_int(treasury, "amount");
if (scriptPubKey && amount) {
npayees++;
available -= amount;
base58_decode(scriptPubKey, script_treasury);
job_pack_tx(coind, script_dests, amount, script_treasury);
//debuglog("%s treasury %u\n", coind->symbol, amount);
}
}
if (masternode_enabled && masternode) {
const char *payee = json_get_string(masternode, "payee");
json_int_t amount = json_get_int(masternode, "amount");
if (payee && amount) {
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
}
}
sprintf(payees, "%02x", npayees);
strcat(templ->coinb2, payees);
strcat(templ->coinb2, script_dests);
job_pack_tx(coind, templ->coinb2, available, NULL);
strcat(templ->coinb2, "00000000"); // locktime
coind->reward = (double)available/100000000*coind->reward_mul;
//debuglog("%s %d dests %s\n", coind->symbol, npayees, script_dests);
return;
}
// Add Sinovate[SIN]
if(strcmp(coind->symbol, "SIN") == 0)
{
int npayees = 1;
char payees[2];
char sinpayee[256] = {0};
char sinscript[1024] = {0};
char devpayee[256] = {0};
char devscript[1024] = {0};
const char *devpayaddr = json_get_string(json_result, "payee");
json_int_t devfee_amount = json_get_int(json_result, "payee_amount");
snprintf(devpayee, 255, "%s", devpayaddr);
base58_decode(devpayee, devscript);
npayees++;
available -= devfee_amount;
const char* mnpayaddrs[7] = {0};
json_value* masternodes = json_get_array(json_result, "masternode");
json_int_t mnamounts[7] = {0};
for(int i = 0; i < masternodes->u.array.length; i++) {
mnpayaddrs[i] = json_get_string(masternodes->u.array.values[i], "payee");
mnamounts[i] = json_get_int(masternodes->u.array.values[i], "amount");
available -= mnamounts[i];
npayees++;
}
sprintf(payees, "%02x", npayees);
strcat(templ->coinb2, payees);
job_pack_tx(coind, templ->coinb2, available, NULL);
job_pack_tx(coind, templ->coinb2, devfee_amount, devscript);
for(int i = 0; i < masternodes->u.array.length; i++) {
snprintf(sinpayee, 255, "%s", mnpayaddrs[i]);
base58_decode(sinpayee, sinscript);
job_pack_tx(coind, templ->coinb2, mnamounts[i], sinscript);
}
strcat(templ->coinb2, "00000000");
coind->reward = (double)available/100000000;
return;
}
if(strcmp(coind->symbol, "BITC") == 0)
{
char *params = (char *)malloc(1024);
if (params) {
sprintf(params, "[\"%s\", %i]", coind->wallet, templ->height);
//std::cout << "Params:" << params << std::endl;
json_value *json = rpc_call(&coind->rpc, "createcoinbaseforaddress", params);
free(params);
if (json) {
json_value *json_result = json_get_object(json, "result");
if (json_result) {
sprintf(templ->coinb1, "%s", json_get_string(json_result, "coinbasepart1"));
templ->coinb1[strlen(templ->coinb1) - 16] = '\0';
sprintf(templ->coinb2, "%s", json_get_string(json_result, "coinbasepart2"));
}
}
}
return;
}
if(strcmp(coind->symbol, "XVC") == 0)
{
char charity_payee[256];
json_value* incentive = json_get_object(json_result, "incentive");
if (incentive) {
const char* payee = json_get_string(incentive, "address");
if (payee) snprintf(charity_payee, 255, "%s", payee);
else sprintf(charity_payee, "%s", coind->charity_address);
bool enforced = json_get_bool(incentive, "enforced");