refactor: Tidy fixups

Requested by clang-tidy:

src/wallet/salvage.cpp:119:18: error: use emplace_back instead of push_back [modernize-use-emplace,-warnings-as-errors]
   119 |         warnings.push_back(Untranslated("Salvage: Database salvage found errors, all data may not be recoverable."));
       |                  ^~~~~~~~~~
       |                  emplace_back(
This commit is contained in:
MarcoFalke 2024-10-09 15:10:35 +02:00
parent fa72646f2b
commit fa3e074304
No known key found for this signature in database
3 changed files with 17 additions and 17 deletions

View file

@ -24,24 +24,24 @@ namespace wallet {
static feebumper::Result PreconditionChecks(const CWallet& wallet, const CWalletTx& wtx, bool require_mine, std::vector<bilingual_str>& errors) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet) static feebumper::Result PreconditionChecks(const CWallet& wallet, const CWalletTx& wtx, bool require_mine, std::vector<bilingual_str>& errors) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
{ {
if (wallet.HasWalletSpend(wtx.tx)) { if (wallet.HasWalletSpend(wtx.tx)) {
errors.push_back(Untranslated("Transaction has descendants in the wallet")); errors.emplace_back(Untranslated("Transaction has descendants in the wallet"));
return feebumper::Result::INVALID_PARAMETER; return feebumper::Result::INVALID_PARAMETER;
} }
{ {
if (wallet.chain().hasDescendantsInMempool(wtx.GetHash())) { if (wallet.chain().hasDescendantsInMempool(wtx.GetHash())) {
errors.push_back(Untranslated("Transaction has descendants in the mempool")); errors.emplace_back(Untranslated("Transaction has descendants in the mempool"));
return feebumper::Result::INVALID_PARAMETER; return feebumper::Result::INVALID_PARAMETER;
} }
} }
if (wallet.GetTxDepthInMainChain(wtx) != 0) { if (wallet.GetTxDepthInMainChain(wtx) != 0) {
errors.push_back(Untranslated("Transaction has been mined, or is conflicted with a mined transaction")); errors.emplace_back(Untranslated("Transaction has been mined, or is conflicted with a mined transaction"));
return feebumper::Result::WALLET_ERROR; return feebumper::Result::WALLET_ERROR;
} }
if (!SignalsOptInRBF(*wtx.tx)) { if (!SignalsOptInRBF(*wtx.tx)) {
errors.push_back(Untranslated("Transaction is not BIP 125 replaceable")); errors.emplace_back(Untranslated("Transaction is not BIP 125 replaceable"));
return feebumper::Result::WALLET_ERROR; return feebumper::Result::WALLET_ERROR;
} }
@ -55,7 +55,7 @@ static feebumper::Result PreconditionChecks(const CWallet& wallet, const CWallet
// if not, we can't bump the fee, because the wallet has no way of knowing the value of the other inputs (thus the fee) // if not, we can't bump the fee, because the wallet has no way of knowing the value of the other inputs (thus the fee)
isminefilter filter = wallet.GetLegacyScriptPubKeyMan() && wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) ? ISMINE_WATCH_ONLY : ISMINE_SPENDABLE; isminefilter filter = wallet.GetLegacyScriptPubKeyMan() && wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) ? ISMINE_WATCH_ONLY : ISMINE_SPENDABLE;
if (!AllInputsMine(wallet, *wtx.tx, filter)) { if (!AllInputsMine(wallet, *wtx.tx, filter)) {
errors.push_back(Untranslated("Transaction contains inputs that don't belong to this wallet")); errors.emplace_back(Untranslated("Transaction contains inputs that don't belong to this wallet"));
return feebumper::Result::WALLET_ERROR; return feebumper::Result::WALLET_ERROR;
} }
} }
@ -167,7 +167,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
{ {
// For now, cannot specify both new outputs to use and an output index to send change // For now, cannot specify both new outputs to use and an output index to send change
if (!outputs.empty() && original_change_index.has_value()) { if (!outputs.empty() && original_change_index.has_value()) {
errors.push_back(Untranslated("The options 'outputs' and 'original_change_index' are incompatible. You can only either specify a new set of outputs, or designate a change output to be recycled.")); errors.emplace_back(Untranslated("The options 'outputs' and 'original_change_index' are incompatible. You can only either specify a new set of outputs, or designate a change output to be recycled."));
return Result::INVALID_PARAMETER; return Result::INVALID_PARAMETER;
} }
@ -178,14 +178,14 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
errors.clear(); errors.clear();
auto it = wallet.mapWallet.find(txid); auto it = wallet.mapWallet.find(txid);
if (it == wallet.mapWallet.end()) { if (it == wallet.mapWallet.end()) {
errors.push_back(Untranslated("Invalid or non-wallet transaction id")); errors.emplace_back(Untranslated("Invalid or non-wallet transaction id"));
return Result::INVALID_ADDRESS_OR_KEY; return Result::INVALID_ADDRESS_OR_KEY;
} }
const CWalletTx& wtx = it->second; const CWalletTx& wtx = it->second;
// Make sure that original_change_index is valid // Make sure that original_change_index is valid
if (original_change_index.has_value() && original_change_index.value() >= wtx.tx->vout.size()) { if (original_change_index.has_value() && original_change_index.value() >= wtx.tx->vout.size()) {
errors.push_back(Untranslated("Change position is out of range")); errors.emplace_back(Untranslated("Change position is out of range"));
return Result::INVALID_PARAMETER; return Result::INVALID_PARAMETER;
} }
@ -201,7 +201,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
for (const CTxIn& txin : wtx.tx->vin) { for (const CTxIn& txin : wtx.tx->vin) {
const Coin& coin = coins.at(txin.prevout); const Coin& coin = coins.at(txin.prevout);
if (coin.out.IsNull()) { if (coin.out.IsNull()) {
errors.push_back(Untranslated(strprintf("%s:%u is already spent", txin.prevout.hash.GetHex(), txin.prevout.n))); errors.emplace_back(Untranslated(strprintf("%s:%u is already spent", txin.prevout.hash.GetHex(), txin.prevout.n)));
return Result::MISC_ERROR; return Result::MISC_ERROR;
} }
PreselectedInput& preset_txin = new_coin_control.Select(txin.prevout); PreselectedInput& preset_txin = new_coin_control.Select(txin.prevout);
@ -319,7 +319,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
auto res = CreateTransaction(wallet, recipients, /*change_pos=*/std::nullopt, new_coin_control, false); auto res = CreateTransaction(wallet, recipients, /*change_pos=*/std::nullopt, new_coin_control, false);
if (!res) { if (!res) {
errors.push_back(Untranslated("Unable to create transaction.") + Untranslated(" ") + util::ErrorString(res)); errors.emplace_back(Untranslated("Unable to create transaction.") + Untranslated(" ") + util::ErrorString(res));
return Result::WALLET_ERROR; return Result::WALLET_ERROR;
} }
@ -361,7 +361,7 @@ Result CommitTransaction(CWallet& wallet, const uint256& txid, CMutableTransacti
} }
auto it = txid.IsNull() ? wallet.mapWallet.end() : wallet.mapWallet.find(txid); auto it = txid.IsNull() ? wallet.mapWallet.end() : wallet.mapWallet.find(txid);
if (it == wallet.mapWallet.end()) { if (it == wallet.mapWallet.end()) {
errors.push_back(Untranslated("Invalid or non-wallet transaction id")); errors.emplace_back(Untranslated("Invalid or non-wallet transaction id"));
return Result::MISC_ERROR; return Result::MISC_ERROR;
} }
const CWalletTx& oldWtx = it->second; const CWalletTx& oldWtx = it->second;
@ -382,7 +382,7 @@ Result CommitTransaction(CWallet& wallet, const uint256& txid, CMutableTransacti
// mark the original tx as bumped // mark the original tx as bumped
bumped_txid = tx->GetHash(); bumped_txid = tx->GetHash();
if (!wallet.MarkReplaced(oldWtx.GetHash(), bumped_txid)) { if (!wallet.MarkReplaced(oldWtx.GetHash(), bumped_txid)) {
errors.push_back(Untranslated("Created new bumpfee transaction but could not mark the original transaction as replaced")); errors.emplace_back(Untranslated("Created new bumpfee transaction but could not mark the original transaction as replaced"));
} }
return Result::OK; return Result::OK;
} }

View file

@ -117,7 +117,7 @@ bool RecoverDatabaseFile(const ArgsManager& args, const fs::path& file_path, bil
Db db(env->dbenv.get(), 0); Db db(env->dbenv.get(), 0);
result = db.verify(newFilename.c_str(), nullptr, &strDump, DB_SALVAGE | DB_AGGRESSIVE); result = db.verify(newFilename.c_str(), nullptr, &strDump, DB_SALVAGE | DB_AGGRESSIVE);
if (result == DB_VERIFY_BAD) { if (result == DB_VERIFY_BAD) {
warnings.push_back(Untranslated("Salvage: Database salvage found errors, all data may not be recoverable.")); warnings.emplace_back(Untranslated("Salvage: Database salvage found errors, all data may not be recoverable."));
} }
if (result != 0 && result != DB_VERIFY_BAD) { if (result != 0 && result != DB_VERIFY_BAD) {
error = strprintf(Untranslated("Salvage: Database salvage failed with result %d."), result); error = strprintf(Untranslated("Salvage: Database salvage failed with result %d."), result);
@ -144,7 +144,7 @@ bool RecoverDatabaseFile(const ArgsManager& args, const fs::path& file_path, bil
break; break;
getline(strDump, valueHex); getline(strDump, valueHex);
if (valueHex == DATA_END) { if (valueHex == DATA_END) {
warnings.push_back(Untranslated("Salvage: WARNING: Number of keys in data does not match number of values.")); warnings.emplace_back(Untranslated("Salvage: WARNING: Number of keys in data does not match number of values."));
break; break;
} }
salvagedData.emplace_back(ParseHex(keyHex), ParseHex(valueHex)); salvagedData.emplace_back(ParseHex(keyHex), ParseHex(valueHex));
@ -153,7 +153,7 @@ bool RecoverDatabaseFile(const ArgsManager& args, const fs::path& file_path, bil
bool fSuccess; bool fSuccess;
if (keyHex != DATA_END) { if (keyHex != DATA_END) {
warnings.push_back(Untranslated("Salvage: WARNING: Unexpected end of file while reading salvage output.")); warnings.emplace_back(Untranslated("Salvage: WARNING: Unexpected end of file while reading salvage output."));
fSuccess = false; fSuccess = false;
} else { } else {
fSuccess = (result == 0); fSuccess = (result == 0);

View file

@ -290,7 +290,7 @@ std::shared_ptr<CWallet> LoadWalletInternal(WalletContext& context, const std::s
// Legacy wallets are being deprecated, warn if the loaded wallet is legacy // Legacy wallets are being deprecated, warn if the loaded wallet is legacy
if (!wallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { if (!wallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
warnings.push_back(_("Wallet loaded successfully. The legacy wallet type is being deprecated and support for creating and opening legacy wallets will be removed in the future. Legacy wallets can be migrated to a descriptor wallet with migratewallet.")); warnings.emplace_back(_("Wallet loaded successfully. The legacy wallet type is being deprecated and support for creating and opening legacy wallets will be removed in the future. Legacy wallets can be migrated to a descriptor wallet with migratewallet."));
} }
NotifyWalletLoaded(context, wallet); NotifyWalletLoaded(context, wallet);
@ -483,7 +483,7 @@ std::shared_ptr<CWallet> CreateWallet(WalletContext& context, const std::string&
// Legacy wallets are being deprecated, warn if a newly created wallet is legacy // Legacy wallets are being deprecated, warn if a newly created wallet is legacy
if (!(wallet_creation_flags & WALLET_FLAG_DESCRIPTORS)) { if (!(wallet_creation_flags & WALLET_FLAG_DESCRIPTORS)) {
warnings.push_back(_("Wallet created successfully. The legacy wallet type is being deprecated and support for creating and opening legacy wallets will be removed in the future.")); warnings.emplace_back(_("Wallet created successfully. The legacy wallet type is being deprecated and support for creating and opening legacy wallets will be removed in the future."));
} }
status = DatabaseStatus::SUCCESS; status = DatabaseStatus::SUCCESS;