mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-11 12:22:39 -03:00
refactor: move DuplicateMockDatabase to wallet/test/util.h
This commit is contained in:
parent
ee7a984f85
commit
373c99633e
3 changed files with 29 additions and 24 deletions
|
@ -52,30 +52,6 @@ static void AddTx(CWallet& wallet)
|
||||||
wallet.AddToWallet(MakeTransactionRef(mtx), TxStateInactive{});
|
wallet.AddToWallet(MakeTransactionRef(mtx), TxStateInactive{});
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database, DatabaseOptions& options)
|
|
||||||
{
|
|
||||||
auto new_database = CreateMockWalletDatabase(options);
|
|
||||||
|
|
||||||
// Get a cursor to the original database
|
|
||||||
auto batch = database.MakeBatch();
|
|
||||||
batch->StartCursor();
|
|
||||||
|
|
||||||
// Get a batch for the new database
|
|
||||||
auto new_batch = new_database->MakeBatch();
|
|
||||||
|
|
||||||
// Read all records from the original database and write them to the new one
|
|
||||||
while (true) {
|
|
||||||
CDataStream key(SER_DISK, CLIENT_VERSION);
|
|
||||||
CDataStream value(SER_DISK, CLIENT_VERSION);
|
|
||||||
bool complete;
|
|
||||||
batch->ReadAtCursor(key, value, complete);
|
|
||||||
if (complete) break;
|
|
||||||
new_batch->Write(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new_database;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void WalletLoading(benchmark::Bench& bench, bool legacy_wallet)
|
static void WalletLoading(benchmark::Bench& bench, bool legacy_wallet)
|
||||||
{
|
{
|
||||||
const auto test_setup = MakeNoLogFileContext<TestingSetup>();
|
const auto test_setup = MakeNoLogFileContext<TestingSetup>();
|
||||||
|
|
|
@ -44,6 +44,30 @@ std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cc
|
||||||
return wallet;
|
return wallet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database, DatabaseOptions& options)
|
||||||
|
{
|
||||||
|
auto new_database = CreateMockWalletDatabase(options);
|
||||||
|
|
||||||
|
// Get a cursor to the original database
|
||||||
|
auto batch = database.MakeBatch();
|
||||||
|
batch->StartCursor();
|
||||||
|
|
||||||
|
// Get a batch for the new database
|
||||||
|
auto new_batch = new_database->MakeBatch();
|
||||||
|
|
||||||
|
// Read all records from the original database and write them to the new one
|
||||||
|
while (true) {
|
||||||
|
CDataStream key(SER_DISK, CLIENT_VERSION);
|
||||||
|
CDataStream value(SER_DISK, CLIENT_VERSION);
|
||||||
|
bool complete;
|
||||||
|
batch->ReadAtCursor(key, value, complete);
|
||||||
|
if (complete) break;
|
||||||
|
new_batch->Write(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new_database;
|
||||||
|
}
|
||||||
|
|
||||||
std::string getnewaddress(CWallet& w)
|
std::string getnewaddress(CWallet& w)
|
||||||
{
|
{
|
||||||
constexpr auto output_type = OutputType::BECH32;
|
constexpr auto output_type = OutputType::BECH32;
|
||||||
|
|
|
@ -18,9 +18,14 @@ class Chain;
|
||||||
|
|
||||||
namespace wallet {
|
namespace wallet {
|
||||||
class CWallet;
|
class CWallet;
|
||||||
|
struct DatabaseOptions;
|
||||||
|
class WalletDatabase;
|
||||||
|
|
||||||
std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, ArgsManager& args, const CKey& key);
|
std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, ArgsManager& args, const CKey& key);
|
||||||
|
|
||||||
|
// Creates a copy of the provided database
|
||||||
|
std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database, DatabaseOptions& options);
|
||||||
|
|
||||||
/** Returns a new encoded destination from the wallet (hardcoded to BECH32) */
|
/** Returns a new encoded destination from the wallet (hardcoded to BECH32) */
|
||||||
std::string getnewaddress(CWallet& w);
|
std::string getnewaddress(CWallet& w);
|
||||||
/** Returns a new destination, of an specific type, from the wallet */
|
/** Returns a new destination, of an specific type, from the wallet */
|
||||||
|
|
Loading…
Reference in a new issue