Skip to content

Commit 045eeb8

Browse files
committed
Rename account to label where appropriate
This change only updates strings and adds RPC aliases, but should simplify the implementation of address labels in bitcoin/bitcoin#7729, by getting renaming out of the way and letting it focus on semantics. The difference between accounts and labels is that labels apply only to addresses, while accounts apply to both addresses and transactions (transactions have "from" and "to" accounts). The code associating accounts with transactions is clumsy and unreliable so we would like get rid of it.
1 parent c39dd2e commit 045eeb8

File tree

10 files changed

+253
-231
lines changed

10 files changed

+253
-231
lines changed

doc/release-notes.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ RPC changes
6363

6464
- The `createrawtransaction` RPC will now accept an array or dictionary (kept for compatibility) for the `outputs` parameter. This means the order of transaction outputs can be specified by the client.
6565
- The `fundrawtransaction` RPC will reject the previously deprecated `reserveChangeKey` option.
66+
- Wallet `getnewaddress` and `addmultisigaddress` RPC `account` named
67+
parameters have been renamed to `label` with no change in behavior.
68+
- Wallet `getlabeladdress`, `getreceivedbylabel`, `listreceivedbylabel`, and
69+
`setlabel` RPCs have been added to replace `getaccountaddress`,
70+
`getreceivedbyaccount`, `listreceivedbyaccount`, and `setaccount` RPCs,
71+
which are now deprecated. There is no change in behavior between the
72+
new RPCs and deprecated RPCs.
73+
- Wallet `listreceivedbylabel`, `listreceivedbyaccount` and `listunspent` RPCs
74+
add `label` fields to returned JSON objects that previously only had
75+
`account` fields.
6676

6777
External wallet files
6878
---------------------

