mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-09 10:43:19 -05:00
Merge #19310: wallet: BerkeleyDatabase make BerkeleyDatabase::Create, CreateMock, and CreateDummy non-static functions
da7a83c5ee
Remove WalletDatabase::Create, CreateMock, and CreateDummy (Andrew Chow)d6045d0ac6
scripted-diff: Replace WalletDatabase::Create* with CreateWalletDatabase (Andrew Chow)45c08f8a7b
Add Create*WalletDatabase functions (Andrew Chow) Pull request description: Instead of having `Create`, `CreateMock`, and `CreateDummy` being static functions in `BerkeleyDatabase`, move these to standalone functions in `walletdb.cpp`. This prepares us for having different `WalletDatabase` classes. Part of #18971. This was originally one commit but has been split into 3 to make it (hopefully) easier to review. ACKs for top commit: MarcoFalke: ACKda7a83c5ee
🎂 ryanofsky: Code review ACKda7a83c5ee
. Easy review, nice scripted-diff Tree-SHA512: 1feb7cb3889168c555154bf3701a49095fd6b8cab911d44b7f7efbf6fcee2280ccb3d4afec8a83755b39a592ecd13b90a318faa655c321f87bdabdf1e2312327
This commit is contained in:
commit
dbd7a91fdf
15 changed files with 74 additions and 65 deletions
|
@ -31,7 +31,7 @@ static void CoinSelection(benchmark::State& state)
|
||||||
{
|
{
|
||||||
NodeContext node;
|
NodeContext node;
|
||||||
auto chain = interfaces::MakeChain(node);
|
auto chain = interfaces::MakeChain(node);
|
||||||
CWallet wallet(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet wallet(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
wallet.SetupLegacyScriptPubKeyMan();
|
wallet.SetupLegacyScriptPubKeyMan();
|
||||||
std::vector<std::unique_ptr<CWalletTx>> wtxs;
|
std::vector<std::unique_ptr<CWalletTx>> wtxs;
|
||||||
LOCK(wallet.cs_wallet);
|
LOCK(wallet.cs_wallet);
|
||||||
|
@ -65,7 +65,7 @@ static void CoinSelection(benchmark::State& state)
|
||||||
typedef std::set<CInputCoin> CoinSet;
|
typedef std::set<CInputCoin> CoinSet;
|
||||||
static NodeContext testNode;
|
static NodeContext testNode;
|
||||||
static auto testChain = interfaces::MakeChain(testNode);
|
static auto testChain = interfaces::MakeChain(testNode);
|
||||||
static CWallet testWallet(testChain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
static CWallet testWallet(testChain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
std::vector<std::unique_ptr<CWalletTx>> wtxn;
|
std::vector<std::unique_ptr<CWalletTx>> wtxn;
|
||||||
|
|
||||||
// Copied from src/wallet/test/coinselector_tests.cpp
|
// Copied from src/wallet/test/coinselector_tests.cpp
|
||||||
|
|
|
@ -26,7 +26,7 @@ static void WalletBalance(benchmark::State& state, const bool set_dirty, const b
|
||||||
|
|
||||||
NodeContext node;
|
NodeContext node;
|
||||||
std::unique_ptr<interfaces::Chain> chain = interfaces::MakeChain(node);
|
std::unique_ptr<interfaces::Chain> chain = interfaces::MakeChain(node);
|
||||||
CWallet wallet{chain.get(), WalletLocation(), WalletDatabase::CreateMock()};
|
CWallet wallet{chain.get(), WalletLocation(), CreateMockWalletDatabase()};
|
||||||
{
|
{
|
||||||
wallet.SetupLegacyScriptPubKeyMan();
|
wallet.SetupLegacyScriptPubKeyMan();
|
||||||
bool first_run;
|
bool first_run;
|
||||||
|
|
|
@ -59,7 +59,7 @@ void EditAddressAndSubmit(
|
||||||
void TestAddAddressesToSendBook(interfaces::Node& node)
|
void TestAddAddressesToSendBook(interfaces::Node& node)
|
||||||
{
|
{
|
||||||
TestChain100Setup test;
|
TestChain100Setup test;
|
||||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), WalletLocation(), WalletDatabase::CreateMock());
|
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), WalletLocation(), CreateMockWalletDatabase());
|
||||||
wallet->SetupLegacyScriptPubKeyMan();
|
wallet->SetupLegacyScriptPubKeyMan();
|
||||||
bool firstRun;
|
bool firstRun;
|
||||||
wallet->LoadWallet(firstRun);
|
wallet->LoadWallet(firstRun);
|
||||||
|
|
|
@ -140,7 +140,7 @@ void TestGUI(interfaces::Node& node)
|
||||||
}
|
}
|
||||||
node.context()->connman = std::move(test.m_node.connman);
|
node.context()->connman = std::move(test.m_node.connman);
|
||||||
node.context()->mempool = std::move(test.m_node.mempool);
|
node.context()->mempool = std::move(test.m_node.mempool);
|
||||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), WalletLocation(), WalletDatabase::CreateMock());
|
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), WalletLocation(), CreateMockWalletDatabase());
|
||||||
bool firstRun;
|
bool firstRun;
|
||||||
wallet->LoadWallet(firstRun);
|
wallet->LoadWallet(firstRun);
|
||||||
{
|
{
|
||||||
|
|
|
@ -120,25 +120,6 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return object for accessing database at specified path. */
|
|
||||||
static std::unique_ptr<BerkeleyDatabase> Create(const fs::path& path)
|
|
||||||
{
|
|
||||||
std::string filename;
|
|
||||||
return MakeUnique<BerkeleyDatabase>(GetWalletEnv(path, filename), std::move(filename));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Return object for accessing dummy database with no read/write capabilities. */
|
|
||||||
static std::unique_ptr<BerkeleyDatabase> CreateDummy()
|
|
||||||
{
|
|
||||||
return MakeUnique<BerkeleyDatabase>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Return object for accessing temporary in-memory database. */
|
|
||||||
static std::unique_ptr<BerkeleyDatabase> CreateMock()
|
|
||||||
{
|
|
||||||
return MakeUnique<BerkeleyDatabase>(std::make_shared<BerkeleyEnvironment>(), "");
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Rewrite the entire database on disk, with the exception of key pszSkip if non-zero
|
/** Rewrite the entire database on disk, with the exception of key pszSkip if non-zero
|
||||||
*/
|
*/
|
||||||
bool Rewrite(const char* pszSkip=nullptr);
|
bool Rewrite(const char* pszSkip=nullptr);
|
||||||
|
|
|
@ -116,7 +116,7 @@ bool RecoverDatabaseFile(const fs::path& file_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
DbTxn* ptxn = env->TxnBegin();
|
DbTxn* ptxn = env->TxnBegin();
|
||||||
CWallet dummyWallet(nullptr, WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet dummyWallet(nullptr, WalletLocation(), CreateDummyWalletDatabase());
|
||||||
for (KeyValPair& row : salvagedData)
|
for (KeyValPair& row : salvagedData)
|
||||||
{
|
{
|
||||||
/* Filter for only private key type KV pairs to be added to the salvaged wallet */
|
/* Filter for only private key type KV pairs to be added to the salvaged wallet */
|
||||||
|
|
|
@ -29,7 +29,7 @@ typedef std::set<CInputCoin> CoinSet;
|
||||||
static std::vector<COutput> vCoins;
|
static std::vector<COutput> vCoins;
|
||||||
static NodeContext testNode;
|
static NodeContext testNode;
|
||||||
static auto testChain = interfaces::MakeChain(testNode);
|
static auto testChain = interfaces::MakeChain(testNode);
|
||||||
static CWallet testWallet(testChain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
static CWallet testWallet(testChain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
static CAmount balance = 0;
|
static CAmount balance = 0;
|
||||||
|
|
||||||
CoinEligibilityFilter filter_standard(1, 6, 0);
|
CoinEligibilityFilter filter_standard(1, 6, 0);
|
||||||
|
@ -283,7 +283,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
|
||||||
// Make sure that can use BnB when there are preset inputs
|
// Make sure that can use BnB when there are preset inputs
|
||||||
empty_wallet();
|
empty_wallet();
|
||||||
{
|
{
|
||||||
std::unique_ptr<CWallet> wallet = MakeUnique<CWallet>(m_chain.get(), WalletLocation(), WalletDatabase::CreateMock());
|
std::unique_ptr<CWallet> wallet = MakeUnique<CWallet>(m_chain.get(), WalletLocation(), CreateMockWalletDatabase());
|
||||||
bool firstRun;
|
bool firstRun;
|
||||||
wallet->LoadWallet(firstRun);
|
wallet->LoadWallet(firstRun);
|
||||||
wallet->SetupLegacyScriptPubKeyMan();
|
wallet->SetupLegacyScriptPubKeyMan();
|
||||||
|
|
|
@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2PK compressed
|
// P2PK compressed
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
scriptPubKey = GetScriptForRawPubKey(pubkeys[0]);
|
scriptPubKey = GetScriptForRawPubKey(pubkeys[0]);
|
||||||
|
@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2PK uncompressed
|
// P2PK uncompressed
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
scriptPubKey = GetScriptForRawPubKey(uncompressedPubkey);
|
scriptPubKey = GetScriptForRawPubKey(uncompressedPubkey);
|
||||||
|
@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2PKH compressed
|
// P2PKH compressed
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
scriptPubKey = GetScriptForDestination(PKHash(pubkeys[0]));
|
scriptPubKey = GetScriptForDestination(PKHash(pubkeys[0]));
|
||||||
|
@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2PKH uncompressed
|
// P2PKH uncompressed
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
scriptPubKey = GetScriptForDestination(PKHash(uncompressedPubkey));
|
scriptPubKey = GetScriptForDestination(PKHash(uncompressedPubkey));
|
||||||
|
@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2SH
|
// P2SH
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// (P2PKH inside) P2SH inside P2SH (invalid)
|
// (P2PKH inside) P2SH inside P2SH (invalid)
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// (P2PKH inside) P2SH inside P2WSH (invalid)
|
// (P2PKH inside) P2SH inside P2WSH (invalid)
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2WPKH inside P2WSH (invalid)
|
// P2WPKH inside P2WSH (invalid)
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// (P2PKH inside) P2WSH inside P2WSH (invalid)
|
// (P2PKH inside) P2WSH inside P2WSH (invalid)
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2WPKH compressed
|
// P2WPKH compressed
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
||||||
|
@ -212,7 +212,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2WPKH uncompressed
|
// P2WPKH uncompressed
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
|
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
|
||||||
|
@ -231,7 +231,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// scriptPubKey multisig
|
// scriptPubKey multisig
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2SH multisig
|
// P2SH multisig
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
|
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
|
||||||
|
@ -283,7 +283,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2WSH multisig with compressed keys
|
// P2WSH multisig with compressed keys
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
||||||
|
@ -309,7 +309,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2WSH multisig with uncompressed key
|
// P2WSH multisig with uncompressed key
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
|
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
|
||||||
|
@ -335,7 +335,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2WSH multisig wrapped in P2SH
|
// P2WSH multisig wrapped in P2SH
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
|
|
||||||
|
@ -362,7 +362,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// OP_RETURN
|
// OP_RETURN
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
||||||
|
@ -376,7 +376,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// witness unspendable
|
// witness unspendable
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
||||||
|
@ -390,7 +390,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// witness unknown
|
// witness unknown
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
||||||
|
@ -404,7 +404,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// Nonstandard
|
// Nonstandard
|
||||||
{
|
{
|
||||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet keystore(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
keystore.SetupLegacyScriptPubKeyMan();
|
keystore.SetupLegacyScriptPubKeyMan();
|
||||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
||||||
|
|
|
@ -19,7 +19,7 @@ BOOST_AUTO_TEST_CASE(CanProvide)
|
||||||
// Set up wallet and keyman variables.
|
// Set up wallet and keyman variables.
|
||||||
NodeContext node;
|
NodeContext node;
|
||||||
std::unique_ptr<interfaces::Chain> chain = interfaces::MakeChain(node);
|
std::unique_ptr<interfaces::Chain> chain = interfaces::MakeChain(node);
|
||||||
CWallet wallet(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet wallet(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
LegacyScriptPubKeyMan& keyman = *wallet.GetOrCreateLegacyScriptPubKeyMan();
|
LegacyScriptPubKeyMan& keyman = *wallet.GetOrCreateLegacyScriptPubKeyMan();
|
||||||
|
|
||||||
// Make a 1 of 2 multisig script
|
// Make a 1 of 2 multisig script
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
WalletTestingSetup::WalletTestingSetup(const std::string& chainName)
|
WalletTestingSetup::WalletTestingSetup(const std::string& chainName)
|
||||||
: TestingSetup(chainName),
|
: TestingSetup(chainName),
|
||||||
m_wallet(m_chain.get(), WalletLocation(), WalletDatabase::CreateMock())
|
m_wallet(m_chain.get(), WalletLocation(), CreateMockWalletDatabase())
|
||||||
{
|
{
|
||||||
bool fFirstRun;
|
bool fFirstRun;
|
||||||
m_wallet.LoadWallet(fFirstRun);
|
m_wallet.LoadWallet(fFirstRun);
|
||||||
|
|
|
@ -80,7 +80,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
|
||||||
|
|
||||||
// Verify ScanForWalletTransactions fails to read an unknown start block.
|
// Verify ScanForWalletTransactions fails to read an unknown start block.
|
||||||
{
|
{
|
||||||
CWallet wallet(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet wallet(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
{
|
{
|
||||||
LOCK(wallet.cs_wallet);
|
LOCK(wallet.cs_wallet);
|
||||||
wallet.SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash());
|
wallet.SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash());
|
||||||
|
@ -99,7 +99,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
|
||||||
// Verify ScanForWalletTransactions picks up transactions in both the old
|
// Verify ScanForWalletTransactions picks up transactions in both the old
|
||||||
// and new block files.
|
// and new block files.
|
||||||
{
|
{
|
||||||
CWallet wallet(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet wallet(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
{
|
{
|
||||||
LOCK(wallet.cs_wallet);
|
LOCK(wallet.cs_wallet);
|
||||||
wallet.SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash());
|
wallet.SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash());
|
||||||
|
@ -125,7 +125,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
|
||||||
// Verify ScanForWalletTransactions only picks transactions in the new block
|
// Verify ScanForWalletTransactions only picks transactions in the new block
|
||||||
// file.
|
// file.
|
||||||
{
|
{
|
||||||
CWallet wallet(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet wallet(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
{
|
{
|
||||||
LOCK(wallet.cs_wallet);
|
LOCK(wallet.cs_wallet);
|
||||||
wallet.SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash());
|
wallet.SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash());
|
||||||
|
@ -150,7 +150,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
|
||||||
|
|
||||||
// Verify ScanForWalletTransactions scans no blocks.
|
// Verify ScanForWalletTransactions scans no blocks.
|
||||||
{
|
{
|
||||||
CWallet wallet(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet wallet(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
{
|
{
|
||||||
LOCK(wallet.cs_wallet);
|
LOCK(wallet.cs_wallet);
|
||||||
wallet.SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash());
|
wallet.SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash());
|
||||||
|
@ -189,7 +189,7 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
|
||||||
// before the missing block, and success for a key whose creation time is
|
// before the missing block, and success for a key whose creation time is
|
||||||
// after.
|
// after.
|
||||||
{
|
{
|
||||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
wallet->SetupLegacyScriptPubKeyMan();
|
wallet->SetupLegacyScriptPubKeyMan();
|
||||||
WITH_LOCK(wallet->cs_wallet, wallet->SetLastBlockProcessed(newTip->nHeight, newTip->GetBlockHash()));
|
WITH_LOCK(wallet->cs_wallet, wallet->SetLastBlockProcessed(newTip->nHeight, newTip->GetBlockHash()));
|
||||||
AddWallet(wallet);
|
AddWallet(wallet);
|
||||||
|
@ -254,7 +254,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
|
||||||
|
|
||||||
// Import key into wallet and call dumpwallet to create backup file.
|
// Import key into wallet and call dumpwallet to create backup file.
|
||||||
{
|
{
|
||||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
{
|
{
|
||||||
auto spk_man = wallet->GetOrCreateLegacyScriptPubKeyMan();
|
auto spk_man = wallet->GetOrCreateLegacyScriptPubKeyMan();
|
||||||
LOCK2(wallet->cs_wallet, spk_man->cs_KeyStore);
|
LOCK2(wallet->cs_wallet, spk_man->cs_KeyStore);
|
||||||
|
@ -276,7 +276,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
|
||||||
// Call importwallet RPC and verify all blocks with timestamps >= BLOCK_TIME
|
// Call importwallet RPC and verify all blocks with timestamps >= BLOCK_TIME
|
||||||
// were scanned, and no prior blocks were scanned.
|
// were scanned, and no prior blocks were scanned.
|
||||||
{
|
{
|
||||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
LOCK(wallet->cs_wallet);
|
LOCK(wallet->cs_wallet);
|
||||||
wallet->SetupLegacyScriptPubKeyMan();
|
wallet->SetupLegacyScriptPubKeyMan();
|
||||||
|
|
||||||
|
@ -312,7 +312,7 @@ BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup)
|
||||||
NodeContext node;
|
NodeContext node;
|
||||||
auto chain = interfaces::MakeChain(node);
|
auto chain = interfaces::MakeChain(node);
|
||||||
|
|
||||||
CWallet wallet(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
CWallet wallet(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
auto spk_man = wallet.GetOrCreateLegacyScriptPubKeyMan();
|
auto spk_man = wallet.GetOrCreateLegacyScriptPubKeyMan();
|
||||||
CWalletTx wtx(&wallet, m_coinbase_txns.back());
|
CWalletTx wtx(&wallet, m_coinbase_txns.back());
|
||||||
|
|
||||||
|
@ -486,7 +486,7 @@ public:
|
||||||
ListCoinsTestingSetup()
|
ListCoinsTestingSetup()
|
||||||
{
|
{
|
||||||
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
|
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
|
||||||
wallet = MakeUnique<CWallet>(m_chain.get(), WalletLocation(), WalletDatabase::CreateMock());
|
wallet = MakeUnique<CWallet>(m_chain.get(), WalletLocation(), CreateMockWalletDatabase());
|
||||||
{
|
{
|
||||||
LOCK2(wallet->cs_wallet, ::cs_main);
|
LOCK2(wallet->cs_wallet, ::cs_main);
|
||||||
wallet->SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash());
|
wallet->SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash());
|
||||||
|
@ -604,7 +604,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)
|
||||||
{
|
{
|
||||||
NodeContext node;
|
NodeContext node;
|
||||||
auto chain = interfaces::MakeChain(node);
|
auto chain = interfaces::MakeChain(node);
|
||||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||||
wallet->SetupLegacyScriptPubKeyMan();
|
wallet->SetupLegacyScriptPubKeyMan();
|
||||||
wallet->SetMinVersion(FEATURE_LATEST);
|
wallet->SetMinVersion(FEATURE_LATEST);
|
||||||
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
|
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
|
||||||
|
|
|
@ -3705,7 +3705,7 @@ bool CWallet::Verify(interfaces::Chain& chain, const WalletLocation& location, b
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep same database environment instance across Verify/Recover calls below.
|
// Keep same database environment instance across Verify/Recover calls below.
|
||||||
std::unique_ptr<WalletDatabase> database = WalletDatabase::Create(wallet_path);
|
std::unique_ptr<WalletDatabase> database = CreateWalletDatabase(wallet_path);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!WalletBatch::VerifyEnvironment(wallet_path, error_string)) {
|
if (!WalletBatch::VerifyEnvironment(wallet_path, error_string)) {
|
||||||
|
@ -3729,7 +3729,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
|
||||||
if (gArgs.GetBoolArg("-zapwallettxes", false)) {
|
if (gArgs.GetBoolArg("-zapwallettxes", false)) {
|
||||||
chain.initMessage(_("Zapping all transactions from wallet...").translated);
|
chain.initMessage(_("Zapping all transactions from wallet...").translated);
|
||||||
|
|
||||||
std::unique_ptr<CWallet> tempWallet = MakeUnique<CWallet>(&chain, location, WalletDatabase::Create(location.GetPath()));
|
std::unique_ptr<CWallet> tempWallet = MakeUnique<CWallet>(&chain, location, CreateWalletDatabase(location.GetPath()));
|
||||||
DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx);
|
DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx);
|
||||||
if (nZapWalletRet != DBErrors::LOAD_OK) {
|
if (nZapWalletRet != DBErrors::LOAD_OK) {
|
||||||
error = strprintf(_("Error loading %s: Wallet corrupted"), walletFile);
|
error = strprintf(_("Error loading %s: Wallet corrupted"), walletFile);
|
||||||
|
@ -3743,7 +3743,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
|
||||||
bool fFirstRun = true;
|
bool fFirstRun = true;
|
||||||
// TODO: Can't use std::make_shared because we need a custom deleter but
|
// TODO: Can't use std::make_shared because we need a custom deleter but
|
||||||
// should be possible to use std::allocate_shared.
|
// should be possible to use std::allocate_shared.
|
||||||
std::shared_ptr<CWallet> walletInstance(new CWallet(&chain, location, WalletDatabase::Create(location.GetPath())), ReleaseWallet);
|
std::shared_ptr<CWallet> walletInstance(new CWallet(&chain, location, CreateWalletDatabase(location.GetPath())), ReleaseWallet);
|
||||||
DBErrors nLoadWalletRet = walletInstance->LoadWallet(fFirstRun);
|
DBErrors nLoadWalletRet = walletInstance->LoadWallet(fFirstRun);
|
||||||
if (nLoadWalletRet != DBErrors::LOAD_OK) {
|
if (nLoadWalletRet != DBErrors::LOAD_OK) {
|
||||||
if (nLoadWalletRet == DBErrors::CORRUPT) {
|
if (nLoadWalletRet == DBErrors::CORRUPT) {
|
||||||
|
|
|
@ -1023,3 +1023,22 @@ bool IsWalletLoaded(const fs::path& wallet_path)
|
||||||
{
|
{
|
||||||
return IsBDBWalletLoaded(wallet_path);
|
return IsBDBWalletLoaded(wallet_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return object for accessing database at specified path. */
|
||||||
|
std::unique_ptr<BerkeleyDatabase> CreateWalletDatabase(const fs::path& path)
|
||||||
|
{
|
||||||
|
std::string filename;
|
||||||
|
return MakeUnique<BerkeleyDatabase>(GetWalletEnv(path, filename), std::move(filename));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return object for accessing dummy database with no read/write capabilities. */
|
||||||
|
std::unique_ptr<BerkeleyDatabase> CreateDummyWalletDatabase()
|
||||||
|
{
|
||||||
|
return MakeUnique<BerkeleyDatabase>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return object for accessing temporary in-memory database. */
|
||||||
|
std::unique_ptr<BerkeleyDatabase> CreateMockWalletDatabase()
|
||||||
|
{
|
||||||
|
return MakeUnique<BerkeleyDatabase>(std::make_shared<BerkeleyEnvironment>(), "");
|
||||||
|
}
|
||||||
|
|
|
@ -293,4 +293,13 @@ bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, st
|
||||||
/** Return whether a wallet database is currently loaded. */
|
/** Return whether a wallet database is currently loaded. */
|
||||||
bool IsWalletLoaded(const fs::path& wallet_path);
|
bool IsWalletLoaded(const fs::path& wallet_path);
|
||||||
|
|
||||||
|
/** Return object for accessing database at specified path. */
|
||||||
|
std::unique_ptr<BerkeleyDatabase> CreateWalletDatabase(const fs::path& path);
|
||||||
|
|
||||||
|
/** Return object for accessing dummy database with no read/write capabilities. */
|
||||||
|
std::unique_ptr<BerkeleyDatabase> CreateDummyWalletDatabase();
|
||||||
|
|
||||||
|
/** Return object for accessing temporary in-memory database. */
|
||||||
|
std::unique_ptr<BerkeleyDatabase> CreateMockWalletDatabase();
|
||||||
|
|
||||||
#endif // BITCOIN_WALLET_WALLETDB_H
|
#endif // BITCOIN_WALLET_WALLETDB_H
|
||||||
|
|
|
@ -28,7 +28,7 @@ static std::shared_ptr<CWallet> CreateWallet(const std::string& name, const fs::
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
// dummy chain interface
|
// dummy chain interface
|
||||||
std::shared_ptr<CWallet> wallet_instance(new CWallet(nullptr /* chain */, WalletLocation(name), WalletDatabase::Create(path)), WalletToolReleaseWallet);
|
std::shared_ptr<CWallet> wallet_instance(new CWallet(nullptr /* chain */, WalletLocation(name), CreateWalletDatabase(path)), WalletToolReleaseWallet);
|
||||||
LOCK(wallet_instance->cs_wallet);
|
LOCK(wallet_instance->cs_wallet);
|
||||||
bool first_run = true;
|
bool first_run = true;
|
||||||
DBErrors load_wallet_ret = wallet_instance->LoadWallet(first_run);
|
DBErrors load_wallet_ret = wallet_instance->LoadWallet(first_run);
|
||||||
|
@ -57,7 +57,7 @@ static std::shared_ptr<CWallet> LoadWallet(const std::string& name, const fs::pa
|
||||||
}
|
}
|
||||||
|
|
||||||
// dummy chain interface
|
// dummy chain interface
|
||||||
std::shared_ptr<CWallet> wallet_instance(new CWallet(nullptr /* chain */, WalletLocation(name), WalletDatabase::Create(path)), WalletToolReleaseWallet);
|
std::shared_ptr<CWallet> wallet_instance(new CWallet(nullptr /* chain */, WalletLocation(name), CreateWalletDatabase(path)), WalletToolReleaseWallet);
|
||||||
DBErrors load_wallet_ret;
|
DBErrors load_wallet_ret;
|
||||||
try {
|
try {
|
||||||
bool first_run;
|
bool first_run;
|
||||||
|
@ -107,7 +107,7 @@ static void WalletShowInfo(CWallet* wallet_instance)
|
||||||
static bool SalvageWallet(const fs::path& path)
|
static bool SalvageWallet(const fs::path& path)
|
||||||
{
|
{
|
||||||
// Create a Database handle to allow for the db to be initialized before recovery
|
// Create a Database handle to allow for the db to be initialized before recovery
|
||||||
std::unique_ptr<WalletDatabase> database = WalletDatabase::Create(path);
|
std::unique_ptr<WalletDatabase> database = CreateWalletDatabase(path);
|
||||||
|
|
||||||
// Initialize the environment before recovery
|
// Initialize the environment before recovery
|
||||||
bilingual_str error_string;
|
bilingual_str error_string;
|
||||||
|
|
Loading…
Add table
Reference in a new issue