Skip to content

Commit fae6aca

Browse files
author
MarcoFalke
committed
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(
1 parent fa5ff55 commit fae6aca

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

src/wallet/feebumper.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,24 @@ namespace wallet {
2424
static feebumper::Result PreconditionChecks(const CWallet& wallet, const CWalletTx& wtx, bool require_mine, std::vector<bilingual_str>& errors) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
2525
{
2626
if (wallet.HasWalletSpend(wtx.tx)) {
27-
errors.push_back(Untranslated("Transaction has descendants in the wallet"));
27+
errors.emplace_back(Untranslated("Transaction has descendants in the wallet"));
2828
return feebumper::Result::INVALID_PARAMETER;
2929
}
3030

3131
{
3232
if (wallet.chain().hasDescendantsInMempool(wtx.GetHash())) {
33-
errors.push_back(Untranslated("Transaction has descendants in the mempool"));
33+
errors.emplace_back(Untranslated("Transaction has descendants in the mempool"));
3434
return feebumper::Result::INVALID_PARAMETER;
3535
}
3636
}
3737

3838
if (wallet.GetTxDepthInMainChain(wtx) != 0) {
39-
errors.push_back(Untranslated("Transaction has been mined, or is conflicted with a mined transaction"));
39+
errors.emplace_back(Untranslated("Transaction has been mined, or is conflicted with a mined transaction"));
4040
return feebumper::Result::WALLET_ERROR;
4141
}
4242

4343
if (!SignalsOptInRBF(*wtx.tx)) {
44-
errors.push_back(Untranslated("Transaction is not BIP 125 replaceable"));
44+
errors.emplace_back(Untranslated("Transaction is not BIP 125 replaceable"));
4545
return feebumper::Result::WALLET_ERROR;
4646
}
4747

@@ -55,7 +55,7 @@ static feebumper::Result PreconditionChecks(const CWallet& wallet, const CWallet
5555
// 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)
5656
isminefilter filter = wallet.GetLegacyScriptPubKeyMan() && wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) ? ISMINE_WATCH_ONLY : ISMINE_SPENDABLE;
5757
if (!AllInputsMine(wallet, *wtx.tx, filter)) {
58-
errors.push_back(Untranslated("Transaction contains inputs that don't belong to this wallet"));
58+
errors.emplace_back(Untranslated("Transaction contains inputs that don't belong to this wallet"));
5959
return feebumper::Result::WALLET_ERROR;
6060
}
6161
}
@@ -167,7 +167,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
167167
{
168168
// For now, cannot specify both new outputs to use and an output index to send change
169169
if (!outputs.empty() && original_change_index.has_value()) {
170-
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."));
170+
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."));
171171
return Result::INVALID_PARAMETER;
172172
}
173173

@@ -178,14 +178,14 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
178178
errors.clear();
179179
auto it = wallet.mapWallet.find(txid);
180180
if (it == wallet.mapWallet.end()) {
181-
errors.push_back(Untranslated("Invalid or non-wallet transaction id"));
181+
errors.emplace_back(Untranslated("Invalid or non-wallet transaction id"));
182182
return Result::INVALID_ADDRESS_OR_KEY;
183183
}
184184
const CWalletTx& wtx = it->second;
185185

186186
// Make sure that original_change_index is valid
187187
if (original_change_index.has_value() && original_change_index.value() >= wtx.tx->vout.size()) {
188-
errors.push_back(Untranslated("Change position is out of range"));
188+
errors.emplace_back(Untranslated("Change position is out of range"));
189189
return Result::INVALID_PARAMETER;
190190
}
191191

@@ -201,7 +201,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
201201
for (const CTxIn& txin : wtx.tx->vin) {
202202
const Coin& coin = coins.at(txin.prevout);
203203
if (coin.out.IsNull()) {
204-
errors.push_back(Untranslated(strprintf("%s:%u is already spent", txin.prevout.hash.GetHex(), txin.prevout.n)));
204+
errors.emplace_back(Untranslated(strprintf("%s:%u is already spent", txin.prevout.hash.GetHex(), txin.prevout.n)));
205205
return Result::MISC_ERROR;
206206
}
207207
PreselectedInput& preset_txin = new_coin_control.Select(txin.prevout);
@@ -319,7 +319,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
319319

320320
auto res = CreateTransaction(wallet, recipients, /*change_pos=*/std::nullopt, new_coin_control, false);
321321
if (!res) {
322-
errors.push_back(Untranslated("Unable to create transaction.") + Untranslated(" ") + util::ErrorString(res));
322+
errors.emplace_back(Untranslated("Unable to create transaction.") + Untranslated(" ") + util::ErrorString(res));
323323
return Result::WALLET_ERROR;
324324
}
325325

@@ -361,7 +361,7 @@ Result CommitTransaction(CWallet& wallet, const uint256& txid, CMutableTransacti
361361
}
362362
auto it = txid.IsNull() ? wallet.mapWallet.end() : wallet.mapWallet.find(txid);
363363
if (it == wallet.mapWallet.end()) {
364-
errors.push_back(Untranslated("Invalid or non-wallet transaction id"));
364+
errors.emplace_back(Untranslated("Invalid or non-wallet transaction id"));
365365
return Result::MISC_ERROR;
366366
}
367367
const CWalletTx& oldWtx = it->second;
@@ -382,7 +382,7 @@ Result CommitTransaction(CWallet& wallet, const uint256& txid, CMutableTransacti
382382
// mark the original tx as bumped
383383
bumped_txid = tx->GetHash();
384384
if (!wallet.MarkReplaced(oldWtx.GetHash(), bumped_txid)) {
385-
errors.push_back(Untranslated("Created new bumpfee transaction but could not mark the original transaction as replaced"));
385+
errors.emplace_back(Untranslated("Created new bumpfee transaction but could not mark the original transaction as replaced"));
386386
}
387387
return Result::OK;
388388
}

src/wallet/salvage.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ bool RecoverDatabaseFile(const ArgsManager& args, const fs::path& file_path, bil
116116
Db db(env->dbenv.get(), 0);
117117
result = db.verify(newFilename.c_str(), nullptr, &strDump, DB_SALVAGE | DB_AGGRESSIVE);
118118
if (result == DB_VERIFY_BAD) {
119-
warnings.push_back(Untranslated("Salvage: Database salvage found errors, all data may not be recoverable."));
119+
warnings.emplace_back(Untranslated("Salvage: Database salvage found errors, all data may not be recoverable."));
120120
}
121121
if (result != 0 && result != DB_VERIFY_BAD) {
122122
error = strprintf(Untranslated("Salvage: Database salvage failed with result %d."), result);
@@ -143,7 +143,7 @@ bool RecoverDatabaseFile(const ArgsManager& args, const fs::path& file_path, bil
143143
break;
144144
getline(strDump, valueHex);
145145
if (valueHex == DATA_END) {
146-
warnings.push_back(Untranslated("Salvage: WARNING: Number of keys in data does not match number of values."));
146+
warnings.emplace_back(Untranslated("Salvage: WARNING: Number of keys in data does not match number of values."));
147147
break;
148148
}
149149
salvagedData.emplace_back(ParseHex(keyHex), ParseHex(valueHex));
@@ -152,7 +152,7 @@ bool RecoverDatabaseFile(const ArgsManager& args, const fs::path& file_path, bil
152152

153153
bool fSuccess;
154154
if (keyHex != DATA_END) {
155-
warnings.push_back(Untranslated("Salvage: WARNING: Unexpected end of file while reading salvage output."));
155+
warnings.emplace_back(Untranslated("Salvage: WARNING: Unexpected end of file while reading salvage output."));
156156
fSuccess = false;
157157
} else {
158158
fSuccess = (result == 0);

src/wallet/wallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ std::shared_ptr<CWallet> LoadWalletInternal(WalletContext& context, const std::s
290290

291291
// Legacy wallets are being deprecated, warn if the loaded wallet is legacy
292292
if (!wallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
293-
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."));
293+
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."));
294294
}
295295

296296
NotifyWalletLoaded(context, wallet);
@@ -483,7 +483,7 @@ std::shared_ptr<CWallet> CreateWallet(WalletContext& context, const std::string&
483483

484484
// Legacy wallets are being deprecated, warn if a newly created wallet is legacy
485485
if (!(wallet_creation_flags & WALLET_FLAG_DESCRIPTORS)) {
486-
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."));
486+
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."));
487487
}
488488

489489
status = DatabaseStatus::SUCCESS;

0 commit comments

Comments
 (0)