mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-13 14:13:52 +02:00
The intermediate watchonly wallet created during exportwatchonlywallet is
a pure build artifact — it is always discarded once BackupWallet() copies
it to the destination. Creating it as an in-memory SQLiteDatabase
(SQLITE_OPEN_MEMORY) removes the need to write files to the wallets
directory and eliminates the cleanup handler that deleted those files on
both success and failure paths.
Introduces InMemoryWalletDatabase (a minimal SQLiteDatabase subclass) and
MakeInMemoryWalletDatabase() factory in sqlite.h/cpp, following the same
pattern as MockableSQLiteDatabase / CreateMockableWalletDatabase() in the
test utilities. MockableSQLiteDatabase now derives from InMemoryWalletDatabase,
removing its redundant Files() override.
The wallet is named after the source wallet ("<name>_watchonly_temp") so
concurrent exports of different wallets use distinct names and log lines
remain traceable to the source wallet.
78 lines
2.6 KiB
C++
78 lines
2.6 KiB
C++
// Copyright (c) 2021-present The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef BITCOIN_WALLET_TEST_UTIL_H
|
|
#define BITCOIN_WALLET_TEST_UTIL_H
|
|
|
|
#include <addresstype.h>
|
|
#include <wallet/db.h>
|
|
#include <wallet/scriptpubkeyman.h>
|
|
#include <wallet/sqlite.h>
|
|
|
|
#include <memory>
|
|
|
|
class ArgsManager;
|
|
class CChain;
|
|
class CKey;
|
|
enum class OutputType;
|
|
namespace interfaces {
|
|
class Chain;
|
|
} // namespace interfaces
|
|
|
|
namespace wallet {
|
|
class CWallet;
|
|
class WalletDatabase;
|
|
struct WalletContext;
|
|
|
|
static const DatabaseFormat DATABASE_FORMATS[] = {
|
|
DatabaseFormat::SQLITE,
|
|
};
|
|
|
|
const std::string ADDRESS_BCRT1_UNSPENDABLE = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj";
|
|
|
|
std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, const CKey& key);
|
|
|
|
std::shared_ptr<CWallet> TestCreateWallet(WalletContext& context);
|
|
std::shared_ptr<CWallet> TestCreateWallet(std::unique_ptr<WalletDatabase> database, WalletContext& context, uint64_t create_flags);
|
|
std::shared_ptr<CWallet> TestLoadWallet(WalletContext& context);
|
|
std::shared_ptr<CWallet> TestLoadWallet(std::unique_ptr<WalletDatabase> database, WalletContext& context);
|
|
void TestUnloadWallet(std::shared_ptr<CWallet>&& wallet);
|
|
|
|
/** Returns a new encoded destination from the wallet (hardcoded to BECH32) */
|
|
std::string getnewaddress(CWallet& w);
|
|
/** Returns a new destination, of an specific type, from the wallet */
|
|
CTxDestination getNewDestination(CWallet& w, OutputType output_type);
|
|
|
|
using MockableData = std::map<SerializeData, SerializeData, std::less<>>;
|
|
|
|
|
|
class MockableSQLiteBatch : public SQLiteBatch
|
|
{
|
|
public:
|
|
using SQLiteBatch::SQLiteBatch;
|
|
using SQLiteBatch::WriteKey;
|
|
};
|
|
|
|
/** A WalletDatabase whose contents and return values can be modified as needed for testing
|
|
**/
|
|
class MockableSQLiteDatabase : public InMemoryWalletDatabase
|
|
{
|
|
public:
|
|
MockableSQLiteDatabase();
|
|
|
|
bool Backup(const std::string& strDest) const override { return true; }
|
|
|
|
std::string Filename() override { return "mockable"; }
|
|
std::string Format() override { return "sqlite-mock"; }
|
|
std::unique_ptr<DatabaseBatch> MakeBatch() override { return std::make_unique<MockableSQLiteBatch>(*this); }
|
|
};
|
|
|
|
std::unique_ptr<WalletDatabase> CreateMockableWalletDatabase();
|
|
MockableSQLiteDatabase& GetMockableDatabase(CWallet& wallet);
|
|
|
|
DescriptorScriptPubKeyMan* CreateDescriptor(CWallet& keystore, const std::string& desc_str, bool success);
|
|
} // namespace wallet
|
|
|
|
#endif // BITCOIN_WALLET_TEST_UTIL_H
|