diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -1214,6 +1214,7 @@ // Make a JSONRPCRequest to pass on to the right signrawtransaction* command JSONRPCRequest new_request; new_request.id = request.id; + new_request.URI = std::move(request.URI); new_request.params.setArray(); // For signing with private keys diff --git a/test/functional/rpc_signrawtransaction.py b/test/functional/rpc_signrawtransaction.py --- a/test/functional/rpc_signrawtransaction.py +++ b/test/functional/rpc_signrawtransaction.py @@ -7,12 +7,17 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_raises_rpc_error +RPC_WALLET_NOT_SPECIFIED = "Wallet file not specified (must request wallet " + \ + "RPC through /wallet/ uri-path)." + class SignRawTransactionsTest(BitcoinTestFramework): def set_test_params(self): self.setup_clean_chain = True - self.num_nodes = 1 - self.extra_args = [["-deprecatedrpc=signrawtransaction"]] + self.num_nodes = 2 + self.extra_args = [["-deprecatedrpc=signrawtransaction"], + ["-deprecatedrpc=signrawtransaction", "-wallet=w1", + "-wallet=w2"]] def successful_signing_test(self): """Creates and signs a valid raw transaction with one input. @@ -193,10 +198,58 @@ self.nodes[0].signrawtransactionwithkey, rawTx, privKeys, inputs, sighash) + def multiwallet_signing_test(self): + """Creates and signs a raw transaction with a multiwallet node. + + Expected results: + + 1) The transaction is not signed if no wallet is specified + 2) The transaction is signed if the correct wallet URI is given""" + inputs = [ + # Valid pay-to-pubkey scripts + {'txid': '9b907ef1e3c26fc71fe4a4b3580bc75264112f95050014157059c736f0202e71', + 'vout': 0, 'amount': 3.14159, + 'scriptPubKey': '76a91460baa0f494b38ce3c940dea67f3804dc52d1fb9488ac'}, + ] + + outputs = {'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB': 0.1} + + multiwallet_node = self.nodes[1] + + rawTx = multiwallet_node.createrawtransaction(inputs, outputs) + + # The multiwallet node cannot sign the transaction if no wallet is + # specified + assert_raises_rpc_error(-19, RPC_WALLET_NOT_SPECIFIED, + multiwallet_node.signrawtransactionwithwallet, + rawTx) + + # The multiwallet node can sign the transaction using w1 + w1 = multiwallet_node.get_wallet_rpc('w1') + w1.generate(101) + + utxo = w1.listunspent()[0] + inputs = [{ + 'txid': utxo['txid'], + 'vout': utxo['vout'], + }] + + rawTx_w1 = w1.createrawtransaction(inputs, outputs) + + rawTxSigned_w1 = w1.signrawtransactionwithwallet(rawTx_w1) + assert rawTxSigned_w1['complete'] + assert 'errors' not in rawTxSigned_w1 + + # Perform the same test on signrawtransaction + rawTxSigned_w1 = w1.signrawtransaction(rawTx_w1) + assert rawTxSigned_w1['complete'] + assert 'errors' not in rawTxSigned_w1 + def run_test(self): self.successful_signing_test() self.script_verification_error_test() self.test_sighashes() + self.multiwallet_signing_test() if __name__ == '__main__':