From 3557f99cf592be352cd2168157121a0cffbd6116 Mon Sep 17 00:00:00 2001 From: Gregory Maxwell Date: Sun, 5 Aug 2012 23:37:59 -0400 Subject: Correctly handle missing inputs in signrawtransaction. Fixes #1654. Signrawtransaction rpc was crashing when some inputs were unknown, and even with that fixed was failing to handle all the known inputs if there were unknown inputs in front of them. This commit instead attempts to fetch inputs one at a time. --- src/rpcrawtransaction.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/rpcrawtransaction.cpp') diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 66e4d85f37..57cba15ecf 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -321,18 +321,23 @@ Value signrawtransaction(const Array& params, bool fHelp) // Fetch previous transactions (inputs): map mapPrevOut; + for (unsigned int i = 0; i < mergedTx.vin.size(); i++) { + CTransaction tempTx; MapPrevTx mapPrevTx; CTxDB txdb("r"); map unused; bool fInvalid; - mergedTx.FetchInputs(txdb, unused, false, false, mapPrevTx, fInvalid); + + // FetchInputs aborts on failure, so we go one at a time. + tempTx.vin.push_back(mergedTx.vin[i]); + tempTx.FetchInputs(txdb, unused, false, false, mapPrevTx, fInvalid); // Copy results into mapPrevOut: - BOOST_FOREACH(const CTxIn& txin, mergedTx.vin) + BOOST_FOREACH(const CTxIn& txin, tempTx.vin) { const uint256& prevHash = txin.prevout.hash; - if (mapPrevTx.count(prevHash)) + if (mapPrevTx.count(prevHash) && mapPrevTx[prevHash].second.vout.size()>txin.prevout.n) mapPrevOut[txin.prevout] = mapPrevTx[prevHash].second.vout[txin.prevout.n].scriptPubKey; } } -- cgit v1.2.3