Changeset View
Changeset View
Standalone View
Standalone View
src/bench/wallet_balance.cpp
// Copyright (c) 2012-2019 The Bitcoin Core developers | // Copyright (c) 2012-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <bench/bench.h> | #include <bench/bench.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <interfaces/chain.h> | #include <interfaces/chain.h> | ||||
#include <node/context.h> | #include <node/context.h> | ||||
#include <optional.h> | |||||
#include <test/util/mining.h> | #include <test/util/mining.h> | ||||
#include <test/util/setup_common.h> | #include <test/util/setup_common.h> | ||||
#include <test/util/wallet.h> | #include <test/util/wallet.h> | ||||
#include <validationinterface.h> | #include <validationinterface.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
static void WalletBalance(benchmark::State &state, const bool set_dirty, | static void WalletBalance(benchmark::State &state, const bool set_dirty, | ||||
const bool add_watchonly, const bool add_mine) { | const bool add_watchonly, const bool add_mine) { | ||||
Show All 11 Lines | CWallet wallet{config.GetChainParams(), chain.get(), WalletLocation(), | ||||
bool first_run; | bool first_run; | ||||
if (wallet.LoadWallet(first_run) != DBErrors::LOAD_OK) { | if (wallet.LoadWallet(first_run) != DBErrors::LOAD_OK) { | ||||
assert(false); | assert(false); | ||||
} | } | ||||
} | } | ||||
auto handler = chain->handleNotifications({&wallet, [](CWallet *) {}}); | auto handler = chain->handleNotifications({&wallet, [](CWallet *) {}}); | ||||
const Optional<std::string> address_mine{ | const std::optional<std::string> address_mine{ | ||||
add_mine ? Optional<std::string>{getnewaddress(config, wallet)} | add_mine ? std::optional<std::string>{getnewaddress(config, wallet)} | ||||
: nullopt}; | : std::nullopt}; | ||||
if (add_watchonly) { | if (add_watchonly) { | ||||
importaddress(wallet, ADDRESS_WATCHONLY); | importaddress(wallet, ADDRESS_WATCHONLY); | ||||
} | } | ||||
for (int i = 0; i < 100; ++i) { | for (int i = 0; i < 100; ++i) { | ||||
generatetoaddress(config, g_testing_setup->m_node, | generatetoaddress(config, g_testing_setup->m_node, | ||||
address_mine.get_value_or(ADDRESS_WATCHONLY)); | address_mine.value_or(ADDRESS_WATCHONLY)); | ||||
generatetoaddress(config, g_testing_setup->m_node, ADDRESS_WATCHONLY); | generatetoaddress(config, g_testing_setup->m_node, ADDRESS_WATCHONLY); | ||||
} | } | ||||
SyncWithValidationInterfaceQueue(); | SyncWithValidationInterfaceQueue(); | ||||
// Cache | // Cache | ||||
auto bal = wallet.GetBalance(); | auto bal = wallet.GetBalance(); | ||||
while (state.KeepRunning()) { | while (state.KeepRunning()) { | ||||
Show All 34 Lines |