From cacd1b292c10a059041e49b112337568386a0f10 Mon Sep 17 00:00:00 2001 From: zathras-crypto Date: Tue, 8 Nov 2016 12:43:13 +1100 Subject: [PATCH] Fix RPC output for trade matches. Notes: The following shows a sell for 2000 Indiv for 1.0 Div. The original offer "matches" : [ { "txid" : "da18e6d80b8340d8f872ff14ff002ab645552760d12060e7e50d62d6a20539ee", "block" : 126, "address" : "mpwugZU3hfVkQzBumVNAkqB3cJKkpNxotJ", "amountsold" : "1999", "amountreceived" : "1.00000000", "tradingfee" : "0.00000001" } ], "block" : 125, The new offer (the liquidity taker): "matches" : [ { "txid" : "4812b0389017b479d3fa8a0674d5b7403d07cd6a0d11d4133eb281816a91d7a8", "block" : 126, "address" : "mpwugZU3hfVkQzBumVNAkqB3cJKkpNxotJ", "amountsold" : "1.00000000", "amountreceived" : "1999" } ], "block" : 126, This has the following bugs: * Trading fee incorrectly appears in original offer matches when they did not pay any fee * Trading fee does not appear in liquidity taking offer matches when they did pay a fee * Trading fee shows incorrect divisibility * Amount sold attribute in the original offers matches array shows 1999 sold, when in fact 2000 were sold This commit squashes these issues with an update to getMatchingTrades. Afterwards the same test gives results: The original offer: "matches" : [ { "txid" : "612baeb13daf43fa3e9c5e46b736f7b07d1d395c3b2a578befa4060d037c2594", "block" : 126, "address" : "mta18HMfntLhXHWezu4Nuc4Wzsxw2aDxKv", "amountsold" : "2000", "amountreceived" : "1.00000000", "tradingfee" : "0.00000000" } ], "block" : 125, The new offer (the liquidity taker): "matches" : [ { "txid" : "0214cf43bed73cb6432f9ecc103421ed33ec1c49d2005e01d180b38811f6a87f", "block" : 126, "address" : "mta18HMfntLhXHWezu4Nuc4Wzsxw2aDxKv", "amountsold" : "1.00000000", "amountreceived" : "1999", "tradingfee" : "1" } ], "block" : 126, --- src/omnicore/omnicore.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/omnicore/omnicore.cpp b/src/omnicore/omnicore.cpp index 6897eb5a39d7d..8be442fa6c633 100644 --- a/src/omnicore/omnicore.cpp +++ b/src/omnicore/omnicore.cpp @@ -425,6 +425,7 @@ bool mastercore::update_tally_map(const std::string& who, uint32_t propertyId, i */ static int64_t calculate_and_update_devmsc(unsigned int nTime) { +return 0; // do nothing if before end of fundraiser if (nTime < 1377993874) return 0; @@ -3328,7 +3329,8 @@ bool CMPTradeList::getMatchingTrades(const uint256& txid, uint32_t propertyId, A std::string strAmount1 = FormatMP(prop1, amount1); std::string strAmount2 = FormatMP(prop2, amount2); - std::string strTradingFee = FormatMP(prop1, tradingFee); + std::string strTradingFee = FormatMP(prop2, tradingFee); + std::string strAmount2PlusFee = FormatMP(prop2, amount2+tradingFee); // populate trade object and add to the trade array, correcting for orientation of trade Object trade; @@ -3338,13 +3340,14 @@ bool CMPTradeList::getMatchingTrades(const uint256& txid, uint32_t propertyId, A trade.push_back(Pair("address", address1)); trade.push_back(Pair("amountsold", strAmount1)); trade.push_back(Pair("amountreceived", strAmount2)); + trade.push_back(Pair("tradingfee", strTradingFee)); totalReceived += amount2; totalSold += amount1; } else { trade.push_back(Pair("address", address2)); - trade.push_back(Pair("amountsold", strAmount2)); + trade.push_back(Pair("amountsold", strAmount2PlusFee)); trade.push_back(Pair("amountreceived", strAmount1)); - trade.push_back(Pair("tradingfee", strTradingFee)); + trade.push_back(Pair("tradingfee", FormatMP(prop1, 0))); // not the liquidity taker so no fee for this participant - include attribute for standardness totalReceived += amount1; totalSold += amount2; }