mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-11-15 20:53:55 +01:00
merge unrelated tx blocks in MoneroWallet.cpp:mergeTx()
cleanup; remove -g for debugger
This commit is contained in:
+22
-25
@@ -348,21 +348,10 @@ namespace monero {
|
||||
*
|
||||
* @param tx is the transaction to merge into the existing txs
|
||||
* @param txMap maps tx ids to txs
|
||||
* @param blockMap maps block heights to blocks
|
||||
* @param skipIfAbsent specifies if the tx should not be added if it doesn't already exist
|
||||
*/
|
||||
void mergeTx(shared_ptr<MoneroTxWallet> tx, map<string, shared_ptr<MoneroTxWallet>>& txMap, bool skipIfAbsent) {
|
||||
|
||||
if (tx->block != boost::none) {
|
||||
bool found = false;
|
||||
for (const shared_ptr<MoneroTx>& blockTx : tx->block.get()->txs) {
|
||||
if (tx == blockTx) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) throw new runtime_error("But this tx's block does not reference the tx");
|
||||
}
|
||||
|
||||
void mergeTx(shared_ptr<MoneroTxWallet> tx, map<string, shared_ptr<MoneroTxWallet>>& txMap, map<uint64_t, shared_ptr<MoneroBlock>>& blockMap, bool skipIfAbsent) {
|
||||
if (tx->id == boost::none) throw runtime_error("Tx id is not initialized");
|
||||
|
||||
// if tx doesn't exist, add it (unless skipped)
|
||||
@@ -381,7 +370,16 @@ namespace monero {
|
||||
aTx->merge(aTx, tx);
|
||||
}
|
||||
|
||||
cout << "Now how back is the tx map? " << txMap.size() << endl;
|
||||
// if confirmed, merge tx's block
|
||||
if (tx->getHeight() != boost::none) {
|
||||
map<uint64_t, shared_ptr<MoneroBlock>>::const_iterator blockIter = blockMap.find(tx->getHeight().get());
|
||||
if (blockIter == blockMap.end()) {
|
||||
blockMap[tx->getHeight().get()] = tx->block.get();
|
||||
} else {
|
||||
shared_ptr<MoneroBlock>& aBlock = blockMap[tx->getHeight().get()];
|
||||
aBlock->merge(aBlock, tx->block.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1197,8 +1195,9 @@ namespace monero {
|
||||
|
||||
// cache types into maps for merging and lookup
|
||||
map<string, shared_ptr<MoneroTxWallet>> txMap;
|
||||
map<uint64_t, shared_ptr<MoneroBlock>> blockMap;
|
||||
for (const shared_ptr<MoneroTxWallet>& tx : txs) {
|
||||
mergeTx(tx, txMap, false);
|
||||
mergeTx(tx, txMap, blockMap, false);
|
||||
}
|
||||
|
||||
// fetch and merge outputs if requested
|
||||
@@ -1214,7 +1213,7 @@ namespace monero {
|
||||
for (const shared_ptr<MoneroOutputWallet>& output : outputs) {
|
||||
shared_ptr<MoneroTxWallet> tx = static_pointer_cast<MoneroTxWallet>(output->tx);
|
||||
if (outputTxs.find(tx) == outputTxs.end()) {
|
||||
mergeTx(tx, txMap, true);
|
||||
mergeTx(tx, txMap, blockMap, true);
|
||||
outputTxs.insert(tx);
|
||||
}
|
||||
}
|
||||
@@ -1316,6 +1315,7 @@ namespace monero {
|
||||
// collect unique txs
|
||||
uint64_t chainHeight = getChainHeight();
|
||||
map<string, shared_ptr<MoneroTxWallet>> txMap;
|
||||
map<uint64_t, shared_ptr<MoneroBlock>> blockMap;
|
||||
|
||||
// get confirmed incoming transfers
|
||||
if (isIn) {
|
||||
@@ -1323,8 +1323,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(*wallet2, chainHeight, i->first, i->second);
|
||||
if (tx->getHeight().get() != 360559l) continue;
|
||||
mergeTx(tx, txMap, false);
|
||||
mergeTx(tx, txMap, blockMap, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1336,8 +1335,7 @@ namespace monero {
|
||||
wallet2->get_payments_out(payments, minHeight, maxHeight, accountIndex, subaddressIndices);
|
||||
for (std::list<std::pair<crypto::hash, tools::wallet2::confirmed_transfer_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) {
|
||||
shared_ptr<MoneroTxWallet> tx = buildTxWithOutgoingTransfer(*wallet2, chainHeight, i->first, i->second);
|
||||
if (tx->getHeight().get() != 360559l) continue;
|
||||
mergeTx(tx, txMap, false);
|
||||
mergeTx(tx, txMap, blockMap, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1349,9 +1347,8 @@ namespace monero {
|
||||
wallet2->get_unconfirmed_payments_out(upayments, accountIndex, subaddressIndices);
|
||||
for (std::list<std::pair<crypto::hash, tools::wallet2::unconfirmed_transfer_details>>::const_iterator i = upayments.begin(); i != upayments.end(); ++i) {
|
||||
shared_ptr<MoneroTxWallet> tx = buildTxWithOutgoingTransferUnconfirmed(*wallet2, i->first, i->second);
|
||||
if (tx->getHeight().get() != 360559l) continue;
|
||||
if (txReq.isFailed != boost::none && txReq.isFailed.get() != tx->isFailed.get()) continue; // skip merging if tx unrequested
|
||||
mergeTx(tx, txMap, false);
|
||||
mergeTx(tx, txMap, blockMap, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1364,8 +1361,7 @@ namespace monero {
|
||||
wallet2->get_unconfirmed_payments(payments, accountIndex, subaddressIndices);
|
||||
for (std::list<std::pair<crypto::hash, tools::wallet2::pool_payment_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) {
|
||||
shared_ptr<MoneroTxWallet> tx = buildTxWithIncomingTransferUnconfirmed(*wallet2, i->first, i->second);
|
||||
if (tx->getHeight().get() != 360559l) continue;
|
||||
mergeTx(tx, txMap, false);
|
||||
mergeTx(tx, txMap, blockMap, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1421,10 +1417,11 @@ namespace monero {
|
||||
|
||||
// collect unique txs and blocks
|
||||
map<string, shared_ptr<MoneroTxWallet>> txMap;
|
||||
map<uint64_t, shared_ptr<MoneroBlock>> blockMap;
|
||||
for (const auto& outputW2 : outputsW2) {
|
||||
// TODO: skip tx building if w2 output filtered by indices, etc
|
||||
shared_ptr<MoneroTxWallet> tx = buildTxWithVout(*wallet2, outputW2);
|
||||
mergeTx(tx, txMap, false);
|
||||
mergeTx(tx, txMap, blockMap, false);
|
||||
}
|
||||
|
||||
// collect requested vouts
|
||||
|
||||
Reference in New Issue
Block a user