aboutsummaryrefslogtreecommitdiff
path: root/src/bitcoinrpc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bitcoinrpc.cpp')
-rw-r--r--src/bitcoinrpc.cpp126
1 files changed, 53 insertions, 73 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index b32ca9f15d..24fa97588c 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -115,6 +115,21 @@ HexBits(unsigned int nBits)
return HexStr(BEGIN(uBits.cBits), END(uBits.cBits));
}
+static std::string
+HelpRequiringPassphrase()
+{
+ return pwalletMain->IsCrypted()
+ ? "\nrequires wallet passphrase to be set with walletpassphrase first"
+ : "";
+}
+
+static inline void
+EnsureWalletIsUnlocked()
+{
+ if (pwalletMain->IsLocked())
+ throw JSONRPCError(-13, "Error: Please enter the wallet passphrase with walletpassphrase first.");
+}
+
enum DecomposeMode {
DM_NONE = 0,
DM_HASH,
@@ -371,10 +386,7 @@ string CRPCTable::help(string strCommand) const
const CRPCCommand *pcmd = mi->second;
string strMethod = mi->first;
// We already filter duplicates, but these deprecated screw up the sort order
- if (strMethod == "getamountreceived" ||
- strMethod == "getallreceived" ||
- strMethod == "getblocknumber" || // deprecated
- (strMethod.find("label") != string::npos))
+ if (strMethod.find("label") != string::npos)
continue;
if (strCommand != "" && strMethod != strCommand)
continue;
@@ -421,10 +433,10 @@ Value stop(const Array& params, bool fHelp)
if (fHelp || params.size() != 0)
throw runtime_error(
"stop\n"
- "Stop bitcoin server.");
+ "Stop Bitcoin server.");
// Shutdown will take long enough that the response should get back
- QueueShutdown();
- return "bitcoin server stopping";
+ uiInterface.QueueShutdown();
+ return "Bitcoin server stopping";
}
@@ -439,18 +451,6 @@ Value getblockcount(const Array& params, bool fHelp)
}
-// deprecated
-Value getblocknumber(const Array& params, bool fHelp)
-{
- if (fHelp || params.size() != 0)
- throw runtime_error(
- "getblocknumber\n"
- "Deprecated. Use getblockcount.");
-
- return nBestHeight;
-}
-
-
Value getconnectioncount(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
@@ -577,7 +577,7 @@ Value getnewaddress(const Array& params, bool fHelp)
if (fHelp || params.size() > 1)
throw runtime_error(
"getnewaddress [account]\n"
- "Returns a new bitcoin address for receiving payments. "
+ "Returns a new Bitcoin address for receiving payments. "
"If [account] is specified (recommended), it is added to the address book "
"so payments received with the address will be credited to [account].");
@@ -644,7 +644,7 @@ Value getaccountaddress(const Array& params, bool fHelp)
if (fHelp || params.size() != 1)
throw runtime_error(
"getaccountaddress <account>\n"
- "Returns the current bitcoin address for receiving payments to this account.");
+ "Returns the current Bitcoin address for receiving payments to this account.");
// Parse the account first so we don't generate a key if there's an error
string strAccount = AccountFromValue(params[0]);
@@ -667,7 +667,7 @@ Value setaccount(const Array& params, bool fHelp)
CBitcoinAddress address(params[0].get_str());
if (!address.IsValid())
- throw JSONRPCError(-5, "Invalid bitcoin address");
+ throw JSONRPCError(-5, "Invalid Bitcoin address");
string strAccount;
@@ -697,7 +697,7 @@ Value getaccount(const Array& params, bool fHelp)
CBitcoinAddress address(params[0].get_str());
if (!address.IsValid())
- throw JSONRPCError(-5, "Invalid bitcoin address");
+ throw JSONRPCError(-5, "Invalid Bitcoin address");
string strAccount;
map<CBitcoinAddress, string>::iterator mi = pwalletMain->mapAddressBook.find(address);
@@ -746,19 +746,15 @@ Value settxfee(const Array& params, bool fHelp)
Value sendtoaddress(const Array& params, bool fHelp)
{
- if (pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 4))
- throw runtime_error(
- "sendtoaddress <bitcoinaddress> <amount> [comment] [comment-to]\n"
- "<amount> is a real and is rounded to the nearest 0.00000001\n"
- "requires wallet passphrase to be set with walletpassphrase first");
- if (!pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 4))
+ if (fHelp || params.size() < 2 || params.size() > 4)
throw runtime_error(
"sendtoaddress <bitcoinaddress> <amount> [comment] [comment-to]\n"
- "<amount> is a real and is rounded to the nearest 0.00000001");
+ "<amount> is a real and is rounded to the nearest 0.00000001"
+ + HelpRequiringPassphrase());
CBitcoinAddress address(params[0].get_str());
if (!address.IsValid())
- throw JSONRPCError(-5, "Invalid bitcoin address");
+ throw JSONRPCError(-5, "Invalid Bitcoin address");
// Amount
int64 nAmount = AmountFromValue(params[1]);
@@ -787,8 +783,7 @@ Value signmessage(const Array& params, bool fHelp)
"signmessage <bitcoinaddress> <message>\n"
"Sign a message with the private key of an address");
- if (pwalletMain->IsLocked())
- throw JSONRPCError(-13, "Error: Please enter the wallet passphrase with walletpassphrase first.");
+ EnsureWalletIsUnlocked();
string strAddress = params[0].get_str();
string strMessage = params[1].get_str();
@@ -856,7 +851,7 @@ Value getreceivedbyaddress(const Array& params, bool fHelp)
CBitcoinAddress address = CBitcoinAddress(params[0].get_str());
CScript scriptPubKey;
if (!address.IsValid())
- throw JSONRPCError(-5, "Invalid bitcoin address");
+ throw JSONRPCError(-5, "Invalid Bitcoin address");
scriptPubKey.SetBitcoinAddress(address);
if (!IsMine(*pwalletMain,scriptPubKey))
return (double)0.0;
@@ -1069,20 +1064,16 @@ Value movecmd(const Array& params, bool fHelp)
Value sendfrom(const Array& params, bool fHelp)
{
- if (pwalletMain->IsCrypted() && (fHelp || params.size() < 3 || params.size() > 6))
+ if (fHelp || params.size() < 3 || params.size() > 6)
throw runtime_error(
"sendfrom <fromaccount> <tobitcoinaddress> <amount> [minconf=1] [comment] [comment-to]\n"
- "<amount> is a real and is rounded to the nearest 0.00000001\n"
- "requires wallet passphrase to be set with walletpassphrase first");
- if (!pwalletMain->IsCrypted() && (fHelp || params.size() < 3 || params.size() > 6))
- throw runtime_error(
- "sendfrom <fromaccount> <tobitcoinaddress> <amount> [minconf=1] [comment] [comment-to]\n"
- "<amount> is a real and is rounded to the nearest 0.00000001");
+ "<amount> is a real and is rounded to the nearest 0.00000001"
+ + HelpRequiringPassphrase());
string strAccount = AccountFromValue(params[0]);
CBitcoinAddress address(params[1].get_str());
if (!address.IsValid())
- throw JSONRPCError(-5, "Invalid bitcoin address");
+ throw JSONRPCError(-5, "Invalid Bitcoin address");
int64 nAmount = AmountFromValue(params[2]);
int nMinDepth = 1;
if (params.size() > 3)
@@ -1095,8 +1086,7 @@ Value sendfrom(const Array& params, bool fHelp)
if (params.size() > 5 && params[5].type() != null_type && !params[5].get_str().empty())
wtx.mapValue["to"] = params[5].get_str();
- if (pwalletMain->IsLocked())
- throw JSONRPCError(-13, "Error: Please enter the wallet passphrase with walletpassphrase first.");
+ EnsureWalletIsUnlocked();
// Check funds
int64 nBalance = GetAccountBalance(strAccount, nMinDepth);
@@ -1114,15 +1104,11 @@ Value sendfrom(const Array& params, bool fHelp)
Value sendmany(const Array& params, bool fHelp)
{
- if (pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 4))
+ if (fHelp || params.size() < 2 || params.size() > 4)
throw runtime_error(
"sendmany <fromaccount> {address:amount,...} [minconf=1] [comment]\n"
- "amounts are double-precision floating point numbers\n"
- "requires wallet passphrase to be set with walletpassphrase first");
- if (!pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 4))
- throw runtime_error(
- "sendmany <fromaccount> {address:amount,...} [minconf=1] [comment]\n"
- "amounts are double-precision floating point numbers");
+ "amounts are double-precision floating point numbers"
+ + HelpRequiringPassphrase());
string strAccount = AccountFromValue(params[0]);
Object sendTo = params[1].get_obj();
@@ -1143,7 +1129,7 @@ Value sendmany(const Array& params, bool fHelp)
{
CBitcoinAddress address(s.name_);
if (!address.IsValid())
- throw JSONRPCError(-5, string("Invalid bitcoin address:")+s.name_);
+ throw JSONRPCError(-5, string("Invalid Bitcoin address:")+s.name_);
if (setAddress.count(address))
throw JSONRPCError(-8, string("Invalid parameter, duplicated address: ")+s.name_);
@@ -1157,8 +1143,7 @@ Value sendmany(const Array& params, bool fHelp)
vecSend.push_back(make_pair(scriptPubKey, nAmount));
}
- if (pwalletMain->IsLocked())
- throw JSONRPCError(-13, "Error: Please enter the wallet passphrase with walletpassphrase first.");
+ EnsureWalletIsUnlocked();
// Check funds
int64 nBalance = GetAccountBalance(strAccount, nMinDepth);
@@ -1187,7 +1172,7 @@ Value addmultisigaddress(const Array& params, bool fHelp)
{
string msg = "addmultisigaddress <nrequired> <'[\"key\",\"key\"]'> [account]\n"
"Add a nrequired-to-sign multisignature address to the wallet\"\n"
- "each key is a bitcoin address or hex-encoded public key\n"
+ "each key is a Bitcoin address or hex-encoded public key\n"
"If [account] is specified, assign address to [account].";
throw runtime_error(msg);
}
@@ -1211,7 +1196,7 @@ Value addmultisigaddress(const Array& params, bool fHelp)
{
const std::string& ks = keys[i].get_str();
- // Case 1: bitcoin address and we have full public key:
+ // Case 1: Bitcoin address and we have full public key:
CBitcoinAddress address(ks);
if (address.IsValid())
{
@@ -1757,17 +1742,13 @@ Value backupwallet(const Array& params, bool fHelp)
Value keypoolrefill(const Array& params, bool fHelp)
{
- if (pwalletMain->IsCrypted() && (fHelp || params.size() > 0))
+ if (fHelp || params.size() > 0)
throw runtime_error(
"keypoolrefill\n"
- "Fills the keypool, requires wallet passphrase to be set.");
- if (!pwalletMain->IsCrypted() && (fHelp || params.size() > 0))
- throw runtime_error(
- "keypoolrefill\n"
- "Fills the keypool.");
+ "Fills the keypool."
+ + HelpRequiringPassphrase());
- if (pwalletMain->IsLocked())
- throw JSONRPCError(-13, "Error: Please enter the wallet passphrase with walletpassphrase first.");
+ EnsureWalletIsUnlocked();
pwalletMain->TopUpKeyPool();
@@ -1947,8 +1928,8 @@ Value encryptwallet(const Array& params, bool fHelp)
// BDB seems to have a bad habit of writing old data into
// slack space in .dat files; that is bad if the old data is
// unencrypted private keys. So:
- QueueShutdown();
- return "wallet encrypted; bitcoin server stopping, restart to run with encrypted wallet";
+ uiInterface.QueueShutdown();
+ return "wallet encrypted; Bitcoin server stopping, restart to run with encrypted wallet";
}
@@ -2257,7 +2238,6 @@ static const CRPCCommand vRPCCommands[] =
{ "help", &help, true },
{ "stop", &stop, true },
{ "getblockcount", &getblockcount, true },
- { "getblocknumber", &getblocknumber, true },
{ "getconnectioncount", &getconnectioncount, true },
{ "getdifficulty", &getdifficulty, true },
{ "getgenerate", &getgenerate, true },
@@ -2640,7 +2620,7 @@ void ThreadRPCServer2(void* parg)
strWhatAmI = strprintf(_("To use the %s option"), "\"-server\"");
else if (mapArgs.count("-daemon"))
strWhatAmI = strprintf(_("To use the %s option"), "\"-daemon\"");
- ThreadSafeMessageBox(strprintf(
+ uiInterface.ThreadSafeMessageBox(strprintf(
_("%s, you must set a rpcpassword in the configuration file:\n %s\n"
"It is recommended you use the following random password:\n"
"rpcuser=bitcoinrpc\n"
@@ -2650,8 +2630,8 @@ void ThreadRPCServer2(void* parg)
strWhatAmI.c_str(),
GetConfigFile().string().c_str(),
EncodeBase58(&rand_pwd[0],&rand_pwd[0]+32).c_str()),
- _("Error"), wxOK | wxMODAL);
- QueueShutdown();
+ _("Error"), CClientUIInterface::OK | CClientUIInterface::MODAL);
+ uiInterface.QueueShutdown();
return;
}
@@ -2670,9 +2650,9 @@ void ThreadRPCServer2(void* parg)
}
catch(boost::system::system_error &e)
{
- ThreadSafeMessageBox(strprintf(_("An error occured while setting up the RPC port %i for listening: %s"), endpoint.port(), e.what()),
- _("Error"), wxOK | wxMODAL);
- QueueShutdown();
+ uiInterface.ThreadSafeMessageBox(strprintf(_("An error occured while setting up the RPC port %i for listening: %s"), endpoint.port(), e.what()),
+ _("Error"), CClientUIInterface::OK | CClientUIInterface::MODAL);
+ uiInterface.QueueShutdown();
return;
}