Skip to content

Loading…

Normalize wallet RPC commands (refillkeypool, unlockwallet, lockwallet, setpassphrase) #1983

Closed
wants to merge 1 commit into from

6 participants

@kjj2

Updates 4 odd RPC commands to match other RPC commands which tend to follow a naming scheme.

The old names still work as aliases of the new names, but don't show up in the help lists.

See: https://bitcointalk.org/index.php?topic=122345.0

@jgarzik
Bitcoin member

I like the old, deprecated names much better than the new ones ;p

@Diapolo

IMHO, we should define, what deprecated means in that case and when it is considered safe to remove old naming conventions :). Perhaps add a date or version, when this is the case.

@gavinandresen
Bitcoin member

ENOCARE/ACK.

(I don't really care, changes looks fine).

@laanwj
Bitcoin member

Have we really arrived at the point that we deprecate commands (and thus break backwards compatibility) for aesthetic reasons?

This means we'll end up with duplicate commands for a long time, make it harder for people to google the commands. And communicating this to users is another problem, as we don't have an official API documentation to say "this will be deprecated in version XXX".

It's not worth the trouble.

@Diapolo

I just wanted to ask :), your points indeed are clear and valid! As this pull renames without removing the old names that problem doesn't rise.

@sipa
Bitcoin member

I think the only RPC makeover worth doing is a much more fundamental one, where we normalize commands, separate them clearly into modules (as already reflected in the source code... but who would now guess that gettransaction is a wallet RPC, and getrawtransaction a blockchain one?), normalize the data types used (amount as strings/satoshis/floats, difficulty as targethash/hexbits/float), perhaps add support for multiple wallets, make the error codes consistent, ...

That is much more work though, and probably means some RPC v2 mechanism like was already proposed before. About this... -ENOCARE

@gavinandresen
Bitcoin member

@laanwj : "setaccount" used to be called "setlabel", so there is a precedent for breaking compatibility (after maintaing the old names for a while) just for aesthetic reasons.

@jgarzik
Bitcoin member

Consensus seems to be "don't care / meh / not worth the trouble"... closing.

Perhaps put this on a list for a bigger RPC revamp, or right before RPC is locked in stone for version 1.0 (whenever that is).

@jgarzik jgarzik closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 5, 2012
  1. Normalize wallet RPC commands (refillkeypool, unlockwallet, lockwalle…

    kjj2 committed
    …t, setpassphrase)
Showing with 31 additions and 27 deletions.
  1. +8 −4 src/bitcoinrpc.cpp
  2. +4 −4 src/bitcoinrpc.h
  3. +19 −19 src/rpcwallet.cpp
