Simplify change address filtering
This commit is contained in:
64
src/rpc.cpp
64
src/rpc.cpp
@@ -333,7 +333,7 @@ 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<QPair<QString, QString>> txidFilter) {
|
void RPC::refreshReceivedZTrans(QList<QString> zaddrs) {
|
||||||
|
|
||||||
// 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()) {
|
||||||
@@ -366,7 +366,9 @@ void RPC::refreshReceivedZTrans(QList<QString> zaddrs, QList<QPair<QString, QStr
|
|||||||
QSet<QString> txids;
|
QSet<QString> txids;
|
||||||
for (auto it = zaddrTxids->constBegin(); it != zaddrTxids->constEnd(); it++) {
|
for (auto it = zaddrTxids->constBegin(); it != zaddrTxids->constEnd(); it++) {
|
||||||
for (auto& i : it.value().get<json::array_t>()) {
|
for (auto& i : it.value().get<json::array_t>()) {
|
||||||
txids.insert(QString::fromStdString(i["txid"].get<json::string_t>()));
|
// Filter out change txs
|
||||||
|
if (! i["change"].get<json::boolean_t>())
|
||||||
|
txids.insert(QString::fromStdString(i["txid"].get<json::string_t>()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,32 +390,34 @@ void RPC::refreshReceivedZTrans(QList<QString> zaddrs, QList<QPair<QString, QStr
|
|||||||
// Combine them both together. For every zAddr's txid, get the amount, fee, confirmations and time
|
// Combine them both together. For every zAddr's txid, get the amount, fee, confirmations and time
|
||||||
for (auto it = zaddrTxids->constBegin(); it != zaddrTxids->constEnd(); it++) {
|
for (auto it = zaddrTxids->constBegin(); it != zaddrTxids->constEnd(); it++) {
|
||||||
for (auto& i : it.value().get<json::array_t>()) {
|
for (auto& i : it.value().get<json::array_t>()) {
|
||||||
|
// Filter out change txs
|
||||||
|
if (i["change"].get<json::boolean_t>())
|
||||||
|
continue;
|
||||||
|
|
||||||
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
|
// Lookup txid in the map
|
||||||
// for a change address.
|
auto txidInfo = txidDetails->value(txid);
|
||||||
// Note: the txidFilter is the list of all sent TxIDs
|
|
||||||
|
|
||||||
// First, find if the current txid is in the filtered list
|
// And then find the values
|
||||||
auto filteredTxid = std::find_if(txidFilter.begin(), txidFilter.end(), [=] (auto item) {
|
if (txidInfo == nullptr) {
|
||||||
return item.second == txid;
|
std::cout << zaddr.toStdString() << std::endl;
|
||||||
});
|
std::cout << txid.toStdString() << std::endl;
|
||||||
|
|
||||||
// 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, "" };
|
|
||||||
txdata.push_front(tx);
|
|
||||||
}
|
}
|
||||||
|
unsigned long timestamp;
|
||||||
|
if (txidInfo.find("time") != txidInfo.end()) {
|
||||||
|
timestamp = txidInfo["time"].get<json::number_unsigned_t>();
|
||||||
|
} else {
|
||||||
|
timestamp = txidInfo["blocktime"].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, "" };
|
||||||
|
txdata.push_front(tx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,7 +459,7 @@ void RPC::getInfoThenRefresh() {
|
|||||||
|
|
||||||
// Refresh everything.
|
// Refresh everything.
|
||||||
refreshBalances();
|
refreshBalances();
|
||||||
refreshAddresses(); // This calls refreshZSentTransactions() -> which calls refreshReceivedZTrans(0)
|
refreshAddresses(); // This calls refreshZSentTransactions() and refreshReceivedZTrans()
|
||||||
refreshTransactions();
|
refreshTransactions();
|
||||||
|
|
||||||
// Call to see if the blockchain is syncing.
|
// Call to see if the blockchain is syncing.
|
||||||
@@ -501,8 +505,9 @@ void RPC::refreshAddresses() {
|
|||||||
zaddresses->push_back(addr);
|
zaddresses->push_back(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh the sent txs from all these zaddresses
|
// Refresh the sent and received txs from all these zaddresses
|
||||||
refreshSentZTrans(*zaddresses);
|
refreshSentZTrans();
|
||||||
|
refreshReceivedZTrans(*zaddresses);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -615,20 +620,15 @@ 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() {
|
||||||
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.
|
|
||||||
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,
|
||||||
[=] (QString txid) {
|
[=] (QString txid) {
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ private:
|
|||||||
void refreshBalances();
|
void refreshBalances();
|
||||||
|
|
||||||
void refreshTransactions();
|
void refreshTransactions();
|
||||||
void refreshSentZTrans (QList<QString> zaddresses);
|
void refreshSentZTrans ();
|
||||||
void refreshReceivedZTrans (QList<QString> zaddrs, QList<QPair<QString, QString>> txidFilter);
|
void refreshReceivedZTrans (QList<QString> zaddresses);
|
||||||
|
|
||||||
bool processUnspent (const json& reply);
|
bool processUnspent (const json& reply);
|
||||||
void updateUI (bool anyUnconfirmed);
|
void updateUI (bool anyUnconfirmed);
|
||||||
|
|||||||
Reference in New Issue
Block a user