14 #define DISABLE_METADEX
16 #define LOG_FILENAME "mastercore.log"
17 #define INFO_FILENAME "mastercore_crowdsales.log"
18 #define OWNERS_FILENAME "mastercore_owners.log"
22 #define TEST_ECO_PROPERTY_1 (0x80000003UL)
26 #define MAX_INT_8_BYTES (9223372036854775807UL)
29 #define DEV_MSC_BLOCK_290629 (1743358325718)
31 #define SP_STRING_FIELD_LEN 256
34 #define TRANSFER_FEE_PER_OWNER (1)
37 #define FORMAT_BOOST_TXINDEXKEY "index-tx-%s"
38 #define FORMAT_BOOST_SPKEY "sp-%d"
41 #define MP_TX_PKT_V0 0
42 #define MP_TX_PKT_V1 1
45 #define MAX_BTC_OUTPUTS 16
47 #define MAX_SHA256_OBFUSCATION_TIMES 255
49 #define PACKET_SIZE_CLASS_A 19
50 #define PACKET_SIZE 31
51 #define MAX_PACKETS 64
78 #define MSC_PROPERTY_TYPE_INDIVISIBLE 1
79 #define MSC_PROPERTY_TYPE_DIVISIBLE 2
80 #define MSC_PROPERTY_TYPE_INDIVISIBLE_REPLACING 65
81 #define MSC_PROPERTY_TYPE_DIVISIBLE_REPLACING 66
82 #define MSC_PROPERTY_TYPE_INDIVISIBLE_APPENDING 129
83 #define MSC_PROPERTY_TYPE_DIVISIBLE_APPENDING 130
113 #define PKT_RETURNED_OBJECT (1000)
115 #define PKT_ERROR ( -9000)
116 #define DEX_ERROR_SELLOFFER (-10000)
117 #define DEX_ERROR_ACCEPT (-20000)
118 #define DEX_ERROR_PAYMENT (-30000)
120 #define PKT_ERROR_SP (-40000)
122 #define PKT_ERROR_STO (-50000)
123 #define PKT_ERROR_SEND (-60000)
124 #define PKT_ERROR_TRADEOFFER (-70000)
125 #define PKT_ERROR_METADEX (-80000)
126 #define METADEX_ERROR (-81000)
127 #define PKT_ERROR_TOKENS (-82000)
129 #define OMNI_PROPERTY_BTC 0
130 #define OMNI_PROPERTY_MSC 1
131 #define OMNI_PROPERTY_TMSC 2
138 #define MP_MAKE_ERROR_AND_LOG_FUNC(n) \
140 template<TINYFORMAT_ARGTYPES(n)> \
141 static inline int mp_category_log(const char* category, const char* format, TINYFORMAT_VARARGS(n)) \
143 if(!LogAcceptCategory(category)) return 0; \
144 return mp_LogPrintStr(tfm::format(format, TINYFORMAT_PASSARGS(n))); \
146 template<TINYFORMAT_ARGTYPES(n)> \
147 static inline int mp_log(TINYFORMAT_VARARGS(n)) \
149 return mp_LogPrintStr(tfm::format("%s", TINYFORMAT_PASSARGS(n))); \
151 template<TINYFORMAT_ARGTYPES(n)> \
152 static inline int mp_log(const char* format, TINYFORMAT_VARARGS(n)) \
154 return mp_LogPrintStr(tfm::format(format, TINYFORMAT_PASSARGS(n))); \
156 template<TINYFORMAT_ARGTYPES(n)> \
157 static inline int file_log(const char* format, TINYFORMAT_VARARGS(n)) \
159 return mp_LogPrintStr(tfm::format(format, TINYFORMAT_PASSARGS(n))); \
161 template<TINYFORMAT_ARGTYPES(n)> \
162 static inline int file_log(TINYFORMAT_VARARGS(n)) \
164 return mp_LogPrintStr(tfm::format("%s", TINYFORMAT_PASSARGS(n))); \
167 template<TINYFORMAT_ARGTYPES(n)> \
168 static inline bool mp_error(const char* format, TINYFORMAT_VARARGS(n)) \
170 mp_LogPrintStr("ERROR: " + tfm::format(format, TINYFORMAT_PASSARGS(n)) + "\n"); \
179 std::
string FormatMP(
unsigned int, int64_t n,
bool fSign = false);
180 uint256 send_MP(const
string &FromAddress, const
string &ToAddress, const
string &RedeemAddress,
unsigned int PropertyID, uint64_t Amount);
181 int64_t
feeCheck(const
string &address);
199 typedef std::map<unsigned int, BalanceRecord>
TokenMap;
205 const TokenMap::const_iterator it = mp_token.find(which_property);
207 return (it != mp_token.end());
214 unsigned int ret = 0;
216 my_it = mp_token.begin();
217 if (my_it != mp_token.end()) ret = my_it->first;
226 if (my_it == mp_token.end())
return 0;
244 now64 = mp_token[which_property].balance[ttype];
246 if ((
PENDING != ttype) && (0>(now64 + amount)))
252 mp_token[which_property].balance[ttype] = now64;
263 my_it = mp_token.begin();
275 money = mp_token[which_property].balance[
BALANCE];
278 pending = mp_token[which_property].balance[
PENDING];
283 printf(
"%22s [SO_RESERVE= %22s , ACCEPT_RESERVE= %22s ] %22s\n",
288 printf(
"%14lu [SO_RESERVE= %14lu , ACCEPT_RESERVE= %14lu ] %14ld\n", money, so_r, a_r, pending);
291 return (money + so_r + a_r);
302 if (
propertyExists(which_property)) ret64 = mp_token[which_property].balance[ttype];
324 CMPSTOList(
const boost::filesystem::path &path,
size_t nCacheSize,
bool fMemory,
bool fWipe):sWritten(0),sRead(0)
326 options.paranoid_checks =
true;
327 options.create_if_missing =
true;
328 readoptions.verify_checksums =
true;
329 iteroptions.verify_checksums =
true;
330 iteroptions.fill_cache =
false;
331 syncoptions.sync =
true;
332 leveldb::Status status = leveldb::DB::Open(options, path.string(), &
sdb);
333 printf(
"%s(): %s, line %d, file: %s\n", __FUNCTION__, status.ToString().c_str(), __LINE__, __FILE__);
342 void getRecipients(
const uint256 txid,
string filterAddress, Array *recipientArray, uint64_t *total, uint64_t *stoFee);
347 bool exists(
string address);
367 CMPTradeList(
const boost::filesystem::path &path,
size_t nCacheSize,
bool fMemory,
bool fWipe):tWritten(0),tRead(0)
369 options.paranoid_checks =
true;
370 options.create_if_missing =
true;
371 readoptions.verify_checksums =
true;
372 iteroptions.verify_checksums =
true;
373 iteroptions.fill_cache =
false;
374 syncoptions.sync =
true;
375 leveldb::Status status = leveldb::DB::Open(options, path.string(), &
tdb);
376 printf(
"%s(): %s, line %d, file: %s\n", __FUNCTION__, status.ToString().c_str(), __LINE__, __FILE__);
385 void recordTrade(
const uint256 txid1,
const uint256 txid2,
string address1,
string address2,
unsigned int prop1,
unsigned int prop2, uint64_t amount1, uint64_t amount2,
int blockNum);
390 bool getMatchingTrades(
const uint256 txid,
unsigned int propertyId, Array *tradeArray, uint64_t *totalSold, uint64_t *totalBought);
421 CMPTxList(
const boost::filesystem::path &path,
size_t nCacheSize,
bool fMemory,
bool fWipe):nWritten(0),nRead(0)
423 options.paranoid_checks =
true;
424 options.create_if_missing =
true;
426 readoptions.verify_checksums =
true;
427 iteroptions.verify_checksums =
true;
428 iteroptions.fill_cache =
false;
429 syncoptions.sync =
true;
431 leveldb::Status status = leveldb::DB::Open(options, path.string(), &
pdb);
433 printf(
"%s(): %s, line %d, file: %s\n", __FUNCTION__, status.ToString().c_str(), __LINE__, __FILE__);
442 void recordTX(
const uint256 &txid,
bool fValid,
int nBlock,
unsigned int type, uint64_t nValue);
443 void recordPaymentTX(
const uint256 &txid,
bool fValid,
int nBlock,
unsigned int vout,
unsigned int propertyId, uint64_t nValue,
string buyer,
string seller);
450 bool getPurchaseDetails(
const uint256 txid,
int purchaseNumber,
string *buyer,
string *seller, uint64_t *vout, uint64_t *propertyId, uint64_t *nValue);
474 printf(
"%s : %s %d %ld\n", txid.
GetHex().c_str(), src.c_str(),
prop,
amount);
493 string getLabel(
const string &address);
518 bool isCrowdsalePurchase(
uint256 txid,
string address, int64_t *propertyId = NULL, int64_t *userTokens = NULL, int64_t *issuerTokens = NULL);
519 bool isMPinBlockRange(
int starting_block,
int ending_block,
bool bDeleteFound);
522 int ClassB_send(
const string &senderAddress,
const string &receiverAddress,
const string &redemptionAddress,
const vector<unsigned char> &
data,
uint256 & txid, int64_t additional = 0);
524 uint256 send_INTERNAL_1packet(
const string &FromAddress,
const string &ToAddress,
const string &RedeemAddress,
unsigned int PropertyID, uint64_t Amount,
525 unsigned int PropertyID_2, uint64_t Amount_2,
unsigned int TransactionType, int64_t additional,
int *error_code = NULL);
533 int64_t
getTotalTokens(
unsigned int propertyId, int64_t *n_owners_total = NULL);
539 bool isTransactionTypeAllowed(
int txBlock,
unsigned int txProperty,
unsigned int txType,
unsigned short version,
bool bAllowNullProperty =
false);
541 bool getValidMPTX(
const uint256 &txid,
int *block = NULL,
unsigned int *type = NULL, uint64_t *nAmended = NULL);
uint32_t GetLatestBlockTime(void)
uint256 send_MP(const string &FromAddress, const string &ToAddress, const string &RedeemAddress, unsigned int PropertyID, uint64_t Amount)
int getNumberOfPurchases(const uint256 txid)
uint64_t global_balance_reserved_maineco[100000]
bool exists(const uint256 &txid)
int64_t getMoney(unsigned int which_property, TallyType ttype)
bool isTestEcosystemProperty(unsigned int property)
int deleteAboveBlock(int blockNum)
int ClassB_send(const string &senderAddress, const string &receiverAddress, const string &redemptionAddress, const vector< unsigned char > &data, uint256 &txid, int64_t additional=0)
bool getTX(const uint256 &txid, string &value)
int mastercore_handler_disc_begin(int nBlockNow, CBlockIndex const *pBlockIndex)
bool isMainEcosystemProperty(unsigned int property)
int64_t getMPbalance(const string &Address, unsigned int property, TallyType ttype)
bool exists(const uint256 &txid)
uint64_t global_MSC_RESERVED_total
int64_t getUserAvailableMPbalance(const string &Address, unsigned int property)
uint64_t global_balance_reserved_testeco[100000]
bool exists(string address)
bool update_tally_map(string who, unsigned int which_currency, int64_t amount, TallyType ttype)
bool getMatchingTrades(const uint256 txid, unsigned int propertyId, Array *tradeArray, uint64_t *totalSold, uint64_t *totalBought)
void recordMetaDExCancelTX(const uint256 &txidMaster, const uint256 &txidSub, bool fValid, int nBlock, unsigned int propertyId, uint64_t nValue)
bool propertyExists(unsigned int which_property) const
CMPTradeList(const boost::filesystem::path &path, size_t nCacheSize, bool fMemory, bool fWipe)
CMPTally * getTally(const string &address)
void getRecipients(const uint256 txid, string filterAddress, Array *recipientArray, uint64_t *total, uint64_t *stoFee)
int mastercore_handler_block_begin(int nBlockNow, CBlockIndex const *pBlockIndex)
string getLabel(const string &address)
uint64_t global_balance_money_maineco[100000]
int mastercore_init(void)
int mastercore_save_state(CBlockIndex const *pBlockIndex)
#define OMNI_PROPERTY_MSC
leveldb::WriteOptions writeoptions
leveldb::ReadOptions iteroptions
bool isPropertyDivisible(unsigned int propertyId)
int deleteAboveBlock(int blockNum)
void recordPaymentTX(const uint256 &txid, bool fValid, int nBlock, unsigned int vout, unsigned int propertyId, uint64_t nValue, string buyer, string seller)
uint64_t global_balance_money_testeco[100000]
int64_t print(int which_property=OMNI_PROPERTY_MSC, bool bDivisible=true)
int getNumberOfMetaDExCancels(const uint256 txid)
char * c_strMasterProtocolTXType(int i)
bool isCrowdsalePurchase(uint256 txid, string address, int64_t *propertyId=NULL, int64_t *userTokens=NULL, int64_t *issuerTokens=NULL)
bool getValidMPTX(const uint256 &txid, int *block=NULL, unsigned int *type=NULL, uint64_t *nAmended=NULL)
leveldb::WriteOptions syncoptions
leveldb::WriteOptions syncoptions
leveldb::ReadOptions readoptions
int mastercore_handler_tx(const CTransaction &tx, int nBlock, unsigned int idx, CBlockIndex const *pBlockIndex)
bool isMPinBlockRange(int, int, bool)
int getMPTradeCountTotal()
bool isCrowdsaleActive(unsigned int propertyId)
CCriticalSection cs_tally
CMPTradeList * t_tradelistdb
leveldb::ReadOptions readoptions
int setLastAlert(int blockHeight)
CMPTxList(const boost::filesystem::path &path, size_t nCacheSize, bool fMemory, bool fWipe)
bool updateMoney(unsigned int which_property, int64_t amount, TallyType ttype)
int mastercore_handler_block_end(int nBlockNow, CBlockIndex const *pBlockIndex, unsigned int)
bool isMPinBlockRange(int starting_block, int ending_block, bool bDeleteFound)
std::map< string, CMPTally > mp_tally_map
bool isMetaDExOfferActive(const uint256 txid, unsigned int propertyId)
void print(uint256 txid) const
void recordSTOReceive(std::string, const uint256 &, int, unsigned int, uint64_t)
uint256 send_INTERNAL_1packet(const string &FromAddress, const string &ToAddress, const string &RedeemAddress, unsigned int PropertyID, uint64_t Amount, unsigned int PropertyID_2, uint64_t Amount_2, unsigned int TransactionType, int64_t additional, int *error_code=NULL)
std::map< unsigned int, BalanceRecord > TokenMap
std::string GetHex() const
uint256 findMetaDExCancel(const uint256 txid)
int64_t getTotalTokens(unsigned int propertyId, int64_t *n_owners_total=NULL)
string getKeyValue(string key)
string getPropertyName(unsigned int propertyId)
leveldb::WriteOptions writeoptions
leveldb::ReadOptions iteroptions
bool getPurchaseDetails(const uint256 txid, int purchaseNumber, string *buyer, string *seller, uint64_t *vout, uint64_t *propertyId, uint64_t *nValue)
leveldb::ReadOptions readoptions
int mastercore_handler_disc_end(int nBlockNow, CBlockIndex const *pBlockIndex)
string strMPProperty(unsigned int i)
The block chain is a tree shaped structure starting with the genesis block at the root...
void recordTX(const uint256 &txid, bool fValid, int nBlock, unsigned int type, uint64_t nValue)
int getMPTransactionCountBlock(int block)
std::string FormatIndivisibleMP(int64_t n)
leveldb::WriteOptions writeoptions
#define MP_MAKE_ERROR_AND_LOG_FUNC(n)
int const MAX_STATE_HISTORY
CMPSTOList(const boost::filesystem::path &path, size_t nCacheSize, bool fMemory, bool fWipe)
The basic transaction that is broadcasted on the network and contained in blocks. ...
std::string getMasterCoreAlertString()
static const CCheckpointData data
int getMPTransactionCountTotal()
bool checkExpiredAlerts(unsigned int curBlock, uint64_t curTime)
int mp_LogPrintStr(const std::string &str)
leveldb::ReadOptions iteroptions
int64_t feeCheck(const string &address)
std::string FormatMP(unsigned int, int64_t n, bool fSign=false)
std::map< uint256, CMPPending > PendingMap
bool IsMyAddress(const std::string &address)
const std::string ExodusAddress()
std::string getMySTOReceipts(string filterAddress)
bool isTransactionTypeAllowed(int txBlock, unsigned int txProperty, unsigned int txType, unsigned short version, bool bAllowNullProperty=false)
leveldb::WriteOptions syncoptions
void recordTrade(const uint256 txid1, const uint256 txid2, string address1, string address2, unsigned int prop1, unsigned int prop2, uint64_t amount1, uint64_t amount2, int blockNum)
std::string FormatDivisibleMP(int64_t n, bool fSign=false)
uint64_t global_MSC_total