mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-10-20 00:28:41 +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 -----------------------------
|
||||
|
||||
Reference in New Issue
Block a user