Skip to content

Commit

Permalink
Merge bitcoin#11536: Rename account to label where appropriate
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ryanofsky authored and xdustinface committed Dec 22, 2020
1 parent 1c8f475 commit e86a0c0
Show file tree
Hide file tree
Showing 10 changed files with 368 additions and 355 deletions.
5 changes: 5 additions & 0 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "getreceivedbyaddress", 2, "addlocked" },
{ "getreceivedbyaccount", 1, "minconf" },
{ "getreceivedbyaccount", 2, "addlocked" },
{ "getreceivedbylabel", 1, "minconf" },
{ "getreceivedbylabel", 2, "addlocked" },
{ "listaddressbalances", 0, "minamount" },
{ "listreceivedbyaddress", 0, "minconf" },
{ "listreceivedbyaddress", 1, "addlocked" },
Expand All @@ -56,6 +58,9 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "listreceivedbyaccount", 1, "addlocked" },
{ "listreceivedbyaccount", 2, "include_empty" },
{ "listreceivedbyaccount", 3, "include_watchonly" },
{ "listreceivedbylabel", 1, "addlocked" },
{ "listreceivedbylabel", 2, "include_empty" },
{ "listreceivedbylabel", 3, "include_watchonly" },
{ "getbalance", 1, "minconf" },
{ "getbalance", 2, "addlocked" },
{ "getbalance", 3, "include_watchonly" },
Expand Down
4 changes: 3 additions & 1 deletion src/rpc/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ enum RPCErrorCode
//! Wallet errors
RPC_WALLET_ERROR = -4, //!< Unspecified problem with wallet (key not found etc.)
RPC_WALLET_INSUFFICIENT_FUNDS = -6, //!< Not enough funds in wallet or account
RPC_WALLET_INVALID_ACCOUNT_NAME = -11, //!< Invalid account name
RPC_WALLET_INVALID_LABEL_NAME = -11, //!< Invalid label name
RPC_WALLET_KEYPOOL_RAN_OUT = -12, //!< Keypool ran out, call keypoolrefill first
RPC_WALLET_UNLOCK_NEEDED = -13, //!< Enter the wallet passphrase with walletpassphrase first
RPC_WALLET_PASSPHRASE_INCORRECT = -14, //!< The wallet passphrase entered was incorrect
Expand All @@ -87,6 +87,8 @@ enum RPCErrorCode
RPC_WALLET_NOT_SPECIFIED = -19, //!< No wallet specified (error when there are multiple wallets loaded)


//! Backwards compatible aliases
RPC_WALLET_INVALID_ACCOUNT_NAME = RPC_WALLET_INVALID_LABEL_NAME,
//! Unused reserved codes, kept around for backwards compatibility. Do not reuse.
RPC_FORBIDDEN_BY_SAFE_MODE = -2, //!< Server is in safe mode, and command is not allowed in safe mode
};
Expand Down
206 changes: 106 additions & 100 deletions src/wallet/rpcwallet.cpp

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,12 +1041,12 @@ bool CWallet::AccountMove(std::string strFrom, std::string strTo, CAmount nAmoun
return true;
}

