Skip to content
15 changes: 6 additions & 9 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,11 @@ void OptionsModel::setDisplayUnit(const QVariant& value)
void OptionsModel::setStakeSplitThreshold(const CAmount nStakeSplitThreshold)
{
if (pwalletMain && pwalletMain->nStakeSplitThreshold != nStakeSplitThreshold) {
CWalletDB walletdb(pwalletMain->strWalletFile);
CWalletDB walletdb(pwalletMain->GetDBHandle());
LOCK(pwalletMain->cs_wallet);
{
pwalletMain->nStakeSplitThreshold = nStakeSplitThreshold;
if (pwalletMain->fFileBacked)
walletdb.WriteStakeSplitThreshold(nStakeSplitThreshold);
walletdb.WriteStakeSplitThreshold(nStakeSplitThreshold);
}
}
}
Expand All @@ -513,25 +512,23 @@ bool OptionsModel::isSSTValid()
void OptionsModel::setUseCustomFee(bool fUse)
{
if (pwalletMain && pwalletMain->fUseCustomFee != fUse) {
CWalletDB walletdb(pwalletMain->strWalletFile);
CWalletDB walletdb(pwalletMain->GetDBHandle());
{
LOCK(pwalletMain->cs_wallet);
pwalletMain->fUseCustomFee = fUse;
if (pwalletMain->fFileBacked)
walletdb.WriteUseCustomFee(fUse);
walletdb.WriteUseCustomFee(fUse);
}
}
}

