Skip to content

Commit e625548

Browse files
committed
Merge #12950: bitcoin-tx: Flatten for loop over one element
fa72f34 bitcoin-tx: Remove unused for loop (MarcoFalke) Pull request description: This flattens out a for loop and gets rid of the then unused vector `txVariants`. Tree-SHA512: 68081b313d846ce235a97a642c9d0097c3641350e819d6254001f332b053e41fa63ce49faca68120f5aaf5d5f4bfda104662eae781e2956d76a8915770344045
2 parents 94deb09 + fa72f34 commit e625548

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/bitcoin-tx.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -545,12 +545,10 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
545545
if (!findSighashFlags(nHashType, flagStr))
546546
throw std::runtime_error("unknown sighash flag/sign option");
547547

548-
std::vector<CTransaction> txVariants;
549-
txVariants.push_back(tx);
550-
551548
// mergedTx will end up with all the signatures; it
552549
// starts as a clone of the raw tx:
553-
CMutableTransaction mergedTx(txVariants[0]);
550+
CMutableTransaction mergedTx{tx};
551+
const CTransaction txv{tx};
554552
CCoinsView viewDummy;
555553
CCoinsViewCache view(&viewDummy);
556554

@@ -633,7 +631,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
633631

634632
// Sign what we can:
635633
for (unsigned int i = 0; i < mergedTx.vin.size(); i++) {
636-
CTxIn& txin = mergedTx.vin[i];
634+
const CTxIn& txin = mergedTx.vin[i];
637635
const Coin& coin = view.AccessCoin(txin.prevout);
638636
if (coin.IsSpent()) {
639637
continue;
@@ -647,8 +645,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
647645
ProduceSignature(keystore, MutableTransactionSignatureCreator(&mergedTx, i, amount, nHashType), prevPubKey, sigdata);
648646

649647
// ... and merge in other signatures:
650-
for (const CTransaction& txv : txVariants)
651-
sigdata = CombineSignatures(prevPubKey, MutableTransactionSignatureChecker(&mergedTx, i, amount), sigdata, DataFromTransaction(txv, i));
648+
sigdata = CombineSignatures(prevPubKey, MutableTransactionSignatureChecker(&mergedTx, i, amount), sigdata, DataFromTransaction(txv, i));
652649
UpdateTransaction(mergedTx, i, sigdata);
653650
}
654651

0 commit comments

Comments
 (0)