bool CWallet::GetAccountDestination(CTxDestination &dest, std::string strAccount, bool bForceNew)
bool CWallet::GetLabelDestination(CTxDestination &dest, const std::string& label, bool bForceNew)
{
WalletBatch batch(*database);

CAccount account;
batch.ReadAccount(strAccount, account);
batch.ReadAccount(label, account);

if (!bForceNew) {
if (!account.vchPubKey.IsValid())
Expand All @@ -1071,8 +1071,8 @@ bool CWallet::GetAccountDestination(CTxDestination &dest, std::string strAccount
return false;

dest = account.vchPubKey.GetID();
SetAddressBook(dest, strAccount, "receive");
batch.WriteAccount(strAccount, account);
SetAddressBook(dest, label, "receive");
batch.WriteAccount(label, account);
} else {
dest = account.vchPubKey.GetID();
}
Expand Down Expand Up @@ -2828,7 +2828,7 @@ CAmount CWallet::GetLegacyBalance(const isminefilter& filter, int minDepth, cons
for (const CTxOut& out : wtx.tx->vout) {
if (outgoing && IsChange(out)) {
debit -= out.nValue;
} else if (IsMine(out) & filter && (depth >= minDepth || (fAddLocked && wtx.IsLockedByInstantSend())) && (!account || *account == GetAccountName(out.scriptPubKey))) {
} else if (IsMine(out) & filter && (depth >= minDepth || (fAddLocked && wtx.IsLockedByInstantSend())) && (!account || *account == GetLabelName(out.scriptPubKey))) {
balance += out.nValue;
}
}
Expand Down Expand Up @@ -4279,7 +4279,7 @@ bool CWallet::DelAddressBook(const CTxDestination& address)
return WalletBatch(*database).EraseName(EncodeDestination(address));
}

const std::string& CWallet::GetAccountName(const CScript& scriptPubKey) const
const std::string& CWallet::GetLabelName(const CScript& scriptPubKey) const
{
CTxDestination address;
if (ExtractDestination(scriptPubKey, address) && !scriptPubKey.IsUnspendable()) {
Expand All @@ -4289,9 +4289,9 @@ const std::string& CWallet::GetAccountName(const CScript& scriptPubKey) const
}
}
// A scriptPubKey that doesn't have an entry in the address book is
// associated with the default account ("").
const static std::string DEFAULT_ACCOUNT_NAME;
return DEFAULT_ACCOUNT_NAME;
// associated with the default label ("").
const static std::string DEFAULT_LABEL_NAME;
return DEFAULT_LABEL_NAME;
}

/**
Expand Down Expand Up @@ -4671,15 +4671,15 @@ std::set< std::set<CTxDestination> > CWallet::GetAddressGroupings()
return ret;
}

std::set<CTxDestination> CWallet::GetAccountAddresses(const std::string& strAccount) const
std::set<CTxDestination> CWallet::GetLabelAddresses(const std::string& label) const
{
LOCK(cs_wallet);
std::set<CTxDestination> result;
for (const std::pair<const CTxDestination, CAddressBookData>& item : mapAddressBook)
{
const CTxDestination& address = item.first;
const std::string& strName = item.second.name;
if (strName == strAccount)
if (strName == label)
result.insert(address);
}
return result;
Expand Down
6 changes: 3 additions & 3 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
int64_t IncOrderPosNext(WalletBatch *batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
DBErrors ReorderTransactions();
bool AccountMove(std::string strFrom, std::string strTo, CAmount nAmount, std::string strComment = "") EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool GetAccountDestination(CTxDestination &dest, std::string strAccount, bool bForceNew = false);
bool GetLabelDestination(CTxDestination &dest, const std::string& label, bool bForceNew = false);

void MarkDirty();
bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose=true);
Expand Down Expand Up @@ -1116,7 +1116,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
std::set<std::set<CTxDestination>> GetAddressGroupings() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
std::map<CTxDestination, CAmount> GetAddressBalances();

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

isminetype IsMine(const CTxIn& txin) const;
/**
Expand Down Expand Up @@ -1147,7 +1147,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface

bool DelAddressBook(const CTxDestination& address);

const std::string& GetAccountName(const CScript& scriptPubKey) const;
const std::string& GetLabelName(const CScript& scriptPubKey) const;

void GetScriptForMining(std::shared_ptr<CReserveScript> &script);

Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
# vv Tests less than 2m vv
'p2p_instantsend.py',
'wallet_basic.py',
'wallet_accounts.py',
'wallet_labels.py',
'wallet_dump.py',
'rpc_listtransactions.py',
'feature_multikeysporks.py',
Expand Down
208 changes: 0 additions & 208 deletions test/functional/wallet_accounts.py

This file was deleted.

2 changes: 1 addition & 1 deletion test/functional/wallet_import_rescan.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def check(self, txid=None, amount=None, confirmations=None):

if txid is not None:
tx, = [tx for tx in txs if tx["txid"] == txid]
assert_equal(tx["account"], self.label)
assert_equal(tx["label"], self.label)
assert_equal(tx["address"], self.address["address"])
assert_equal(tx["amount"], amount)
assert_equal(tx["category"], "receive")
Expand Down
Loading

0 comments on commit e86a0c0

Please sign in to comment.