Skip to content

Commit

Permalink
Fix RPC output for trade matches.
Browse files Browse the repository at this point in the history
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,
  • Loading branch information
zathras-crypto committed Nov 8, 2016
1 parent c22c91e commit cacd1b2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/omnicore/omnicore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit cacd1b2

Please sign in to comment.