Skip to content

Commit cead84b

Browse files
committed
Merge bitcoin#11536: Rename account to label where appropriate
d2527bd Rename wallet_accounts.py test (Russell Yanofsky) 045eeb8 Rename account to label where appropriate (Russell Yanofsky) Pull request description: 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#7729, by getting renaming out of the way and letting that change 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. --- There is a rebased version of bitcoin#7729 atop this PR at https://github.com/ryanofsky/bitcoin/commits/pr/label, see bitcoin#7729 (comment). Tree-SHA512: b3f934e612922d6290f50137f8ba71ddfaea4485713c7d97e89400a8b73b09b254f9186dffa462c77f5847721f5af9852b5572ade5443d8ee95dd150b3edb7ff
2 parents 9552dfb + d2527bd commit cead84b

File tree

12 files changed

+378
-356
lines changed

12 files changed

+378
-356
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
@@ -639,8 +639,6 @@ void PaymentServer::fetchPaymentACK(CWallet* wallet, const SendCoinsRecipient& r
639639
payment.add_transactions(transaction.data(), transaction.size());
640640

641641
// Create a new refund address, or re-use:
642-
QString account = tr("Refund from %1").arg(recipient.authenticatedMerchant);
643-
std::string strAccount = account.toStdString();
644642
CPubKey newKey;
645643
if (wallet->GetKeyFromPool(newKey)) {
646644
// BIP70 requests encode the scriptPubKey directly, so we are not restricted to address
@@ -651,7 +649,8 @@ void PaymentServer::fetchPaymentACK(CWallet* wallet, const SendCoinsRecipient& r
651649
const OutputType change_type = wallet->m_default_change_type != OutputType::NONE ? wallet->m_default_change_type : wallet->m_default_address_type;
652650
wallet->LearnRelatedScripts(newKey, change_type);
653651
CTxDestination dest = GetDestinationForKey(newKey, change_type);
654-
wallet->SetAddressBook(dest, strAccount, "refund");
652+
std::string label = tr("Refund from %1").arg(recipient.authenticatedMerchant).toStdString();
653+
wallet->SetAddressBook(dest, label, "refund");
655654

656655
CScript s = GetScriptForDestination(dest);
657656
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
}
@@ -3252,7 +3252,7 @@ bool CWallet::DelAddressBook(const CTxDestination& address)
32523252
return CWalletDB(*dbw).EraseName(EncodeDestination(address));
32533253
}
32543254

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

32703270
/**
@@ -3620,15 +3620,15 @@ std::set< std::set<CTxDestination> > CWallet::GetAddressGroupings()
36203620
return ret;
36213621
}
36223622

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

src/wallet/wallet.h

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

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

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

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

10371037
bool DelAddressBook(const CTxDestination& address);
10381038

1039-
const std::string& GetAccountName(const CScript& scriptPubKey) const;
1039+
const std::string& GetLabelName(const CScript& scriptPubKey) const;
10401040

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

test/functional/test_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
'feature_segwit.py',
6868
# vv Tests less than 2m vv
6969
'wallet_basic.py',
70-
'wallet_accounts.py',
70+
'wallet_labels.py',
7171
'p2p_segwit.py',
7272
'wallet_dump.py',
7373
'rpc_listtransactions.py',

test/functional/wallet_accounts.py

Lines changed: 0 additions & 206 deletions
This file was deleted.

test/functional/wallet_import_rescan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def check(self, txid=None, amount=None, confirmations=None):
7878

7979
if txid is not None:
8080
tx, = [tx for tx in txs if tx["txid"] == txid]
81-
assert_equal(tx["account"], self.label)
81+
assert_equal(tx["label"], self.label)
8282
assert_equal(tx["address"], self.address["address"])
8383
assert_equal(tx["amount"], amount)
8484
assert_equal(tx["category"], "receive")

0 commit comments

Comments
 (0)