refactor: Add handleNotifications method to wallet

Further stylistic cleanups in touched files:

* Sort the includes
* Wrap long single-line constructors into multiple lines
This commit is contained in:
MarcoFalke 2019-04-17 13:27:02 -04:00
parent fa46ac3127
commit fad7c33342
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
4 changed files with 27 additions and 32 deletions

View file

@ -10,31 +10,16 @@
#include <validationinterface.h>
#include <wallet/wallet.h>
struct WalletTestingSetup {
std::unique_ptr<interfaces::Chain> m_chain = interfaces::MakeChain();
CWallet m_wallet;
WalletTestingSetup()
: m_wallet{m_chain.get(), WalletLocation(), WalletDatabase::CreateMock()}
{
}
void handleNotifications()
{
m_wallet.m_chain_notifications_handler = m_chain->handleNotifications(m_wallet);
}
};
static void WalletBalance(benchmark::State& state, const bool set_dirty, const bool add_watchonly, const bool add_mine)
{
const auto& ADDRESS_WATCHONLY = ADDRESS_BCRT1_UNSPENDABLE;
WalletTestingSetup wallet_t{};
auto& wallet = wallet_t.m_wallet;
std::unique_ptr<interfaces::Chain> chain = interfaces::MakeChain();
CWallet wallet{chain.get(), WalletLocation(), WalletDatabase::CreateMock()};
{
bool first_run;
if (wallet.LoadWallet(first_run) != DBErrors::LOAD_OK) assert(false);
wallet_t.handleNotifications();
wallet.handleNotifications();
}

View file

@ -8,12 +8,13 @@
#include <wallet/db.h>
#include <wallet/rpcwallet.h>
WalletTestingSetup::WalletTestingSetup(const std::string& chainName):
TestingSetup(chainName), m_wallet(m_chain.get(), WalletLocation(), WalletDatabase::CreateMock())
WalletTestingSetup::WalletTestingSetup(const std::string& chainName)
: TestingSetup(chainName),
m_wallet(m_chain.get(), WalletLocation(), WalletDatabase::CreateMock())
{
bool fFirstRun;
m_wallet.LoadWallet(fFirstRun);
m_wallet.m_chain_notifications_handler = m_chain->handleNotifications(m_wallet);
m_wallet.handleNotifications();
m_chain_client->registerRpcs();
}

View file

@ -5,9 +5,8 @@
#include <wallet/wallet.h>
#include <checkpoints.h>
#include <chain.h>
#include <wallet/coincontrol.h>
#include <checkpoints.h>
#include <consensus/consensus.h>
#include <consensus/validation.h>
#include <fs.h>
@ -16,7 +15,6 @@
#include <key.h>
#include <key_io.h>
#include <keystore.h>
#include <validation.h>
#include <net.h>
#include <policy/fees.h>
#include <policy/policy.h>
@ -34,6 +32,8 @@
#include <util/moneystr.h>
#include <util/rbf.h>
#include <util/validation.h>
#include <validation.h>
#include <wallet/coincontrol.h>
#include <wallet/fees.h>
#include <algorithm>
@ -4303,7 +4303,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
chain.loadWallet(interfaces::MakeWallet(walletInstance));
// Register with the validation interface. It's ok to do this after rescan since we're still holding locked_chain.
walletInstance->m_chain_notifications_handler = chain.handleNotifications(*walletInstance);
walletInstance->handleNotifications();
walletInstance->SetBroadcastTransactions(gArgs.GetBoolArg("-walletbroadcast", DEFAULT_WALLETBROADCAST));
@ -4316,6 +4316,11 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
return walletInstance;
}
void CWallet::handleNotifications()
{
m_chain_notifications_handler = m_chain->handleNotifications(*this);
}
void CWallet::postInitProcess()
{
auto locked_chain = chain().lock();

View file

@ -11,16 +11,16 @@
#include <interfaces/handler.h>
#include <outputtype.h>
#include <policy/feerate.h>
#include <script/ismine.h>
#include <script/sign.h>
#include <streams.h>
#include <tinyformat.h>
#include <ui_interface.h>
#include <util/strencodings.h>
#include <validationinterface.h>
#include <script/ismine.h>
#include <script/sign.h>
#include <util/system.h>
#include <wallet/crypter.h>
#include <validationinterface.h>
#include <wallet/coinselection.h>
#include <wallet/crypter.h>
#include <wallet/walletdb.h>
#include <wallet/walletutil.h>
@ -767,7 +767,10 @@ public:
unsigned int nMasterKeyMaxID = 0;
/** Construct wallet with specified name and database implementation. */
CWallet(interfaces::Chain* chain, const WalletLocation& location, std::unique_ptr<WalletDatabase> database) : m_chain(chain), m_location(location), database(std::move(database))
CWallet(interfaces::Chain* chain, const WalletLocation& location, std::unique_ptr<WalletDatabase> database)
: m_chain(chain),
m_location(location),
database(std::move(database))
{
}
@ -794,6 +797,9 @@ public:
/** Registered interfaces::Chain::Notifications handler. */
std::unique_ptr<interfaces::Handler> m_chain_notifications_handler;
/** Register the wallet for chain notifications */
void handleNotifications();
/** Interface for accessing chain state. */
interfaces::Chain& chain() const { assert(m_chain); return *m_chain; }
@ -1208,8 +1214,6 @@ public:
/** Add a KeyOriginInfo to the wallet */
bool AddKeyOrigin(const CPubKey& pubkey, const KeyOriginInfo& info);
friend struct WalletTestingSetup;
};
/**