src/qt/paymentserver.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,6 @@ void PaymentServer::fetchPaymentACK(CWallet* wallet, const SendCoinsRecipient& r
634634
payment.add_transactions(transaction.data(), transaction.size());
635635

636636
// Create a new refund address, or re-use:
637-
QString account = tr("Refund from %1").arg(recipient.authenticatedMerchant);
638-
std::string strAccount = account.toStdString();
639637
CPubKey newKey;
640638
if (wallet->GetKeyFromPool(newKey)) {
641639
// BIP70 requests encode the scriptPubKey directly, so we are not restricted to address
@@ -646,7 +644,8 @@ void PaymentServer::fetchPaymentACK(CWallet* wallet, const SendCoinsRecipient& r
646644
const OutputType change_type = wallet->m_default_change_type != OutputType::NONE ? wallet->m_default_change_type : wallet->m_default_address_type;
647645
wallet->LearnRelatedScripts(newKey, change_type);
648646
CTxDestination dest = GetDestinationForKey(newKey, change_type);
649-
wallet->SetAddressBook(dest, strAccount, "refund");
647+
std::string label = tr("Refund from %1").arg(recipient.authenticatedMerchant).toStdString();
648+
wallet->SetAddressBook(dest, label, "refund");
650649

651650
CScript s = GetScriptForDestination(dest);
652651
payments::Output* refund_to = payment.add_refund_to();

src/rpc/client.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@ static const CRPCConvertParam vRPCConvertParams[] =
4040
{ "settxfee", 0, "amount" },
4141
{ "getreceivedbyaddress", 1, "minconf" },
4242
{ "getreceivedbyaccount", 1, "minconf" },
43+
{ "getreceivedbylabel", 1, "minconf" },
4344
{ "listreceivedbyaddress", 0, "minconf" },
4445
{ "listreceivedbyaddress", 1, "include_empty" },
4546
{ "listreceivedbyaddress", 2, "include_watchonly" },
4647
{ "listreceivedbyaddress", 3, "address_filter" },
4748
{ "listreceivedbyaccount", 0, "minconf" },
4849
{ "listreceivedbyaccount", 1, "include_empty" },
4950
{ "listreceivedbyaccount", 2, "include_watchonly" },
51+
{ "listreceivedbylabel", 0, "minconf" },
52+
{ "listreceivedbylabel", 1, "include_empty" },
53+
{ "listreceivedbylabel", 2, "include_watchonly" },
5054
{ "getbalance", 1, "minconf" },
5155
{ "getbalance", 2, "include_watchonly" },
5256
{ "getblockhash", 0, "height" },

src/rpc/protocol.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ enum RPCErrorCode
7676
//! Wallet errors
7777
RPC_WALLET_ERROR = -4, //!< Unspecified problem with wallet (key not found etc.)
7878
RPC_WALLET_INSUFFICIENT_FUNDS = -6, //!< Not enough funds in wallet or account
79-
RPC_WALLET_INVALID_ACCOUNT_NAME = -11, //!< Invalid account name
79+
RPC_WALLET_INVALID_LABEL_NAME = -11, //!< Invalid label name
8080
RPC_WALLET_KEYPOOL_RAN_OUT = -12, //!< Keypool ran out, call keypoolrefill first
8181
RPC_WALLET_UNLOCK_NEEDED = -13, //!< Enter the wallet passphrase with walletpassphrase first
8282
RPC_WALLET_PASSPHRASE_INCORRECT = -14, //!< The wallet passphrase entered was incorrect
@@ -85,6 +85,9 @@ enum RPCErrorCode
8585
RPC_WALLET_ALREADY_UNLOCKED = -17, //!< Wallet is already unlocked
8686
RPC_WALLET_NOT_FOUND = -18, //!< Invalid wallet specified
8787
RPC_WALLET_NOT_SPECIFIED = -19, //!< No wallet specified (error when there are multiple wallets loaded)
88+
89+
//! Backwards compatible aliases
90+
RPC_WALLET_INVALID_ACCOUNT_NAME = RPC_WALLET_INVALID_LABEL_NAME,
8891
};
8992

9093
UniValue JSONRPCRequestObj(const std::string& strMethod, const UniValue& params, const UniValue& id);

src/wallet/rpcwallet.cpp

Lines changed: 106 additions & 100 deletions
Large diffs are not rendered by default.

src/wallet/wallet.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -809,12 +809,12 @@ bool CWallet::AccountMove(std::string strFrom, std::string strTo, CAmount nAmoun
809809
return true;
810810
}
811811

812-
bool CWallet::GetAccountDestination(CTxDestination &dest, std::string strAccount, bool bForceNew)
812+
bool CWallet::GetLabelDestination(CTxDestination &dest, const std::string& label, bool bForceNew)
813813
{
814814
CWalletDB walletdb(*dbw);
815815

816816
CAccount account;
817-
walletdb.ReadAccount(strAccount, account);
817+
walletdb.ReadAccount(label, account);
818818

819819
if (!bForceNew) {
820820
if (!account.vchPubKey.IsValid())
@@ -840,8 +840,8 @@ bool CWallet::GetAccountDestination(CTxDestination &dest, std::string strAccount
840840

841841
LearnRelatedScripts(account.vchPubKey, m_default_address_type);
842842
dest = GetDestinationForKey(account.vchPubKey, m_default_address_type);
843-
SetAddressBook(dest, strAccount, "receive");
844-
walletdb.WriteAccount(strAccount, account);
843+
SetAddressBook(dest, label, "receive");
844+
walletdb.WriteAccount(label, account);
845845
} else {
846846
dest = GetDestinationForKey(account.vchPubKey, m_default_address_type);
847847
}
@@ -2220,7 +2220,7 @@ CAmount CWallet::GetLegacyBalance(const isminefilter& filter, int minDepth, cons
22202220
for (const CTxOut& out : wtx.tx->vout) {
22212221
if (outgoing && IsChange(out)) {
22222222
debit -= out.nValue;
2223-
} else if (IsMine(out) & filter && depth >= minDepth && (!account || *account == GetAccountName(out.scriptPubKey))) {
2223+
} else if (IsMine(out) & filter && depth >= minDepth && (!account || *account == GetLabelName(out.scriptPubKey))) {
22242224
balance += out.nValue;
22252225
}
22262226
}
@@ -3251,7 +3251,7 @@ bool CWallet::DelAddressBook(const CTxDestination& address)
32513251
return CWalletDB(*dbw).EraseName(EncodeDestination(address));
32523252
}
32533253

3254-
const std::string& CWallet::GetAccountName(const CScript& scriptPubKey) const
3254+
const std::string& CWallet::GetLabelName(const CScript& scriptPubKey) const
32553255
{
32563256
CTxDestination address;
32573257
if (ExtractDestination(scriptPubKey, address) && !scriptPubKey.IsUnspendable()) {
@@ -3261,9 +3261,9 @@ const std::string& CWallet::GetAccountName(const CScript& scriptPubKey) const
32613261
}
32623262
}
32633263
// A scriptPubKey that doesn't have an entry in the address book is
3264-
// associated with the default account ("").
3265-
const static std::string DEFAULT_ACCOUNT_NAME;
3266-
return DEFAULT_ACCOUNT_NAME;
3264+
// associated with the default label ("").
3265+
const static std::string DEFAULT_LABEL_NAME;
3266+
return DEFAULT_LABEL_NAME;
32673267
}
32683268

32693269
/**
@@ -3619,15 +3619,15 @@ std::set< std::set<CTxDestination> > CWallet::GetAddressGroupings()
36193619
return ret;
36203620
}
36213621

3622-
std::set<CTxDestination> CWallet::GetAccountAddresses(const std::string& strAccount) const
3622+
std::set<CTxDestination> CWallet::GetLabelAddresses(const std::string& label) const
36233623
{
36243624
LOCK(cs_wallet);
36253625
std::set<CTxDestination> result;
36263626
for (const std::pair<CTxDestination, CAddressBookData>& item : mapAddressBook)
36273627
{
36283628
const CTxDestination& address = item.first;
36293629
const std::string& strName = item.second.name;
3630-
if (strName == strAccount)
3630+
if (strName == label)
36313631
result.insert(address);
36323632
}
36333633
return result;

src/wallet/wallet.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
929929
int64_t IncOrderPosNext(CWalletDB *pwalletdb = nullptr);
930930
DBErrors ReorderTransactions();
931931
bool AccountMove(std::string strFrom, std::string strTo, CAmount nAmount, std::string strComment = "");
932-
bool GetAccountDestination(CTxDestination &dest, std::string strAccount, bool bForceNew = false);
932+
bool GetLabelDestination(CTxDestination &dest, const std::string& label, bool bForceNew = false);
933933

934934
void MarkDirty();
935935
bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose=true);
@@ -1007,7 +1007,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
10071007
std::set< std::set<CTxDestination> > GetAddressGroupings();
10081008
std::map<CTxDestination, CAmount> GetAddressBalances();
10091009

1010-
std::set<CTxDestination> GetAccountAddresses(const std::string& strAccount) const;
1010+
std::set<CTxDestination> GetLabelAddresses(const std::string& label) const;
10111011

10121012
isminetype IsMine(const CTxIn& txin) const;
10131013
/**
@@ -1037,7 +1037,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
10371037

10381038
bool DelAddressBook(const CTxDestination& address);
10391039

1040-
const std::string& GetAccountName(const CScript& scriptPubKey) const;
1040+
const std::string& GetLabelName(const CScript& scriptPubKey) const;
10411041

10421042
void Inventory(const uint256 &hash) override
10431043
{

0 commit comments

Comments
 (0)