compiling with mergeTx() impl less merge() calls

This commit is contained in:
woodser
2019-06-11 13:13:02 -04:00
parent a0a618406e
commit 3757513f62
+5 -51
View File
@@ -209,16 +209,16 @@ namespace monero {
(*tx->block)->txs = txs;
(*tx->block)->height = *aTx->getHeight();
}
aTx->block->merge(tx->block);
//aTx->block->merge(tx->block);
} else {
aTx->merge(*tx);
//aTx->merge(*tx);
}
return;
}
// merge common block of different txs
if (tx->getHeight() != boost::none && *tx->getHeight() == *aTx->getHeight())
(*aTx-block)->merge(*tx->block);
if (tx->getHeight() != boost::none && *tx->getHeight() == *aTx->getHeight()) {
//(*aTx-block)->merge(*tx->block);
//if (aTx.getIsConfirmed()) assertTrue(aTx.getBlock().getTxs().contains(aTx));
}
}
@@ -231,52 +231,6 @@ namespace monero {
}
}
/**
* Merges a transaction into a unique set of transactions.
*
* TODO monero-wallet-rpc: skipIfAbsent only necessary because incoming payments not returned
* when sent from/to same account
*
* @param txs are existing transactions to merge into
* @param tx is the transaction to merge into the existing txs
* @param skipIfAbsent specifies if the tx should not be added
* if it doesn't already exist. Only necessasry to handle
* missing incoming payments from #4500. // TODO
* @returns the merged tx
*/
private static void mergeTx(List<MoneroTxWallet> txs, MoneroTxWallet tx, boolean skipIfAbsent) {
assertNotNull(tx.getId());
for (MoneroTxWallet aTx : txs) {
// merge tx
if (aTx.getId().equals(tx.getId())) {
// merge blocks which only exist when confirmed
if (aTx.getBlock() != null || tx.getBlock() != null) {
if (aTx.getBlock() == null) aTx.setBlock(new MoneroBlock().setTxs(new ArrayList<MoneroTx>(Arrays.asList(aTx))).setHeight(tx.getHeight()));
if (tx.getBlock() == null) tx.setBlock(new MoneroBlock().setTxs(new ArrayList<MoneroTx>(Arrays.asList(tx))).setHeight(aTx.getHeight()));
aTx.getBlock().merge(tx.getBlock());
} else {
aTx.merge(tx);
}
return;
}
// merge common block of different txs
if (tx.getHeight() != null && tx.getHeight().equals(aTx.getHeight())) {
aTx.getBlock().merge(tx.getBlock());
if (aTx.getIsConfirmed()) assertTrue(aTx.getBlock().getTxs().contains(aTx));
}
}
// add tx if it doesn't already exist unless skipped
if (!skipIfAbsent) {
txs.add(tx);
} else {
LOGGER.warn("WARNING: tx does not already exist");
}
}
// ----------------------------- WALLET LISTENER ----------------------------
/**
@@ -727,7 +681,7 @@ namespace monero {
wallet2->get_payments(payments, minHeight, maxHeight, accountIndex, subaddressIndices);
for (std::list<std::pair<crypto::hash, tools::wallet2::payment_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) {
shared_ptr<MoneroTxWallet> tx = buildTxWithIncomingTransfer(i->second.m_tx_hash, i->first, i->second);
mergeTx(txs, tx); // TODO
mergeTx(txs, tx, false);
//txs.push_back(tx);
}
}