mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-05 18:52:29 +02:00
Remove use CValidationInterface in wallet code
This commit does not change behavior.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <chain.h>
|
||||
#include <chainparams.h>
|
||||
#include <interfaces/handler.h>
|
||||
#include <interfaces/wallet.h>
|
||||
#include <net.h>
|
||||
#include <policy/fees.h>
|
||||
@@ -22,6 +23,7 @@
|
||||
#include <uint256.h>
|
||||
#include <util/system.h>
|
||||
#include <validation.h>
|
||||
#include <validationinterface.h>
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
@@ -161,6 +163,55 @@ class LockingStateImpl : public LockImpl, public UniqueLock<CCriticalSection>
|
||||
using UniqueLock::UniqueLock;
|
||||
};
|
||||
|
||||
class NotificationsHandlerImpl : public Handler, CValidationInterface
|
||||
{
|
||||
public:
|
||||
explicit NotificationsHandlerImpl(Chain& chain, Chain::Notifications& notifications)
|
||||
: m_chain(chain), m_notifications(¬ifications)
|
||||
{
|
||||
RegisterValidationInterface(this);
|
||||
}
|
||||
~NotificationsHandlerImpl() override { disconnect(); }
|
||||
void disconnect() override
|
||||
{
|
||||
if (m_notifications) {
|
||||
m_notifications = nullptr;
|
||||
UnregisterValidationInterface(this);
|
||||
}
|
||||
}
|
||||
void TransactionAddedToMempool(const CTransactionRef& tx) override
|
||||
{
|
||||
m_notifications->TransactionAddedToMempool(tx);
|
||||
}
|
||||
void TransactionRemovedFromMempool(const CTransactionRef& tx) override
|
||||
{
|
||||
m_notifications->TransactionRemovedFromMempool(tx);
|
||||
}
|
||||
void BlockConnected(const std::shared_ptr<const CBlock>& block,
|
||||
const CBlockIndex* index,
|
||||
const std::vector<CTransactionRef>& tx_conflicted) override
|
||||
{
|
||||
m_notifications->BlockConnected(*block, tx_conflicted);
|
||||
}
|
||||
void BlockDisconnected(const std::shared_ptr<const CBlock>& block) override
|
||||
{
|
||||
m_notifications->BlockDisconnected(*block);
|
||||
}
|
||||
void ChainStateFlushed(const CBlockLocator& locator) override { m_notifications->ChainStateFlushed(locator); }
|
||||
void ResendWalletTransactions(int64_t best_block_time, CConnman*) override
|
||||
{
|
||||
// `cs_main` is always held when this method is called, so it is safe to
|
||||
// call `assumeLocked`. This is awkward, and the `assumeLocked` method
|
||||
// should be able to be removed entirely if `ResendWalletTransactions`
|
||||
// is replaced by a wallet timer as suggested in
|
||||
// https://github.com/bitcoin/bitcoin/issues/15619
|
||||
auto locked_chain = m_chain.assumeLocked();
|
||||
m_notifications->ResendWalletTransactions(*locked_chain, best_block_time);
|
||||
}
|
||||
Chain& m_chain;
|
||||
Chain::Notifications* m_notifications;
|
||||
};
|
||||
|
||||
class ChainImpl : public Chain
|
||||
{
|
||||
public:
|
||||
@@ -254,6 +305,11 @@ public:
|
||||
void initWarning(const std::string& message) override { InitWarning(message); }
|
||||
void initError(const std::string& message) override { InitError(message); }
|
||||
void loadWallet(std::unique_ptr<Wallet> wallet) override { ::uiInterface.LoadWallet(wallet); }
|
||||
std::unique_ptr<Handler> handleNotifications(Notifications& notifications) override
|
||||
{
|
||||
return MakeUnique<NotificationsHandlerImpl>(*this, notifications);
|
||||
}
|
||||
void waitForNotifications() override { SyncWithValidationInterfaceQueue(); }
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -25,6 +25,7 @@ struct FeeCalculation;
|
||||
|
||||
namespace interfaces {
|
||||
|
||||
class Handler;
|
||||
class Wallet;
|
||||
|
||||
//! Interface giving clients (wallet processes, maybe other analysis tools in
|
||||
@@ -40,6 +41,12 @@ class Wallet;
|
||||
//! asynchronously
|
||||
//! (https://github.com/bitcoin/bitcoin/pull/10973#issuecomment-380101269).
|
||||
//!
|
||||
//! * The isPotentialTip() and waitForNotifications() methods are too low-level
|
||||
//! and should be replaced with a higher level
|
||||
//! waitForNotificationsUpTo(block_hash) method that the wallet can call
|
||||
//! instead
|
||||
//! (https://github.com/bitcoin/bitcoin/pull/10973#discussion_r266995234).
|
||||
//!
|
||||
//! * The relayTransactions() and submitToMemoryPool() methods could be replaced
|
||||
//! with a higher-level broadcastTransaction method
|
||||
//! (https://github.com/bitcoin/bitcoin/pull/14978#issuecomment-459373984).
|
||||
@@ -217,6 +224,25 @@ public:
|
||||
|
||||
//! Send wallet load notification to the GUI.
|
||||
virtual void loadWallet(std::unique_ptr<Wallet> wallet) = 0;
|
||||
|
||||
//! Chain notifications.
|
||||
class Notifications
|
||||
{
|
||||
public:
|
||||
virtual ~Notifications() {}
|
||||
virtual void TransactionAddedToMempool(const CTransactionRef& tx) {}
|
||||
virtual void TransactionRemovedFromMempool(const CTransactionRef& ptx) {}
|
||||
virtual void BlockConnected(const CBlock& block, const std::vector<CTransactionRef>& tx_conflicted) {}
|
||||
virtual void BlockDisconnected(const CBlock& block) {}
|
||||
virtual void ChainStateFlushed(const CBlockLocator& locator) {}
|
||||
virtual void ResendWalletTransactions(Lock& locked_chain, int64_t best_block_time) {}
|
||||
};
|
||||
|
||||
//! Register handler for notifications.
|
||||
virtual std::unique_ptr<Handler> handleNotifications(Notifications& notifications) = 0;
|
||||
|
||||
//! Wait for pending notifications to be handled.
|
||||
virtual void waitForNotifications() = 0;
|
||||
};
|
||||
|
||||
//! Interface to let node manage chain clients (wallets, or maybe tools for
|
||||
|
||||
Reference in New Issue
Block a user