From 8571d4131f80ec1b09f44ca28aaf7d8ad1ed983d Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 12 Jun 2019 22:17:37 -0400 Subject: [PATCH] implemented MoneroBlock::merge() except txIds --- src/daemon/MoneroDaemon.cpp | 33 ++++++++++++++++++++++++++++++++- todo.txt | 2 ++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/daemon/MoneroDaemon.cpp b/src/daemon/MoneroDaemon.cpp index 2edc048..5d28188 100644 --- a/src/daemon/MoneroDaemon.cpp +++ b/src/daemon/MoneroDaemon.cpp @@ -123,8 +123,39 @@ namespace monero { void MoneroBlock::merge(const MoneroBlock& block) { cout << "MoneroBlock::merge()" << endl; + + // merge header fields MoneroBlockHeader::merge(block); - throw runtime_error("Not implemented"); + + // merge coinbase tx + if (coinbaseTx == boost::none) coinbaseTx = block.coinbaseTx; + else if (block.coinbaseTx != boost::none) (**coinbaseTx).merge(**block.coinbaseTx); + + // merge non-coinbase txs + if (txs.empty()) txs = block.txs; + else if (!block.txs.empty()) { + for (const shared_ptr& thatTx : block.txs) { + bool found = false; + for (const shared_ptr& thisTx : txs) { + if (thatTx->id == thatTx->id) { + thisTx->merge(*thatTx); + found = true; + break; + } + } + if (!found) txs.push_back(thatTx); + } + } + if (!txs.empty()) { + for (const shared_ptr& tx : txs) { + tx->block = shared_ptr(this); + } + } + + // merge other fields + hex = MoneroUtils::reconcile(hex, block.hex); + //txIds = MoneroUtils::reconcile(txIds, block.txIds); // TODO: implement + throw runtime_error("ready to reconcile txIds"); } void MoneroTx::merge(const MoneroTx& tx) { diff --git a/todo.txt b/todo.txt index acc70f8..99d90df 100644 --- a/todo.txt +++ b/todo.txt @@ -1,3 +1,5 @@ +separate model interfaces/impl + DaemonConnection is its own object rename external-libs/monero to monero-core for clarity onSyncProgress(startHeight, currentHeight, endHeight, percentDone, message)? \ No newline at end of file