Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/node.cpp
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
#include <boost/signals2/signal.hpp> | #include <boost/signals2/signal.hpp> | ||||
class HTTPRPCRequestProcessor; | class HTTPRPCRequestProcessor; | ||||
namespace interfaces { | namespace interfaces { | ||||
namespace { | namespace { | ||||
class NodeImpl : public Node { | class NodeImpl : public Node { | ||||
private: | |||||
ChainstateManager &chainman() { return *Assert(m_context->chainman); } | |||||
public: | public: | ||||
NodeImpl(NodeContext *context) { setContext(context); } | NodeImpl(NodeContext *context) { setContext(context); } | ||||
void initLogging() override { InitLogging(*Assert(m_context->args)); } | void initLogging() override { InitLogging(*Assert(m_context->args)); } | ||||
void initParameterInteraction() override { | void initParameterInteraction() override { | ||||
InitParameterInteraction(*Assert(m_context->args)); | InitParameterInteraction(*Assert(m_context->args)); | ||||
} | } | ||||
bilingual_str getWarnings() override { return GetWarnings(true); } | bilingual_str getWarnings() override { return GetWarnings(true); } | ||||
bool baseInitialize(Config &config) override { | bool baseInitialize(Config &config) override { | ||||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | public: | ||||
height = ::pindexBestHeader->nHeight; | height = ::pindexBestHeader->nHeight; | ||||
block_time = ::pindexBestHeader->GetBlockTime(); | block_time = ::pindexBestHeader->GetBlockTime(); | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
int getNumBlocks() override { | int getNumBlocks() override { | ||||
LOCK(::cs_main); | LOCK(::cs_main); | ||||
return ::ChainActive().Height(); | assert(std::addressof(::ChainActive()) == | ||||
std::addressof(chainman().ActiveChain())); | |||||
return chainman().ActiveChain().Height(); | |||||
} | } | ||||
BlockHash getBestBlockHash() override { | BlockHash getBestBlockHash() override { | ||||
const CBlockIndex *tip = | const CBlockIndex *tip; | ||||
WITH_LOCK(::cs_main, return ::ChainActive().Tip()); | { | ||||
// TODO: Temporary scope to check correctness of refactored | |||||
// code. Should be removed manually after backport of | |||||
// https://github.com/bitcoin/bitcoin/pull/20158 | |||||
LOCK(cs_main); | |||||
assert(std::addressof(::ChainActive()) == | |||||
std::addressof(chainman().ActiveChain())); | |||||
tip = chainman().ActiveChain().Tip(); | |||||
} | |||||
return tip ? tip->GetBlockHash() | return tip ? tip->GetBlockHash() | ||||
: Params().GenesisBlock().GetHash(); | : Params().GenesisBlock().GetHash(); | ||||
} | } | ||||
int64_t getLastBlockTime() override { | int64_t getLastBlockTime() override { | ||||
LOCK(::cs_main); | LOCK(::cs_main); | ||||
if (::ChainActive().Tip()) { | assert(std::addressof(::ChainActive()) == | ||||
return ::ChainActive().Tip()->GetBlockTime(); | std::addressof(chainman().ActiveChain())); | ||||
if (chainman().ActiveChain().Tip()) { | |||||
return chainman().ActiveChain().Tip()->GetBlockTime(); | |||||
} | } | ||||
// Genesis block's time of current network | // Genesis block's time of current network | ||||
return Params().GenesisBlock().GetBlockTime(); | return Params().GenesisBlock().GetBlockTime(); | ||||
} | } | ||||
double getVerificationProgress() override { | double getVerificationProgress() override { | ||||
const CBlockIndex *tip; | const CBlockIndex *tip; | ||||
{ | { | ||||
LOCK(::cs_main); | LOCK(::cs_main); | ||||
tip = ::ChainActive().Tip(); | assert(std::addressof(::ChainActive()) == | ||||
std::addressof(chainman().ActiveChain())); | |||||
tip = chainman().ActiveChain().Tip(); | |||||
} | } | ||||
return GuessVerificationProgress(Params().TxData(), tip); | return GuessVerificationProgress(Params().TxData(), tip); | ||||
} | } | ||||
bool isInitialBlockDownload() override { | bool isInitialBlockDownload() override { | ||||
return ::ChainstateActive().IsInitialBlockDownload(); | const CChainState *active_chainstate; | ||||
{ | |||||
// TODO: Temporary scope to check correctness of refactored | |||||
// code. Should be removed manually after backport of | |||||
// https://github.com/bitcoin/bitcoin/pull/20158 | |||||
LOCK(::cs_main); | |||||
active_chainstate = &m_context->chainman->ActiveChainstate(); | |||||
assert(std::addressof(::ChainstateActive()) == | |||||
std::addressof(*active_chainstate)); | |||||
} | |||||
return active_chainstate->IsInitialBlockDownload(); | |||||
} | } | ||||
bool getReindex() override { return ::fReindex; } | bool getReindex() override { return ::fReindex; } | ||||
bool getImporting() override { return ::fImporting; } | bool getImporting() override { return ::fImporting; } | ||||
void setNetworkActive(bool active) override { | void setNetworkActive(bool active) override { | ||||
if (m_context->connman) { | if (m_context->connman) { | ||||
m_context->connman->SetNetworkActive(active); | m_context->connman->SetNetworkActive(active); | ||||
} | } | ||||
} | } | ||||
Show All 16 Lines | public: | ||||
void rpcSetTimerInterfaceIfUnset(RPCTimerInterface *iface) override { | void rpcSetTimerInterfaceIfUnset(RPCTimerInterface *iface) override { | ||||
RPCSetTimerInterfaceIfUnset(iface); | RPCSetTimerInterfaceIfUnset(iface); | ||||
} | } | ||||
void rpcUnsetTimerInterface(RPCTimerInterface *iface) override { | void rpcUnsetTimerInterface(RPCTimerInterface *iface) override { | ||||
RPCUnsetTimerInterface(iface); | RPCUnsetTimerInterface(iface); | ||||
} | } | ||||
bool getUnspentOutput(const COutPoint &output, Coin &coin) override { | bool getUnspentOutput(const COutPoint &output, Coin &coin) override { | ||||
LOCK(::cs_main); | LOCK(::cs_main); | ||||
return ::ChainstateActive().CoinsTip().GetCoin(output, coin); | assert(std::addressof(::ChainstateActive()) == | ||||
std::addressof(chainman().ActiveChainstate())); | |||||
return chainman().ActiveChainstate().CoinsTip().GetCoin(output, | |||||
coin); | |||||
} | } | ||||
WalletClient &walletClient() override { | WalletClient &walletClient() override { | ||||
return *Assert(m_context->wallet_client); | return *Assert(m_context->wallet_client); | ||||
} | } | ||||
std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) override { | std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) override { | ||||
return MakeHandler(::uiInterface.InitMessage_connect(fn)); | return MakeHandler(::uiInterface.InitMessage_connect(fn)); | ||||
} | } | ||||
std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) override { | std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) override { | ||||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |