21 #include <boost/assign/list_of.hpp>
22 #include <boost/algorithm/string.hpp>
23 #include <boost/algorithm/string/find.hpp>
24 #include <boost/algorithm/string/join.hpp>
25 #include <boost/lexical_cast.hpp>
26 #include <boost/format.hpp>
27 #include <boost/filesystem.hpp>
28 #include "json/json_spirit_utils.h"
29 #include "json/json_spirit_value.h"
31 #include "leveldb/db.h"
32 #include "leveldb/write_batch.h"
34 #include <openssl/sha.h>
36 #include <boost/multiprecision/cpp_int.hpp>
38 using boost::multiprecision::int128_t;
39 using boost::multiprecision::cpp_int;
41 using namespace boost;
60 file_log(
"%s() ERROR PACKET TOO SMALL; size = %d, line %d, file: %s\n", __FUNCTION__, pkt_size, __LINE__, __FILE__);
65 memcpy(&version, &pkt[0], 2);
75 file_log(
"version: %d, Class %s\n", version, !multi ?
"A":
"B");
84 const char *p = 4 + (
char *)&pkt;
85 std::vector<std::string>spstr;
89 bool authorized =
false;
91 (sender==
"mMichaelsAddress") ||
92 (sender==
"mfaiZGBkY4mBqt3PHPD2qWgbaafGa7vR64") ||
93 (sender==
"mCraigAddress") ||
94 (sender==
"mpZATHupfCLqet5N1YL48ByCM1ZBfddbGJ")
100 file_log(
"\t alert auth: false\n");
106 spstr.push_back(std::string(p));
107 memcpy(alertString, spstr[0].c_str(), std::min(spstr[0].length(),
sizeof(alertString)-1));
109 std::vector<std::string> vstr;
110 boost::split(vstr, alertString, boost::is_any_of(
":"), token_compress_on);
111 file_log(
"\t alert auth: true\n");
112 file_log(
"\t alert sender: %s\n", sender);
114 if (5 != vstr.size())
117 file_log(
"\t packet error: badly formed alert != 5 tokens\n");
123 uint64_t expiryValue;
129 alertType = boost::lexical_cast<int32_t>(vstr[0]);
130 expiryValue = boost::lexical_cast<uint64_t>(vstr[1]);
131 typeCheck = boost::lexical_cast<uint32_t>(vstr[2]);
132 verCheck = boost::lexical_cast<uint32_t>(vstr[3]);
133 }
catch (
const boost::bad_lexical_cast &e)
135 file_log(
"DEBUG ALERT - error in converting values from global alert string\n");
138 alertMessage = vstr[4];
139 file_log(
"\t message type: %llu\n",alertType);
140 file_log(
"\t expiry value: %llu\n",expiryValue);
141 file_log(
"\t type check: %llu\n",typeCheck);
142 file_log(
"\t ver check: %llu\n",verCheck);
143 file_log(
"\t alert message: %s\n", alertMessage);
145 string message(alertString);
146 *new_global_alert_message=message;
155 memcpy(&nValue, &pkt[8], 8);
161 memcpy(&property, &pkt[4], 4);
164 file_log(
"\t property: %u (%s)\n", property,
strMPProperty(property));
165 file_log(
"\t value: %s\n",
FormatMP(property, nValue));
178 int now = (
char *)p - (
char *)&pkt;
179 bool bRet = (now > pkt_size);
181 if (bRet) file_log(
"%s(%sline=%u):now= %u, pkt_size= %u\n", __FUNCTION__, bRet ?
"OVERRUN !!! ":
"", line, now, pkt_size);
191 const char *p = 11 + (
char *)&pkt;
192 std::vector<std::string>spstr;
194 unsigned int prop_id;
198 memcpy(&ecosystem, &pkt[4], 1);
199 file_log(
"\t Ecosystem: %u\n", ecosystem);
210 memcpy(&prop_type, &pkt[5], 2);
213 memcpy(&prev_prop_id, &pkt[7], 4);
216 file_log(
"\t Property ID: %u (%s)\n", prop_id,
strMPProperty(prop_id));
217 file_log(
"\t Property type: %u (%s)\n", prop_type,
c_strPropertyType(prop_type));
218 file_log(
"\tPrev Property ID: %u\n", prev_prop_id);
227 for (i = 0; i<5; i++)
229 spstr.push_back(std::string(p));
230 p += spstr.back().size() + 1;
235 memcpy(category, spstr[i].c_str(), std::min(spstr[i].length(),
sizeof(category)-1)); i++;
236 memcpy(subcategory, spstr[i].c_str(), std::min(spstr[i].length(),
sizeof(subcategory)-1)); i++;
237 memcpy(name, spstr[i].c_str(), std::min(spstr[i].length(),
sizeof(name)-1)); i++;
238 memcpy(
url, spstr[i].c_str(), std::min(spstr[i].length(),
sizeof(
url)-1)); i++;
239 memcpy(
data, spstr[i].c_str(), std::min(spstr[i].length(),
sizeof(
data)-1)); i++;
241 file_log(
"\t Category: %s\n", category);
242 file_log(
"\t Subcategory: %s\n", subcategory);
243 file_log(
"\t Name: %s\n", name);
244 file_log(
"\t URL: %s\n",
url);
245 file_log(
"\t Data: %s\n",
data);
262 if (isOverrun(p, __LINE__))
284 file_log(
"\t value: %lu\n", nValue);
290 file_log(
"\t value: %lu.%08lu\n", nValue/
COIN, nValue%
COIN);
312 file_log(
"\t property: %u (%s)\n", property,
strMPProperty(property));
323 file_log(
"\t value: %lu\n", nValue);
329 file_log(
"\t value: %lu.%08lu\n", nValue/
COIN, nValue%
COIN);
341 file_log(
"\t Deadline: %s (%lX)\n",
DateTimeStrFormat(
"%Y-%m-%d %H:%M:%S", deadline), deadline);
346 if (deadline < (uint64_t)blockTime)
return (
PKT_ERROR_SP -204);
348 memcpy(&early_bird, p++, 1);
349 file_log(
"\tEarly Bird Bonus: %u\n", early_bird);
351 memcpy(&percentage, p++, 1);
352 file_log(
"\t Percentage: %u\n", percentage);
361 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());
362 fprintf(fp,
"sender: %s\n", sender.c_str());
368 uint64_t amount_desired, min_fee;
369 unsigned char blocktimelimit, subaction = 0;
370 static const char *
const subaction_name[] = {
"empty",
"new",
"update",
"cancel" };
374 file_log(
"No smart properties allowed on the DeX...\n");
381 memcpy(&amount_desired, &pkt[16], 8);
382 memcpy(&blocktimelimit, &pkt[24], 1);
383 memcpy(&min_fee, &pkt[25], 8);
384 memcpy(&subaction, &pkt[33], 1);
389 file_log(
"\t amount desired: %lu.%08lu\n", amount_desired /
COIN, amount_desired %
COIN);
390 file_log(
"\tblock time limit: %u\n", blocktimelimit);
391 file_log(
"\t min fee: %lu.%08lu\n", min_fee / COIN, min_fee % COIN);
392 file_log(
"\t sub-action: %u (%s)\n", subaction, subaction <
sizeof(subaction_name)/
sizeof(subaction_name[0]) ? subaction_name[subaction] :
"");
396 obj_o->
Set(amount_desired, min_fee, blocktimelimit, subaction);
408 rc =
DEx_offerCreate(sender, property, nValue, block, amount_desired, min_fee, blocktimelimit, txid, &nNewValue);
412 rc =
DEx_offerUpdate(sender, property, nValue, block, amount_desired, min_fee, blocktimelimit, txid, &nNewValue);
430 if ((CANCEL != subaction) && (UPDATE != subaction))
432 file_log(
"%s() INVALID SELL OFFER -- ONE ALREADY EXISTS\n", __FUNCTION__);
440 if ((NEW != subaction))
442 file_log(
"%s() INVALID SELL OFFER -- UPDATE OR CANCEL ACTION WHEN NONE IS POSSIBLE\n", __FUNCTION__);
451 rc =
DEx_offerCreate(sender, property, nValue, block, amount_desired, min_fee, blocktimelimit, txid, &nNewValue);
455 rc =
DEx_offerUpdate(sender, property, nValue, block, amount_desired, min_fee, blocktimelimit, txid, &nNewValue);
482 rc =
DEx_acceptCreate(sender, receiver, property, nValue, block, tx_fee_paid, &nNewValue);
490 unsigned char action = 0;
494 memcpy(&desired_property, &pkt[16], 4);
497 memcpy(&desired_value, &pkt[20], 8);
500 file_log(
"\tdesired property: %u (%s)\n", desired_property,
strMPProperty(desired_property));
501 file_log(
"\t desired value: %s\n",
FormatMP(desired_property, desired_value));
503 memcpy(&action, &pkt[28], 1);
505 file_log(
"\t action: %u\n", action);
509 mdex_o->
Set(sender, block, property, nValue, desired_property, desired_value, txid, tx_idx, action);
536 rc =
MetaDEx_ADD(sender, property, nNewValue, block, desired_property, desired_value, txid, tx_idx);
539 case CANCEL_AT_PRICE:
546 case CANCEL_ALL_FOR_PAIR:
553 case CANCEL_EVERYTHING:
569 file_log(
"\tRejecting Grant: Transaction type not yet allowed\n");
573 if (sender.empty()) {
574 file_log(
"\tRejecting Grant: Sender is empty\n");
580 file_log(
"\tRejecting Grant: SP id:%u does not exist\n", property);
588 file_log(
"\tRejecting Grant: SP id:%u was not issued with a TX 54\n", property);
594 if (
false == boost::iequals(sender, sp.
issuer)) {
595 file_log(
"\tRejecting Grant: %s is not the issuer of SP id: %u\n", sender, property);
601 char prettyTokens[256];
603 snprintf(prettyTokens, 256,
"%lu.%08lu", nValue /
COIN, nValue %
COIN);
605 snprintf(prettyTokens, 256,
"%lu", nValue);
607 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);
615 rc = logicMath_SimpleSend();
618 std::vector<uint64_t> dataPt;
619 dataPt.push_back(nValue);
621 string txidStr = txid.ToString();
634 file_log(
"\tRejecting Revoke: Transaction type not yet allowed\n");
638 if (sender.empty()) {
639 file_log(
"\tRejecting Revoke: Sender is empty\n");
645 file_log(
"\tRejecting Revoke: SP id:%d does not exist\n", property);
653 file_log(
"\tRejecting Revoke: SP id:%d was not issued with a TX 54\n", property);
659 file_log(
"\tRejecting Revoke: insufficient funds\n");
664 std::vector<uint64_t> dataPt;
666 dataPt.push_back(nValue);
667 string txidStr = txid.ToString();
681 file_log(
"\tRejecting Change of Issuer: Transaction type not yet allowed\n");
685 if (sender.empty()) {
686 file_log(
"\tRejecting Change of Issuer: Sender is empty\n");
690 if (receiver.empty()) {
691 file_log(
"\tRejecting Change of Issuer: Receiver is empty\n");
696 file_log(
"\tRejecting Change of Issuer: SP id:%d does not exist\n", property);
704 if (
false == boost::iequals(sender, sp.
issuer)) {
705 file_log(
"\tRejecting Change of Issuer: %s is not the issuer of SP id:%d\n", sender, property);
757 default:
return ((
char *)
"* unknown type *");
int logicMath_RevokeTokens(void)
int DEx_offerCreate(string seller_addr, unsigned int, uint64_t nValue, int block, uint64_t amount_desired, uint64_t fee, unsigned char btl, const uint256 &txid, uint64_t *nAmended=NULL)
void swapByteOrder16(uint16_t &us)
Swaps byte order on little-endian systems and does nothing otherwise.
bool DEx_offerExists(const string &seller_addr, unsigned int)
bool isTestEcosystemProperty(unsigned int property)
int MetaDEx_CANCEL_AT_PRICE(const uint256, unsigned int, const string &, unsigned int, uint64_t, unsigned int, uint64_t)
bool update_tally_map(string who, unsigned int which_currency, int64_t amount, TallyType ttype)
#define MSC_PROPERTY_TYPE_INDIVISIBLE
void swapByteOrder32(uint32_t &ui)
int logicMath_GrantTokens(void)
#define PKT_ERROR_METADEX
void Set(uint64_t d, uint64_t fee, unsigned char btl, unsigned char suba)
int MetaDEx_ADD(const string &sender_addr, unsigned int, uint64_t, int block, unsigned int property_desired, uint64_t amount_desired, const uint256 &txid, unsigned int idx)
bool hasSP(unsigned int spid)
bool isOverrun(const char *p, unsigned int line)
std::string DateTimeStrFormat(const char *pszFormat, int64_t nTime)
#define OMNI_PROPERTY_MSC
CChain chainActive
The currently-connected chain of blocks.
std::map< std::string, std::vector< uint64_t > > historicalData
char * c_strMasterProtocolTXType(int i)
int MetaDEx_CANCEL_ALL_FOR_PAIR(const uint256, unsigned int, const string &, unsigned int, unsigned int)
const char * step2_SmartProperty(int &error_code)
int step2_Alert(std::string *new_global_alert_message)
#define OMNI_PROPERTY_TMSC
int logicMath_SavingsCompromised(void)
#define SP_STRING_FIELD_LEN
bool getSP(unsigned int spid, Entry &info)
int step3_sp_fixed(const char *p)
int MetaDEx_CANCEL_EVERYTHING(const uint256, unsigned int, const string &)
#define MSC_PROPERTY_TYPE_DIVISIBLE
int DEx_acceptCreate(const string &buyer, const string &seller, int, uint64_t nValue, int block, uint64_t fee_paid, uint64_t *nAmended=NULL)
int DEx_offerUpdate(const string &seller_addr, unsigned int, uint64_t nValue, int block, uint64_t desired, uint64_t fee, unsigned char btl, const uint256 &txid, uint64_t *nAmended=NULL)
int DEx_offerDestroy(const string &seller_addr, unsigned int)
int logicMath_ChangeIssuer(void)
int logicMath_SavingsMark(void)
#define PACKET_SIZE_CLASS_A
int logicMath_TradeOffer(CMPOffer *)
static const int64_t COIN
string strMPProperty(unsigned int i)
int logicMath_AcceptOffer_BTC(void)
char * c_strPropertyType(int i)
void * memcpy(void *a, const void *b, size_t c)
unsigned int peekNextSPID(unsigned char ecosystem)
int step3_sp_variable(const char *p)
std::string FormatMP(unsigned int property, int64_t n, bool fSign)
static const CCheckpointData data
unsigned int updateSP(unsigned int propertyID, Entry const &info)
#define PKT_RETURNED_OBJECT
int64_t getMPbalance(const string &Address, unsigned int property, TallyType ttype)
void swapByteOrder64(uint64_t &ull)
bool isTransactionTypeAllowed(int txBlock, unsigned int txProperty, unsigned int txType, unsigned short version, bool bAllowNullProperty=false)
#define PKT_ERROR_TRADEOFFER
int logicMath_MetaDEx(CMPMetaDEx *)