Supress showing change receives in the transactions table.

This commit is contained in:
Aditya Kulkarni
2018-10-23 17:12:06 -07:00
parent 9694ab7439
commit dd256bd304
3 changed files with 33 additions and 23 deletions

View File

@@ -333,7 +333,7 @@ void RPC::getBatchRPC(
} }
/// Batch RPC methods /// Batch RPC methods
void RPC::getReceivedZTrans(QList<QString> zaddrs) { void RPC::refreshReceivedZTrans(QList<QString> zaddrs, QList<QString> txidFilter) {
// 1. For each z-Addr, get list of received txs // 1. For each z-Addr, get list of received txs
getBatchRPC(zaddrs, getBatchRPC(zaddrs,
[=] (QString zaddr) { [=] (QString zaddr) {
@@ -376,16 +376,20 @@ void RPC::getReceivedZTrans(QList<QString> zaddrs) {
auto zaddr = it.key(); auto zaddr = it.key();
auto txid = QString::fromStdString(i["txid"].get<json::string_t>()); auto txid = QString::fromStdString(i["txid"].get<json::string_t>());
// Lookup txid in the map // We're filter out all the txids from this list, so as to not show a "received" transaction for a change address.
auto txidInfo = txidDetails->value(txid); // Note: the txidFilter is the list of all sent TxIDs
if (!txidFilter.contains(txid)) {
// Lookup txid in the map
auto txidInfo = txidDetails->value(txid);
// And then find the values // And then find the values
auto timestamp = txidInfo["time"].get<json::number_unsigned_t>(); auto timestamp = txidInfo["time"].get<json::number_unsigned_t>();
auto amount = i["amount"].get<json::number_float_t>(); auto amount = i["amount"].get<json::number_float_t>();
auto confirmations = txidInfo["confirmations"].get<json::number_unsigned_t>(); auto confirmations = txidInfo["confirmations"].get<json::number_unsigned_t>();
TransactionItem tx{ QString("receive"), timestamp, zaddr, txid, amount, confirmations }; TransactionItem tx{ QString("receive"), timestamp, zaddr, txid, amount, confirmations };
txdata.push_front(tx); txdata.push_front(tx);
}
} }
} }
@@ -427,9 +431,8 @@ void RPC::getInfoThenRefresh() {
// Refresh everything. // Refresh everything.
refreshBalances(); refreshBalances();
refreshAddresses(); refreshAddresses(); // This calls refreshZSentTransactions() -> which calls refreshReceivedZTrans(0)
refreshTransactions(); refreshTransactions();
refreshZSentTransactions();
// Call to see if the blockchain is syncing. // Call to see if the blockchain is syncing.
json payload = { json payload = {
@@ -474,8 +477,8 @@ void RPC::refreshAddresses() {
zaddresses->push_back(addr); zaddresses->push_back(addr);
} }
// Temp // Refresh the sent txs from all these zaddresses
getReceivedZTrans(*zaddresses); refreshSentZTrans(*zaddresses);
}); });
} }
@@ -579,7 +582,7 @@ void RPC::refreshTransactions() {
} }
// Read sent Z transactions from the file. // Read sent Z transactions from the file.
void RPC::refreshZSentTransactions() { void RPC::refreshSentZTrans(QList<QString> zaddresses) {
auto sentZTxs = SentTxStore::readSentTxFile(); auto sentZTxs = SentTxStore::readSentTxFile();
QList<QString> txids; QList<QString> txids;
@@ -587,6 +590,9 @@ void RPC::refreshZSentTransactions() {
txids.push_back(sentTx.txid); txids.push_back(sentTx.txid);
} }
// We need to filter out the sent txids from the zreceived list.
refreshReceivedZTrans(zaddresses, txids);
// Look up all the txids to get the confirmation count for them. // Look up all the txids to get the confirmation count for them.
getBatchRPC(txids, getBatchRPC(txids,
[=] (QString txid) { [=] (QString txid) {

View File

@@ -50,8 +50,10 @@ private:
void doSendRPC (const json& payload, const std::function<void(json)>& cb); void doSendRPC (const json& payload, const std::function<void(json)>& cb);
void refreshBalances(); void refreshBalances();
void refreshTransactions(); void refreshTransactions();
void refreshZSentTransactions(); void refreshSentZTrans (QList<QString> zaddresses);
void refreshReceivedZTrans (QList<QString> zaddrs, QList<QString> txidFilter);
bool processUnspent (const json& reply); bool processUnspent (const json& reply);
void updateUI (bool anyUnconfirmed); void updateUI (bool anyUnconfirmed);
@@ -69,7 +71,6 @@ private:
void handleTxError (const QString& error); void handleTxError (const QString& error);
// Batch // Batch
void getReceivedZTrans(QList<QString> zaddrs);
void getBatchRPC(const QList<QString>& payloads, void getBatchRPC(const QList<QString>& payloads,
std::function<json(QString)> payloadGenerator, std::function<json(QString)> payloadGenerator,
std::function<void(QMap<QString, json>*)> cb); std::function<void(QMap<QString, json>*)> cb);

View File

@@ -37,18 +37,21 @@ void TxTableModel::addTData(const QList<TransactionItem>& data) {
updateAllData(); updateAllData();
} }
void TxTableModel::updateAllData() { void TxTableModel::updateAllData() {
delete modeldata; auto newmodeldata = new QList<TransactionItem>();
modeldata = new QList<TransactionItem>();
if (tTrans != nullptr) std::copy( tTrans->begin(), tTrans->end(), std::back_inserter(*modeldata)); if (tTrans != nullptr) std::copy( tTrans->begin(), tTrans->end(), std::back_inserter(*newmodeldata));
if (zsTrans != nullptr) std::copy(zsTrans->begin(), zsTrans->end(), std::back_inserter(*modeldata)); if (zsTrans != nullptr) std::copy(zsTrans->begin(), zsTrans->end(), std::back_inserter(*newmodeldata));
if (zrTrans != nullptr) std::copy(zrTrans->begin(), zrTrans->end(), std::back_inserter(*modeldata)); if (zrTrans != nullptr) std::copy(zrTrans->begin(), zrTrans->end(), std::back_inserter(*newmodeldata));
// Sort by reverse time // Sort by reverse time
std::sort(modeldata->begin(), modeldata->end(), [=] (auto a, auto b) { std::sort(newmodeldata->begin(), newmodeldata->end(), [=] (auto a, auto b) {
return a.datetime > b.datetime; // reverse sort return a.datetime > b.datetime; // reverse sort
}); });
// And then swap out the modeldata with the new one.
delete modeldata;
modeldata = newmodeldata;
dataChanged(index(0, 0), index(modeldata->size()-1, columnCount(index(0,0))-1)); dataChanged(index(0, 0), index(modeldata->size()-1, columnCount(index(0,0))-1));
layoutChanged(); layoutChanged();