void OptionsModel::setCustomFeeValue(const CAmount& value)
{
if (pwalletMain && pwalletMain->nCustomFee != value) {
CWalletDB walletdb(pwalletMain->strWalletFile);
CWalletDB walletdb(pwalletMain->GetDBHandle());
{
LOCK(pwalletMain->cs_wallet);
pwalletMain->nCustomFee = value;
if (pwalletMain->fFileBacked)
walletdb.WriteCustomFeeValue(value);
walletdb.WriteCustomFeeValue(value);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/qt/pivx/settings/settingsmultisendwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void SettingsMultisendWidget::clearAll()
std::vector<std::pair<std::string, int> > vMultiSendTemp = pwalletMain->vMultiSend;
bool fRemoved = true;
pwalletMain->vMultiSend.clear();
CWalletDB walletdb(pwalletMain->strWalletFile);
CWalletDB walletdb(pwalletMain->GetDBHandle());
if (!walletdb.EraseMultiSend(vMultiSendTemp))
fRemoved = false;
if (!walletdb.WriteMultiSend(pwalletMain->vMultiSend))
Expand Down Expand Up @@ -317,7 +317,7 @@ void SettingsMultisendWidget::addMultiSend(QString address, int percentage, QStr
AddressBook::AddressBookPurpose::SEND);
}

CWalletDB walletdb(pwalletMain->strWalletFile);
CWalletDB walletdb(pwalletMain->GetDBHandle());
if (!walletdb.WriteMultiSend(pwalletMain->vMultiSend)) {
inform(tr("Error saving MultiSend, failed saving properties to the database."));
return;
Expand All @@ -341,7 +341,7 @@ void SettingsMultisendWidget::activate()
pwalletMain->fMultiSendStake = ui->checkBoxStake->isChecked();
pwalletMain->fMultiSendMasternodeReward = ui->checkBoxRewards->isChecked();

CWalletDB walletdb(pwalletMain->strWalletFile);
CWalletDB walletdb(pwalletMain->GetDBHandle());
if (!walletdb.WriteMSettings(pwalletMain->fMultiSendStake, pwalletMain->fMultiSendMasternodeReward, pwalletMain->nLastMultiSendHeight))
strRet = tr("MultiSend activated but writing settings to DB failed");
else
Expand All @@ -357,7 +357,7 @@ void SettingsMultisendWidget::deactivate()
if (pwalletMain->isMultiSendEnabled()) {
QString strRet;
pwalletMain->setMultiSendDisabled();
CWalletDB walletdb(pwalletMain->strWalletFile);
CWalletDB walletdb(pwalletMain->GetDBHandle());
inform(!walletdb.WriteMSettings(false, false, pwalletMain->nLastMultiSendHeight) ?
tr("MultiSend deactivated but writing settings to DB failed") :
tr("MultiSend deactivated")
Expand Down
2 changes: 1 addition & 1 deletion src/sapling/sapling_operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ static CacheCheckResult CheckCachedNote(const SaplingNoteEntry& t, const libzcas
if (sspkm->IsSaplingSpent(*(nd.nullifier))) {
LogPrintf("Removed note %s as it appears to be already spent.\n", noteStr);
prevTx.MarkDirty();
CWalletDB(pwalletMain->strWalletFile, "r+").WriteTx(prevTx);
CWalletDB(pwalletMain->GetDBHandle(), "r+").WriteTx(prevTx);
pwalletMain->NotifyTransactionChanged(pwalletMain, t.op.hash, CT_UPDATED);
return CacheCheckResult::SPENT;
}
Expand Down
26 changes: 8 additions & 18 deletions src/sapling/saplingscriptpubkeyman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ libzcash::SaplingPaymentAddress SaplingScriptPubKeyMan::GenerateNewSaplingZKey()
} while (wallet->HaveSaplingSpendingKey(xsk.ToXFVK()));

// Update the chain model in the database
if (wallet->fFileBacked && !CWalletDB(wallet->strWalletFile).WriteHDChain(hdChain))
if (!CWalletDB(wallet->GetDBHandle()).WriteHDChain(hdChain))
throw std::runtime_error(std::string(__func__) + ": Writing HD chain model failed");

// Create new metadata
Expand Down Expand Up @@ -994,13 +994,9 @@ bool SaplingScriptPubKeyMan::AddSaplingZKey(
return false;
}

if (!wallet->fFileBacked) {
return true;
}

if (!wallet->IsCrypted()) {
auto ivk = sk.expsk.full_viewing_key().in_viewing_key();
return CWalletDB(wallet->strWalletFile).WriteSaplingZKey(ivk, sk, mapSaplingZKeyMetadata[ivk]);
return CWalletDB(wallet->GetDBHandle()).WriteSaplingZKey(ivk, sk, mapSaplingZKeyMetadata[ivk]);
}

return true;
Expand Down Expand Up @@ -1046,12 +1042,8 @@ bool SaplingScriptPubKeyMan::AddSaplingIncomingViewingKey(
return false;
}

if (!wallet->fFileBacked) {
return true;
}

if (!wallet->IsCrypted()) {
return CWalletDB(wallet->strWalletFile).WriteSaplingPaymentAddress(addr, ivk);
return CWalletDB(wallet->GetDBHandle()).WriteSaplingPaymentAddress(addr, ivk);
}

return true;
Expand Down Expand Up @@ -1084,16 +1076,14 @@ bool SaplingScriptPubKeyMan::AddCryptedSaplingSpendingKeyDB(const libzcash::Sapl
{
if (!wallet->AddCryptedSaplingSpendingKey(extfvk, vchCryptedSecret))
return false;
if (!wallet->fFileBacked)
return true;
{
LOCK(wallet->cs_wallet);
if (wallet->pwalletdbEncryption) {
return wallet->pwalletdbEncryption->WriteCryptedSaplingZKey(extfvk,
vchCryptedSecret,
mapSaplingZKeyMetadata[extfvk.fvk.in_viewing_key()]);
} else {
return CWalletDB(wallet->strWalletFile).WriteCryptedSaplingZKey(extfvk,
return CWalletDB(wallet->GetDBHandle()).WriteCryptedSaplingZKey(extfvk,
vchCryptedSecret,
mapSaplingZKeyMetadata[extfvk.fvk.in_viewing_key()]);
}
Expand Down Expand Up @@ -1180,7 +1170,7 @@ void SaplingScriptPubKeyMan::SetHDSeed(const CKeyID& keyID, bool force, bool mem

// Update the commonOVK to recover t->shield notes
commonOVK = getCommonOVKFromSeed();
if (!memonly && !CWalletDB(wallet->strWalletFile).WriteSaplingCommonOVK(*commonOVK)) {
if (!memonly && !CWalletDB(wallet->GetDBHandle()).WriteSaplingCommonOVK(*commonOVK)) {
throw std::runtime_error(std::string(__func__) + ": writing sapling commonOVK failed");
}
}
Expand All @@ -1191,7 +1181,7 @@ void SaplingScriptPubKeyMan::SetHDChain(CHDChain& chain, bool memonly)
if (chain.chainType != HDChain::ChainCounterType::Sapling)
throw std::runtime_error(std::string(__func__) + ": trying to store an invalid chain type");

if (!memonly && !CWalletDB(wallet->strWalletFile).WriteHDChain(chain))
if (!memonly && !CWalletDB(wallet->GetDBHandle()).WriteHDChain(chain))
throw std::runtime_error(std::string(__func__) + ": writing sapling chain failed");

hdChain = chain;
Expand All @@ -1208,7 +1198,7 @@ uint256 SaplingScriptPubKeyMan::getCommonOVK()

// Else, look for it in the database
uint256 ovk;
if (CWalletDB(wallet->strWalletFile).ReadSaplingCommonOVK(ovk)) {
if (CWalletDB(wallet->GetDBHandle()).ReadSaplingCommonOVK(ovk)) {
commonOVK = std::move(ovk);
return *commonOVK;
}
Expand All @@ -1217,7 +1207,7 @@ uint256 SaplingScriptPubKeyMan::getCommonOVK()
// So we should always call this after unlocking the wallet during a spend
// from a transparent address, or when changing/setting the HD seed.
commonOVK = getCommonOVKFromSeed();
if (!CWalletDB(wallet->strWalletFile).WriteSaplingCommonOVK(*commonOVK)) {
if (!CWalletDB(wallet->GetDBHandle()).WriteSaplingCommonOVK(*commonOVK)) {
throw std::runtime_error("Unable to write sapling Common OVK to database");
}
return *commonOVK;
Expand Down
3 changes: 2 additions & 1 deletion src/test/librust/wallet_zkeys_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ BOOST_AUTO_TEST_CASE(WriteCryptedSaplingZkeyDirectToDb) {

// Create a new wallet from the existing wallet path
bool fFirstRun;
CWallet wallet2(pwalletMain->strWalletFile);
std::unique_ptr<CWalletDBWrapper> dbw(new CWalletDBWrapper(&bitdb, pwalletMain->GetDBHandle().GetName()));
CWallet wallet2(std::move(dbw));
BOOST_CHECK_EQUAL(DB_LOAD_OK, wallet2.LoadWallet(fFirstRun));

// Confirm it's not the same as the other wallet
Expand Down
Loading