Skip to content

Commit c7048aa

Browse files
committed
Simplify SignTransaction precomputation loop
1 parent addb9b5 commit c7048aa

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/script/sign.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -640,25 +640,22 @@ bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore,
640640

641641
PrecomputedTransactionData txdata;
642642
std::vector<CTxOut> spent_outputs;
643-
spent_outputs.resize(mtx.vin.size());
644-
bool have_all_spent_outputs = true;
645-
for (unsigned int i = 0; i < mtx.vin.size(); i++) {
643+
for (unsigned int i = 0; i < mtx.vin.size(); ++i) {
646644
CTxIn& txin = mtx.vin[i];
647645
auto coin = coins.find(txin.prevout);
648646
if (coin == coins.end() || coin->second.IsSpent()) {
649-
have_all_spent_outputs = false;
647+
txdata.Init(txConst, /* spent_outputs */ {}, /* force */ true);
648+
break;
650649
} else {
651-
spent_outputs[i] = CTxOut(coin->second.out.nValue, coin->second.out.scriptPubKey);
650+
spent_outputs.emplace_back(coin->second.out.nValue, coin->second.out.scriptPubKey);
652651
}
653652
}
654-
if (have_all_spent_outputs) {
653+
if (spent_outputs.size() == mtx.vin.size()) {
655654
txdata.Init(txConst, std::move(spent_outputs), true);
656-
} else {
657-
txdata.Init(txConst, {}, true);
658655
}
659656

660657
// Sign what we can:
661-
for (unsigned int i = 0; i < mtx.vin.size(); i++) {
658+
for (unsigned int i = 0; i < mtx.vin.size(); ++i) {
662659
CTxIn& txin = mtx.vin[i];
663660
auto coin = coins.find(txin.prevout);
664661
if (coin == coins.end() || coin->second.IsSpent()) {

0 commit comments

Comments
 (0)