@@ -2428,11 +2428,17 @@ bool CWallet::SignTransaction(CMutableTransaction& tx) const
2428
2428
2429
2429
bool CWallet::SignTransaction (CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int , std::string>& input_errors) const
2430
2430
{
2431
- // Sign the tx with ScriptPubKeyMans
2432
- // Because each ScriptPubKeyMan can sign more than one input, we need to keep track of each ScriptPubKeyMan that has signed this transaction.
2433
- // Each iteration, we may sign more txins than the txin that is specified in that iteration.
2434
- // We assume that each input is signed by only one ScriptPubKeyMan.
2435
- std::set<uint256> visited_spk_mans;
2431
+ // Try to sign with all ScriptPubKeyMans
2432
+ for (ScriptPubKeyMan* spk_man : GetAllScriptPubKeyMans ()) {
2433
+ // spk_man->SignTransaction will return true if the transaction is complete,
2434
+ // so we can exit early and return true if that happens
2435
+ if (spk_man->SignTransaction (tx, coins, sighash, input_errors)) {
2436
+ return true ;
2437
+ }
2438
+ }
2439
+
2440
+ // At this point, one input was not fully signed otherwise we would have exited already
2441
+ // Find that input and figure out what went wrong.
2436
2442
for (unsigned int i = 0 ; i < tx.vin .size (); i++) {
2437
2443
// Get the prevout
2438
2444
CTxIn& txin = tx.vin [i];
@@ -2444,33 +2450,10 @@ bool CWallet::SignTransaction(CMutableTransaction& tx, const std::map<COutPoint,
2444
2450
2445
2451
// Check if this input is complete
2446
2452
SignatureData sigdata = DataFromTransaction (tx, i, coin->second .out );
2447
- if (sigdata.complete ) {
2448
- continue ;
2449
- }
2450
-
2451
- // Input needs to be signed, find the right ScriptPubKeyMan
2452
- std::set<ScriptPubKeyMan*> spk_mans = GetScriptPubKeyMans (coin->second .out .scriptPubKey , sigdata);
2453
- if (spk_mans.size () == 0 ) {
2453
+ if (!sigdata.complete ) {
2454
2454
input_errors[i] = " Unable to sign input, missing keys" ;
2455
2455
continue ;
2456
2456
}
2457
-
2458
- for (auto & spk_man : spk_mans) {
2459
- // If we've already been signed by this spk_man, skip it
2460
- if (visited_spk_mans.count (spk_man->GetID ()) > 0 ) {
2461
- continue ;
2462
- }
2463
-
2464
- // Sign the tx.
2465
- // spk_man->SignTransaction will return true if the transaction is complete,
2466
- // so we can exit early and return true if that happens.
2467
- if (spk_man->SignTransaction (tx, coins, sighash, input_errors)) {
2468
- return true ;
2469
- }
2470
-
2471
- // Add this spk_man to visited_spk_mans so we can skip it later
2472
- visited_spk_mans.insert (spk_man->GetID ());
2473
- }
2474
2457
}
2475
2458
return false ;
2476
2459
}
0 commit comments