forked from m21/mastercore
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmastercore_tx.cpp
More file actions
769 lines (617 loc) · 23 KB
/
mastercore_tx.cpp
File metadata and controls
769 lines (617 loc) · 23 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
// Master Protocol transaction code
#include "base58.h"
#include "rpcserver.h"
#include "init.h"
#include "util.h"
#include "wallet.h"
#include "alert.h"
#include <stdint.h>
#include <string.h>
#include <map>
#include <fstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <boost/assign/list_of.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/find.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/format.hpp>
#include <boost/filesystem.hpp>
#include "json/json_spirit_utils.h"
#include "json/json_spirit_value.h"
#include "leveldb/db.h"
#include "leveldb/write_batch.h"
#include <openssl/sha.h>
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::int128_t;
using boost::multiprecision::cpp_int;
using namespace std;
using namespace boost;
using namespace boost::assign;
using namespace json_spirit;
using namespace leveldb;
#include "mastercore.h"
using namespace mastercore;
#include "mastercore_convert.h"
#include "mastercore_dex.h"
#include "mastercore_tx.h"
#include "mastercore_sp.h"
// initial packet interpret step
int CMPTransaction::step1()
{
if (PACKET_SIZE_CLASS_A > pkt_size) // class A could be 19 bytes
{
file_log("%s() ERROR PACKET TOO SMALL; size = %d, line %d, file: %s\n", __FUNCTION__, pkt_size, __LINE__, __FILE__);
return -(PKT_ERROR -1);
}
// collect version
memcpy(&version, &pkt[0], 2);
swapByteOrder16(version);
// blank out version bytes in the packet
pkt[0]=0; pkt[1]=0;
memcpy(&type, &pkt[0], 4);
swapByteOrder32(type);
file_log("version: %d, Class %s\n", version, !multi ? "A":"B");
file_log("\t type: %u (%s)\n", type, c_strMasterProtocolTXType(type));
return (type);
}
// extract alert info for alert packets
int CMPTransaction::step2_Alert(std::string *new_global_alert_message)
{
const char *p = 4 + (char *)&pkt;
std::vector<std::string>spstr;
char alertString[SP_STRING_FIELD_LEN];
// is sender authorized?
bool authorized = false;
if (
// TESTNET
(sender == "mpDex4kSX4iscrmiEQ8fBiPoyeTH55z23j") || // Michael
(sender == "mCraigAddress") || // Craig
(sender == "mpZATHupfCLqet5N1YL48ByCM1ZBfddbGJ") || // Zathras
// MAINNET
(sender == "1MicH2Vu4YVSvREvxW1zAx2XKo2GQomeXY") || // Michael
(sender == "16Zwbujf1h3v1DotKcn9XXt1m7FZn2o4mj") || // Craig
(sender == "1zAtHRASgdHvZDfHs6xJquMghga4eG7gy") || // Zathras
(sender == "1EXoDusjGwvnjZUyKkxZ4UHEf77z6A5S4P") // Exodus
//(sender=="1Anyone2Else3Who4Should5Be6Here") // Who else? JR? David? DexX?
) authorized = true;
if(!authorized)
{
// not authorized, ignore alert
file_log("\t alert auth: false\n");
return (PKT_ERROR -912);
}
else
{
// authorized, decode and make sure there are 4 tokens, then replace global_alert_message
spstr.push_back(std::string(p));
memcpy(alertString, spstr[0].c_str(), std::min(spstr[0].length(),sizeof(alertString)-1));
std::vector<std::string> vstr;
boost::split(vstr, alertString, boost::is_any_of(":"), token_compress_on);
file_log("\t alert auth: true\n");
file_log("\t alert sender: %s\n", sender);
if (5 != vstr.size())
{
// there are not 5 tokens in the alert, badly formed alert and must discard
file_log("\t packet error: badly formed alert != 5 tokens\n");
return (PKT_ERROR -911);
}
else
{
int32_t alertType;
uint64_t expiryValue;
uint32_t typeCheck;
uint32_t verCheck;
string alertMessage;
try
{
alertType = boost::lexical_cast<int32_t>(vstr[0]);
expiryValue = boost::lexical_cast<uint64_t>(vstr[1]);
typeCheck = boost::lexical_cast<uint32_t>(vstr[2]);
verCheck = boost::lexical_cast<uint32_t>(vstr[3]);
} catch (const boost::bad_lexical_cast &e)
{
file_log("DEBUG ALERT - error in converting values from global alert string\n");
return (PKT_ERROR -910); //(something went wrong)
}
alertMessage = vstr[4];
file_log("\t message type: %llu\n",alertType);
file_log("\t expiry value: %llu\n",expiryValue);
file_log("\t type check: %llu\n",typeCheck);
file_log("\t ver check: %llu\n",verCheck);
file_log("\t alert message: %s\n", alertMessage);
// copy the alert string into the global_alert_message and return a 0 rc
string message(alertString);
*new_global_alert_message=message;
// we have a new alert, fire a notify event if needed
CAlert::Notify(alertMessage, true);
return 0;
}
}
}
// extract Value for certain types of packets
int CMPTransaction::step2_Value()
{
memcpy(&nValue, &pkt[8], 8);
swapByteOrder64(nValue);
// here we are copying nValue into nNewValue to be stored into our leveldb later: MP_txlist
nNewValue = nValue;
memcpy(&property, &pkt[4], 4);
swapByteOrder32(property);
file_log("\t property: %u (%s)\n", property, strMPProperty(property));
file_log("\t value: %s\n", FormatMP(property, nValue));
if (MAX_INT_8_BYTES < nValue)
{
return (PKT_ERROR -801); // out of range
}
return 0;
}
// overrun check, are we beyond the end of packet?
bool CMPTransaction::isOverrun(const char *p, unsigned int line)
{
int now = (char *)p - (char *)&pkt;
bool bRet = (now > pkt_size);
if (bRet) file_log("%s(%sline=%u):now= %u, pkt_size= %u\n", __FUNCTION__, bRet ? "OVERRUN !!! ":"", line, now, pkt_size);
return bRet;
}
// extract Smart Property data
// RETURNS: the pointer to the next piece to be parsed
// ERROR is returns NULL and/or sets the error_code
const char *CMPTransaction::step2_SmartProperty(int &error_code)
{
const char *p = 11 + (char *)&pkt;
std::vector<std::string>spstr;
unsigned int i;
unsigned int prop_id;
error_code = 0;
memcpy(&ecosystem, &pkt[4], 1);
file_log("\t Ecosystem: %u\n", ecosystem);
// valid values are 1 & 2
if ((OMNI_PROPERTY_MSC != ecosystem) && (OMNI_PROPERTY_TMSC != ecosystem))
{
error_code = (PKT_ERROR_SP -501);
return NULL;
}
prop_id = _my_sps->peekNextSPID(ecosystem);
memcpy(&prop_type, &pkt[5], 2);
swapByteOrder16(prop_type);
memcpy(&prev_prop_id, &pkt[7], 4);
swapByteOrder32(prev_prop_id);
file_log("\t Property ID: %u (%s)\n", prop_id, strMPProperty(prop_id));
file_log("\t Property type: %u (%s)\n", prop_type, c_strPropertyType(prop_type));
file_log("\tPrev Property ID: %u\n", prev_prop_id);
// only 1 & 2 are valid right now
if ((MSC_PROPERTY_TYPE_INDIVISIBLE != prop_type) && (MSC_PROPERTY_TYPE_DIVISIBLE != prop_type))
{
error_code = (PKT_ERROR_SP -502);
return NULL;
}
for (i = 0; i<5; i++)
{
spstr.push_back(std::string(p));
p += spstr.back().size() + 1;
}
i = 0;
memcpy(category, spstr[i].c_str(), std::min(spstr[i].length(),sizeof(category)-1)); i++;
memcpy(subcategory, spstr[i].c_str(), std::min(spstr[i].length(),sizeof(subcategory)-1)); i++;
memcpy(name, spstr[i].c_str(), std::min(spstr[i].length(),sizeof(name)-1)); i++;
memcpy(url, spstr[i].c_str(), std::min(spstr[i].length(),sizeof(url)-1)); i++;
memcpy(data, spstr[i].c_str(), std::min(spstr[i].length(),sizeof(data)-1)); i++;
file_log("\t Category: %s\n", category);
file_log("\t Subcategory: %s\n", subcategory);
file_log("\t Name: %s\n", name);
file_log("\t URL: %s\n", url);
file_log("\t Data: %s\n", data);
if (!isTransactionTypeAllowed(block, prop_id, type, version))
{
error_code = (PKT_ERROR_SP -503);
return NULL;
}
// name can not be NULL
if ('\0' == name[0])
{
error_code = (PKT_ERROR_SP -505);
return NULL;
}
if (!p) error_code = (PKT_ERROR_SP -510);
if (isOverrun(p, __LINE__))
{
error_code = (PKT_ERROR_SP -800);
return NULL;
}
return p;
}
int CMPTransaction::step3_sp_fixed(const char *p)
{
if (!p) return (PKT_ERROR_SP -1);
memcpy(&nValue, p, 8);
swapByteOrder64(nValue);
p += 8;
// here we are copying nValue into nNewValue to be stored into our leveldb later: MP_txlist
nNewValue = nValue;
if (MSC_PROPERTY_TYPE_INDIVISIBLE == prop_type)
{
file_log("\t value: %lu\n", nValue);
if (0 == nValue) return (PKT_ERROR_SP -101);
}
else
if (MSC_PROPERTY_TYPE_DIVISIBLE == prop_type)
{
file_log("\t value: %lu.%08lu\n", nValue/COIN, nValue%COIN);
if (0 == nValue) return (PKT_ERROR_SP -102);
}
if (MAX_INT_8_BYTES < nValue)
{
return (PKT_ERROR -802); // out of range
}
if (isOverrun(p, __LINE__)) return (PKT_ERROR_SP -900);
return 0;
}
int CMPTransaction::step3_sp_variable(const char *p)
{
if (!p) return (PKT_ERROR_SP -1);
memcpy(&property, p, 4); // property desired
swapByteOrder32(property);
p += 4;
file_log("\t property: %u (%s)\n", property, strMPProperty(property));
memcpy(&nValue, p, 8);
swapByteOrder64(nValue);
p += 8;
// here we are copying nValue into nNewValue to be stored into our leveldb later: MP_txlist
nNewValue = nValue;
if (MSC_PROPERTY_TYPE_INDIVISIBLE == prop_type)
{
file_log("\t value: %lu\n", nValue);
if (0 == nValue) return (PKT_ERROR_SP -201);
}
else
if (MSC_PROPERTY_TYPE_DIVISIBLE == prop_type)
{
file_log("\t value: %lu.%08lu\n", nValue/COIN, nValue%COIN);
if (0 == nValue) return (PKT_ERROR_SP -202);
}
if (MAX_INT_8_BYTES < nValue)
{
return (PKT_ERROR -803); // out of range
}
memcpy(&deadline, p, 8);
swapByteOrder64(deadline);
p += 8;
file_log("\t Deadline: %s (%lX)\n", DateTimeStrFormat("%Y-%m-%d %H:%M:%S", deadline), deadline);
if (!deadline) return (PKT_ERROR_SP -203); // deadline cannot be 0
// deadline can not be smaller than the timestamp of the current block
if (deadline < (uint64_t)blockTime) return (PKT_ERROR_SP -204);
memcpy(&early_bird, p++, 1);
file_log("\tEarly Bird Bonus: %u\n", early_bird);
memcpy(&percentage, p++, 1);
file_log("\t Percentage: %u\n", percentage);
if (isOverrun(p, __LINE__)) return (PKT_ERROR_SP -765);
return 0;
}
void CMPTransaction::printInfo(FILE *fp)
{
fprintf(fp, "BLOCK: %d txid: %s, Block Time: %s\n", block, txid.GetHex().c_str(), DateTimeStrFormat("%Y-%m-%d %H:%M:%S", blockTime).c_str());
fprintf(fp, "sender: %s\n", sender.c_str());
}
int CMPTransaction::logicMath_TradeOffer(CMPOffer *obj_o)
{
int rc = PKT_ERROR_TRADEOFFER;
uint64_t amount_desired, min_fee;
unsigned char blocktimelimit, subaction = 0;
static const char * const subaction_name[] = { "empty", "new", "update", "cancel" };
if ((OMNI_PROPERTY_TMSC != property) && (OMNI_PROPERTY_MSC != property))
{
file_log("No smart properties allowed on the DeX...\n");
return PKT_ERROR_TRADEOFFER -72;
}
// block height checks, for instance DEX is only available on MSC starting with block 290630
if (!isTransactionTypeAllowed(block, property, type, version)) return -88888;
memcpy(&amount_desired, &pkt[16], 8);
memcpy(&blocktimelimit, &pkt[24], 1);
memcpy(&min_fee, &pkt[25], 8);
memcpy(&subaction, &pkt[33], 1);
swapByteOrder64(amount_desired);
swapByteOrder64(min_fee);
file_log("\t amount desired: %lu.%08lu\n", amount_desired / COIN, amount_desired % COIN);
file_log("\tblock time limit: %u\n", blocktimelimit);
file_log("\t min fee: %lu.%08lu\n", min_fee / COIN, min_fee % COIN);
file_log("\t sub-action: %u (%s)\n", subaction, subaction < sizeof(subaction_name)/sizeof(subaction_name[0]) ? subaction_name[subaction] : "");
if (obj_o)
{
obj_o->Set(amount_desired, min_fee, blocktimelimit, subaction);
return PKT_RETURNED_OBJECT;
}
// figure out which Action this is based on amount for sale, version & etc.
switch (version)
{
case MP_TX_PKT_V0:
if (0 != nValue)
{
if (!DEx_offerExists(sender, property))
{
rc = DEx_offerCreate(sender, property, nValue, block, amount_desired, min_fee, blocktimelimit, txid, &nNewValue);
}
else
{
rc = DEx_offerUpdate(sender, property, nValue, block, amount_desired, min_fee, blocktimelimit, txid, &nNewValue);
}
}
else
// what happens if nValue is 0 for V0 ? ANSWER: check if exists and it does -- cancel, otherwise invalid
{
if (DEx_offerExists(sender, property))
{
rc = DEx_offerDestroy(sender, property);
}
}
break;
case MP_TX_PKT_V1:
{
if (DEx_offerExists(sender, property))
{
if ((CANCEL != subaction) && (UPDATE != subaction))
{
file_log("%s() INVALID SELL OFFER -- ONE ALREADY EXISTS\n", __FUNCTION__);
rc = PKT_ERROR_TRADEOFFER -11;
break;
}
}
else
{
// Offer does not exist
if ((NEW != subaction))
{
file_log("%s() INVALID SELL OFFER -- UPDATE OR CANCEL ACTION WHEN NONE IS POSSIBLE\n", __FUNCTION__);
rc = PKT_ERROR_TRADEOFFER -12;
break;
}
}
switch (subaction)
{
case NEW:
rc = DEx_offerCreate(sender, property, nValue, block, amount_desired, min_fee, blocktimelimit, txid, &nNewValue);
break;
case UPDATE:
rc = DEx_offerUpdate(sender, property, nValue, block, amount_desired, min_fee, blocktimelimit, txid, &nNewValue);
break;
case CANCEL:
rc = DEx_offerDestroy(sender, property);
break;
default:
rc = (PKT_ERROR -999);
break;
}
break;
}
default:
rc = (PKT_ERROR -500); // neither V0 nor V1
break;
};
return rc;
}
int CMPTransaction::logicMath_AcceptOffer_BTC()
{
int rc = DEX_ERROR_ACCEPT;
// the min fee spec requirement is checked in the following function
rc = DEx_acceptCreate(sender, receiver, property, nValue, block, tx_fee_paid, &nNewValue);
return rc;
}
int CMPTransaction::logicMath_MetaDEx(CMPMetaDEx *mdex_o)
{
int rc = PKT_ERROR_METADEX -100;
unsigned char action = 0;
if (!isTransactionTypeAllowed(block, property, type, version)) return (PKT_ERROR_METADEX -888);
memcpy(&desired_property, &pkt[16], 4);
swapByteOrder32(desired_property);
memcpy(&desired_value, &pkt[20], 8);
swapByteOrder64(desired_value);
file_log("\tdesired property: %u (%s)\n", desired_property, strMPProperty(desired_property));
file_log("\t desired value: %s\n", FormatMP(desired_property, desired_value));
memcpy(&action, &pkt[28], 1);
file_log("\t action: %u\n", action);
if (mdex_o)
{
mdex_o->Set(sender, block, property, nValue, desired_property, desired_value, txid, tx_idx, action);
return PKT_RETURNED_OBJECT;
}
switch (action)
{
case ADD:
if (!isTransactionTypeAllowed(block, desired_property, type, version)) return (PKT_ERROR_METADEX -889);
// ensure we are not trading same property for itself
if (property == desired_property) return (PKT_ERROR_METADEX -5);
// ensure no cross-over of currencies from Test Eco to normal
if (isTestEcosystemProperty(property) != isTestEcosystemProperty(desired_property)) return (PKT_ERROR_METADEX -4);
// ensure the desired property exists in our universe
if (!_my_sps->hasSP(desired_property)) return (PKT_ERROR_METADEX -30);
if (!nValue) return (PKT_ERROR_METADEX -11);
if (!desired_value) return (PKT_ERROR_METADEX -12);
// ensure sufficient balance is available to offer
if (getMPbalance(sender, property, BALANCE) < (int64_t)nValue) return (PKT_ERROR_METADEX -567);
// Does the sender have any tokens?
if (0 >= nNewValue) return (PKT_ERROR_METADEX -3);
rc = MetaDEx_ADD(sender, property, nNewValue, block, desired_property, desired_value, txid, tx_idx);
break;
case CANCEL_AT_PRICE:
// ensure the 4 necessary parameters for this command are provided
// TODO
// ...
rc = MetaDEx_CANCEL_AT_PRICE(txid, block, sender, property, nNewValue, desired_property, desired_value);
break;
case CANCEL_ALL_FOR_PAIR:
// ensure the 2 necessary parameters for this command are provided
// TODO
// ...
rc = MetaDEx_CANCEL_ALL_FOR_PAIR(txid, block, sender, property, desired_property);
break;
case CANCEL_EVERYTHING:
rc = MetaDEx_CANCEL_EVERYTHING(txid, block, sender);
break;
default:
return (PKT_ERROR_METADEX -999);
}
return rc;
}
int CMPTransaction::logicMath_GrantTokens()
{
int rc = PKT_ERROR_TOKENS - 1000;
if (!isTransactionTypeAllowed(block, property, type, version)) {
file_log("\tRejecting Grant: Transaction type not yet allowed\n");
return (PKT_ERROR_TOKENS - 22);
}
if (sender.empty()) {
file_log("\tRejecting Grant: Sender is empty\n");
return (PKT_ERROR_TOKENS - 23);
}
// manual issuance check
if (false == _my_sps->hasSP(property)) {
file_log("\tRejecting Grant: SP id:%u does not exist\n", property);
return (PKT_ERROR_TOKENS - 24);
}
CMPSPInfo::Entry sp;
_my_sps->getSP(property, sp);
if (false == sp.manual) {
file_log("\tRejecting Grant: SP id:%u was not issued with a TX 54\n", property);
return (PKT_ERROR_TOKENS - 25);
}
// issuer check
if (false == boost::iequals(sender, sp.issuer)) {
file_log("\tRejecting Grant: %s is not the issuer of SP id: %u\n", sender, property);
return (PKT_ERROR_TOKENS - 26);
}
// overflow tokens check
if (MAX_INT_8_BYTES - sp.num_tokens < nValue) {
char prettyTokens[256];
if (sp.isDivisible()) {
snprintf(prettyTokens, 256, "%lu.%08lu", nValue / COIN, nValue % COIN);
} else {
snprintf(prettyTokens, 256, "%lu", nValue);
}
file_log("\tRejecting Grant: granting %s tokens on SP id:%u would overflow the maximum limit for tokens in a smart property\n", prettyTokens, property);
return (PKT_ERROR_TOKENS - 27);
}
// grant the tokens
update_tally_map(sender, property, nValue, BALANCE);
// call the send logic
rc = logicMath_SimpleSend();
// record this grant
std::vector<uint64_t> dataPt;
dataPt.push_back(nValue);
dataPt.push_back(0);
string txidStr = txid.ToString();
sp.historicalData.insert(std::make_pair(txidStr, dataPt));
sp.update_block = chainActive[block]->GetBlockHash();
_my_sps->updateSP(property, sp);
return rc;
}
int CMPTransaction::logicMath_RevokeTokens()
{
int rc = PKT_ERROR_TOKENS - 1000;
if (!isTransactionTypeAllowed(block, property, type, version)) {
file_log("\tRejecting Revoke: Transaction type not yet allowed\n");
return (PKT_ERROR_TOKENS - 22);
}
if (sender.empty()) {
file_log("\tRejecting Revoke: Sender is empty\n");
return (PKT_ERROR_TOKENS - 23);
}
// manual issuance check
if (false == _my_sps->hasSP(property)) {
file_log("\tRejecting Revoke: SP id:%d does not exist\n", property);
return (PKT_ERROR_TOKENS - 24);
}
CMPSPInfo::Entry sp;
_my_sps->getSP(property, sp);
if (false == sp.manual) {
file_log("\tRejecting Revoke: SP id:%d was not issued with a TX 54\n", property);
return (PKT_ERROR_TOKENS - 25);
}
// insufficient funds check and revoke
if (false == update_tally_map(sender, property, -nValue, BALANCE)) {
file_log("\tRejecting Revoke: insufficient funds\n");
return (PKT_ERROR_TOKENS - 111);
}
// record this revoke
std::vector<uint64_t> dataPt;
dataPt.push_back(0);
dataPt.push_back(nValue);
string txidStr = txid.ToString();
sp.historicalData.insert(std::make_pair(txidStr, dataPt));
sp.update_block = chainActive[block]->GetBlockHash();
_my_sps->updateSP(property, sp);
rc = 0;
return rc;
}
int CMPTransaction::logicMath_ChangeIssuer()
{
int rc = PKT_ERROR_TOKENS - 1000;
if (!isTransactionTypeAllowed(block, property, type, version)) {
file_log("\tRejecting Change of Issuer: Transaction type not yet allowed\n");
return (PKT_ERROR_TOKENS - 22);
}
if (sender.empty()) {
file_log("\tRejecting Change of Issuer: Sender is empty\n");
return (PKT_ERROR_TOKENS - 23);
}
if (receiver.empty()) {
file_log("\tRejecting Change of Issuer: Receiver is empty\n");
return (PKT_ERROR_TOKENS - 23);
}
if (false == _my_sps->hasSP(property)) {
file_log("\tRejecting Change of Issuer: SP id:%d does not exist\n", property);
return (PKT_ERROR_TOKENS - 24);
}
CMPSPInfo::Entry sp;
_my_sps->getSP(property, sp);
// issuer check
if (false == boost::iequals(sender, sp.issuer)) {
file_log("\tRejecting Change of Issuer: %s is not the issuer of SP id:%d\n", sender, property);
return (PKT_ERROR_TOKENS - 26);
}
// record this change of issuer
sp.issuer = receiver;
sp.update_block = chainActive[block]->GetBlockHash();
_my_sps->updateSP(property, sp);
rc = 0;
return rc;
}
int CMPTransaction::logicMath_SavingsMark()
{
int rc = -12345;
return rc;
}
int CMPTransaction::logicMath_SavingsCompromised()
{
int rc = -23456;
return rc;
}
char *mastercore::c_strMasterProtocolTXType(int i)
{
switch (i)
{
case MSC_TYPE_SIMPLE_SEND: return ((char *)"Simple Send");
case MSC_TYPE_RESTRICTED_SEND: return ((char *)"Restricted Send");
case MSC_TYPE_SEND_TO_OWNERS: return ((char *)"Send To Owners");
case MSC_TYPE_SAVINGS_MARK: return ((char *)"Savings");
case MSC_TYPE_SAVINGS_COMPROMISED: return ((char *)"Savings COMPROMISED");
case MSC_TYPE_RATELIMITED_MARK: return ((char *)"Rate-Limiting");
case MSC_TYPE_AUTOMATIC_DISPENSARY: return ((char *)"Automatic Dispensary");
case MSC_TYPE_TRADE_OFFER: return ((char *)"DEx Sell Offer");
case MSC_TYPE_METADEX: return ((char *)"MetaDEx token trade");
case MSC_TYPE_ACCEPT_OFFER_BTC: return ((char *)"DEx Accept Offer");
case MSC_TYPE_CREATE_PROPERTY_FIXED: return ((char *)"Create Property - Fixed");
case MSC_TYPE_CREATE_PROPERTY_VARIABLE: return ((char *)"Create Property - Variable");
case MSC_TYPE_PROMOTE_PROPERTY: return ((char *)"Promote Property");
case MSC_TYPE_CLOSE_CROWDSALE: return ((char *)"Close Crowdsale");
case MSC_TYPE_CREATE_PROPERTY_MANUAL: return ((char *)"Create Property - Manual");
case MSC_TYPE_GRANT_PROPERTY_TOKENS: return ((char *)"Grant Property Tokens");
case MSC_TYPE_REVOKE_PROPERTY_TOKENS: return ((char *)"Revoke Property Tokens");
case MSC_TYPE_CHANGE_ISSUER_ADDRESS: return ((char *)"Change Issuer Address");
case MSC_TYPE_NOTIFICATION: return ((char *)"Notification");
case OMNICORE_MESSAGE_TYPE_ALERT: return ((char *)"ALERT");
default: return ((char *)"* unknown type *");
}
}