Skip to content

Commit

Permalink
UI: remove old trade history update function
Browse files Browse the repository at this point in the history
Note - old function inefficient in that it reparsed all wallet transactions every update
  • Loading branch information
zathras-crypto committed May 19, 2015
1 parent 033b6ce commit f0b9fe7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 311 deletions.
310 changes: 0 additions & 310 deletions src/qt/tradehistorydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,316 +462,6 @@ void TradeHistoryDialog::UpdateData()
}
}

/*
void TradeHistoryDialog::update()
{
//pending orders
int rowcount = 0;
// handle pending transactions first
for(PendingMap::iterator it = my_pending.begin(); it != my_pending.end(); ++it)
{
CMPPending *p_pending = &(it->second);
uint256 txid = it->first;
string txidStr = txid.GetHex();
string senderAddress = p_pending->src;
uint64_t propertyId = p_pending->prop;
bool divisible = isPropertyDivisible(propertyId);
string displayAmount;
int64_t amount = p_pending->amount;
string displayToken;
string displayValid;
string displayAddress = senderAddress;
int64_t type = p_pending->type;
if (type == 21)
{
if (divisible) { displayAmount = FormatDivisibleShortMP(amount); } else { displayAmount = FormatIndivisibleMP(amount); }
QString txTimeStr = "Unconfirmed";
string statusText = "Pending";
string displayText = "Sell ";
string displayInToken;
string displayOutToken;
if(divisible) { displayText += FormatDivisibleShortMP(amount); } else { displayText += FormatIndivisibleMP(amount); }
if(propertyId < 3)
{
if(propertyId == 1) { displayText += " MSC"; displayOutToken = " MSC"; }
if(propertyId == 2) { displayText += " TMSC"; displayOutToken = " TMSC"; }
}
else
{
string s = static_cast<ostringstream*>( &(ostringstream() << propertyId) )->str();
displayText += " SPT#" + s + "";
displayOutToken = " SPT#" + s;
}
displayText += " (awaiting confirmation)";
string displayIn = "---";
string displayOut = "---";
//icon
QIcon ic = QIcon(":/icons/transaction_0");
// add to history
ui->tradeHistoryTable->setRowCount(rowcount+1);
QTableWidgetItem *dateCell = new QTableWidgetItem(txTimeStr);
QTableWidgetItem *statusCell = new QTableWidgetItem(QString::fromStdString(statusText));
QTableWidgetItem *infoCell = new QTableWidgetItem(QString::fromStdString(displayText));
QTableWidgetItem *amountOutCell = new QTableWidgetItem(QString::fromStdString(displayOut));
QTableWidgetItem *amountInCell = new QTableWidgetItem(QString::fromStdString(displayIn));
QTableWidgetItem *iconCell = new QTableWidgetItem;
QTableWidgetItem *txidCell = new QTableWidgetItem(QString::fromStdString(txidStr));
iconCell->setIcon(ic);
amountOutCell->setTextAlignment(Qt::AlignRight + Qt::AlignVCenter);
amountOutCell->setForeground(QColor("#EE0000"));
amountInCell->setTextAlignment(Qt::AlignRight + Qt::AlignVCenter);
amountInCell->setForeground(QColor("#00AA00"));
if (rowcount % 2)
{
dateCell->setBackground(QColor("#F0F0F0"));
statusCell->setBackground(QColor("#F0F0F0"));
infoCell->setBackground(QColor("#F0F0F0"));
amountOutCell->setBackground(QColor("#F0F0F0"));
amountInCell->setBackground(QColor("#F0F0F0"));
iconCell->setBackground(QColor("#F0F0F0"));
txidCell->setBackground(QColor("#F0F0F0"));
}
amountInCell->setForeground(QColor("#000000"));
amountOutCell->setForeground(QColor("#000000"));
ui->tradeHistoryTable->setItem(rowcount, 0, txidCell);
ui->tradeHistoryTable->setItem(rowcount, 2, iconCell);
ui->tradeHistoryTable->setItem(rowcount, 3, dateCell);
ui->tradeHistoryTable->setItem(rowcount, 4, statusCell);
ui->tradeHistoryTable->setItem(rowcount, 5, infoCell);
ui->tradeHistoryTable->setItem(rowcount, 6, amountOutCell);
ui->tradeHistoryTable->setItem(rowcount, 7, amountInCell);
rowcount += 1;
}
}
//wallet orders
CWallet *wallet = pwalletMain;
string sAddress = "";
int64_t nStartBlock = 0;
int64_t nEndBlock = 999999;
// rewrite to use original listtransactions methodology from core
LOCK(wallet->cs_wallet);
std::list<CAccountingEntry> acentries;
CWallet::TxItems txOrdered = pwalletMain->OrderedTxItems(acentries, "*");
// iterate backwards
for (CWallet::TxItems::reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
{
CWalletTx *const pwtx = (*it).second.first;
if (pwtx != 0)
{
uint256 hash = pwtx->GetHash();
CTransaction wtx;
uint256 blockHash = 0;
if (!GetTransaction(hash, wtx, blockHash, true)) continue;
// get the time of the tx
int64_t nTime = pwtx->GetTxTime();
// get the height of the transaction and check it's within the chosen parameters
blockHash = pwtx->hashBlock;
if ((0 == blockHash) || (NULL == GetBlockIndex(blockHash))) continue;
CBlockIndex* pBlockIndex = GetBlockIndex(blockHash);
if (NULL == pBlockIndex) continue;
int blockHeight = pBlockIndex->nHeight;
if ((blockHeight < nStartBlock) || (blockHeight > nEndBlock)) continue; // ignore it if not within our range
// check if the transaction exists in txlist, and if so is it correct type (21)
if (p_txlistdb->exists(hash))
{
// get type from levelDB
string strValue;
if (!p_txlistdb->getTX(hash, strValue)) continue;
std::vector<std::string> vstr;
boost::split(vstr, strValue, boost::is_any_of(":"), boost::token_compress_on);
if (4 <= vstr.size())
{
// if tx21, get the details for the list
if(21 == atoi(vstr[2]))
{
string statusText;
unsigned int propertyIdForSale = 0;
unsigned int propertyIdDesired = 0;
uint64_t amountForSale = 0;
uint64_t amountDesired = 0;
string address;
bool divisibleForSale = false;
bool divisibleDesired = false;
Array tradeArray;
int64_t totalBought = 0;
int64_t totalSold = 0;
bool orderOpen = false;
bool valid = false;
CMPMetaDEx temp_metadexoffer;
CMPTransaction mp_obj;
int parseRC = parseTransaction(true, wtx, blockHeight, 0, &mp_obj);
if (0 <= parseRC) //negative RC means no MP content/badly encoded TX, we shouldn't see this if TX in levelDB but check for sanity
{
if (0<=mp_obj.step1())
{
//MPTxType = mp_obj.getTypeString();
//MPTxTypeInt = mp_obj.getType();
address = mp_obj.getSender();
//if (!filterAddress.empty()) if ((senderAddress != filterAddress) && (refAddress != filterAddress)) return -1; // return negative rc if filtering & no match
int tmpblock=0;
uint32_t tmptype=0;
uint64_t amountNew=0;
valid=getValidMPTX(hash, &tmpblock, &tmptype, &amountNew);
if (0 == mp_obj.step2_Value())
{
propertyIdForSale = mp_obj.getProperty();
amountForSale = mp_obj.getAmount();
divisibleForSale = isPropertyDivisible(propertyIdForSale);
if (0 <= mp_obj.interpretPacket(NULL,&temp_metadexoffer))
{
propertyIdDesired = temp_metadexoffer.getDesProperty();
divisibleDesired = isPropertyDivisible(propertyIdDesired);
amountDesired = temp_metadexoffer.getAmountDesired();
//mdex_action = temp_metadexoffer.getAction();
t_tradelistdb->getMatchingTrades(hash, propertyIdForSale, &tradeArray, &totalSold, &totalBought);
// status - is order cancelled/closed-filled/open/open-partialfilled?
// is the sell offer still open - need more efficient way to do this
for (md_PropertiesMap::iterator my_it = metadex.begin(); my_it != metadex.end(); ++my_it)
{
if (my_it->first == propertyIdForSale) //at minimum only go deeper if it's the right property id
{
md_PricesMap & prices = my_it->second;
for (md_PricesMap::iterator it = prices.begin(); it != prices.end(); ++it)
{
md_Set & indexes = (it->second);
for (md_Set::iterator it = indexes.begin(); it != indexes.end(); ++it)
{
CMPMetaDEx obj = *it;
if( obj.getHash().GetHex() == hash.GetHex() ) orderOpen = true;
}
}
}
}
}
}
}
}
// work out status
bool partialFilled = false;
bool filled = false;
if(totalSold>0) partialFilled = true;
if(totalSold>=amountForSale) filled = true;
statusText = "Unknown";
if((!orderOpen) && (!partialFilled)) statusText = "Cancelled";
if((!orderOpen) && (partialFilled)) statusText = "Part Cancel";
if((!orderOpen) && (filled)) statusText = "Filled";
if((orderOpen) && (!partialFilled)) statusText = "Open";
if((orderOpen) && (partialFilled)) statusText = "Part Filled";
// add to list
string displayText = "Sell ";
string displayIn = "";
string displayOut = "-";
string displayInToken;
string displayOutToken;
if(divisibleForSale) { displayText += FormatDivisibleShortMP(amountForSale); } else { displayText += FormatIndivisibleMP(amountForSale); }
if(propertyIdForSale < 3)
{
if(propertyIdForSale == 1) { displayText += " MSC for "; displayOutToken = " MSC"; }
if(propertyIdForSale == 2) { displayText += " TMSC for "; displayOutToken = " TMSC"; }
}
else
{
string s = static_cast<ostringstream*>( &(ostringstream() << propertyIdForSale) )->str();
displayText += " SPT#" + s + " for ";
displayOutToken = " SPT#" + s;
}
if(divisibleDesired) { displayText += FormatDivisibleShortMP(amountDesired); } else { displayText += FormatIndivisibleMP(amountDesired); }
if(propertyIdDesired < 3)
{
if(propertyIdDesired == 1) { displayText += " MSC"; displayInToken = " MSC"; }
if(propertyIdDesired == 2) { displayText += " TMSC"; displayInToken = " TMSC"; }
}
else
{
string s = static_cast<ostringstream*>( &(ostringstream() << propertyIdDesired) )->str();
displayText += " SPT#" + s;
displayInToken = " SPT#" + s;
}
if(divisibleDesired) { displayIn += FormatDivisibleShortMP(totalBought); } else { displayIn += FormatIndivisibleMP(totalBought); }
if(divisibleForSale) { displayOut += FormatDivisibleShortMP(totalSold); } else { displayOut += FormatIndivisibleMP(totalSold); }
if(totalBought == 0) displayIn = "0";
if(totalSold == 0) displayOut = "0";
displayIn += displayInToken;
displayOut += displayOutToken;
QDateTime txTime;
txTime.setTime_t(nTime);
QString txTimeStr = txTime.toString(Qt::SystemLocaleShortDate);
//icon
QIcon ic = QIcon(":/icons/transaction_0");
if(statusText == "Cancelled") ic =QIcon(":/icons/meta_cancelled");
if(statusText == "Part Cancel") ic = QIcon(":/icons/meta_partialclosed");
if(statusText == "Filled") ic = QIcon(":/icons/meta_filled");
if(statusText == "Open") ic = QIcon(":/icons/meta_open");
if(statusText == "Part Filled") ic = QIcon(":/icons/meta_partial");
if(!valid) ic = QIcon(":/icons/transaction_invalid");
// add to order history
ui->tradeHistoryTable->setRowCount(rowcount+1);
QTableWidgetItem *dateCell = new QTableWidgetItem(txTimeStr);
QTableWidgetItem *statusCell = new QTableWidgetItem(QString::fromStdString(statusText));
QTableWidgetItem *infoCell = new QTableWidgetItem(QString::fromStdString(displayText));
QTableWidgetItem *amountOutCell = new QTableWidgetItem(QString::fromStdString(displayOut));
QTableWidgetItem *amountInCell = new QTableWidgetItem(QString::fromStdString(displayIn));
QTableWidgetItem *iconCell = new QTableWidgetItem;
QTableWidgetItem *txidCell = new QTableWidgetItem(QString::fromStdString(hash.GetHex()));
iconCell->setIcon(ic);
//addressCell->setTextAlignment(Qt::AlignLeft + Qt::AlignVCenter);
//addressCell->setForeground(QColor("#707070"));
amountOutCell->setTextAlignment(Qt::AlignRight + Qt::AlignVCenter);
amountOutCell->setForeground(QColor("#EE0000"));
amountInCell->setTextAlignment(Qt::AlignRight + Qt::AlignVCenter);
amountInCell->setForeground(QColor("#00AA00"));
if (rowcount % 2)
{
dateCell->setBackground(QColor("#F0F0F0"));
statusCell->setBackground(QColor("#F0F0F0"));
infoCell->setBackground(QColor("#F0F0F0"));
amountOutCell->setBackground(QColor("#F0F0F0"));
amountInCell->setBackground(QColor("#F0F0F0"));
iconCell->setBackground(QColor("#F0F0F0"));
txidCell->setBackground(QColor("#F0F0F0"));
}
if((!orderOpen) && (filled)) //make filled orders background
{
dateCell->setForeground(QColor("#707070"));
statusCell->setForeground(QColor("#707070"));
infoCell->setForeground(QColor("#707070"));
amountOutCell->setForeground(QColor("#993333"));
amountInCell->setForeground(QColor("#006600"));
}
if(displayIn.substr(0,2) == "0 ") amountInCell->setForeground(QColor("#000000"));
if(displayOut.substr(0,2) == "0 ") amountOutCell->setForeground(QColor("#000000"));
ui->tradeHistoryTable->setItem(rowcount, 0, txidCell);
ui->tradeHistoryTable->setItem(rowcount, 2, iconCell);
ui->tradeHistoryTable->setItem(rowcount, 3, dateCell);
ui->tradeHistoryTable->setItem(rowcount, 4, statusCell);
ui->tradeHistoryTable->setItem(rowcount, 5, infoCell);
ui->tradeHistoryTable->setItem(rowcount, 6, amountOutCell);
ui->tradeHistoryTable->setItem(rowcount, 7, amountInCell);
rowcount += 1;
}
}
}
}
}
}
*/

void TradeHistoryDialog::setModel(WalletModel *model)
{
this->model = model;
Expand Down
1 change: 0 additions & 1 deletion src/qt/tradehistorydialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class TradeHistoryDialog : public QDialog
TradeHistoryMap tradeHistoryMap;

public slots:
// void update();
void contextualMenu(const QPoint &point);
void showDetails();
void copyTxID();
Expand Down

0 comments on commit f0b9fe7

Please sign in to comment.