Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/chain.cpp
Show First 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | class LockImpl : public Chain::Lock, public UniqueLock<RecursiveMutex> { | ||||
CValidationState &state) override { | CValidationState &state) override { | ||||
LockAssertion lock(::cs_main); | LockAssertion lock(::cs_main); | ||||
return ContextualCheckTransactionForCurrentBlock(params, tx, state); | return ContextualCheckTransactionForCurrentBlock(params, tx, state); | ||||
} | } | ||||
using UniqueLock::UniqueLock; | using UniqueLock::UniqueLock; | ||||
}; // namespace interfaces | }; // namespace interfaces | ||||
class NotificationsHandlerImpl : public Handler, CValidationInterface { | class NotificationsProxy : public CValidationInterface { | ||||
public: | public: | ||||
explicit NotificationsHandlerImpl(Chain &chain, | explicit NotificationsProxy( | ||||
Chain::Notifications ¬ifications) | std::shared_ptr<Chain::Notifications> notifications) | ||||
: m_chain(chain), m_notifications(¬ifications) { | : m_notifications(std::move(notifications)) {} | ||||
RegisterValidationInterface(this); | virtual ~NotificationsProxy() = default; | ||||
} | |||||
~NotificationsHandlerImpl() override { disconnect(); } | |||||
void disconnect() override { | |||||
if (m_notifications) { | |||||
m_notifications = nullptr; | |||||
UnregisterValidationInterface(this); | |||||
} | |||||
} | |||||
void TransactionAddedToMempool(const CTransactionRef &tx) override { | void TransactionAddedToMempool(const CTransactionRef &tx) override { | ||||
m_notifications->TransactionAddedToMempool(tx); | m_notifications->TransactionAddedToMempool(tx); | ||||
} | } | ||||
void TransactionRemovedFromMempool(const CTransactionRef &tx) override { | void TransactionRemovedFromMempool(const CTransactionRef &tx) override { | ||||
m_notifications->TransactionRemovedFromMempool(tx); | m_notifications->TransactionRemovedFromMempool(tx); | ||||
} | } | ||||
void BlockConnected( | void BlockConnected( | ||||
const std::shared_ptr<const CBlock> &block, | const std::shared_ptr<const CBlock> &block, | ||||
const CBlockIndex *index, | const CBlockIndex *index, | ||||
const std::vector<CTransactionRef> &tx_conflicted) override { | const std::vector<CTransactionRef> &tx_conflicted) override { | ||||
m_notifications->BlockConnected(*block, tx_conflicted); | m_notifications->BlockConnected(*block, tx_conflicted); | ||||
} | } | ||||
void | void | ||||
BlockDisconnected(const std::shared_ptr<const CBlock> &block) override { | BlockDisconnected(const std::shared_ptr<const CBlock> &block) override { | ||||
m_notifications->BlockDisconnected(*block); | m_notifications->BlockDisconnected(*block); | ||||
} | } | ||||
void UpdatedBlockTip(const CBlockIndex *index, | void UpdatedBlockTip(const CBlockIndex *index, | ||||
const CBlockIndex *fork_index, | const CBlockIndex *fork_index, | ||||
bool is_ibd) override { | bool is_ibd) override { | ||||
m_notifications->UpdatedBlockTip(); | m_notifications->UpdatedBlockTip(); | ||||
} | } | ||||
void ChainStateFlushed(const CBlockLocator &locator) override { | void ChainStateFlushed(const CBlockLocator &locator) override { | ||||
m_notifications->ChainStateFlushed(locator); | m_notifications->ChainStateFlushed(locator); | ||||
} | } | ||||
Chain &m_chain; | std::shared_ptr<Chain::Notifications> m_notifications; | ||||
Chain::Notifications *m_notifications; | }; | ||||
class NotificationsHandlerImpl : public Handler { | |||||
public: | |||||
explicit NotificationsHandlerImpl( | |||||
std::shared_ptr<Chain::Notifications> notifications) | |||||
: m_proxy(std::make_shared<NotificationsProxy>( | |||||
std::move(notifications))) { | |||||
RegisterSharedValidationInterface(m_proxy); | |||||
} | |||||
~NotificationsHandlerImpl() override { disconnect(); } | |||||
void disconnect() override { | |||||
if (m_proxy) { | |||||
UnregisterSharedValidationInterface(m_proxy); | |||||
m_proxy.reset(); | |||||
} | |||||
} | |||||
std::shared_ptr<NotificationsProxy> m_proxy; | |||||
}; | }; | ||||
class RpcHandlerImpl : public Handler { | class RpcHandlerImpl : public Handler { | ||||
public: | public: | ||||
explicit RpcHandlerImpl(const CRPCCommand &command) | explicit RpcHandlerImpl(const CRPCCommand &command) | ||||
: m_command(command), m_wrapped_command(&command) { | : m_command(command), m_wrapped_command(&command) { | ||||
m_command.actor = [this](Config &config, | m_command.actor = [this](Config &config, | ||||
const JSONRPCRequest &request, | const JSONRPCRequest &request, | ||||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
void loadWallet(std::unique_ptr<Wallet> wallet) override { | void loadWallet(std::unique_ptr<Wallet> wallet) override { | ||||
::uiInterface.LoadWallet(wallet); | ::uiInterface.LoadWallet(wallet); | ||||
} | } | ||||
void showProgress(const std::string &title, int progress, | void showProgress(const std::string &title, int progress, | ||||
bool resume_possible) override { | bool resume_possible) override { | ||||
::uiInterface.ShowProgress(title, progress, resume_possible); | ::uiInterface.ShowProgress(title, progress, resume_possible); | ||||
} | } | ||||
std::unique_ptr<Handler> | std::unique_ptr<Handler> handleNotifications( | ||||
handleNotifications(Notifications ¬ifications) override { | std::shared_ptr<Notifications> notifications) override { | ||||
return std::make_unique<NotificationsHandlerImpl>(*this, | return std::make_unique<NotificationsHandlerImpl>( | ||||
notifications); | std::move(notifications)); | ||||
} | } | ||||
void waitForNotificationsIfNewBlocksConnected( | void waitForNotificationsIfNewBlocksConnected( | ||||
const BlockHash &old_tip) override { | const BlockHash &old_tip) override { | ||||
if (!old_tip.IsNull()) { | if (!old_tip.IsNull()) { | ||||
LOCK(::cs_main); | LOCK(::cs_main); | ||||
if (old_tip == ::ChainActive().Tip()->GetBlockHash()) { | if (old_tip == ::ChainActive().Tip()->GetBlockHash()) { | ||||
return; | return; | ||||
} | } | ||||
Show All 37 Lines |