Make filtering out change explicit
This commit is contained in:
28
src/rpc.cpp
28
src/rpc.cpp
@@ -333,7 +333,8 @@ void RPC::getBatchRPC(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Refresh received z txs by calling z_listreceivedbyaddress/gettransaction
|
// 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.
|
// We'll only refresh the received Z txs if settings allows us.
|
||||||
if (!Settings::getInstance()->getSaveZtxs()) {
|
if (!Settings::getInstance()->getSaveZtxs()) {
|
||||||
QList<TransactionItem> emptylist;
|
QList<TransactionItem> emptylist;
|
||||||
@@ -390,18 +391,27 @@ void RPC::refreshReceivedZTrans(QList<QString> zaddrs, QList<QString> txidFilter
|
|||||||
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>());
|
||||||
|
|
||||||
// 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
|
// 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);
|
auto txidInfo = txidDetails->value(txid);
|
||||||
|
// Lookup txid in the map
|
||||||
|
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -592,7 +602,8 @@ void RPC::refreshTransactions() {
|
|||||||
(it["address"].is_null() ? "" : QString::fromStdString(it["address"])),
|
(it["address"].is_null() ? "" : QString::fromStdString(it["address"])),
|
||||||
QString::fromStdString(it["txid"]),
|
QString::fromStdString(it["txid"]),
|
||||||
it["amount"].get<json::number_float_t>() + fee,
|
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);
|
txdata.push_back(tx);
|
||||||
@@ -606,14 +617,17 @@ void RPC::refreshTransactions() {
|
|||||||
// Read sent Z transactions from the file.
|
// Read sent Z transactions from the file.
|
||||||
void RPC::refreshSentZTrans(QList<QString> zaddresses) {
|
void RPC::refreshSentZTrans(QList<QString> zaddresses) {
|
||||||
auto sentZTxs = SentTxStore::readSentTxFile();
|
auto sentZTxs = SentTxStore::readSentTxFile();
|
||||||
|
|
||||||
QList<QString> txids;
|
QList<QString> txids;
|
||||||
|
QList<QPair<QString, QString>> txidsForFilter;
|
||||||
|
|
||||||
for (auto sentTx: sentZTxs) {
|
for (auto sentTx: sentZTxs) {
|
||||||
txids.push_back(sentTx.txid);
|
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.
|
// 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.
|
// Look up all the txids to get the confirmation count for them.
|
||||||
getBatchRPC(txids,
|
getBatchRPC(txids,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ struct TransactionItem {
|
|||||||
QString txid;
|
QString txid;
|
||||||
double amount;
|
double amount;
|
||||||
unsigned long confirmations;
|
unsigned long confirmations;
|
||||||
|
QString fromAddr;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RPC
|
class RPC
|
||||||
@@ -53,7 +54,7 @@ private:
|
|||||||
|
|
||||||
void refreshTransactions();
|
void refreshTransactions();
|
||||||
void refreshSentZTrans (QList<QString> zaddresses);
|
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);
|
bool processUnspent (const json& reply);
|
||||||
void updateUI (bool anyUnconfirmed);
|
void updateUI (bool anyUnconfirmed);
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ QList<TransactionItem> SentTxStore::readSentTxFile() {
|
|||||||
sentTx["address"].toString(),
|
sentTx["address"].toString(),
|
||||||
sentTx["txid"].toString(),
|
sentTx["txid"].toString(),
|
||||||
sentTx["amount"].toDouble() + sentTx["fee"].toDouble(),
|
sentTx["amount"].toDouble() + sentTx["fee"].toDouble(),
|
||||||
0};
|
0, sentTx["from"].toString()};
|
||||||
items.push_back(t);
|
items.push_back(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,6 +81,7 @@ void SentTxStore::addToSentTx(Tx tx, QString txid) {
|
|||||||
auto list = jsonDoc.array();
|
auto list = jsonDoc.array();
|
||||||
QJsonObject txItem;
|
QJsonObject txItem;
|
||||||
txItem["type"] = "sent";
|
txItem["type"] = "sent";
|
||||||
|
txItem["from"] = tx.fromAddr;
|
||||||
txItem["datetime"] = QDateTime().currentSecsSinceEpoch();
|
txItem["datetime"] = QDateTime().currentSecsSinceEpoch();
|
||||||
txItem["address"] = QString(); // The sent address is blank, to be consistent with t-Addr sent behaviour
|
txItem["address"] = QString(); // The sent address is blank, to be consistent with t-Addr sent behaviour
|
||||||
txItem["txid"] = txid;
|
txItem["txid"] = txid;
|
||||||
|
|||||||
Reference in New Issue
Block a user