diff --git a/src/mastercore.h b/src/mastercore.h index 539afbf4b154a..3da9f5886e509 100644 --- a/src/mastercore.h +++ b/src/mastercore.h @@ -32,8 +32,6 @@ using json_spirit::Array; using std::string; -#define DISABLE_METADEX - #define LOG_FILENAME "mastercore.log" #define INFO_FILENAME "mastercore_crowdsales.log" #define OWNERS_FILENAME "mastercore_owners.log" diff --git a/src/mastercore_dex.cpp b/src/mastercore_dex.cpp index b9dc2b110d663..be659db2d13f7 100644 --- a/src/mastercore_dex.cpp +++ b/src/mastercore_dex.cpp @@ -346,12 +346,6 @@ void CMPMetaDEx::Set(const string &sa, int b, unsigned int c, uint64_t nValue, u subaction = suba; } -CMPMetaDEx::CMPMetaDEx(const string &addr, int b, unsigned int c, uint64_t nValue, unsigned int cd, uint64_t ad, const uint256 &tx, unsigned int i, unsigned char suba, uint64_t lfors) -{ - still_left_forsale = lfors; - Set(addr, b,c,nValue,cd,ad,tx,i,suba); -} - std::string CMPMetaDEx::ToString() const { return strprintf("%s:%34s in %d/%03u, txid: %s , trade #%u %s for #%u %s", @@ -721,7 +715,7 @@ AcceptMap::iterator my_it = my_accepts.begin(); } // pretty much directly linked to the ADD TX21 command off the wire -int mastercore::MetaDEx_ADD(const string &sender_addr, unsigned int prop, uint64_t amount, int block, unsigned int property_desired, uint64_t amount_desired, const uint256 &txid, unsigned int idx) +int mastercore::MetaDEx_ADD(const std::string& sender_addr, unsigned int prop, uint64_t amount, int block, unsigned int property_desired, uint64_t amount_desired, const uint256& txid, unsigned int idx) { int rc = METADEX_ERROR -1; @@ -816,7 +810,7 @@ int rc = METADEX_ERROR -1; return rc; } -int mastercore::MetaDEx_CANCEL_AT_PRICE(const uint256 txid, unsigned int block, const string &sender_addr, unsigned int prop, uint64_t amount, unsigned int property_desired, uint64_t amount_desired) +int mastercore::MetaDEx_CANCEL_AT_PRICE(const uint256& txid, unsigned int block, const std::string& sender_addr, unsigned int prop, uint64_t amount, unsigned int property_desired, uint64_t amount_desired) { int rc = METADEX_ERROR -20; CMPMetaDEx mdex(sender_addr, 0, prop, amount, property_desired, amount_desired, 0, 0, CMPTransaction::CANCEL_AT_PRICE); @@ -874,7 +868,7 @@ const CMPMetaDEx *p_mdex = NULL; return rc; } -int mastercore::MetaDEx_CANCEL_ALL_FOR_PAIR(const uint256 txid, unsigned int block, const string &sender_addr, unsigned int prop, unsigned int property_desired) +int mastercore::MetaDEx_CANCEL_ALL_FOR_PAIR(const uint256& txid, unsigned int block, const std::string& sender_addr, unsigned int prop, unsigned int property_desired) { int rc = METADEX_ERROR -30; md_PricesMap *prices = get_Prices(prop); @@ -928,9 +922,9 @@ const CMPMetaDEx *p_mdex = NULL; } // scan the orderbook and remove everything for an address -int mastercore::MetaDEx_CANCEL_EVERYTHING(const uint256 txid, unsigned int block, const string &sender_addr) +int mastercore::MetaDEx_CANCEL_EVERYTHING(const uint256& txid, unsigned int block, const std::string& sender_addr, unsigned char ecosystem) { -int rc = METADEX_ERROR -40; + int rc = METADEX_ERROR -40; file_log("%s()\n", __FUNCTION__); @@ -942,6 +936,10 @@ int rc = METADEX_ERROR -40; { unsigned int prop = my_it->first; + // skip property, if it is not in the expected ecosystem + if (isMainEcosystemProperty(ecosystem) && !isMainEcosystemProperty(prop)) continue; + if (isTestEcosystemProperty(ecosystem) && !isTestEcosystemProperty(prop)) continue; + file_log(" ## property: %u\n", prop); md_PricesMap & prices = my_it->second; @@ -956,7 +954,7 @@ int rc = METADEX_ERROR -40; { file_log("%s= %s\n", price.str(DISPLAY_PRECISION_LEN, std::ios_base::fixed) , it->ToString()); - if ((it->getAddr() != sender_addr)) + if (it->getAddr() != sender_addr) { ++it; continue; diff --git a/src/mastercore_dex.h b/src/mastercore_dex.h index 54340c05667c9..33ef99f567a59 100644 --- a/src/mastercore_dex.h +++ b/src/mastercore_dex.h @@ -61,12 +61,15 @@ class CMPOffer uint64_t getOfferAmountOriginal() const { return offer_amount_original; } uint64_t getBTCDesiredOriginal() const { return BTC_desired_original; } - CMPOffer():offerBlock(0),offer_amount_original(0),property(0),BTC_desired_original(0),min_fee(0),blocktimelimit(0),txid(0) + CMPOffer() + : offerBlock(0), offer_amount_original(0), property(0), BTC_desired_original(0), min_fee(0), blocktimelimit(0), + txid(0), subaction(0) { } - CMPOffer(int b, uint64_t a, unsigned int cu, uint64_t d, uint64_t fee, unsigned char btl, const uint256 &tx) - :offerBlock(b),offer_amount_original(a),property(cu),BTC_desired_original(d),min_fee(fee),blocktimelimit(btl),txid(tx) + CMPOffer(int b, uint64_t a, unsigned int cu, uint64_t d, uint64_t fee, unsigned char btl, const uint256& tx) + : offerBlock(b), offer_amount_original(a), property(cu), BTC_desired_original(d), min_fee(fee), blocktimelimit(btl), + txid(tx), subaction(0) { if (msc_debug_dex) file_log("%s(%lu): %s , line %d, file: %s\n", __FUNCTION__, a, txid.GetHex(), __LINE__, __FILE__); } @@ -203,12 +206,9 @@ class CMPMetaDEx uint64_t amount_forsale; // the amount for sale specified when the offer was placed unsigned int desired_property; int64_t amount_desired; - uint64_t still_left_forsale; - unsigned char subaction; - - string addr; + std::string addr; public: uint256 getHash() const { return txid; } @@ -246,13 +246,19 @@ class CMPMetaDEx } // needed only by the RPC functions - CMPMetaDEx():block(0),txid(0),idx(0),property(0),amount_forsale(0),desired_property(0),amount_desired(0),still_left_forsale(0),subaction(0) + // needed only by the RPC functions + CMPMetaDEx() + : block(0), txid(0), idx(0), property(0), amount_forsale(0), desired_property(0), amount_desired(0), + still_left_forsale(0), subaction(0) { - still_left_forsale = 0; - addr.empty(); } - CMPMetaDEx(const string &, int, unsigned int, uint64_t, unsigned int, uint64_t, const uint256 &, unsigned int, unsigned char, uint64_t lfors = 0); + CMPMetaDEx(const std::string& addr, int b, unsigned int c, uint64_t nValue, unsigned int cd, uint64_t ad, + const uint256& tx, unsigned int i, unsigned char suba, uint64_t lfors = 0) + : block(b), txid(tx), idx(i), property(c), amount_forsale(nValue), desired_property(cd), amount_desired(ad), + still_left_forsale(lfors), subaction(suba), addr(addr) + { + } void Set(const string &, int, unsigned int, uint64_t, unsigned int, uint64_t, const uint256 &, unsigned int, unsigned char); @@ -311,10 +317,10 @@ int DEx_acceptCreate(const string &buyer, const string &seller, int, uint64_t nV int DEx_acceptDestroy(const string &buyer, const string &seller, int, bool bForceErase = false); int DEx_payment(uint256 txid, unsigned int vout, string seller, string buyer, uint64_t BTC_paid, int blockNow, uint64_t *nAmended = NULL); -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); -int MetaDEx_CANCEL_AT_PRICE(const uint256, unsigned int, const string &, unsigned int, uint64_t, unsigned int, uint64_t); -int MetaDEx_CANCEL_ALL_FOR_PAIR(const uint256, unsigned int, const string &, unsigned int, unsigned int); -int MetaDEx_CANCEL_EVERYTHING(const uint256, unsigned int, const string &); +int MetaDEx_ADD(const std::string& sender_addr, unsigned int, uint64_t, int block, unsigned int property_desired, uint64_t amount_desired, const uint256& txid, unsigned int idx); +int MetaDEx_CANCEL_AT_PRICE(const uint256&, unsigned int, const std::string&, unsigned int, uint64_t, unsigned int, uint64_t); +int MetaDEx_CANCEL_ALL_FOR_PAIR(const uint256&, unsigned int, const std::string&, unsigned int, unsigned int); +int MetaDEx_CANCEL_EVERYTHING(const uint256& txid, unsigned int block, const std::string& sender_addr, unsigned char ecosystem); md_PricesMap *get_Prices(unsigned int prop); md_Set *get_Indexes(md_PricesMap *p, XDOUBLE price); diff --git a/src/mastercore_rpc.cpp b/src/mastercore_rpc.cpp index 622fcc1d0080a..d5f41c212cf49 100644 --- a/src/mastercore_rpc.cpp +++ b/src/mastercore_rpc.cpp @@ -845,7 +845,6 @@ int check_prop_valid(int64_t tmpPropId, string error, string exist_error ) { return tmpPropId; } -#ifndef DISABLE_METADEX Value getorderbook_MP(const Array& params, bool fHelp) { if (fHelp || params.size() < 1) @@ -1035,7 +1034,6 @@ Value gettradehistory_MP(const Array& params, bool fHelp) return response; } -#endif Value getactivedexsells_MP(const Array& params, bool fHelp) { diff --git a/src/mastercore_tx.cpp b/src/mastercore_tx.cpp index 87c74b8d018e8..1c0071c6ca004 100644 --- a/src/mastercore_tx.cpp +++ b/src/mastercore_tx.cpp @@ -479,10 +479,8 @@ int rc = DEX_ERROR_ACCEPT; 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); + int rc = PKT_ERROR_METADEX -100; + unsigned char action = 0; memcpy(&desired_property, &pkt[16], 4); swapByteOrder32(desired_property); @@ -506,46 +504,80 @@ unsigned char action = 0; switch (action) { case ADD: - if (!isTransactionTypeAllowed(block, desired_property, type, version)) return (PKT_ERROR_METADEX -889); + { + if (!isTransactionTypeAllowed(block, 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 + // ensure no cross-over of properties from test to main ecosystem 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 offered and desired values are positive + if (0 >= static_cast(nNewValue)) return (PKT_ERROR_METADEX -11); + if (0 >= static_cast(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); + if (getMPbalance(sender, property, BALANCE) < static_cast(nNewValue)) return (PKT_ERROR_METADEX -567); 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 - // ... + { + if (!isTransactionTypeAllowed(block, property, type, version)) return (PKT_ERROR_METADEX -890); + + // ensure we are not trading same property for itself + if (property == desired_property) return (PKT_ERROR_METADEX -5); + + // ensure no cross-over of properties from test to main ecosystem + 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); + + // ensure offered and desired values are positive + if (0 >= static_cast(nNewValue)) return (PKT_ERROR_METADEX -11); + if (0 >= static_cast(desired_value)) return (PKT_ERROR_METADEX -12); + 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 - // ... + { + if (!isTransactionTypeAllowed(block, property, type, version)) return (PKT_ERROR_METADEX -891); + + // ensure we are not trading same property for itself + if (property == desired_property) return (PKT_ERROR_METADEX -5); + + // ensure no cross-over of properties from test to main ecosystem + 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); + rc = MetaDEx_CANCEL_ALL_FOR_PAIR(txid, block, sender, property, desired_property); break; + } case CANCEL_EVERYTHING: - rc = MetaDEx_CANCEL_EVERYTHING(txid, block, sender); + { + // cancel all open orders, if offered and desired properties are within the same ecosystem, + // otherwise cancel all open orders for all properties of both ecosystems + unsigned char ecosystem = 0; + if (isMainEcosystemProperty(property) && isMainEcosystemProperty(desired_property)) ecosystem = OMNI_PROPERTY_MSC; + if (isTestEcosystemProperty(property) && isTestEcosystemProperty(desired_property)) ecosystem = OMNI_PROPERTY_TMSC; + + if (!isTransactionTypeAllowed(block, ecosystem, type, version, true)) return (PKT_ERROR_METADEX -892); + + rc = MetaDEx_CANCEL_EVERYTHING(txid, block, sender, ecosystem); break; + } default: return (PKT_ERROR_METADEX -999); diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 6e81dfb48b08c..ac989bbaf1f8a 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -104,7 +104,6 @@ static const CRPCConvertParam vRPCConvertParams[] = { "getallbalancesforid_MP", 0 }, { "listblocktransactions_MP", 0 }, { "setautocommit_OMNI", 0 }, -#if 0 // disabled for pre meta DEx release { "trade_MP", 2 }, { "trade_MP", 4 }, { "trade_MP", 5 }, @@ -115,7 +114,6 @@ static const CRPCConvertParam vRPCConvertParams[] = { "gettradessince_MP", 2 }, { "gettradehistory_MP", 1 }, { "gettradehistory_MP", 2 }, -#endif // omni_rpctx { "send_OMNI", 2 }, { "sendsto_OMNI", 1 }, diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 274949f464ac1..a7ae73bbd57d1 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -364,14 +364,12 @@ static const CRPCCommand vRPCCommands[] = { "omni layer", "getgrants_MP", &getgrants_MP, false, false, true }, { "omni layer", "getactivedexsells_MP", &getactivedexsells_MP, false, false, true }, { "omni layer", "getactivecrowdsales_MP", &getactivecrowdsales_MP, false, false, true }, -#if 0 // disabled for pre meta DEx release - { "omni layer", "trade_MP", &sendtrade_OMNI, false, false, true }, - { "omni layer", "getorderbook_MP", &getorderbook_MP, false, false, true }, - { "omni layer", "gettradessince_MP", &gettradessince_MP, false, false, true }, - { "omni layer", "getopenorders_MP", &getopenorders_MP, false, false, true }, - { "omni layer", "gettradehistory_MP", &gettradehistory_MP, false, false, true }, - { "omni layer", "gettrade_MP", &gettrade_MP, false, false, true }, -#endif + { "hidden", "trade_MP", &sendtrade_OMNI, false, false, true }, + { "hidden", "getorderbook_MP", &getorderbook_MP, false, false, true }, + { "hidden", "gettradessince_MP", &gettradessince_MP, false, false, true }, + { "hidden", "getopenorders_MP", &getopenorders_MP, false, false, true }, + { "hidden", "gettradehistory_MP", &gettradehistory_MP, false, false, true }, + { "hidden", "gettrade_MP", &gettrade_MP, false, false, true }, { "omni layer", "sendtoowners_MP", &sendsto_OMNI, false, false, true }, { "omni layer", "sendrawtx_MP", &sendrawtx_MP, false, false, true }, { "omni layer", "getsto_MP", &getsto_MP, false, false, true },