diff --git a/qa/rpc-tests/abandonconflict.py b/qa/rpc-tests/abandonconflict.py --- a/qa/rpc-tests/abandonconflict.py +++ b/qa/rpc-tests/abandonconflict.py @@ -51,7 +51,7 @@ outputs[self.nodes[0].getnewaddress()] = Decimal("14.99998") outputs[self.nodes[1].getnewaddress()] = Decimal("5") - signed = self.nodes[0].signrawtransaction(self.nodes[0].createrawtransaction(inputs, outputs)) + signed = self.nodes[0].signrawtransaction(self.nodes[0].createrawtransaction(inputs, outputs), None, None, "ALL") txAB1 = self.nodes[0].sendrawtransaction(signed["hex"]) # Identify the 14.99998btc output @@ -63,7 +63,7 @@ inputs.append({"txid":txC, "vout":nC}) outputs = {} outputs[self.nodes[0].getnewaddress()] = Decimal("24.9996") - signed2 = self.nodes[0].signrawtransaction(self.nodes[0].createrawtransaction(inputs, outputs)) + signed2 = self.nodes[0].signrawtransaction(self.nodes[0].createrawtransaction(inputs, outputs), None, None, "ALL") txABC2 = self.nodes[0].sendrawtransaction(signed2["hex"]) # In mempool txs from self should increase balance from change @@ -134,7 +134,7 @@ outputs = {} outputs[self.nodes[1].getnewaddress()] = Decimal("9.9999") tx = self.nodes[0].createrawtransaction(inputs, outputs) - signed = self.nodes[0].signrawtransaction(tx) + signed = self.nodes[0].signrawtransaction(tx, None, None, "ALL") self.nodes[1].sendrawtransaction(signed["hex"]) self.nodes[1].generate(1) diff --git a/qa/rpc-tests/bip65-cltv-p2p.py b/qa/rpc-tests/bip65-cltv-p2p.py --- a/qa/rpc-tests/bip65-cltv-p2p.py +++ b/qa/rpc-tests/bip65-cltv-p2p.py @@ -33,7 +33,6 @@ Mine 1 new version block. Mine 1 old version block, see that the node rejects. ''' - class BIP65Test(ComparisonTestFramework): def __init__(self): @@ -57,7 +56,7 @@ inputs = [{ "txid" : from_txid, "vout" : 0}] outputs = { to_address : amount } rawtx = node.createrawtransaction(inputs, outputs) - signresult = node.signrawtransaction(rawtx) + signresult = node.signrawtransaction(rawtx, None, None, "ALL") tx = CTransaction() f = BytesIO(hex_str_to_bytes(signresult['hex'])) tx.deserialize(f) diff --git a/qa/rpc-tests/bip68-112-113-p2p.py b/qa/rpc-tests/bip68-112-113-p2p.py --- a/qa/rpc-tests/bip68-112-113-p2p.py +++ b/qa/rpc-tests/bip68-112-113-p2p.py @@ -124,7 +124,7 @@ def sign_transaction(self, node, unsignedtx): rawtx = ToHex(unsignedtx) - signresult = node.signrawtransaction(rawtx) + signresult = node.signrawtransaction(rawtx, None, None, "ALL") tx = CTransaction() f = BytesIO(hex_str_to_bytes(signresult['hex'])) tx.deserialize(f) diff --git a/qa/rpc-tests/bip68-sequence.py b/qa/rpc-tests/bip68-sequence.py --- a/qa/rpc-tests/bip68-sequence.py +++ b/qa/rpc-tests/bip68-sequence.py @@ -84,7 +84,7 @@ tx1.vin = [CTxIn(COutPoint(int(utxo["txid"], 16), utxo["vout"]), nSequence=sequence_value)] tx1.vout = [CTxOut(value, CScript([b'a']))] - tx1_signed = self.nodes[0].signrawtransaction(ToHex(tx1))["hex"] + tx1_signed = self.nodes[0].signrawtransaction(ToHex(tx1), None, None, "ALL")["hex"] tx1_id = self.nodes[0].sendrawtransaction(tx1_signed) tx1_id = int(tx1_id, 16) @@ -195,7 +195,7 @@ # Overestimate the size of the tx - signatures should be less than 120 bytes, and leave 50 for the output tx_size = len(ToHex(tx))//2 + 120*num_inputs + 50 tx.vout.append(CTxOut(int(value-self.relayfee*tx_size*COIN/1000), CScript([b'a']))) - rawtx = self.nodes[0].signrawtransaction(ToHex(tx))["hex"] + rawtx = self.nodes[0].signrawtransaction(ToHex(tx), None, None, "ALL")["hex"] try: self.nodes[0].sendrawtransaction(rawtx) @@ -226,7 +226,7 @@ tx2.nVersion = 2 tx2.vin = [CTxIn(COutPoint(tx1.sha256, 0), nSequence=0)] tx2.vout = [CTxOut(int(tx1.vout[0].nValue - self.relayfee*COIN), CScript([b'a']))] - tx2_raw = self.nodes[0].signrawtransaction(ToHex(tx2))["hex"] + tx2_raw = self.nodes[0].signrawtransaction(ToHex(tx2), None, None, "ALL")["hex"] tx2 = FromHex(tx2, tx2_raw) tx2.rehash() @@ -300,7 +300,7 @@ utxos = self.nodes[0].listunspent() tx5.vin.append(CTxIn(COutPoint(int(utxos[0]["txid"], 16), utxos[0]["vout"]), nSequence=1)) tx5.vout[0].nValue += int(utxos[0]["amount"]*COIN) - raw_tx5 = self.nodes[0].signrawtransaction(ToHex(tx5))["hex"] + raw_tx5 = self.nodes[0].signrawtransaction(ToHex(tx5), None, None, "ALL")["hex"] try: self.nodes[0].sendrawtransaction(raw_tx5) @@ -365,7 +365,7 @@ tx2.vout = [CTxOut(int(tx1.vout[0].nValue - self.relayfee*COIN), CScript([b'a']))] # sign tx2 - tx2_raw = self.nodes[0].signrawtransaction(ToHex(tx2))["hex"] + tx2_raw = self.nodes[0].signrawtransaction(ToHex(tx2), None, None, "ALL")["hex"] tx2 = FromHex(tx2, tx2_raw) tx2.rehash() @@ -416,7 +416,7 @@ rawtxfund = self.nodes[1].fundrawtransaction(rawtx)['hex'] tx = FromHex(CTransaction(), rawtxfund) tx.nVersion = 2 - tx_signed = self.nodes[1].signrawtransaction(ToHex(tx))["hex"] + tx_signed = self.nodes[1].signrawtransaction(ToHex(tx), None, None, "ALL")["hex"] try: tx_id = self.nodes[1].sendrawtransaction(tx_signed) assert(before_activation == False) diff --git a/qa/rpc-tests/bip9-softforks.py b/qa/rpc-tests/bip9-softforks.py --- a/qa/rpc-tests/bip9-softforks.py +++ b/qa/rpc-tests/bip9-softforks.py @@ -27,8 +27,6 @@ test that enforcement has not triggered (which triggers ACTIVE) test that enforcement has triggered ''' - - class BIP9SoftForksTest(ComparisonTestFramework): def __init__(self): @@ -58,7 +56,7 @@ return tx def sign_transaction(self, node, tx): - signresult = node.signrawtransaction(bytes_to_hex_str(tx.serialize())) + signresult = node.signrawtransaction(bytes_to_hex_str(tx.serialize()), None, None, "ALL") tx = CTransaction() f = BytesIO(hex_str_to_bytes(signresult['hex'])) tx.deserialize(f) diff --git a/qa/rpc-tests/bipdersig-p2p.py b/qa/rpc-tests/bipdersig-p2p.py --- a/qa/rpc-tests/bipdersig-p2p.py +++ b/qa/rpc-tests/bipdersig-p2p.py @@ -65,7 +65,7 @@ inputs = [{ "txid" : from_txid, "vout" : 0}] outputs = { to_address : amount } rawtx = node.createrawtransaction(inputs, outputs) - signresult = node.signrawtransaction(rawtx) + signresult = node.signrawtransaction(rawtx, None, None, "ALL") tx = CTransaction() f = BytesIO(hex_str_to_bytes(signresult['hex'])) tx.deserialize(f) diff --git a/qa/rpc-tests/fundrawtransaction.py b/qa/rpc-tests/fundrawtransaction.py --- a/qa/rpc-tests/fundrawtransaction.py +++ b/qa/rpc-tests/fundrawtransaction.py @@ -456,7 +456,7 @@ rawTx = self.nodes[2].createrawtransaction(inputs, outputs) fundedTx = self.nodes[2].fundrawtransaction(rawTx) - signedTx = self.nodes[2].signrawtransaction(fundedTx['hex']) + signedTx = self.nodes[2].signrawtransaction(fundedTx['hex'], None, None, "ALL") txId = self.nodes[2].sendrawtransaction(signedTx['hex']) self.sync_all() self.nodes[1].generate(1) @@ -518,7 +518,7 @@ #now we need to unlock self.nodes[1].walletpassphrase("test", 600) - signedTx = self.nodes[1].signrawtransaction(fundedTx['hex']) + signedTx = self.nodes[1].signrawtransaction(fundedTx['hex'], None, None, "ALL") txId = self.nodes[1].sendrawtransaction(signedTx['hex']) self.nodes[1].generate(1) self.sync_all() @@ -579,7 +579,7 @@ outputs = {self.nodes[0].getnewaddress():0.15,self.nodes[0].getnewaddress():0.04} rawTx = self.nodes[1].createrawtransaction(inputs, outputs) fundedTx = self.nodes[1].fundrawtransaction(rawTx) - fundedAndSignedTx = self.nodes[1].signrawtransaction(fundedTx['hex']) + fundedAndSignedTx = self.nodes[1].signrawtransaction(fundedTx['hex'], None, None, "ALL") txId = self.nodes[1].sendrawtransaction(fundedAndSignedTx['hex']) self.sync_all() self.nodes[0].generate(1) @@ -637,9 +637,9 @@ assert_greater_than(result["changepos"], -1) assert_equal(result["fee"] + res_dec["vout"][result["changepos"]]["value"], watchonly_amount / 10) - signedtx = self.nodes[3].signrawtransaction(result["hex"]) + signedtx = self.nodes[3].signrawtransaction(result["hex"], None, None, "ALL") assert(not signedtx["complete"]) - signedtx = self.nodes[0].signrawtransaction(signedtx["hex"]) + signedtx = self.nodes[0].signrawtransaction(signedtx["hex"], None, None, "ALL") assert(signedtx["complete"]) self.nodes[0].sendrawtransaction(signedtx["hex"]) self.nodes[0].generate(1) diff --git a/qa/rpc-tests/mempool_limit.py b/qa/rpc-tests/mempool_limit.py --- a/qa/rpc-tests/mempool_limit.py +++ b/qa/rpc-tests/mempool_limit.py @@ -36,7 +36,7 @@ self.nodes[0].settxfee(self.relayfee) # specifically fund this tx with low fee txF = self.nodes[0].fundrawtransaction(tx) self.nodes[0].settxfee(0) # return to automatic fee selection - txFS = self.nodes[0].signrawtransaction(txF['hex']) + txFS = self.nodes[0].signrawtransaction(txF['hex'], None, None, "ALL") txid = self.nodes[0].sendrawtransaction(txFS['hex']) relayfee = self.nodes[0].getnetworkinfo()['relayfee'] diff --git a/qa/rpc-tests/mempool_packages.py b/qa/rpc-tests/mempool_packages.py --- a/qa/rpc-tests/mempool_packages.py +++ b/qa/rpc-tests/mempool_packages.py @@ -35,7 +35,7 @@ for i in range(num_outputs): outputs[node.getnewaddress()] = send_value rawtx = node.createrawtransaction(inputs, outputs) - signedtx = node.signrawtransaction(rawtx) + signedtx = node.signrawtransaction(rawtx, None, None, "ALL") txid = node.sendrawtransaction(signedtx['hex']) fulltx = node.getrawtransaction(txid, 1) assert(len(fulltx['vout']) == num_outputs) # make sure we didn't generate a change output @@ -218,7 +218,7 @@ for i in range(2): outputs[self.nodes[0].getnewaddress()] = send_value rawtx = self.nodes[0].createrawtransaction(inputs, outputs) - signedtx = self.nodes[0].signrawtransaction(rawtx) + signedtx = self.nodes[0].signrawtransaction(rawtx, None, None, "ALL") txid = self.nodes[0].sendrawtransaction(signedtx['hex']) tx0_id = txid value = send_value @@ -242,7 +242,7 @@ inputs = [ {'txid' : tx1_id, 'vout': 0}, {'txid' : txid, 'vout': 0} ] outputs = { self.nodes[0].getnewaddress() : send_value + value - 4*fee } rawtx = self.nodes[0].createrawtransaction(inputs, outputs) - signedtx = self.nodes[0].signrawtransaction(rawtx) + signedtx = self.nodes[0].signrawtransaction(rawtx, None, None, "ALL") txid = self.nodes[0].sendrawtransaction(signedtx['hex']) sync_mempools(self.nodes) diff --git a/qa/rpc-tests/mempool_reorg.py b/qa/rpc-tests/mempool_reorg.py --- a/qa/rpc-tests/mempool_reorg.py +++ b/qa/rpc-tests/mempool_reorg.py @@ -57,7 +57,7 @@ # Set the time lock timelock_tx = timelock_tx.replace("ffffffff", "11111191", 1) timelock_tx = timelock_tx[:-8] + hex(self.nodes[0].getblockcount() + 2)[2:] + "000000" - timelock_tx = self.nodes[0].signrawtransaction(timelock_tx)["hex"] + timelock_tx = self.nodes[0].signrawtransaction(timelock_tx, None, None, "ALL")["hex"] assert_raises(JSONRPCException, self.nodes[0].sendrawtransaction, timelock_tx) # Broadcast and mine spend_102 and 103: diff --git a/qa/rpc-tests/merkle_blocks.py b/qa/rpc-tests/merkle_blocks.py --- a/qa/rpc-tests/merkle_blocks.py +++ b/qa/rpc-tests/merkle_blocks.py @@ -44,9 +44,9 @@ node0utxos = self.nodes[0].listunspent(1) tx1 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 49.99}) - txid1 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx1)["hex"]) + txid1 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx1, None, None, "ALL")["hex"]) tx2 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 49.99}) - txid2 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx2)["hex"]) + txid2 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx2, None, None, "ALL")["hex"]) assert_raises(JSONRPCException, self.nodes[0].gettxoutproof, [txid1]) self.nodes[0].generate(1) @@ -64,7 +64,7 @@ txin_spent = self.nodes[1].listunspent(1).pop() tx3 = self.nodes[1].createrawtransaction([txin_spent], {self.nodes[0].getnewaddress(): 49.98}) - self.nodes[0].sendrawtransaction(self.nodes[1].signrawtransaction(tx3)["hex"]) + self.nodes[0].sendrawtransaction(self.nodes[1].signrawtransaction(tx3, None, None, "ALL")["hex"]) self.nodes[0].generate(1) self.sync_all() diff --git a/qa/rpc-tests/nulldummy.py b/qa/rpc-tests/nulldummy.py --- a/qa/rpc-tests/nulldummy.py +++ b/qa/rpc-tests/nulldummy.py @@ -83,7 +83,7 @@ inputs = [{ "txid" : txid, "vout" : 0}] outputs = { to_address : amount } rawtx = node.createrawtransaction(inputs, outputs) - signresult = node.signrawtransaction(rawtx) + signresult = node.signrawtransaction(rawtx, None, None, "ALL") tx = CTransaction() f = BytesIO(hex_str_to_bytes(signresult['hex'])) tx.deserialize(f) diff --git a/qa/rpc-tests/prioritise_transaction.py b/qa/rpc-tests/prioritise_transaction.py --- a/qa/rpc-tests/prioritise_transaction.py +++ b/qa/rpc-tests/prioritise_transaction.py @@ -33,7 +33,8 @@ def run_test(self): utxo_count = 90 utxos = create_confirmed_utxos(self.relayfee, self.nodes[0], utxo_count) - base_fee = self.relayfee*100 # our transactions are smaller than 100kb + # our transactions are smaller than 100kb + base_fee = self.relayfee*100 txids = [] # Create 3 batches of transactions at 3 different fee rate levels @@ -53,7 +54,8 @@ for j in txids[i]: assert(j in mempool) sizes[i] += mempool[j]['size'] - assert(sizes[i] > LEGACY_MAX_BLOCK_SIZE) # Fail => raise utxo_count + # Fail => raise utxo_count + assert(sizes[i] > LEGACY_MAX_BLOCK_SIZE) # add a fee delta to something in the cheapest bucket and make sure it gets mined # also check that a different entry in the cheapest bucket is NOT mined (lower @@ -112,7 +114,7 @@ inputs.append({"txid" : utxo["txid"], "vout" : utxo["vout"]}) outputs[self.nodes[0].getnewaddress()] = utxo["amount"] - self.relayfee raw_tx = self.nodes[0].createrawtransaction(inputs, outputs) - tx_hex = self.nodes[0].signrawtransaction(raw_tx)["hex"] + tx_hex = self.nodes[0].signrawtransaction(raw_tx, None, None, "ALL")["hex"] txid = self.nodes[0].sendrawtransaction(tx_hex) # A tx that spends an in-mempool tx has 0 priority, so we can use it to @@ -122,7 +124,7 @@ outputs = {} outputs[self.nodes[0].getnewaddress()] = utxo["amount"] - self.relayfee raw_tx2 = self.nodes[0].createrawtransaction(inputs, outputs) - tx2_hex = self.nodes[0].signrawtransaction(raw_tx2)["hex"] + tx2_hex = self.nodes[0].signrawtransaction(raw_tx2, None, None, "ALL")["hex"] tx2_id = self.nodes[0].decoderawtransaction(tx2_hex)["txid"] try: @@ -142,5 +144,6 @@ assert_equal(self.nodes[0].sendrawtransaction(tx2_hex), tx2_id) assert(tx2_id in self.nodes[0].getrawmempool()) + if __name__ == '__main__': PrioritiseTransactionTest().main() diff --git a/qa/rpc-tests/rawtransactions.py b/qa/rpc-tests/rawtransactions.py --- a/qa/rpc-tests/rawtransactions.py +++ b/qa/rpc-tests/rawtransactions.py @@ -59,7 +59,7 @@ inputs = [ {'txid' : "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000", 'vout' : 1}] #won't exists outputs = { self.nodes[0].getnewaddress() : 4.998 } rawtx = self.nodes[2].createrawtransaction(inputs, outputs) - rawtx = self.nodes[2].signrawtransaction(rawtx) + rawtx = self.nodes[2].signrawtransaction(rawtx, None, None, "ALL") try: rawtx = self.nodes[2].sendrawtransaction(rawtx['hex']) @@ -130,11 +130,13 @@ inputs = [{ "txid" : txId, "vout" : vout['n'], "scriptPubKey" : vout['scriptPubKey']['hex']}] outputs = { self.nodes[0].getnewaddress() : 2.19 } rawTx = self.nodes[2].createrawtransaction(inputs, outputs) - rawTxPartialSigned = self.nodes[1].signrawtransaction(rawTx, inputs) - assert_equal(rawTxPartialSigned['complete'], False) #node1 only has one key, can't comp. sign the tx + rawTxPartialSigned = self.nodes[1].signrawtransaction(rawTx, inputs, None, "ALL") + # node1 only has one key, can't comp. sign the tx + assert_equal(rawTxPartialSigned['complete'], False) - rawTxSigned = self.nodes[2].signrawtransaction(rawTx, inputs) - assert_equal(rawTxSigned['complete'], True) #node2 can sign the tx compl., own two of three keys + rawTxSigned = self.nodes[2].signrawtransaction(rawTx, inputs, None, "ALL") + # node2 can sign the tx compl., own two of three keys + assert_equal(rawTxSigned['complete'], True) self.nodes[2].sendrawtransaction(rawTxSigned['hex']) rawTx = self.nodes[0].decoderawtransaction(rawTxSigned['hex']) self.sync_all() diff --git a/qa/rpc-tests/smartfees.py b/qa/rpc-tests/smartfees.py --- a/qa/rpc-tests/smartfees.py +++ b/qa/rpc-tests/smartfees.py @@ -88,7 +88,7 @@ # If this is the initial split we actually need to sign the transaction # Otherwise we just need to insert the property ScriptSig if (initial_split) : - completetx = from_node.signrawtransaction(rawtx)["hex"] + completetx = from_node.signrawtransaction(rawtx, None, None, "ALL")["hex"] else : completetx = rawtx[0:82] + SCRIPT_SIG[prevtxout["vout"]] + rawtx[84:] txid = from_node.sendrawtransaction(completetx, True) diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -502,7 +502,7 @@ outputs[self_address] = float(amount+fee) self_rawtx = from_node.createrawtransaction(inputs, outputs) - self_signresult = from_node.signrawtransaction(self_rawtx) + self_signresult = from_node.signrawtransaction(self_rawtx, None, None, "ALL") self_txid = from_node.sendrawtransaction(self_signresult["hex"], True) vout = find_output(from_node, self_txid, amount+fee) @@ -512,7 +512,7 @@ outputs = { to_node.getnewaddress() : float(amount) } rawtx = from_node.createrawtransaction(inputs, outputs) - signresult = from_node.signrawtransaction(rawtx) + signresult = from_node.signrawtransaction(rawtx, None, None, "ALL") txid = from_node.sendrawtransaction(signresult["hex"], True) return (txid, signresult["hex"]) @@ -542,7 +542,7 @@ outputs[to_node.getnewaddress()] = float(amount) rawtx = from_node.createrawtransaction(inputs, outputs) - signresult = from_node.signrawtransaction(rawtx) + signresult = from_node.signrawtransaction(rawtx, None, None, "ALL") txid = from_node.sendrawtransaction(signresult["hex"], True) return (txid, signresult["hex"], fee) @@ -679,7 +679,7 @@ outputs[addr1] = satoshi_round(send_value/2) outputs[addr2] = satoshi_round(send_value/2) raw_tx = node.createrawtransaction(inputs, outputs) - signed_tx = node.signrawtransaction(raw_tx)["hex"] + signed_tx = node.signrawtransaction(raw_tx, None, None, "ALL")["hex"] txid = node.sendrawtransaction(signed_tx) while (node.getmempoolinfo()['size'] > 0): @@ -713,7 +713,7 @@ inputs = [{ "txid" : coinbase, "vout" : 0}] outputs = { to_address : amount } rawtx = node.createrawtransaction(inputs, outputs) - signresult = node.signrawtransaction(rawtx) + signresult = node.signrawtransaction(rawtx, None, None, "ALL") assert_equal(signresult["complete"], True) return signresult["hex"] diff --git a/qa/rpc-tests/txn_clone.py b/qa/rpc-tests/txn_clone.py --- a/qa/rpc-tests/txn_clone.py +++ b/qa/rpc-tests/txn_clone.py @@ -30,7 +30,8 @@ starting_balance = 1250 for i in range(4): assert_equal(self.nodes[i].getbalance(), starting_balance) - self.nodes[i].getnewaddress("") # bug workaround, coins generated assigned to first getnewaddress! + # bug workaround, coins generated assigned to first getnewaddress! + self.nodes[i].getnewaddress("") # Assign coins to foo and bar accounts: self.nodes[0].settxfee(.001) @@ -73,7 +74,7 @@ output1 = clone_raw[pos0 + output_len : pos0 + 2 * output_len] clone_raw = clone_raw[:pos0] + output1 + output0 + clone_raw[pos0 + 2 * output_len:] - # Use a different signature hash type to sign. This creates an equivalent but malleated clone. + # Use a different signature hash type to sign. This creates an equivalent but malleated clone. # Don't send the clone anywhere yet tx1_clone = self.nodes[0].signrawtransaction(clone_raw, None, None, "ALL|ANYONECANPAY") assert_equal(tx1_clone["complete"], True) diff --git a/qa/rpc-tests/txn_doublespend.py b/qa/rpc-tests/txn_doublespend.py --- a/qa/rpc-tests/txn_doublespend.py +++ b/qa/rpc-tests/txn_doublespend.py @@ -62,7 +62,7 @@ outputs[node1_address] = 1240 outputs[change_address] = 1248 - 1240 + doublespend_fee rawtx = self.nodes[0].createrawtransaction(inputs, outputs) - doublespend = self.nodes[0].signrawtransaction(rawtx) + doublespend = self.nodes[0].signrawtransaction(rawtx, None, None, "ALL") assert_equal(doublespend["complete"], True) # Create two spends using 1 50 BTC coin each diff --git a/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py --- a/qa/rpc-tests/wallet.py +++ b/qa/rpc-tests/wallet.py @@ -99,7 +99,7 @@ inputs.append({ "txid" : utxo["txid"], "vout" : utxo["vout"]}) outputs[self.nodes[2].getnewaddress("from1")] = utxo["amount"] - 3 raw_tx = self.nodes[0].createrawtransaction(inputs, outputs) - txns_to_send.append(self.nodes[0].signrawtransaction(raw_tx)) + txns_to_send.append(self.nodes[0].signrawtransaction(raw_tx, None, None, "ALL")) # Have node 1 (miner) send the transactions self.nodes[1].sendrawtransaction(txns_to_send[0]["hex"], True) @@ -180,7 +180,7 @@ rawTx = self.nodes[1].createrawtransaction(inputs, outputs).replace("c0833842", "00000000") #replace 11.11 with 0.0 (int32) decRawTx = self.nodes[1].decoderawtransaction(rawTx) - signedRawTx = self.nodes[1].signrawtransaction(rawTx) + signedRawTx = self.nodes[1].signrawtransaction(rawTx, None, None, "ALL") decRawTx = self.nodes[1].decoderawtransaction(signedRawTx['hex']) zeroValueTxid= decRawTx['txid'] sendResp = self.nodes[1].sendrawtransaction(signedRawTx['hex']) @@ -357,7 +357,7 @@ node0_balance = self.nodes[0].getbalance() # Split into two chains rawtx = self.nodes[0].createrawtransaction([{"txid":singletxid, "vout":0}], {chain_addrs[0]:node0_balance/2-Decimal('0.01'), chain_addrs[1]:node0_balance/2-Decimal('0.01')}) - signedtx = self.nodes[0].signrawtransaction(rawtx) + signedtx = self.nodes[0].signrawtransaction(rawtx, None, None, "ALL") singletxid = self.nodes[0].sendrawtransaction(signedtx["hex"]) self.nodes[0].generate(1) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -773,6 +773,12 @@ " \"ALL|ANYONECANPAY\"\n" " \"NONE|ANYONECANPAY\"\n" " \"SINGLE|ANYONECANPAY\"\n" + " \"ALL|FORKID\"\n" + " \"NONE|FORKID\"\n" + " \"SINGLE|FORKID\"\n" + " \"ALL|FORKID|ANYONECANPAY\"\n" + " \"NONE|FORKID|ANYONECANPAY\"\n" + " \"SINGLE|FORKID|ANYONECANPAY\"\n" "\nResult:\n" "{\n" @@ -967,18 +973,28 @@ const CKeyStore &keystore = tempKeystore; #endif - int nHashType = SIGHASH_ALL; + int nHashType = SIGHASH_ALL | SIGHASH_FORKID; if (request.params.size() > 3 && !request.params[3].isNull()) { static std::map mapSigHashValues = boost::assign::map_list_of(std::string("ALL"), int(SIGHASH_ALL))( std::string("ALL|ANYONECANPAY"), - int(SIGHASH_ALL | SIGHASH_ANYONECANPAY))(std::string("NONE"), - int(SIGHASH_NONE))( - std::string("NONE|ANYONECANPAY"), - int(SIGHASH_NONE | SIGHASH_ANYONECANPAY))(std::string("SINGLE"), - int(SIGHASH_SINGLE))( + int(SIGHASH_ALL | SIGHASH_ANYONECANPAY))( + std::string("ALL|FORKID"), int(SIGHASH_ALL | SIGHASH_FORKID))( + std::string("ALL|FORKID|ANYONECANPAY"), + int(SIGHASH_ALL | SIGHASH_FORKID | SIGHASH_ANYONECANPAY))( + std::string("NONE"), + int(SIGHASH_NONE))(std::string("NONE|ANYONECANPAY"), + int(SIGHASH_NONE | SIGHASH_ANYONECANPAY))( + std::string("NONE|FORKID"), int(SIGHASH_NONE | SIGHASH_FORKID))( + std::string("NONE|FORKID|ANYONECANPAY"), + int(SIGHASH_NONE | SIGHASH_FORKID | SIGHASH_ANYONECANPAY))( + std::string("SINGLE"), int(SIGHASH_SINGLE))( std::string("SINGLE|ANYONECANPAY"), - int(SIGHASH_SINGLE | SIGHASH_ANYONECANPAY)); + int(SIGHASH_SINGLE | SIGHASH_ANYONECANPAY))( + std::string("SINGLE|FORKID"), + int(SIGHASH_SINGLE | SIGHASH_FORKID))( + std::string("SINGLE|FORKID|ANYONECANPAY"), + int(SIGHASH_SINGLE | SIGHASH_FORKID | SIGHASH_ANYONECANPAY)); std::string strHashType = request.params[3].get_str(); if (!mapSigHashValues.count(strHashType)) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid sighash param"); @@ -987,7 +1003,9 @@ nHashType = mapSigHashValues[strHashType]; } - bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE); + bool fHashSingle = + ((nHashType & ~(SIGHASH_ANYONECANPAY | SIGHASH_FORKID)) == + SIGHASH_SINGLE); // Script verification errors. UniValue vErrors(UniValue::VARR); @@ -996,7 +1014,7 @@ // rehashing. const CTransaction txConst(mergedTx); // Sign what we can: - for (unsigned int i = 0; i < mergedTx.vin.size(); i++) { + for (size_t i = 0; i < mergedTx.vin.size(); i++) { CTxIn &txin = mergedTx.vin[i]; const CCoins *coins = view.AccessCoins(txin.prevout.hash); if (coins == nullptr || !coins->IsAvailable(txin.prevout.n)) { @@ -1029,11 +1047,13 @@ ScriptError serror = SCRIPT_ERR_OK; if (!VerifyScript( - txin.scriptSig, prevPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, + txin.scriptSig, prevPubKey, + STANDARD_SCRIPT_VERIFY_FLAGS | SCRIPT_ENABLE_SIGHASH_FORKID, TransactionSignatureChecker(&txConst, i, amount), &serror)) { TxInErrorToJSON(txin, vErrors, ScriptErrorString(serror)); } } + bool fComplete = vErrors.empty(); UniValue result(UniValue::VOBJ); diff --git a/src/script/sign.cpp b/src/script/sign.cpp --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -145,9 +145,10 @@ sigdata.scriptSig = PushAll(result); // Test solution - return solved && - VerifyScript(sigdata.scriptSig, fromPubKey, - STANDARD_SCRIPT_VERIFY_FLAGS, creator.Checker()); + return solved && VerifyScript(sigdata.scriptSig, fromPubKey, + STANDARD_SCRIPT_VERIFY_FLAGS | + SCRIPT_ENABLE_SIGHASH_FORKID, + creator.Checker()); } SignatureData DataFromTransaction(const CMutableTransaction &tx,