Browse Source

Make filtering out change explicit

recurring
Aditya Kulkarni 6 years ago
parent
commit
60c047bf71
  1. 28
      src/rpc.cpp
  2. 3
      src/rpc.h
  3. 3
      src/senttxstore.cpp

28
src/rpc.cpp

@ -333,7 +333,8 @@ void RPC::getBatchRPC(
}
// Refresh received z txs by calling z_listreceivedbyaddress/gettransaction
void RPC::refreshReceivedZTrans(QList<QString> zaddrs, QList<QString> txidFilter) {
void RPC::refreshReceivedZTrans(QList<QString> zaddrs, QList<QPair<QString, QString>> txidFilter) {
// We'll only refresh the received Z txs if settings allows us.
if (!Settings::getInstance()->getSaveZtxs()) {
QList<TransactionItem> emptylist;
@ -390,18 +391,27 @@ void RPC::refreshReceivedZTrans(QList<QString> zaddrs, QList<QString> txidFilter
auto zaddr = it.key();
auto txid = QString::fromStdString(i["txid"].get<json::string_t>());
// 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<json::number_unsigned_t>();
auto amount = i["amount"].get<json::number_float_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);
}
}
@ -592,7 +602,8 @@ void RPC::refreshTransactions() {
(it["address"].is_null() ? "" : QString::fromStdString(it["address"])),
QString::fromStdString(it["txid"]),
it["amount"].get<json::number_float_t>() + fee,
it["confirmations"].get<json::number_unsigned_t>()
it["confirmations"].get<json::number_unsigned_t>(),
""
};
txdata.push_back(tx);
@ -606,14 +617,17 @@ void RPC::refreshTransactions() {
// Read sent Z transactions from the file.
void RPC::refreshSentZTrans(QList<QString> zaddresses) {
auto sentZTxs = SentTxStore::readSentTxFile();
QList<QString> txids;
QList<QPair<QString, QString>> txidsForFilter;
for (auto sentTx: sentZTxs) {
txids.push_back(sentTx.txid);
txidsForFilter.push_back(QPair<QString, QString>(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,

3
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<QString> zaddresses);
void refreshReceivedZTrans (QList<QString> zaddrs, QList<QString> txidFilter);
void refreshReceivedZTrans (QList<QString> zaddrs, QList<QPair<QString, QString>> txidFilter);
bool processUnspent (const json& reply);
void updateUI (bool anyUnconfirmed);

3
src/senttxstore.cpp

@ -42,7 +42,7 @@ QList<TransactionItem> 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;

Loading…
Cancel
Save