View
12 src/bitcoinrpc.cpp
@@ -223,10 +223,14 @@ static const CRPCCommand vRPCCommands[] =
{ "listreceivedbyaddress", &listreceivedbyaddress, false, false },
{ "listreceivedbyaccount", &listreceivedbyaccount, false, false },
{ "backupwallet", &backupwallet, true, false },
- { "keypoolrefill", &keypoolrefill, true, false },
- { "walletpassphrase", &walletpassphrase, true, false },
- { "walletpassphrasechange", &walletpassphrasechange, false, false },
- { "walletlock", &walletlock, true, false },
+ { "keypoolrefill", &refillkeypool, true, false }, // deprecated
+ { "refillkeypool", &refillkeypool, true, false },
+ { "walletpassphrase", &unlockwallet, true, false }, // deprecated
+ { "unlockwallet", &unlockwallet, true, false },
+ { "walletpassphrasechange", &setpassphrase, false, false }, // deprecated
+ { "setpassphrase", &setpassphrase, false, false },
+ { "walletlock", &lockwallet, true, false }, // deprecated
+ { "lockwallet", &lockwallet, true, false },
{ "encryptwallet", &encryptwallet, false, false },
{ "validateaddress", &validateaddress, true, false },
{ "getbalance", &getbalance, false, false },
View
8 src/bitcoinrpc.h
@@ -167,10 +167,10 @@ extern json_spirit::Value listaccounts(const json_spirit::Array& params, bool fH
extern json_spirit::Value listsinceblock(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value gettransaction(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value backupwallet(const json_spirit::Array& params, bool fHelp);
-extern json_spirit::Value keypoolrefill(const json_spirit::Array& params, bool fHelp);
-extern json_spirit::Value walletpassphrase(const json_spirit::Array& params, bool fHelp);
-extern json_spirit::Value walletpassphrasechange(const json_spirit::Array& params, bool fHelp);
-extern json_spirit::Value walletlock(const json_spirit::Array& params, bool fHelp);
+extern json_spirit::Value refillkeypool(const json_spirit::Array& params, bool fHelp);
+extern json_spirit::Value unlockwallet(const json_spirit::Array& params, bool fHelp);
+extern json_spirit::Value setpassphrase(const json_spirit::Array& params, bool fHelp);
+extern json_spirit::Value lockwallet(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value encryptwallet(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value validateaddress(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getinfo(const json_spirit::Array& params, bool fHelp);
View
38 src/rpcwallet.cpp
@@ -18,14 +18,14 @@ static CCriticalSection cs_nWalletUnlockTime;
std::string HelpRequiringPassphrase()
{
return pwalletMain->IsCrypted()
- ? "\nrequires wallet passphrase to be set with walletpassphrase first"
+ ? "\nrequires wallet passphrase to be set with unlockwallet first"
: "";
}
void EnsureWalletIsUnlocked()
{
if (pwalletMain->IsLocked())
- throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
+ throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with unlockwallet first.");
}
void WalletTxToJSON(const CWalletTx& wtx, Object& entry)
@@ -106,7 +106,7 @@ Value getnewaddress(const Array& params, bool fHelp)
// Generate a new key that is added to wallet
CPubKey newKey;
if (!pwalletMain->GetKeyFromPool(newKey, false))
- throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
+ throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call refillkeypool first");
CKeyID keyID = newKey.GetID();
pwalletMain->SetAddressBookName(keyID, strAccount);
@@ -144,7 +144,7 @@ CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false)
if (!account.vchPubKey.IsValid() || bForceNew || bKeyUsed)
{
if (!pwalletMain->GetKeyFromPool(account.vchPubKey, false))
- throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
+ throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call refillkeypool first");
pwalletMain->SetAddressBookName(account.vchPubKey.GetID(), strAccount);
walletdb.WriteAccount(strAccount, account);
@@ -265,7 +265,7 @@ Value sendtoaddress(const Array& params, bool fHelp)
wtx.mapValue["to"] = params[3].get_str();
if (pwalletMain->IsLocked())
- throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
+ throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with unlockwallet first.");
string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx);
if (strError != "")
@@ -1234,11 +1234,11 @@ Value backupwallet(const Array& params, bool fHelp)
}
-Value keypoolrefill(const Array& params, bool fHelp)
+Value refillkeypool(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 0)
throw runtime_error(
- "keypoolrefill\n"
+ "refillkeypool\n"
"Fills the keypool."
+ HelpRequiringPassphrase());
@@ -1305,16 +1305,16 @@ void ThreadCleanWalletPassphrase(void* parg)
delete (int64*)parg;
}
-Value walletpassphrase(const Array& params, bool fHelp)
+Value unlockwallet(const Array& params, bool fHelp)
{
if (pwalletMain->IsCrypted() && (fHelp || params.size() != 2))
throw runtime_error(
- "walletpassphrase <passphrase> <timeout>\n"
+ "unlockwallet <passphrase> <timeout>\n"
"Stores the wallet decryption key in memory for <timeout> seconds.");
if (fHelp)
return true;
if (!pwalletMain->IsCrypted())
- throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrase was called.");
+ throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but unlockwallet was called.");
if (!pwalletMain->IsLocked())
throw JSONRPCError(RPC_WALLET_ALREADY_UNLOCKED, "Error: Wallet is already unlocked.");
@@ -1333,7 +1333,7 @@ Value walletpassphrase(const Array& params, bool fHelp)
}
else
throw runtime_error(
- "walletpassphrase <passphrase> <timeout>\n"
+ "unlockwallet <passphrase> <timeout>\n"
"Stores the wallet decryption key in memory for <timeout> seconds.");
NewThread(ThreadTopUpKeyPool, NULL);
@@ -1344,16 +1344,16 @@ Value walletpassphrase(const Array& params, bool fHelp)
}
-Value walletpassphrasechange(const Array& params, bool fHelp)
+Value setpassphrase(const Array& params, bool fHelp)
{
if (pwalletMain->IsCrypted() && (fHelp || params.size() != 2))
throw runtime_error(
- "walletpassphrasechange <oldpassphrase> <newpassphrase>\n"
+ "setpassphrase <oldpassphrase> <newpassphrase>\n"
"Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>.");
if (fHelp)
return true;
if (!pwalletMain->IsCrypted())
- throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrasechange was called.");
+ throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but setpassphrase was called.");
// TODO: get rid of these .c_str() calls by implementing SecureString::operator=(std::string)
// Alternately, find a way to make params[0] mlock()'d to begin with.
@@ -1367,7 +1367,7 @@ Value walletpassphrasechange(const Array& params, bool fHelp)
if (strOldWalletPass.length() < 1 || strNewWalletPass.length() < 1)
throw runtime_error(
- "walletpassphrasechange <oldpassphrase> <newpassphrase>\n"
+ "setpassphrase <oldpassphrase> <newpassphrase>\n"
"Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>.");
if (!pwalletMain->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass))
@@ -1377,18 +1377,18 @@ Value walletpassphrasechange(const Array& params, bool fHelp)
}
-Value walletlock(const Array& params, bool fHelp)
+Value lockwallet(const Array& params, bool fHelp)
{
if (pwalletMain->IsCrypted() && (fHelp || params.size() != 0))
throw runtime_error(
- "walletlock\n"
+ "lockwallet\n"
"Removes the wallet encryption key from memory, locking the wallet.\n"
- "After calling this method, you will need to call walletpassphrase again\n"
+ "After calling this method, you will need to call unlockwallet again\n"
"before being able to call any methods which require the wallet to be unlocked.");
if (fHelp)
return true;
if (!pwalletMain->IsCrypted())
- throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called.");
+ throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but lockwallet was called.");
{
LOCK(cs_nWalletUnlockTime);
Something went wrong with that request. Please try again.