[wallet] Kill accounts
This commit does the following changes: - [wallet] Remove 'account' argument from GetLegacyBalance() - GetLegacyBalance() is never called with an account argument. Remove the argument and helper functions. - [wallet] Remove CWallet::ListAccountCreditDebit() - Function no longer used. - [wallet] Remove AccountMove() - Function no longer used. - [wallet] Remove AddAccountingEntry() - Function no longer used. - [wallet] Remove GetAccountCreditDebit() - Function no longer used. - [wallet] Don't rewrite accounting entries when reordering wallet transactions. - Accounting entries are deprecated. Don't rewrite them to the wallet database when re-ordering transactions. - [wallet] Remove WriteAccountingEntry() - Function no longer used. - [wallet] Don't read acentry key-values from wallet on load. - [wallet] Remove ListAccountCreditDebit() - Function no longer used. - [wallet] Remove CAccountingEntry class - No longer used - [wallet] Remove GetLabelDestination - Function no longer used. - [wallet] Delete unused account functions - ReadAccount - WriteAccount - EraseAccount - DeleteLabel - [wallet] Remove fromAccount argument from CommitTransaction() - [wallet] Remove strFromAccount. - No longer used. - [wallet] Remove strSentAccount from GetAmounts(). - No longer used. - [wallet] Update zapwallettxes comment to remove accounts. - [wallet] Remove CAccount - No longer used - [docs] fix typo in release notes for PR 14023 (cherry picked from commit c9c32e6b844fc79467b7e24c6c916142a0d08484)
This commit is contained in:
parent
3ef50b3647
commit
8af7e138ac
|
@ -214,7 +214,6 @@ UniValue getrawchangeaddress(const UniValue& params, bool fHelp)
|
|||
return keyIO.EncodeDestination(keyID);
|
||||
}
|
||||
|
||||
|
||||
static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, CWalletTx& wtxNew)
|
||||
{
|
||||
CAmount curBalance = pwalletMain->GetBalance();
|
||||
|
@ -601,7 +600,6 @@ UniValue sendmany(const UniValue& params, bool fHelp)
|
|||
nMinDepth = params[2].get_int();
|
||||
|
||||
CWalletTx wtx;
|
||||
wtx.strFromAccount = "";
|
||||
if (params.size() > 3 && !params[3].isNull() && !params[3].get_str().empty())
|
||||
wtx.mapValue["comment"] = params[3].get_str();
|
||||
|
||||
|
@ -646,8 +644,7 @@ UniValue sendmany(const UniValue& params, bool fHelp)
|
|||
EnsureWalletIsUnlocked();
|
||||
|
||||
// Check funds
|
||||
CAmount nBalance = pwalletMain->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, nullptr);
|
||||
if (totalAmount > nBalance) {
|
||||
if (totalAmount > pwalletMain->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth)) {
|
||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Wallet has insufficient funds");
|
||||
}
|
||||
|
||||
|
@ -883,8 +880,7 @@ void ListTransactions(const CWalletTx& wtx, int nMinDepth, bool fLong, UniValue&
|
|||
std::list<COutputEntry> listReceived;
|
||||
std::list<COutputEntry> listSent;
|
||||
|
||||
std::string dummy_account;
|
||||
wtx.GetAmounts(listReceived, listSent, nFee, dummy_account, filter);
|
||||
wtx.GetAmounts(listReceived, listSent, nFee, filter);
|
||||
|
||||
bool involvesWatchonly = wtx.IsFromMe(ISMINE_WATCH_ONLY);
|
||||
|
||||
|
@ -1030,9 +1026,8 @@ UniValue listtransactions(const UniValue& params, bool fHelp)
|
|||
// iterate backwards until we have nCount items to return:
|
||||
for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
|
||||
{
|
||||
CWalletTx *const pwtx = (*it).second.first;
|
||||
if (pwtx != nullptr)
|
||||
ListTransactions(*pwtx, 0, true, ret, filter);
|
||||
CWalletTx *const pwtx = (*it).second;
|
||||
ListTransactions(*pwtx, 0, true, ret, filter);
|
||||
if ((int)ret.size() >= (nCount+nFrom)) break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,6 +120,7 @@ BOOST_AUTO_TEST_CASE(rpc_addmultisig)
|
|||
BOOST_AUTO_TEST_CASE(rpc_wallet)
|
||||
{
|
||||
// Test RPC calls for various wallet statistics
|
||||
KeyIO keyIO(Params());
|
||||
UniValue r;
|
||||
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
@ -127,19 +128,14 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
|
|||
CPubKey demoPubkey = pwalletMain->GenerateNewKey();
|
||||
CTxDestination demoAddress(CTxDestination(demoPubkey.GetID()));
|
||||
UniValue retValue;
|
||||
string strAccount = "";
|
||||
string strPurpose = "receive";
|
||||
BOOST_CHECK_NO_THROW({ /*Initialize Wallet with an account */
|
||||
BOOST_CHECK_NO_THROW({ /*Initialize Wallet with the demo pubkey*/
|
||||
CWalletDB walletdb(pwalletMain->strWalletFile);
|
||||
CAccount account;
|
||||
account.vchPubKey = demoPubkey;
|
||||
pwalletMain->SetAddressBook(account.vchPubKey.GetID(), strAccount, strPurpose);
|
||||
walletdb.WriteAccount(strAccount, account);
|
||||
pwalletMain->SetAddressBook(demoPubkey.GetID(), "", strPurpose);
|
||||
});
|
||||
|
||||
CPubKey setaccountDemoPubkey = pwalletMain->GenerateNewKey();
|
||||
CTxDestination setaccountDemoAddress(CTxDestination(setaccountDemoPubkey.GetID()));
|
||||
KeyIO keyIO(Params());
|
||||
|
||||
/*********************************
|
||||
* getbalance
|
||||
|
|
|
@ -976,7 +976,6 @@ void CWallet::SyncMetaData(pair<typename TxSpendMap<T>::iterator, typename TxSpe
|
|||
// nTimeReceived not copied on purpose
|
||||
copyTo->nTimeSmart = copyFrom->nTimeSmart;
|
||||
copyTo->fFromMe = copyFrom->fFromMe;
|
||||
copyTo->strFromAccount = copyFrom->strFromAccount;
|
||||
// nOrderPos not copied on purpose
|
||||
// cached members not copied on purpose
|
||||
}
|
||||
|
@ -1413,44 +1412,30 @@ DBErrors CWallet::ReorderTransactions()
|
|||
// Old wallets didn't have any defined order for transactions
|
||||
// Probably a bad idea to change the output of this
|
||||
|
||||
// First: get all CWalletTx and CAccountingEntry into a sorted-by-time multimap.
|
||||
typedef pair<CWalletTx*, CAccountingEntry*> TxPair;
|
||||
typedef multimap<int64_t, TxPair > TxItems;
|
||||
// First: get all CWalletTx into a sorted-by-time multimap.
|
||||
typedef std::multimap<int64_t, CWalletTx*> TxItems;
|
||||
TxItems txByTime;
|
||||
|
||||
for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
|
||||
for (auto &entry : mapWallet)
|
||||
{
|
||||
CWalletTx* wtx = &((*it).second);
|
||||
txByTime.insert(make_pair(wtx->nTimeReceived, TxPair(wtx, (CAccountingEntry*)0)));
|
||||
}
|
||||
list<CAccountingEntry> acentries;
|
||||
walletdb.ListAccountCreditDebit("", acentries);
|
||||
for(CAccountingEntry& entry : acentries)
|
||||
{
|
||||
txByTime.insert(make_pair(entry.nTime, TxPair((CWalletTx*)0, &entry)));
|
||||
CWalletTx *wtx = &entry.second;
|
||||
txByTime.insert(std::make_pair(wtx->nTimeReceived, wtx));
|
||||
}
|
||||
|
||||
nOrderPosNext = 0;
|
||||
std::vector<int64_t> nOrderPosOffsets;
|
||||
for (TxItems::iterator it = txByTime.begin(); it != txByTime.end(); ++it)
|
||||
{
|
||||
CWalletTx *const pwtx = (*it).second.first;
|
||||
CAccountingEntry *const pacentry = (*it).second.second;
|
||||
int64_t& nOrderPos = (pwtx != 0) ? pwtx->nOrderPos : pacentry->nOrderPos;
|
||||
CWalletTx *const pwtx = (*it).second;
|
||||
int64_t& nOrderPos = pwtx->nOrderPos;
|
||||
|
||||
if (nOrderPos == -1)
|
||||
{
|
||||
nOrderPos = nOrderPosNext++;
|
||||
nOrderPosOffsets.push_back(nOrderPos);
|
||||
|
||||
if (pwtx)
|
||||
{
|
||||
if (!walletdb.WriteTx(*pwtx))
|
||||
return DB_LOAD_FAIL;
|
||||
}
|
||||
else
|
||||
if (!walletdb.WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
|
||||
return DB_LOAD_FAIL;
|
||||
if (!walletdb.WriteTx(*pwtx))
|
||||
return DB_LOAD_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1467,14 +1452,8 @@ DBErrors CWallet::ReorderTransactions()
|
|||
continue;
|
||||
|
||||
// Since we're changing the order, write it back
|
||||
if (pwtx)
|
||||
{
|
||||
if (!walletdb.WriteTx(*pwtx))
|
||||
return DB_LOAD_FAIL;
|
||||
}
|
||||
else
|
||||
if (!walletdb.WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
|
||||
return DB_LOAD_FAIL;
|
||||
if (!walletdb.WriteTx(*pwtx))
|
||||
return DB_LOAD_FAIL;
|
||||
}
|
||||
}
|
||||
walletdb.WriteOrderPosNext(nOrderPosNext);
|
||||
|
@ -1638,7 +1617,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletD
|
|||
mapWallet[hash] = wtxIn;
|
||||
CWalletTx& wtx = mapWallet[hash];
|
||||
wtx.BindWallet(this);
|
||||
wtxOrdered.insert(make_pair(wtx.nOrderPos, TxPair(&wtx, (CAccountingEntry*)0)));
|
||||
wtxOrdered.insert(make_pair(wtx.nOrderPos, &wtx));
|
||||
UpdateNullifierNoteMapWithTx(mapWallet[hash]);
|
||||
AddToSpends(hash);
|
||||
}
|
||||
|
@ -1655,7 +1634,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletD
|
|||
{
|
||||
wtx.nTimeReceived = GetTime();
|
||||
wtx.nOrderPos = IncOrderPosNext(pwalletdb);
|
||||
wtxOrdered.insert(make_pair(wtx.nOrderPos, TxPair(&wtx, (CAccountingEntry*)0)));
|
||||
wtxOrdered.insert(make_pair(wtx.nOrderPos, &wtx));
|
||||
|
||||
wtx.nTimeSmart = wtx.nTimeReceived;
|
||||
if (!wtxIn.hashBlock.IsNull())
|
||||
|
@ -1670,19 +1649,13 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletD
|
|||
const TxItems & txOrdered = wtxOrdered;
|
||||
for (TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
|
||||
{
|
||||
CWalletTx *const pwtx = (*it).second.first;
|
||||
CWalletTx *const pwtx = (*it).second;
|
||||
if (pwtx == &wtx)
|
||||
continue;
|
||||
CAccountingEntry *const pacentry = (*it).second.second;
|
||||
int64_t nSmartTime;
|
||||
if (pwtx)
|
||||
{
|
||||
nSmartTime = pwtx->nTimeSmart;
|
||||
if (!nSmartTime)
|
||||
nSmartTime = pwtx->nTimeReceived;
|
||||
}
|
||||
else
|
||||
nSmartTime = pacentry->nTime;
|
||||
nSmartTime = pwtx->nTimeSmart;
|
||||
if (!nSmartTime)
|
||||
nSmartTime = pwtx->nTimeReceived;
|
||||
if (nSmartTime <= latestTolerated)
|
||||
{
|
||||
latestEntry = nSmartTime;
|
||||
|
@ -2592,13 +2565,12 @@ int CWalletTx::GetRequestCount() const
|
|||
}
|
||||
|
||||
// GetAmounts will determine the transparent debits and credits for a given wallet tx.
|
||||
void CWalletTx::GetAmounts(list<COutputEntry>& listReceived,
|
||||
list<COutputEntry>& listSent, CAmount& nFee, string& strSentAccount, const isminefilter& filter) const
|
||||
void CWalletTx::GetAmounts(std::list<COutputEntry>& listReceived,
|
||||
std::list<COutputEntry>& listSent, CAmount& nFee, const isminefilter& filter) const
|
||||
{
|
||||
nFee = 0;
|
||||
listReceived.clear();
|
||||
listSent.clear();
|
||||
strSentAccount = strFromAccount;
|
||||
|
||||
// Is this tx sent/signed by me?
|
||||
CAmount nDebit = GetDebit(filter);
|
||||
|
@ -3210,7 +3182,7 @@ CAmount CWallet::GetImmatureWatchOnlyBalance() const
|
|||
// wallet, and then subtracts the values of TxIns spending from the wallet. This
|
||||
// also has fewer restrictions on which unconfirmed transactions are considered
|
||||
// trusted.
|
||||
CAmount CWallet::GetLegacyBalance(const isminefilter& filter, int minDepth, const std::string* account) const
|
||||
CAmount CWallet::GetLegacyBalance(const isminefilter& filter, int minDepth) const
|
||||
{
|
||||
LOCK2(cs_main, cs_wallet);
|
||||
|
||||
|
@ -3229,21 +3201,17 @@ CAmount CWallet::GetLegacyBalance(const isminefilter& filter, int minDepth, cons
|
|||
for (const CTxOut& out : wtx.vout) {
|
||||
if (outgoing && IsChange(out)) {
|
||||
debit -= out.nValue;
|
||||
} else if (IsMine(out) & filter && depth >= minDepth && (!account || *account == GetAccountName(out.scriptPubKey))) {
|
||||
} else if (IsMine(out) & filter && depth >= minDepth) {
|
||||
balance += out.nValue;
|
||||
}
|
||||
}
|
||||
|
||||
// For outgoing txs, subtract amount debited.
|
||||
if (outgoing && (!account || *account == wtx.strFromAccount)) {
|
||||
if (outgoing) {
|
||||
balance -= debit;
|
||||
}
|
||||
}
|
||||
|
||||
if (account) {
|
||||
balance += CWalletDB(strWalletFile).GetAccountCreditDebit(*account);
|
||||
}
|
||||
|
||||
return balance;
|
||||
}
|
||||
|
||||
|
@ -3961,23 +3929,6 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, std::optional<std::reference_
|
|||
return true;
|
||||
}
|
||||
|
||||
void CWallet::ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries) {
|
||||
CWalletDB walletdb(strWalletFile);
|
||||
return walletdb.ListAccountCreditDebit(strAccount, entries);
|
||||
}
|
||||
|
||||
bool CWallet::AddAccountingEntry(const CAccountingEntry& acentry, CWalletDB & pwalletdb)
|
||||
{
|
||||
if (!pwalletdb.WriteAccountingEntry_Backend(acentry))
|
||||
return false;
|
||||
|
||||
laccentries.push_back(acentry);
|
||||
CAccountingEntry & entry = laccentries.back();
|
||||
wtxOrdered.insert(make_pair(entry.nOrderPos, TxPair((CWalletTx*)0, &entry)));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CAmount CWallet::GetRequiredFee(unsigned int nTxBytes)
|
||||
{
|
||||
return std::max(minTxFee.GetFee(nTxBytes), ::minRelayTxFee.GetFeeForRelay(nTxBytes));
|
||||
|
@ -4685,8 +4636,8 @@ void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const {
|
|||
}
|
||||
|
||||
// Extract block timestamps for those keys
|
||||
for (std::map<CKeyID, CBlockIndex*>::const_iterator it = mapKeyFirstBlock.begin(); it != mapKeyFirstBlock.end(); it++) {
|
||||
mapKeyBirth[it->first] = it->second->GetBlockTime() - TIMESTAMP_WINDOW; // block times can be off
|
||||
for (const auto& entry : mapKeyFirstBlock) {
|
||||
mapKeyBirth[entry.first] = entry.second->GetBlockTime() - TIMESTAMP_WINDOW; // block times can be 2h off
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4915,7 +4866,6 @@ bool CWallet::InitLoadWallet(bool clearWitnessCaches)
|
|||
copyTo->nTimeReceived = copyFrom->nTimeReceived;
|
||||
copyTo->nTimeSmart = copyFrom->nTimeSmart;
|
||||
copyTo->fFromMe = copyFrom->fFromMe;
|
||||
copyTo->strFromAccount = copyFrom->strFromAccount;
|
||||
copyTo->nOrderPos = copyFrom->nOrderPos;
|
||||
walletdb.WriteTx(*copyTo);
|
||||
}
|
||||
|
|
|
@ -428,7 +428,6 @@ public:
|
|||
* be read or written through the map (they will be temporarily added and
|
||||
* removed from the map during serialization):
|
||||
*
|
||||
* "fromaccount" - serialized strFromAccount value
|
||||
* "n" - serialized nOrderPos value
|
||||
* "timesmart" - serialized nTimeSmart value
|
||||
* "spent" - serialized vfSpent value that existed prior to
|
||||
|
@ -442,7 +441,6 @@ public:
|
|||
unsigned int nTimeReceived; //!< time received by this node
|
||||
unsigned int nTimeSmart;
|
||||
char fFromMe;
|
||||
std::string strFromAccount;
|
||||
int64_t nOrderPos; //!< position in ordered transaction list
|
||||
|
||||
// memory only
|
||||
|
@ -496,7 +494,6 @@ public:
|
|||
nTimeReceived = 0;
|
||||
nTimeSmart = 0;
|
||||
fFromMe = false;
|
||||
strFromAccount.clear();
|
||||
fDebitCached = false;
|
||||
fCreditCached = false;
|
||||
fImmatureCreditCached = false;
|
||||
|
@ -528,7 +525,7 @@ public:
|
|||
|
||||
if (!ser_action.ForRead())
|
||||
{
|
||||
mapValue["fromaccount"] = strFromAccount;
|
||||
mapValue["fromaccount"] = "";
|
||||
|
||||
WriteOrderPos(nOrderPos, mapValue);
|
||||
|
||||
|
@ -553,10 +550,7 @@ public:
|
|||
|
||||
if (ser_action.ForRead())
|
||||
{
|
||||
strFromAccount = mapValue["fromaccount"];
|
||||
|
||||
ReadOrderPos(nOrderPos, mapValue);
|
||||
|
||||
nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0;
|
||||
}
|
||||
|
||||
|
@ -614,7 +608,7 @@ public:
|
|||
CAmount GetChange() const;
|
||||
|
||||
void GetAmounts(std::list<COutputEntry>& listReceived,
|
||||
std::list<COutputEntry>& listSent, CAmount& nFee, std::string& strSentAccount, const isminefilter& filter) const;
|
||||
std::list<COutputEntry>& listSent, CAmount& nFee, const isminefilter& filter) const;
|
||||
|
||||
bool IsFromMe(const isminefilter& filter) const
|
||||
{
|
||||
|
@ -680,89 +674,6 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Internal transfers.
|
||||
* Database key is acentry<account><counter>.
|
||||
*/
|
||||
class CAccountingEntry
|
||||
{
|
||||
public:
|
||||
std::string strAccount;
|
||||
CAmount nCreditDebit;
|
||||
int64_t nTime;
|
||||
std::string strOtherAccount;
|
||||
std::string strComment;
|
||||
mapValue_t mapValue;
|
||||
int64_t nOrderPos; //!< position in ordered transaction list
|
||||
uint64_t nEntryNo;
|
||||
|
||||
CAccountingEntry()
|
||||
{
|
||||
SetNull();
|
||||
}
|
||||
|
||||
void SetNull()
|
||||
{
|
||||
nCreditDebit = 0;
|
||||
nTime = 0;
|
||||
strAccount.clear();
|
||||
strOtherAccount.clear();
|
||||
strComment.clear();
|
||||
nOrderPos = -1;
|
||||
nEntryNo = 0;
|
||||
}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
int nVersion = s.GetVersion();
|
||||
if (!(s.GetType() & SER_GETHASH))
|
||||
READWRITE(nVersion);
|
||||
//! Note: strAccount is serialized as part of the key, not here.
|
||||
READWRITE(nCreditDebit);
|
||||
READWRITE(nTime);
|
||||
READWRITE(LIMITED_STRING(strOtherAccount, 65536));
|
||||
|
||||
if (!ser_action.ForRead())
|
||||
{
|
||||
WriteOrderPos(nOrderPos, mapValue);
|
||||
|
||||
if (!(mapValue.empty() && _ssExtra.empty()))
|
||||
{
|
||||
CDataStream ss(s.GetType(), s.GetVersion());
|
||||
ss.insert(ss.begin(), '\0');
|
||||
ss << mapValue;
|
||||
ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
|
||||
strComment.append(ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
READWRITE(LIMITED_STRING(strComment, 65536));
|
||||
|
||||
size_t nSepPos = strComment.find("\0", 0, 1);
|
||||
if (ser_action.ForRead())
|
||||
{
|
||||
mapValue.clear();
|
||||
if (std::string::npos != nSepPos)
|
||||
{
|
||||
CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), s.GetType(), s.GetVersion());
|
||||
ss >> mapValue;
|
||||
_ssExtra = std::vector<char>(ss.begin(), ss.end());
|
||||
}
|
||||
ReadOrderPos(nOrderPos, mapValue);
|
||||
}
|
||||
if (std::string::npos != nSepPos)
|
||||
strComment.erase(nSepPos);
|
||||
|
||||
mapValue.erase("n");
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<char> _ssExtra;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,
|
||||
* and provides the ability to create new transactions.
|
||||
|
@ -1009,10 +920,8 @@ public:
|
|||
std::map<uint256, SaplingOutPoint> mapSaplingNullifiersToNotes;
|
||||
|
||||
std::map<uint256, CWalletTx> mapWallet;
|
||||
std::list<CAccountingEntry> laccentries;
|
||||
|
||||
typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair;
|
||||
typedef std::multimap<int64_t, TxPair > TxItems;
|
||||
typedef std::multimap<int64_t, CWalletTx*> TxItems;
|
||||
TxItems wtxOrdered;
|
||||
|
||||
int64_t nOrderPosNext;
|
||||
|
@ -1207,7 +1116,7 @@ public:
|
|||
CAmount GetImmatureBalance() const;
|
||||
CAmount GetUnconfirmedWatchOnlyBalance() const;
|
||||
CAmount GetImmatureWatchOnlyBalance() const;
|
||||
CAmount GetLegacyBalance(const isminefilter& filter, int minDepth, const std::string* account) const;
|
||||
CAmount GetLegacyBalance(const isminefilter& filter, int minDepth) const;
|
||||
|
||||
/**
|
||||
* Insert additional inputs into the transaction by
|
||||
|
@ -1223,10 +1132,6 @@ public:
|
|||
std::string& strFailReason, const CCoinControl *coinControl = NULL, bool sign = true);
|
||||
bool CommitTransaction(CWalletTx& wtxNew, std::optional<std::reference_wrapper<CReserveKey>> reservekey);
|
||||
|
||||
void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries);
|
||||
|
||||
bool AddAccountingEntry(const CAccountingEntry&, CWalletDB & pwalletdb);
|
||||
|
||||
static CFeeRate minTxFee;
|
||||
/**
|
||||
* Estimate the minimum fee considering user set parameters
|
||||
|
@ -1456,37 +1361,6 @@ public:
|
|||
void KeepScript() { KeepKey(); }
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Account information.
|
||||
* Stored in wallet with key "acc"+string account name.
|
||||
*/
|
||||
class CAccount
|
||||
{
|
||||
public:
|
||||
CPubKey vchPubKey;
|
||||
|
||||
CAccount()
|
||||
{
|
||||
SetNull();
|
||||
}
|
||||
|
||||
void SetNull()
|
||||
{
|
||||
vchPubKey = CPubKey();
|
||||
}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
int nVersion = s.GetVersion();
|
||||
if (!(s.GetType() & SER_GETHASH))
|
||||
READWRITE(nVersion);
|
||||
READWRITE(vchPubKey);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Shielded key and address generalizations
|
||||
//
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -284,82 +285,6 @@ bool CWalletDB::WriteMinVersion(int nVersion)
|
|||
return Write(std::string("minversion"), nVersion);
|
||||
}
|
||||
|
||||
bool CWalletDB::ReadAccount(const string& strAccount, CAccount& account)
|
||||
{
|
||||
account.SetNull();
|
||||
return Read(make_pair(string("acc"), strAccount), account);
|
||||
}
|
||||
|
||||
bool CWalletDB::WriteAccount(const string& strAccount, const CAccount& account)
|
||||
{
|
||||
return Write(make_pair(string("acc"), strAccount), account);
|
||||
}
|
||||
|
||||
bool CWalletDB::WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry)
|
||||
{
|
||||
return Write(std::make_pair(std::string("acentry"), std::make_pair(acentry.strAccount, nAccEntryNum)), acentry);
|
||||
}
|
||||
|
||||
bool CWalletDB::WriteAccountingEntry_Backend(const CAccountingEntry& acentry)
|
||||
{
|
||||
return WriteAccountingEntry(++nAccountingEntryNumber, acentry);
|
||||
}
|
||||
|
||||
CAmount CWalletDB::GetAccountCreditDebit(const string& strAccount)
|
||||
{
|
||||
list<CAccountingEntry> entries;
|
||||
ListAccountCreditDebit(strAccount, entries);
|
||||
|
||||
CAmount nCreditDebit = 0;
|
||||
for (const CAccountingEntry& entry : entries)
|
||||
nCreditDebit += entry.nCreditDebit;
|
||||
|
||||
return nCreditDebit;
|
||||
}
|
||||
|
||||
void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& entries)
|
||||
{
|
||||
bool fAllAccounts = (strAccount == "*");
|
||||
|
||||
Dbc* pcursor = GetCursor();
|
||||
if (!pcursor)
|
||||
throw runtime_error("CWalletDB::ListAccountCreditDebit(): cannot create DB cursor");
|
||||
unsigned int fFlags = DB_SET_RANGE;
|
||||
while (true)
|
||||
{
|
||||
// Read next record
|
||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
||||
if (fFlags == DB_SET_RANGE)
|
||||
ssKey << std::make_pair(std::string("acentry"), std::make_pair((fAllAccounts ? string("") : strAccount), uint64_t(0)));
|
||||
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
|
||||
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
|
||||
fFlags = DB_NEXT;
|
||||
if (ret == DB_NOTFOUND)
|
||||
break;
|
||||
else if (ret != 0)
|
||||
{
|
||||
pcursor->close();
|
||||
throw runtime_error("CWalletDB::ListAccountCreditDebit(): error scanning DB");
|
||||
}
|
||||
|
||||
// Unserialize
|
||||
string strType;
|
||||
ssKey >> strType;
|
||||
if (strType != "acentry")
|
||||
break;
|
||||
CAccountingEntry acentry;
|
||||
ssKey >> acentry.strAccount;
|
||||
if (!fAllAccounts && acentry.strAccount != strAccount)
|
||||
break;
|
||||
|
||||
ssValue >> acentry;
|
||||
ssKey >> acentry.nEntryNo;
|
||||
entries.push_back(acentry);
|
||||
}
|
||||
|
||||
pcursor->close();
|
||||
}
|
||||
|
||||
class CWalletScanState {
|
||||
public:
|
||||
unsigned int nKeys;
|
||||
|
@ -430,9 +355,10 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
|
|||
{
|
||||
char fTmp;
|
||||
char fUnused;
|
||||
ssValue >> fTmp >> fUnused >> wtx.strFromAccount;
|
||||
strErr = strprintf("LoadWallet() upgrading tx ver=%d %d '%s' %s",
|
||||
wtx.fTimeReceivedIsTxTime, fTmp, wtx.strFromAccount, hash.ToString());
|
||||
std::string unused_string;
|
||||
ssValue >> fTmp >> fUnused >> unused_string;
|
||||
strErr = strprintf("LoadWallet() upgrading tx ver=%d %d %s",
|
||||
wtx.fTimeReceivedIsTxTime, fTmp, hash.ToString());
|
||||
wtx.fTimeReceivedIsTxTime = fTmp;
|
||||
}
|
||||
else
|
||||
|
@ -448,23 +374,6 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
|
|||
|
||||
pwallet->AddToWallet(wtx, true, NULL);
|
||||
}
|
||||
else if (strType == "acentry")
|
||||
{
|
||||
string strAccount;
|
||||
ssKey >> strAccount;
|
||||
uint64_t nNumber;
|
||||
ssKey >> nNumber;
|
||||
if (nNumber > nAccountingEntryNumber)
|
||||
nAccountingEntryNumber = nNumber;
|
||||
|
||||
if (!wss.fAnyUnordered)
|
||||
{
|
||||
CAccountingEntry acentry;
|
||||
ssValue >> acentry;
|
||||
if (acentry.nOrderPos == -1)
|
||||
wss.fAnyUnordered = true;
|
||||
}
|
||||
}
|
||||
else if (strType == "watchs")
|
||||
{
|
||||
CScript script;
|
||||
|
@ -934,12 +843,6 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
|
|||
if (wss.fAnyUnordered)
|
||||
result = pwallet->ReorderTransactions();
|
||||
|
||||
pwallet->laccentries.clear();
|
||||
ListAccountCreditDebit("*", pwallet->laccentries);
|
||||
for(CAccountingEntry& entry : pwallet->laccentries) {
|
||||
pwallet->wtxOrdered.insert(make_pair(entry.nOrderPos, CWallet::TxPair((CWalletTx*)0, &entry)));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
|
||||
static const bool DEFAULT_FLUSHWALLET = true;
|
||||
|
||||
class CAccount;
|
||||
class CAccountingEntry;
|
||||
struct CBlockLocator;
|
||||
class CKeyPool;
|
||||
class CMasterKey;
|
||||
|
@ -159,21 +157,11 @@ public:
|
|||
|
||||
bool WriteMinVersion(int nVersion);
|
||||
|
||||
/// This writes directly to the database, and will not update the CWallet's cached accounting entries!
|
||||
/// Use wallet.AddAccountingEntry instead, to write *and* update its caches.
|
||||
bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry);
|
||||
bool WriteAccountingEntry_Backend(const CAccountingEntry& acentry);
|
||||
bool ReadAccount(const std::string& strAccount, CAccount& account);
|
||||
bool WriteAccount(const std::string& strAccount, const CAccount& account);
|
||||
|
||||
/// Write destination data key,value tuple to database
|
||||
bool WriteDestData(const std::string &address, const std::string &key, const std::string &value);
|
||||
/// Erase destination data tuple from wallet database
|
||||
bool EraseDestData(const std::string &address, const std::string &key);
|
||||
|
||||
CAmount GetAccountCreditDebit(const std::string& strAccount);
|
||||
void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries);
|
||||
|
||||
DBErrors LoadWallet(CWallet* pwallet);
|
||||
DBErrors FindWalletTxToZap(CWallet* pwallet, std::vector<uint256>& vTxHash, std::vector<CWalletTx>& vWtx);
|
||||
DBErrors ZapWalletTx(CWallet* pwallet, std::vector<CWalletTx>& vWtx);
|
||||
|
|
Loading…
Reference in New Issue