Skip to content

Commit 1e79c05

Browse files
committed
Split signrawtransaction into wallet and non-wallet
Splits signrwatransaction into a wallet version (signrawtransactionwithwallet) and non-wallet version (signrawtransactionwithkey). signrawtransaction is marked as DEPRECATED and will call the right signrawtransaction* command as per the parameters in order to maintain compatibility. Updated signrawtransactions test to use new RPCs
1 parent 8a98dfe commit 1e79c05

File tree

12 files changed

+380
-214
lines changed

12 files changed

+380
-214
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ BITCOIN_CORE_H = \
132132
rpc/protocol.h \
133133
rpc/safemode.h \
134134
rpc/server.h \
135+
rpc/rawtransaction.h \
135136
rpc/register.h \
136137
rpc/util.h \
137138
scheduler.h \

src/qt/rpcconsole.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const QStringList historyFilter = QStringList()
7070
<< "importmulti"
7171
<< "signmessagewithprivkey"
7272
<< "signrawtransaction"
73+
<< "signrawtransactionwithkey"
7374
<< "walletpassphrase"
7475
<< "walletpassphrasechange"
7576
<< "encryptwallet";
@@ -624,7 +625,7 @@ void RPCConsole::setClientModel(ClientModel *model)
624625
connect(model->getPeerTableModel(), SIGNAL(layoutChanged()), this, SLOT(peerLayoutChanged()));
625626
// peer table signal handling - cache selected node ids
626627
connect(model->getPeerTableModel(), SIGNAL(layoutAboutToBeChanged()), this, SLOT(peerLayoutAboutToChange()));
627-
628+
628629
// set up ban table
629630
ui->banlistWidget->setModel(model->getBanTableModel());
630631
ui->banlistWidget->verticalHeader()->hide();
@@ -772,7 +773,7 @@ void RPCConsole::clear(bool clearHistory)
772773
#else
773774
QString clsKey = "Ctrl-L";
774775
#endif
775-
776+
776777
message(CMD_REPLY, (tr("Welcome to the %1 RPC console.").arg(tr(PACKAGE_NAME)) + "<br>" +
777778
tr("Use up and down arrows to navigate history, and %1 to clear screen.").arg("<b>"+clsKey+"</b>") + "<br>" +
778779
tr("Type %1 for an overview of available commands.").arg("<b>help</b>") + "<br>" +
@@ -1144,7 +1145,7 @@ void RPCConsole::disconnectSelectedNode()
11441145
{
11451146
if(!g_connman)
11461147
return;
1147-
1148+
11481149
// Get selected peer addresses
11491150
QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId);
11501151
for(int i = 0; i < nodes.count(); i++)
@@ -1161,7 +1162,7 @@ void RPCConsole::banSelectedNode(int bantime)
11611162
{
11621163
if (!clientModel || !g_connman)
11631164
return;
1164-
1165+
11651166
// Get selected peer addresses
11661167
QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId);
11671168
for(int i = 0; i < nodes.count(); i++)

src/qt/test/rpcnestedtests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ void RPCNestedTests::rpcNestedTests()
8282
QVERIFY(filtered == "signmessagewithprivkey(…)");
8383
RPCConsole::RPCParseCommandLine(result, "signmessagewithprivkey abc,def", false, &filtered);
8484
QVERIFY(filtered == "signmessagewithprivkey(…)");
85-
RPCConsole::RPCParseCommandLine(result, "signrawtransaction(abc)", false, &filtered);
86-
QVERIFY(filtered == "signrawtransaction(…)");
85+
RPCConsole::RPCParseCommandLine(result, "signrawtransactionwithkey(abc)", false, &filtered);
86+
QVERIFY(filtered == "signrawtransactionwithkey(…)");
8787
RPCConsole::RPCParseCommandLine(result, "walletpassphrase(help())", false, &filtered);
8888
QVERIFY(filtered == "walletpassphrase(…)");
8989
RPCConsole::RPCParseCommandLine(result, "walletpassphrasechange(help(walletpassphrasechange(abc)))", false, &filtered);

src/rpc/client.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ static const CRPCConvertParam vRPCConvertParams[] =
9494
{ "decoderawtransaction", 1, "iswitness" },
9595
{ "signrawtransaction", 1, "prevtxs" },
9696
{ "signrawtransaction", 2, "privkeys" },
97+
{ "signrawtransactionwithkey", 1, "privkeys" },
98+
{ "signrawtransactionwithkey", 2, "prevtxs" },
99+
{ "signrawtransactionwithwallet", 1, "prevtxs" },
97100
{ "sendrawtransaction", 1, "allowhighfees" },
98101
{ "combinerawtransaction", 0, "txs" },
99102
{ "fundrawtransaction", 1, "options" },

src/rpc/rawtransaction.cpp

Lines changed: 217 additions & 134 deletions
Large diffs are not rendered by default.

src/rpc/rawtransaction.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2017 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_RPC_RAWTRANSACTION_H
6+
#define BITCOIN_RPC_RAWTRANSACTION_H
7+
8+
class CBasicKeyStore;
9+
class CMutableTransaction;
10+
class UniValue;
11+
12+
/** Sign a transaction with the given keystore and previous transactions */
13+
UniValue SignTransaction(CMutableTransaction& mtx, const UniValue& prevTxs, CBasicKeyStore *keystore, bool tempKeystore, const UniValue& hashType);
14+
15+
#endif // BITCOIN_RPC_RAWTRANSACTION_H

src/test/rpc_tests.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,6 @@ BOOST_AUTO_TEST_CASE(rpc_rawparams)
6969
BOOST_CHECK_NO_THROW(r = CallRPC(std::string("decoderawtransaction ")+rawtx+" false"));
7070
BOOST_CHECK_THROW(r = CallRPC(std::string("decoderawtransaction ")+rawtx+" false extra"), std::runtime_error);
7171

72-
BOOST_CHECK_THROW(CallRPC("signrawtransaction"), std::runtime_error);
73-
BOOST_CHECK_THROW(CallRPC("signrawtransaction null"), std::runtime_error);
74-
BOOST_CHECK_THROW(CallRPC("signrawtransaction ff00"), std::runtime_error);
75-
BOOST_CHECK_NO_THROW(CallRPC(std::string("signrawtransaction ")+rawtx));
76-
BOOST_CHECK_NO_THROW(CallRPC(std::string("signrawtransaction ")+rawtx+" null null NONE|ANYONECANPAY"));
77-
BOOST_CHECK_NO_THROW(CallRPC(std::string("signrawtransaction ")+rawtx+" [] [] NONE|ANYONECANPAY"));
78-
BOOST_CHECK_THROW(CallRPC(std::string("signrawtransaction ")+rawtx+" null null badenum"), std::runtime_error);
79-
8072
// Only check failure cases for sendrawtransaction, there's no network to send to...
8173
BOOST_CHECK_THROW(CallRPC("sendrawtransaction"), std::runtime_error);
8274
BOOST_CHECK_THROW(CallRPC("sendrawtransaction null"), std::runtime_error);
@@ -119,9 +111,9 @@ BOOST_AUTO_TEST_CASE(rpc_rawsign)
119111
std::string notsigned = r.get_str();
120112
std::string privkey1 = "\"KzsXybp9jX64P5ekX1KUxRQ79Jht9uzW7LorgwE65i5rWACL6LQe\"";
121113
std::string privkey2 = "\"Kyhdf5LuKTRx4ge69ybABsiUAWjVRK4XGxAKk2FQLp2HjGMy87Z4\"";
122-
r = CallRPC(std::string("signrawtransaction ")+notsigned+" "+prevout+" "+"[]");
114+
r = CallRPC(std::string("signrawtransactionwithkey ")+notsigned+" [] "+prevout);
123115
BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == false);
124-
r = CallRPC(std::string("signrawtransaction ")+notsigned+" "+prevout+" "+"["+privkey1+","+privkey2+"]");
116+
r = CallRPC(std::string("signrawtransactionwithkey ")+notsigned+" ["+privkey1+","+privkey2+"] "+prevout);
125117
BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == true);
126118
}
127119

0 commit comments

Comments
 (0)