aboutsummaryrefslogtreecommitdiff
path: root/src/validationinterface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/validationinterface.cpp')
-rw-r--r--src/validationinterface.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp
index c895904b19..f9f61e8a09 100644
--- a/src/validationinterface.cpp
+++ b/src/validationinterface.cpp
@@ -75,8 +75,10 @@ CMainSignals& GetMainSignals()
return g_signals;
}
-void RegisterValidationInterface(CValidationInterface* pwalletIn) {
- ValidationInterfaceConnections& conns = g_signals.m_internals->m_connMainSignals[pwalletIn];
+void RegisterSharedValidationInterface(std::shared_ptr<CValidationInterface> pwalletIn) {
+ // Each connection captures pwalletIn to ensure that each callback is
+ // executed before pwalletIn is destroyed. For more details see #18338.
+ ValidationInterfaceConnections& conns = g_signals.m_internals->m_connMainSignals[pwalletIn.get()];
conns.UpdatedBlockTip = g_signals.m_internals->UpdatedBlockTip.connect(std::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
conns.TransactionAddedToMempool = g_signals.m_internals->TransactionAddedToMempool.connect(std::bind(&CValidationInterface::TransactionAddedToMempool, pwalletIn, std::placeholders::_1));
conns.BlockConnected = g_signals.m_internals->BlockConnected.connect(std::bind(&CValidationInterface::BlockConnected, pwalletIn, std::placeholders::_1, std::placeholders::_2));
@@ -87,6 +89,18 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn) {
conns.NewPoWValidBlock = g_signals.m_internals->NewPoWValidBlock.connect(std::bind(&CValidationInterface::NewPoWValidBlock, pwalletIn, std::placeholders::_1, std::placeholders::_2));
}
+void RegisterValidationInterface(CValidationInterface* callbacks)
+{
+ // Create a shared_ptr with a no-op deleter - CValidationInterface lifecycle
+ // is managed by the caller.
+ RegisterSharedValidationInterface({callbacks, [](CValidationInterface*){}});
+}
+
+void UnregisterSharedValidationInterface(std::shared_ptr<CValidationInterface> callbacks)
+{
+ UnregisterValidationInterface(callbacks.get());
+}
+
void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
if (g_signals.m_internals) {
g_signals.m_internals->m_connMainSignals.erase(pwalletIn);