Skip to content

Commit

Permalink
node/ifaces: NodeImpl: Use existing NodeContext member
Browse files Browse the repository at this point in the history
  • Loading branch information
dongcarl committed Mar 8, 2021
1 parent 4cde4a7 commit 8a1d580
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/node/interfaces.cpp
Expand Up @@ -182,18 +182,21 @@ class NodeImpl : public Node
int getNumBlocks() override
{
LOCK(::cs_main);
return ::ChainActive().Height();
assert(std::addressof(::ChainActive()) == std::addressof(m_context->chainman->ActiveChain()));
return m_context->chainman->ActiveChain().Height();
}
uint256 getBestBlockHash() override
{
const CBlockIndex* tip = WITH_LOCK(::cs_main, return ::ChainActive().Tip());
assert(std::addressof(::ChainActive()) == std::addressof(m_context->chainman->ActiveChain()));
const CBlockIndex* tip = WITH_LOCK(::cs_main, return m_context->chainman->ActiveChain().Tip());
return tip ? tip->GetBlockHash() : Params().GenesisBlock().GetHash();
}
int64_t getLastBlockTime() override
{
LOCK(::cs_main);
if (::ChainActive().Tip()) {
return ::ChainActive().Tip()->GetBlockTime();
assert(std::addressof(::ChainActive()) == std::addressof(m_context->chainman->ActiveChain()));
if (m_context->chainman->ActiveChain().Tip()) {
return m_context->chainman->ActiveChain().Tip()->GetBlockTime();
}
return Params().GenesisBlock().GetBlockTime(); // Genesis block's time of current network
}
Expand All @@ -202,11 +205,15 @@ class NodeImpl : public Node
const CBlockIndex* tip;
{
LOCK(::cs_main);
tip = ::ChainActive().Tip();
assert(std::addressof(::ChainActive()) == std::addressof(m_context->chainman->ActiveChain()));
tip = m_context->chainman->ActiveChain().Tip();
}
return GuessVerificationProgress(Params().TxData(), tip);
}
bool isInitialBlockDownload() override { return ::ChainstateActive().IsInitialBlockDownload(); }
bool isInitialBlockDownload() override {
assert(std::addressof(::ChainstateActive()) == std::addressof(m_context->chainman->ActiveChainstate()));
return m_context->chainman->ActiveChainstate().IsInitialBlockDownload();
}
bool getReindex() override { return ::fReindex; }
bool getImporting() override { return ::fImporting; }
void setNetworkActive(bool active) override
Expand All @@ -231,7 +238,8 @@ class NodeImpl : public Node
bool getUnspentOutput(const COutPoint& output, Coin& coin) override
{
LOCK(::cs_main);
return ::ChainstateActive().CoinsTip().GetCoin(output, coin);
assert(std::addressof(::ChainstateActive()) == std::addressof(m_context->chainman->ActiveChainstate()));
return m_context->chainman->ActiveChainstate().CoinsTip().GetCoin(output, coin);
}
WalletClient& walletClient() override
{
Expand Down

0 comments on commit 8a1d580

Please sign in to comment.