diff --git a/doc/release-notes.md b/doc/release-notes.md --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -4,4 +4,14 @@ This release includes the following features and fixes: - Add `getfinalizedblock` rpc to allow node operators to introspec - the current finalized block. \ No newline at end of file + the current finalized block. + - Wallet `getnewaddress` and `addmultisigaddress` RPC `account` named + parameters have been renamed to `label` with no change in behavior. + - Wallet `getlabeladdress`, `getreceivedbylabel`, `listreceivedbylabel`, and + `setlabel` RPCs have been added to replace `getaccountaddress`, + `getreceivedbyaccount`, `listreceivedbyaccount`, and `setaccount` RPCs, + which are now deprecated. There is no change in behavior between the + new RPCs and deprecated RPCs. + - Wallet `listreceivedbylabel`, `listreceivedbyaccount` and `listunspent` RPCs + add `label` fields to returned JSON objects that previously only had + `account` fields. diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -703,10 +703,9 @@ payment.add_transactions(transaction.data(), transaction.size()); // Create a new refund address, or re-use: - QString account = tr("Refund from %1").arg(recipient.authenticatedMerchant); - std::string strAccount = account.toStdString(); - std::set refundAddresses = - wallet->GetAccountAddresses(strAccount); + std::string label = + tr("Refund from %1").arg(recipient.authenticatedMerchant).toStdString(); + std::set refundAddresses = wallet->GetLabelAddresses(label); if (!refundAddresses.empty()) { CScript s = GetScriptForDestination(*refundAddresses.begin()); payments::Output *refund_to = payment.add_refund_to(); @@ -715,7 +714,7 @@ CPubKey newKey; if (wallet->GetKeyFromPool(newKey)) { CKeyID keyID = newKey.GetID(); - wallet->SetAddressBook(keyID, strAccount, "refund"); + wallet->SetAddressBook(keyID, label, "refund"); CScript s = GetScriptForDestination(keyID); payments::Output *refund_to = payment.add_refund_to(); diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -38,13 +38,17 @@ {"settxfee", 0, "amount"}, {"getreceivedbyaddress", 1, "minconf"}, {"getreceivedbyaccount", 1, "minconf"}, + {"getreceivedbylabel", 1, "minconf"}, {"listreceivedbyaddress", 0, "minconf"}, {"listreceivedbyaddress", 1, "include_empty"}, {"listreceivedbyaddress", 2, "include_watchonly"}, + {"listreceivedbyaddress", 3, "address_filter"}, {"listreceivedbyaccount", 0, "minconf"}, {"listreceivedbyaccount", 1, "include_empty"}, {"listreceivedbyaccount", 2, "include_watchonly"}, - {"listreceivedbyaddress", 3, "address_filter"}, + {"listreceivedbylabel", 0, "minconf"}, + {"listreceivedbylabel", 1, "include_empty"}, + {"listreceivedbylabel", 2, "include_watchonly"}, {"getbalance", 1, "minconf"}, {"getbalance", 2, "include_watchonly"}, {"getblockhash", 0, "height"}, diff --git a/src/rpc/protocol.h b/src/rpc/protocol.h --- a/src/rpc/protocol.h +++ b/src/rpc/protocol.h @@ -96,8 +96,8 @@ RPC_WALLET_ERROR = -4, //!< Not enough funds in wallet or account RPC_WALLET_INSUFFICIENT_FUNDS = -6, - //!< Invalid account name - RPC_WALLET_INVALID_ACCOUNT_NAME = -11, + //!< Invalid label name + RPC_WALLET_INVALID_LABEL_NAME = -11, //!< Keypool ran out, call keypoolrefill first RPC_WALLET_KEYPOOL_RAN_OUT = -12, //!< Enter the wallet passphrase with walletpassphrase first @@ -114,7 +114,9 @@ //!< Invalid wallet specified RPC_WALLET_NOT_FOUND = -18, //!< No wallet specified (error when there are multiple wallets loaded) - RPC_WALLET_NOT_SPECIFIED = -19 + RPC_WALLET_NOT_SPECIFIED = -19, + //!< Backwards compatible aliases + RPC_WALLET_INVALID_ACCOUNT_NAME = RPC_WALLET_INVALID_LABEL_NAME, }; UniValue JSONRPCRequestObj(const std::string &strMethod, const UniValue ¶ms, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -134,13 +134,12 @@ } } -std::string AccountFromValue(const UniValue &value) { - std::string strAccount = value.get_str(); - if (strAccount == "*") { - throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, - "Invalid account name"); +std::string LabelFromValue(const UniValue &value) { + std::string label = value.get_str(); + if (label == "*") { + throw JSONRPCError(RPC_WALLET_INVALID_LABEL_NAME, "Invalid label name"); } - return strAccount; + return label; } static UniValue getnewaddress(const Config &config, @@ -152,32 +151,29 @@ if (request.fHelp || request.params.size() > 1) { throw std::runtime_error( - "getnewaddress ( \"account\" )\n" + "getnewaddress ( \"label\" )\n" "\nReturns a new Bitcoin address for receiving payments.\n" - "If 'account' is specified (DEPRECATED), it is added to the " - "address book \n" - "so payments received with the address will be credited to " - "'account'.\n" + "If 'label' is specified, it is added to the address book \n" + "so payments received with the address will be associated with " + "'label'.\n" "\nArguments:\n" - "1. \"account\" (string, optional) DEPRECATED. The account " - "name for the address to be linked to. If not provided, the " - "default account \"\" is used. It can also be set to the empty " - "string \"\" to represent the default account. The account does " - "not need to exist, it will be created if there is no account by " - "the given name.\n" + "1. \"label\" (string, optional) The label name for the " + "address to be linked to. If not provided, the default label \"\" " + "is used. It can also be set to the empty string \"\" to represent " + "the default label. The label does not need to exist, it will be " + "created if there is no label by the given name.\n" "\nResult:\n" "\"address\" (string) The new bitcoin address\n" "\nExamples:\n" + - HelpExampleCli("getnewaddress", "") + HelpExampleRpc("getnewaddress", "")); } LOCK2(cs_main, pwallet->cs_wallet); - // Parse the account first so we don't generate a key if there's an error - std::string strAccount; + // Parse the label first so we don't generate a key if there's an error + std::string label; if (request.params.size() > 0) { - strAccount = AccountFromValue(request.params[0]); + label = LabelFromValue(request.params[0]); } if (!pwallet->IsLocked()) { @@ -193,15 +189,15 @@ } CKeyID keyID = newKey.GetID(); - pwallet->SetAddressBook(keyID, strAccount, "receive"); + pwallet->SetAddressBook(keyID, label, "receive"); return EncodeDestination(keyID); } -CTxDestination GetAccountAddress(CWallet *const pwallet, std::string strAccount, - bool bForceNew = false) { +CTxDestination GetLabelAddress(CWallet *const pwallet, const std::string &label, + bool bForceNew = false) { CPubKey pubKey; - if (!pwallet->GetAccountPubkey(pubKey, strAccount, bForceNew)) { + if (!pwallet->GetLabelAddress(pubKey, label, bForceNew)) { throw JSONRPCError( RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first"); @@ -210,8 +206,7 @@ return pubKey.GetID(); } -static UniValue getaccountaddress(const Config &config, - const JSONRPCRequest &request) { +UniValue getlabeladdress(const Config &config, const JSONRPCRequest &request) { CWallet *const pwallet = GetWalletForJSONRPCRequest(request); if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { return NullUniValue; @@ -219,32 +214,31 @@ if (request.fHelp || request.params.size() != 1) { throw std::runtime_error( - "getaccountaddress \"account\"\n" - "\nDEPRECATED. Returns the current Bitcoin address for receiving " - "payments to this account.\n" + "getlabeladdress \"label\"\n" + "\nReturns the current Bitcoin address for receiving payments to " + "this label.\n" "\nArguments:\n" - "1. \"account\" (string, required) The account name for the " + "1. \"label\" (string, required) The label name for the " "address. It can also be set to the empty string \"\" to represent " - "the default account. The account does not need to exist, it will " - "be created and a new address created if there is no account by " - "the given name.\n" + "the default label. The label does not need to exist, it will be " + "created and a new address created if there is no label by the " + "given name.\n" "\nResult:\n" - "\"address\" (string) The account bitcoin address\n" + "\"address\" (string) The label bitcoin address\n" "\nExamples:\n" + - HelpExampleCli("getaccountaddress", "") + - HelpExampleCli("getaccountaddress", "\"\"") + - HelpExampleCli("getaccountaddress", "\"myaccount\"") + - HelpExampleRpc("getaccountaddress", "\"myaccount\"")); + HelpExampleCli("getlabeladdress", "") + + HelpExampleCli("getlabeladdress", "\"\"") + + HelpExampleCli("getlabeladdress", "\"mylabel\"") + + HelpExampleRpc("getlabeladdress", "\"mylabel\"")); } - LOCK2(cs_main, pwallet->cs_wallet); - // Parse the account first so we don't generate a key if there's an error - std::string strAccount = AccountFromValue(request.params[0]); + // Parse the label first so we don't generate a key if there's an error + std::string label = LabelFromValue(request.params[0]); UniValue ret(UniValue::VSTR); - ret = EncodeDestination(GetAccountAddress(pwallet, strAccount)); + ret = EncodeDestination(GetLabelAddress(pwallet, label)); return ret; } @@ -288,8 +282,7 @@ return EncodeDestination(keyID); } -static UniValue setaccount(const Config &config, - const JSONRPCRequest &request) { +UniValue setlabel(const Config &config, const JSONRPCRequest &request) { CWallet *const pwallet = GetWalletForJSONRPCRequest(request); if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { return NullUniValue; @@ -298,22 +291,20 @@ if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { throw std::runtime_error( - "setaccount \"address\" \"account\"\n" - "\nDEPRECATED. Sets the account associated with the given " - "address.\n" + "setlabel \"address\" \"label\"\n" + "\nSets the label associated with the given address.\n" "\nArguments:\n" "1. \"address\" (string, required) The bitcoin address to " - "be associated with an account.\n" - "2. \"account\" (string, required) The account to assign " - "the address to.\n" + "be associated with a label.\n" + "2. \"label\" (string, required) The label to assign the " + "address to.\n" "\nExamples:\n" + - HelpExampleCli("setaccount", + HelpExampleCli("setlabel", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"tabby\"") + HelpExampleRpc( - "setaccount", + "setlabel", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"tabby\"")); } - LOCK2(cs_main, pwallet->cs_wallet); CTxDestination dest = @@ -323,26 +314,26 @@ "Invalid Bitcoin address"); } - std::string strAccount; - if (request.params.size() > 1) { - strAccount = AccountFromValue(request.params[1]); + std::string label; + if (!request.params[1].isNull()) { + label = LabelFromValue(request.params[1]); } - // Only add the account if the address is yours. + // Only add the label if the address is yours. if (IsMine(*pwallet, dest)) { - // Detect when changing the account of an address that is the 'unused - // current key' of another account: + // Detect when changing the label of an address that is the 'unused + // current key' of another label: if (pwallet->mapAddressBook.count(dest)) { - std::string strOldAccount = pwallet->mapAddressBook[dest].name; - if (dest == GetAccountAddress(pwallet, strOldAccount)) { - GetAccountAddress(pwallet, strOldAccount, true); + std::string old_label = pwallet->mapAddressBook[dest].name; + if (dest == GetLabelAddress(pwallet, old_label)) { + GetLabelAddress(pwallet, old_label, true); } } - pwallet->SetAddressBook(dest, strAccount, "receive"); + pwallet->SetAddressBook(dest, label, "receive"); } else { throw JSONRPCError(RPC_MISC_ERROR, - "setaccount can only be used with own address"); + "setlabel can only be used with own address"); } return NullUniValue; @@ -418,7 +409,7 @@ LOCK2(cs_main, pwallet->cs_wallet); - std::string strAccount = AccountFromValue(request.params[0]); + std::string strAccount = LabelFromValue(request.params[0]); // Find all addresses that have the given account UniValue ret(UniValue::VARR); @@ -594,15 +585,15 @@ " [\n" " \"address\", (string) The bitcoin address\n" " amount, (numeric) The amount in " + - CURRENCY_UNIT + "\n" - " \"account\" (string, optional) " - "DEPRECATED. The account\n" - " ]\n" - " ,...\n" - " ]\n" - " ,...\n" - "]\n" - "\nExamples:\n" + + CURRENCY_UNIT + + "\n" + " \"label\" (string, optional) The label\n" + " ]\n" + " ,...\n" + " ]\n" + " ,...\n" + "]\n" + "\nExamples:\n" + HelpExampleCli("listaddressgroupings", "") + HelpExampleRpc("listaddressgroupings", "")); } @@ -789,8 +780,8 @@ return ValueFromAmount(nAmount); } -static UniValue getreceivedbyaccount(const Config &config, - const JSONRPCRequest &request) { +UniValue getreceivedbylabel(const Config &config, + const JSONRPCRequest &request) { CWallet *const pwallet = GetWalletForJSONRPCRequest(request); if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { return NullUniValue; @@ -799,30 +790,29 @@ if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { throw std::runtime_error( - "getreceivedbyaccount \"account\" ( minconf )\n" - "\nDEPRECATED. Returns the total amount received by addresses with " - " in transactions with at least [minconf] confirmations.\n" + "getreceivedbylabel \"label\" ( minconf )\n" + "\nReturns the total amount received by addresses with