mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-07 17:00:32 +02:00
Simplify SignTransaction precomputation loop
This commit is contained in:
@ -640,25 +640,22 @@ bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore,
|
|||||||
|
|
||||||
PrecomputedTransactionData txdata;
|
PrecomputedTransactionData txdata;
|
||||||
std::vector<CTxOut> spent_outputs;
|
std::vector<CTxOut> spent_outputs;
|
||||||
spent_outputs.resize(mtx.vin.size());
|
for (unsigned int i = 0; i < mtx.vin.size(); ++i) {
|
||||||
bool have_all_spent_outputs = true;
|
|
||||||
for (unsigned int i = 0; i < mtx.vin.size(); i++) {
|
|
||||||
CTxIn& txin = mtx.vin[i];
|
CTxIn& txin = mtx.vin[i];
|
||||||
auto coin = coins.find(txin.prevout);
|
auto coin = coins.find(txin.prevout);
|
||||||
if (coin == coins.end() || coin->second.IsSpent()) {
|
if (coin == coins.end() || coin->second.IsSpent()) {
|
||||||
have_all_spent_outputs = false;
|
txdata.Init(txConst, /* spent_outputs */ {}, /* force */ true);
|
||||||
|
break;
|
||||||
} else {
|
} else {
|
||||||
spent_outputs[i] = CTxOut(coin->second.out.nValue, coin->second.out.scriptPubKey);
|
spent_outputs.emplace_back(coin->second.out.nValue, coin->second.out.scriptPubKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (have_all_spent_outputs) {
|
if (spent_outputs.size() == mtx.vin.size()) {
|
||||||
txdata.Init(txConst, std::move(spent_outputs), true);
|
txdata.Init(txConst, std::move(spent_outputs), true);
|
||||||
} else {
|
|
||||||
txdata.Init(txConst, {}, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sign what we can:
|
// Sign what we can:
|
||||||
for (unsigned int i = 0; i < mtx.vin.size(); i++) {
|
for (unsigned int i = 0; i < mtx.vin.size(); ++i) {
|
||||||
CTxIn& txin = mtx.vin[i];
|
CTxIn& txin = mtx.vin[i];
|
||||||
auto coin = coins.find(txin.prevout);
|
auto coin = coins.find(txin.prevout);
|
||||||
if (coin == coins.end() || coin->second.IsSpent()) {
|
if (coin == coins.end() || coin->second.IsSpent()) {
|
||||||
|
Reference in New Issue
Block a user