From 0f2bd4b16470df388cec7b3166e99f84ad3d8bfd Mon Sep 17 00:00:00 2001 From: woodser Date: Tue, 11 Jun 2019 14:34:19 -0400 Subject: [PATCH] started implementation of MoneroUtils::reconcile(val1, val2) --- src/daemon/MoneroDaemon.cpp | 3 +++ src/utils/MoneroUtils.h | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/daemon/MoneroDaemon.cpp b/src/daemon/MoneroDaemon.cpp index 5a84b2f..a7192bf 100644 --- a/src/daemon/MoneroDaemon.cpp +++ b/src/daemon/MoneroDaemon.cpp @@ -100,11 +100,14 @@ namespace monero { void MoneroBlockHeader::merge(const MoneroBlockHeader& header) { cout << "MoneroBlockHeader::merge()" << endl; + if (this == &header) return; + id = MoneroUtils::reconcile(id, header.id); throw runtime_error("Not implemented"); } void MoneroBlock::merge(const MoneroBlock& block) { cout << "MoneroBlock::merge()" << endl; + MoneroBlockHeader::merge(block); throw runtime_error("Not implemented"); } diff --git a/src/utils/MoneroUtils.h b/src/utils/MoneroUtils.h index 07d5552..42b4081 100644 --- a/src/utils/MoneroUtils.h +++ b/src/utils/MoneroUtils.h @@ -94,5 +94,25 @@ namespace MoneroUtils CHECK_AND_ASSERT_MES(r, std::string(), "Failed to serialize rct signatures base"); return ss.str(); } + + template boost::optional reconcile(const boost::optional& val1, const boost::optional& val2, boost::optional resolveDefined, boost::optional resolveTrue, boost::optional resolveMax) { + cout << "reconcile(" << val1 << ", " << val2 << ")" << endl; + + // check for equality + if (val1 == val2) return val1; + + // resolve one value none + if (val1 == boost::none || val2 == boost::none) { + if (resolveDefined == false) return boost::none; // TODO: boost::optional equality comparitor wokrs like this? + else return val1 == boost::none ? val2 : val1; + } + + // throw runtime_error("Cannot reconcile values " + val1 + " and " + val2 + " with config: [" + resolveDefined + ", " + resolveTrue + ", " + resolveMax + "]", val1, val2); + throw runtime_error("Cannot reconcile values"); + } + + template boost::optional reconcile(const boost::optional& val1, const boost::optional& val2) { + return reconcile(val1, val2, boost::none, boost::none, boost::none); + } } #endif /* MoneroUtils_h */