aboutsummaryrefslogtreecommitdiff
path: root/src/rpcrawtransaction.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2012-08-20 14:06:27 -0400
committerGavin Andresen <gavinandresen@gmail.com>2012-08-20 14:06:27 -0400
commitd5e7b611736e088801c1d269dfadd2270703bf58 (patch)
treed2f611e187b5f38108c760cfa0cdb5bf9a2e525a /src/rpcrawtransaction.cpp
parentb3a570d158224e6ae6ee72fadd2bf947d7656f23 (diff)
downloadbitcoin-d5e7b611736e088801c1d269dfadd2270703bf58.tar.xz
When using SIGHASH_SINGLE, do not sign inputs that have no corresponding outputs.
This fixes issue #1688
Diffstat (limited to 'src/rpcrawtransaction.cpp')
-rw-r--r--src/rpcrawtransaction.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp
index 57cba15ecf..56a49fd4d3 100644
--- a/src/rpcrawtransaction.cpp
+++ b/src/rpcrawtransaction.cpp
@@ -428,6 +428,8 @@ Value signrawtransaction(const Array& params, bool fHelp)
throw JSONRPCError(-8, "Invalid sighash param");
}
+ bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE);
+
// Sign what we can:
for (unsigned int i = 0; i < mergedTx.vin.size(); i++)
{
@@ -440,7 +442,9 @@ Value signrawtransaction(const Array& params, bool fHelp)
const CScript& prevPubKey = mapPrevOut[txin.prevout];
txin.scriptSig.clear();
- SignSignature(keystore, prevPubKey, mergedTx, i, nHashType);
+ // Only sign SIGHASH_SINGLE if there's a corresponding output:
+ if (!fHashSingle || (i < mergedTx.vout.size()))
+ SignSignature(keystore, prevPubKey, mergedTx, i, nHashType);
// ... and merge in other signatures:
BOOST_FOREACH(const CTransaction& txv, txVariants)