@@ -2428,11 +2428,17 @@ bool CWallet::SignTransaction(CMutableTransaction& tx) const
24282428
24292429bool CWallet::SignTransaction (CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int , std::string>& input_errors) const
24302430{
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.
24362442 for (unsigned int i = 0 ; i < tx.vin .size (); i++) {
24372443 // Get the prevout
24382444 CTxIn& txin = tx.vin [i];
@@ -2444,33 +2450,10 @@ bool CWallet::SignTransaction(CMutableTransaction& tx, const std::map<COutPoint,
24442450
24452451 // Check if this input is complete
24462452 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 ) {
24542454 input_errors[i] = " Unable to sign input, missing keys" ;
24552455 continue ;
24562456 }
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- }
24742457 }
24752458 return false ;
24762459}
0 commit comments