refactor: use monostate instead std::optional in CoreContext

This commit is contained in:
Konstantin Akimov 2024-07-11 22:20:12 +07:00
parent 1394c41c8d
commit 37bd4009c1
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524
2 changed files with 5 additions and 4 deletions

View File

@ -5,8 +5,8 @@
#ifndef BITCOIN_CONTEXT_H #ifndef BITCOIN_CONTEXT_H
#define BITCOIN_CONTEXT_H #define BITCOIN_CONTEXT_H
#include <functional>
#include <variant> #include <variant>
#include <optional>
class ChainstateManager; class ChainstateManager;
class CTxMemPool; class CTxMemPool;
@ -15,7 +15,7 @@ struct LLMQContext;
struct NodeContext; struct NodeContext;
struct WalletContext; struct WalletContext;
using CoreContext = std::variant<std::nullopt_t, using CoreContext = std::variant<std::monostate,
std::reference_wrapper<NodeContext>, std::reference_wrapper<NodeContext>,
std::reference_wrapper<WalletContext>, std::reference_wrapper<WalletContext>,
std::reference_wrapper<CTxMemPool>, std::reference_wrapper<CTxMemPool>,

View File

@ -67,6 +67,7 @@
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <utility> #include <utility>
#include <variant>
using interfaces::BlockTip; using interfaces::BlockTip;
using interfaces::Chain; using interfaces::Chain;
@ -584,11 +585,11 @@ public:
if (context) { if (context) {
m_context_ref = *context; m_context_ref = *context;
} else { } else {
m_context_ref = std::nullopt; m_context_ref = std::monostate{};
} }
} }
NodeContext* m_context{nullptr}; NodeContext* m_context{nullptr};
CoreContext m_context_ref{std::nullopt}; CoreContext m_context_ref;
}; };
bool FillBlock(const CBlockIndex* index, const FoundBlock& block, UniqueLock<RecursiveMutex>& lock, const CChain& active) bool FillBlock(const CBlockIndex* index, const FoundBlock& block, UniqueLock<RecursiveMutex>& lock, const CChain& active)