mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-10-18 07:41:32 +02:00
merge unrelated tx blocks in MoneroWallet.cpp:mergeTx()
cleanup; remove -g for debugger
This commit is contained in:
@@ -64,13 +64,8 @@ namespace monero {
|
||||
// ----------------------- UNDECLARED PRIVATE HELPERS -----------------------
|
||||
|
||||
void mergeTx(vector<shared_ptr<MoneroTx>> txs, const shared_ptr<MoneroTx>& tx) {
|
||||
cout << "Merging this other guy in: " << tx << endl;
|
||||
for (const shared_ptr<MoneroTx>& aTx : txs) {
|
||||
cout << "Comparaing against self tx: " << aTx << endl;
|
||||
if (aTx->id.get() == tx->id.get()) {
|
||||
cout << "And we're merging..." << endl;
|
||||
cout << aTx << endl;
|
||||
cout << tx << endl;
|
||||
aTx->merge(aTx, tx);
|
||||
return;
|
||||
}
|
||||
@@ -150,26 +145,13 @@ namespace monero {
|
||||
}
|
||||
|
||||
void MoneroBlock::merge(const shared_ptr<MoneroBlockHeader>& self, const shared_ptr<MoneroBlockHeader>& other) {
|
||||
cout << "CALLING MONERO BLOCK BASE MERGE" << endl;
|
||||
merge(static_pointer_cast<MoneroBlock>(self), static_pointer_cast<MoneroBlock>(other));
|
||||
}
|
||||
|
||||
void MoneroBlock::merge(const shared_ptr<MoneroBlock>& self, const shared_ptr<MoneroBlock>& other) {
|
||||
cout << "MoneroBlock::merge()" << endl;
|
||||
cout << self << ", " << other << endl;
|
||||
if (this != self.get()) throw runtime_error("this != self");
|
||||
if (self == other) return;
|
||||
cout << "1" << endl;
|
||||
|
||||
cout << "Lets iterate over self block tx pointers" << endl;
|
||||
for (const shared_ptr<MoneroTx>& tx : self->txs) {
|
||||
cout << tx << endl;
|
||||
}
|
||||
|
||||
cout << "Lets iterate over other block tx pointers" << endl;
|
||||
for (const shared_ptr<MoneroTx>& tx : other->txs) {
|
||||
cout << tx << endl;
|
||||
}
|
||||
|
||||
// merge base classes
|
||||
MoneroBlockHeader::merge(self, other);
|
||||
@@ -178,58 +160,17 @@ namespace monero {
|
||||
hex = MoneroUtils::reconcile(hex, other->hex);
|
||||
txIds = MoneroUtils::reconcile(txIds, other->txIds);
|
||||
|
||||
cout << "2" << endl;
|
||||
|
||||
// merge coinbase tx
|
||||
if (coinbaseTx == boost::none) coinbaseTx = other->coinbaseTx;
|
||||
else if (other->coinbaseTx != boost::none) coinbaseTx.get()->merge(*coinbaseTx, *other->coinbaseTx);
|
||||
|
||||
cout << "3" << endl;
|
||||
|
||||
|
||||
// merge non-coinbase txs
|
||||
if (!other->txs.empty()) {
|
||||
cout << "4" << endl;
|
||||
for (const shared_ptr<MoneroTx> otherTx : other->txs) { // NOTE: not using reference so shared_ptr is not deleted when block is dereferenced
|
||||
cout << "5" << endl;
|
||||
cout << "Merging into existing txs: " << otherTx << endl;
|
||||
otherTx->block = self;
|
||||
cout << "Merging into existing txs: " << otherTx << endl;
|
||||
mergeTx(self->txs, otherTx);
|
||||
}
|
||||
}
|
||||
|
||||
// // merge non-coinbase txs
|
||||
// if (txs.empty()) {
|
||||
// txs = other->txs;
|
||||
// cout << "4" << endl;
|
||||
// }
|
||||
// else if (!other->txs.empty()) {
|
||||
// cout << "5" << endl;
|
||||
// for (const shared_ptr<MoneroTx>& thatTx : other->txs) {
|
||||
// bool found = false;
|
||||
// for (const shared_ptr<MoneroTx>& thisTx : txs) {
|
||||
// cout << "6" << endl;
|
||||
// if (thatTx->id == thisTx->id) {
|
||||
// cout << "7" << endl;
|
||||
// thatTx->block = self;
|
||||
// cout << "And here we go for merging txs" << endl;
|
||||
// thisTx->merge(thisTx, thatTx);
|
||||
// found = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (!found) txs.push_back(thatTx);
|
||||
// }
|
||||
// }
|
||||
// cout << "4.2" << endl;
|
||||
// if (!txs.empty()) {
|
||||
// for (const shared_ptr<MoneroTx>& tx : txs) {
|
||||
// tx->block = self;
|
||||
// }
|
||||
// }
|
||||
|
||||
cout << "Returning from MoneroBlock merge" << endl;
|
||||
}
|
||||
|
||||
// ------------------------------- MONERO TX --------------------------------
|
||||
@@ -286,35 +227,23 @@ namespace monero {
|
||||
cout << "MoneroTx::merge()" << endl;
|
||||
if (this != self.get()) throw runtime_error("this != self");
|
||||
cout << self << ", " << other << endl;
|
||||
cout << "1" << endl;
|
||||
if (self == other) return;
|
||||
cout << "2" << endl;
|
||||
|
||||
// merge blocks if they're different which comes back to merging txs
|
||||
if (block != other->block) {
|
||||
cout << "4" << endl;
|
||||
if (block == boost::none) {
|
||||
cout << "5" << endl;
|
||||
block = shared_ptr<MoneroBlock>(new MoneroBlock());
|
||||
block.get()->txs.push_back(self);
|
||||
block.get()->height = other->getHeight();
|
||||
}
|
||||
if (other->block == boost::none) {
|
||||
cout << "About to access other->block" << endl;
|
||||
cout << other->block << endl;
|
||||
cout << "6" << endl;
|
||||
other->block = shared_ptr<MoneroBlock>(new MoneroBlock());
|
||||
cout << "7" << endl;
|
||||
other->block.get()->txs.push_back(other);
|
||||
cout << "8" << endl;
|
||||
other->block.get()->height = self->getHeight();
|
||||
cout << "9" << endl;
|
||||
}
|
||||
cout << "Merging blocks!" << endl;
|
||||
block.get()->merge(block.get(), other->block.get());
|
||||
return;
|
||||
}
|
||||
cout << "merging tx fields!!!" << endl;
|
||||
|
||||
// otherwise merge tx fields
|
||||
id = MoneroUtils::reconcile(id, other->id);
|
||||
@@ -349,8 +278,6 @@ namespace monero {
|
||||
unlockTime = MoneroUtils::reconcile(unlockTime, other->unlockTime);
|
||||
numConfirmations = MoneroUtils::reconcile(numConfirmations, other->numConfirmations);
|
||||
|
||||
cout << "Merging vins!" << endl;
|
||||
|
||||
// merge vins
|
||||
if (!other->vins.empty()) {
|
||||
for (shared_ptr<MoneroOutput> merger : other->vins) {
|
||||
@@ -367,8 +294,6 @@ namespace monero {
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Merging vouts!" << endl;
|
||||
|
||||
// merge vouts
|
||||
if (!other->vouts.empty()) {
|
||||
for (shared_ptr<MoneroOutput> vout : other->vouts) vout->tx = self;
|
||||
@@ -427,8 +352,6 @@ namespace monero {
|
||||
receivedTimestamp = MoneroUtils::reconcile(receivedTimestamp, other->receivedTimestamp, boost::none, boost::none, false); // take earliest receive time
|
||||
lastRelayedTimestamp = MoneroUtils::reconcile(lastRelayedTimestamp, other->lastRelayedTimestamp, boost::none, boost::none, true); // take latest relay time
|
||||
}
|
||||
|
||||
cout << "Returning from MoneroTx::merge()" << endl;
|
||||
}
|
||||
|
||||
// --------------------------- MONERO KEY IMAGE -----------------------------
|
||||
|
||||
+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
|
||||
|
||||
@@ -129,57 +129,20 @@ namespace monero {
|
||||
|
||||
void MoneroTxWallet::merge(const shared_ptr<MoneroTx>& self, const shared_ptr<MoneroTx>& other) {
|
||||
cout << "MoneroTxWallet::merge(MoneroTxs)" << endl;
|
||||
cout << self << ", " << other << endl;
|
||||
|
||||
//cout << "MoneroTxWallet::merge(MoneroTx&, MoneroTx&)" << endl;
|
||||
cout << self->id << endl;
|
||||
cout << "bump" << endl;
|
||||
cout << other->id << endl;
|
||||
cout << "And onward..." << endl;
|
||||
shared_ptr<MoneroTxWallet> temp = dynamic_pointer_cast<MoneroTxWallet>(self);
|
||||
if (temp == nullptr) cout << "you're gonna be in for a bad time" << endl;
|
||||
shared_ptr<MoneroTxWallet> temp2 = dynamic_pointer_cast<MoneroTxWallet>(other);
|
||||
if (temp2 == nullptr) cout << "you're gonna be in for a bad time 2" << endl;
|
||||
|
||||
merge(static_pointer_cast<MoneroTxWallet>(self), static_pointer_cast<MoneroTxWallet>(other));
|
||||
}
|
||||
|
||||
void MoneroTxWallet::merge(const shared_ptr<MoneroTxWallet>& self, const shared_ptr<MoneroTxWallet>& other) {
|
||||
cout << "MoneroTxWallet::merge()" << endl;
|
||||
cout << self << ", " << other << endl;
|
||||
|
||||
|
||||
cout << "Lets iterate over self block tx pointers" << endl;
|
||||
if (self->block != boost::none) {
|
||||
for (const shared_ptr<MoneroTx>& tx : self->block.get()->txs) {
|
||||
cout << tx << endl;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Lets iterate over other block tx pointers" << endl;
|
||||
if (other->block != boost::none) {
|
||||
for (const shared_ptr<MoneroTx>& tx : other->block.get()->txs) {
|
||||
cout << tx << endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (this != self.get()) throw runtime_error("this != self");
|
||||
if (self == other) {
|
||||
cout << "These are the same reference so we're returning" << endl;
|
||||
return;
|
||||
}
|
||||
if (self == other) return;
|
||||
|
||||
// merge base classes
|
||||
cout << "Merging base classes" << endl;
|
||||
MoneroTx::merge(self, other);
|
||||
|
||||
cout << "Returned from MoneroTx::merge()" << endl;
|
||||
|
||||
// merge wallet extensions
|
||||
note = MoneroUtils::reconcile(note, other->note);
|
||||
|
||||
cout << "2" << endl;
|
||||
|
||||
// merge incoming transfers
|
||||
if (!other->incomingTransfers.empty()) {
|
||||
for (const shared_ptr<MoneroIncomingTransfer> transfer : other->incomingTransfers) { // NOTE: not using reference so shared_ptr is not deleted when tx is dereferenced
|
||||
@@ -188,16 +151,12 @@ namespace monero {
|
||||
}
|
||||
}
|
||||
|
||||
cout << "3" << endl;
|
||||
|
||||
// merge outgoing transfer
|
||||
if (other->outgoingTransfer != boost::none) {
|
||||
other->outgoingTransfer.get()->tx = self;
|
||||
if (self->outgoingTransfer == boost::none) self->outgoingTransfer = other->outgoingTransfer;
|
||||
else self->outgoingTransfer.get()->merge(self->outgoingTransfer.get(), other->outgoingTransfer.get());
|
||||
}
|
||||
|
||||
cout << "4" << endl;
|
||||
}
|
||||
|
||||
//boost::property_tree::ptree MoneroUtils::txWalletToPropertyTree(const MoneroTxWallet& tx) {
|
||||
|
||||
Reference in New Issue
Block a user