From 60c047bf7183ed50579043264c1720d16e0386db Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Wed, 24 Oct 2018 09:39:32 -0700 Subject: [PATCH] Make filtering out change explicit --- src/rpc.cpp | 28 +++++++++++++++++++++------- src/rpc.h | 3 ++- src/senttxstore.cpp | 3 ++- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/rpc.cpp b/src/rpc.cpp index d601530..8a00abd 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -333,7 +333,8 @@ void RPC::getBatchRPC( } // Refresh received z txs by calling z_listreceivedbyaddress/gettransaction -void RPC::refreshReceivedZTrans(QList zaddrs, QList txidFilter) { +void RPC::refreshReceivedZTrans(QList zaddrs, QList> txidFilter) { + // We'll only refresh the received Z txs if settings allows us. if (!Settings::getInstance()->getSaveZtxs()) { QList emptylist; @@ -390,18 +391,27 @@ void RPC::refreshReceivedZTrans(QList zaddrs, QList txidFilter auto zaddr = it.key(); auto txid = QString::fromStdString(i["txid"].get()); - // We're filter out all the txids from this list, so as to not show a "received" transaction for a change address. + // We're filter out all the txids from this list, so as to not show a "received" transaction + // for a change address. // Note: the txidFilter is the list of all sent TxIDs - if (!txidFilter.contains(txid)) { - // Lookup txid in the map + + // First, find if the current txid is in the filtered list + auto filteredTxid = std::find_if(txidFilter.begin(), txidFilter.end(), [=] (auto item) { + return item.second == txid; + }); + + // If it is in the filtered list and the z-Addr is the fromAddress in the sent + // z-Addr, then this is a "change" recieve, so skip it + if (filteredTxid != txidFilter.end() && filteredTxid->first != zaddr) { auto txidInfo = txidDetails->value(txid); + // Lookup txid in the map // And then find the values auto timestamp = txidInfo["time"].get(); auto amount = i["amount"].get(); auto confirmations = txidInfo["confirmations"].get(); - TransactionItem tx{ QString("receive"), timestamp, zaddr, txid, amount, confirmations }; + TransactionItem tx{ QString("receive"), timestamp, zaddr, txid, amount, confirmations, "" }; txdata.push_front(tx); } } @@ -592,7 +602,8 @@ void RPC::refreshTransactions() { (it["address"].is_null() ? "" : QString::fromStdString(it["address"])), QString::fromStdString(it["txid"]), it["amount"].get() + fee, - it["confirmations"].get() + it["confirmations"].get(), + "" }; txdata.push_back(tx); @@ -606,14 +617,17 @@ void RPC::refreshTransactions() { // Read sent Z transactions from the file. void RPC::refreshSentZTrans(QList zaddresses) { auto sentZTxs = SentTxStore::readSentTxFile(); + QList txids; + QList> txidsForFilter; for (auto sentTx: sentZTxs) { txids.push_back(sentTx.txid); + txidsForFilter.push_back(QPair(sentTx.fromAddr, sentTx.txid)); } // We need to filter out the sent txids from the zreceived list. - refreshReceivedZTrans(zaddresses, txids); + refreshReceivedZTrans(zaddresses, txidsForFilter); // Look up all the txids to get the confirmation count for them. getBatchRPC(txids, diff --git a/src/rpc.h b/src/rpc.h index 3a9becb..0683054 100644 --- a/src/rpc.h +++ b/src/rpc.h @@ -19,6 +19,7 @@ struct TransactionItem { QString txid; double amount; unsigned long confirmations; + QString fromAddr; }; class RPC @@ -53,7 +54,7 @@ private: void refreshTransactions(); void refreshSentZTrans (QList zaddresses); - void refreshReceivedZTrans (QList zaddrs, QList txidFilter); + void refreshReceivedZTrans (QList zaddrs, QList> txidFilter); bool processUnspent (const json& reply); void updateUI (bool anyUnconfirmed); diff --git a/src/senttxstore.cpp b/src/senttxstore.cpp index caf2128..9d34094 100644 --- a/src/senttxstore.cpp +++ b/src/senttxstore.cpp @@ -42,7 +42,7 @@ QList SentTxStore::readSentTxFile() { sentTx["address"].toString(), sentTx["txid"].toString(), sentTx["amount"].toDouble() + sentTx["fee"].toDouble(), - 0}; + 0, sentTx["from"].toString()}; items.push_back(t); } @@ -81,6 +81,7 @@ void SentTxStore::addToSentTx(Tx tx, QString txid) { auto list = jsonDoc.array(); QJsonObject txItem; txItem["type"] = "sent"; + txItem["from"] = tx.fromAddr; txItem["datetime"] = QDateTime().currentSecsSinceEpoch(); txItem["address"] = QString(); // The sent address is blank, to be consistent with t-Addr sent behaviour txItem["txid"] = txid;