1
1
// Copyright (c) 2010 Satoshi Nakamoto
2
- // Copyright (c) 2009-2014 The Bitcoin Core developers
2
+ // Copyright (c) 2009-2015 The Bitcoin Core developers
3
3
// Distributed under the MIT software license, see the accompanying
4
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
13
13
#include " net.h"
14
14
#include " rpcserver.h"
15
15
#include " script/script.h"
16
+ #include " script/script_error.h"
16
17
#include " script/sign.h"
17
18
#include " script/standard.h"
18
19
#include " uint256.h"
@@ -491,6 +492,18 @@ Value decodescript(const Array& params, bool fHelp)
491
492
return r;
492
493
}
493
494
495
+ /* * Pushes a JSON object for script verification or signing errors to vErrorsRet. */
496
+ static void TxInErrorToJSON (const CTxIn& txin, Array& vErrorsRet, const std::string& strMessage)
497
+ {
498
+ Object entry;
499
+ entry.push_back (Pair (" txid" , txin.prevout .hash .ToString ()));
500
+ entry.push_back (Pair (" vout" , (uint64_t )txin.prevout .n ));
501
+ entry.push_back (Pair (" scriptSig" , HexStr (txin.scriptSig .begin (), txin.scriptSig .end ())));
502
+ entry.push_back (Pair (" sequence" , (uint64_t )txin.nSequence ));
503
+ entry.push_back (Pair (" error" , strMessage));
504
+ vErrorsRet.push_back (entry);
505
+ }
506
+
494
507
Value signrawtransaction (const Array& params, bool fHelp )
495
508
{
496
509
if (fHelp || params.size () < 1 || params.size () > 4 )
@@ -532,8 +545,18 @@ Value signrawtransaction(const Array& params, bool fHelp)
532
545
533
546
" \n Result:\n "
534
547
" {\n "
535
- " \" hex\" : \" value\" , (string) The raw transaction with signature(s) (hex-encoded string)\n "
536
- " \" complete\" : true|false (boolean) if transaction has a complete set of signature\n "
548
+ " \" hex\" : \" value\" , (string) The hex-encoded raw transaction with signature(s)\n "
549
+ " \" complete\" : true|false, (boolean) If the transaction has a complete set of signatures\n "
550
+ " \" errors\" : [ (json array of objects) Script verification errors (if there are any)\n "
551
+ " {\n "
552
+ " \" txid\" : \" hash\" , (string) The hash of the referenced, previous transaction\n "
553
+ " \" vout\" : n, (numeric) The index of the output to spent and used as input\n "
554
+ " \" scriptSig\" : \" hex\" , (string) The hex-encoded signature script\n "
555
+ " \" sequence\" : n, (numeric) Script sequence number\n "
556
+ " \" error\" : \" text\" (string) Verification or signing error related to the input\n "
557
+ " }\n "
558
+ " ,...\n "
559
+ " ]\n "
537
560
" }\n "
538
561
539
562
" \n Examples:\n "
@@ -568,7 +591,6 @@ Value signrawtransaction(const Array& params, bool fHelp)
568
591
// mergedTx will end up with all the signatures; it
569
592
// starts as a clone of the rawtx:
570
593
CMutableTransaction mergedTx (txVariants[0 ]);
571
- bool fComplete = true ;
572
594
573
595
// Fetch previous transactions (inputs):
574
596
CCoinsView viewDummy;
@@ -683,12 +705,15 @@ Value signrawtransaction(const Array& params, bool fHelp)
683
705
684
706
bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE);
685
707
708
+ // Script verification errors
709
+ Array vErrors;
710
+
686
711
// Sign what we can:
687
712
for (unsigned int i = 0 ; i < mergedTx.vin .size (); i++) {
688
713
CTxIn& txin = mergedTx.vin [i];
689
714
const CCoins* coins = view.AccessCoins (txin.prevout .hash );
690
715
if (coins == NULL || !coins->IsAvailable (txin.prevout .n )) {
691
- fComplete = false ;
716
+ TxInErrorToJSON (txin, vErrors, " Input not found or already spent " ) ;
692
717
continue ;
693
718
}
694
719
const CScript& prevPubKey = coins->vout [txin.prevout .n ].scriptPubKey ;
@@ -702,13 +727,19 @@ Value signrawtransaction(const Array& params, bool fHelp)
702
727
BOOST_FOREACH (const CMutableTransaction& txv, txVariants) {
703
728
txin.scriptSig = CombineSignatures (prevPubKey, mergedTx, i, txin.scriptSig , txv.vin [i].scriptSig );
704
729
}
705
- if (!VerifyScript (txin.scriptSig , prevPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, MutableTransactionSignatureChecker (&mergedTx, i)))
706
- fComplete = false ;
730
+ ScriptError serror = SCRIPT_ERR_OK;
731
+ if (!VerifyScript (txin.scriptSig , prevPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, MutableTransactionSignatureChecker (&mergedTx, i), &serror)) {
732
+ TxInErrorToJSON (txin, vErrors, ScriptErrorString (serror));
733
+ }
707
734
}
735
+ bool fComplete = vErrors.empty ();
708
736
709
737
Object result;
710
738
result.push_back (Pair (" hex" , EncodeHexTx (mergedTx)));
711
739
result.push_back (Pair (" complete" , fComplete ));
740
+ if (!vErrors.empty ()) {
741
+ result.push_back (Pair (" errors" , vErrors));
742
+ }
712
743
713
744
return result;
714
745
}
0 commit comments