Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 881 Lines • ▼ Show 20 Lines | bool CWallet::AccountMove(std::string strFrom, std::string strTo, | ||||
credit.nTime = nNow; | credit.nTime = nNow; | ||||
credit.strOtherAccount = strFrom; | credit.strOtherAccount = strFrom; | ||||
credit.strComment = strComment; | credit.strComment = strComment; | ||||
AddAccountingEntry(credit, &walletdb); | AddAccountingEntry(credit, &walletdb); | ||||
return walletdb.TxnCommit(); | return walletdb.TxnCommit(); | ||||
} | } | ||||
bool CWallet::GetAccountPubkey(CPubKey &pubKey, std::string strAccount, | bool CWallet::GetLabelAddress(CPubKey &pubKey, const std::string &label, | ||||
bool bForceNew) { | bool bForceNew) { | ||||
CWalletDB walletdb(*dbw); | CWalletDB walletdb(*dbw); | ||||
CAccount account; | CAccount account; | ||||
walletdb.ReadAccount(strAccount, account); | walletdb.ReadAccount(label, account); | ||||
if (!bForceNew) { | if (!bForceNew) { | ||||
if (!account.vchPubKey.IsValid()) { | if (!account.vchPubKey.IsValid()) { | ||||
bForceNew = true; | bForceNew = true; | ||||
} else { | } else { | ||||
// Check if the current key has been used. | // Check if the current key has been used. | ||||
CScript scriptPubKey = | CScript scriptPubKey = | ||||
GetScriptForDestination(account.vchPubKey.GetID()); | GetScriptForDestination(account.vchPubKey.GetID()); | ||||
Show All 10 Lines | bool CWallet::GetLabelAddress(CPubKey &pubKey, const std::string &label, | ||||
} | } | ||||
// Generate a new key | // Generate a new key | ||||
if (bForceNew) { | if (bForceNew) { | ||||
if (!GetKeyFromPool(account.vchPubKey, false)) { | if (!GetKeyFromPool(account.vchPubKey, false)) { | ||||
return false; | return false; | ||||
} | } | ||||
SetAddressBook(account.vchPubKey.GetID(), strAccount, "receive"); | SetAddressBook(account.vchPubKey.GetID(), label, "receive"); | ||||
walletdb.WriteAccount(strAccount, account); | walletdb.WriteAccount(label, account); | ||||
} | } | ||||
pubKey = account.vchPubKey; | pubKey = account.vchPubKey; | ||||
return true; | return true; | ||||
} | } | ||||
void CWallet::MarkDirty() { | void CWallet::MarkDirty() { | ||||
▲ Show 20 Lines • Show All 1,268 Lines • ▼ Show 20 Lines | for (const auto &entry : mapWallet) { | ||||
// treat change outputs specially, as part of the amount debited. | // treat change outputs specially, as part of the amount debited. | ||||
Amount debit = wtx.GetDebit(filter); | Amount debit = wtx.GetDebit(filter); | ||||
const bool outgoing = debit > Amount::zero(); | const bool outgoing = debit > Amount::zero(); | ||||
for (const CTxOut &out : wtx.tx->vout) { | for (const CTxOut &out : wtx.tx->vout) { | ||||
if (outgoing && IsChange(out)) { | if (outgoing && IsChange(out)) { | ||||
debit -= out.nValue; | debit -= out.nValue; | ||||
} else if (IsMine(out) & filter && depth >= minDepth && | } else if (IsMine(out) & filter && depth >= minDepth && | ||||
(!account || | (!account || | ||||
*account == GetAccountName(out.scriptPubKey))) { | *account == GetLabelName(out.scriptPubKey))) { | ||||
balance += out.nValue; | balance += out.nValue; | ||||
} | } | ||||
} | } | ||||
// For outgoing txs, subtract amount debited. | // For outgoing txs, subtract amount debited. | ||||
if (outgoing && (!account || *account == wtx.strFromAccount)) { | if (outgoing && (!account || *account == wtx.strFromAccount)) { | ||||
balance -= debit; | balance -= debit; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,042 Lines • ▼ Show 20 Lines | bool CWallet::DelAddressBook(const CTxDestination &address) { | ||||
NotifyAddressBookChanged(this, address, "", | NotifyAddressBookChanged(this, address, "", | ||||
::IsMine(*this, address) != ISMINE_NO, "", | ::IsMine(*this, address) != ISMINE_NO, "", | ||||
CT_DELETED); | CT_DELETED); | ||||
CWalletDB(*dbw).ErasePurpose(address); | CWalletDB(*dbw).ErasePurpose(address); | ||||
return CWalletDB(*dbw).EraseName(address); | return CWalletDB(*dbw).EraseName(address); | ||||
} | } | ||||
const std::string &CWallet::GetAccountName(const CScript &scriptPubKey) const { | const std::string &CWallet::GetLabelName(const CScript &scriptPubKey) const { | ||||
CTxDestination address; | CTxDestination address; | ||||
if (ExtractDestination(scriptPubKey, address) && | if (ExtractDestination(scriptPubKey, address) && | ||||
!scriptPubKey.IsUnspendable()) { | !scriptPubKey.IsUnspendable()) { | ||||
auto mi = mapAddressBook.find(address); | auto mi = mapAddressBook.find(address); | ||||
if (mi != mapAddressBook.end()) { | if (mi != mapAddressBook.end()) { | ||||
return mi->second.name; | return mi->second.name; | ||||
} | } | ||||
} | } | ||||
// A scriptPubKey that doesn't have an entry in the address book is | // A scriptPubKey that doesn't have an entry in the address book is | ||||
// associated with the default account (""). | // associated with the default label (""). | ||||
const static std::string DEFAULT_ACCOUNT_NAME; | const static std::string DEFAULT_LABEL_NAME; | ||||
return DEFAULT_ACCOUNT_NAME; | return DEFAULT_LABEL_NAME; | ||||
} | } | ||||
/** | /** | ||||
* Mark old keypool keys as used, and generate all new keys. | * Mark old keypool keys as used, and generate all new keys. | ||||
*/ | */ | ||||
bool CWallet::NewKeyPool() { | bool CWallet::NewKeyPool() { | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
CWalletDB walletdb(*dbw); | CWalletDB walletdb(*dbw); | ||||
▲ Show 20 Lines • Show All 369 Lines • ▼ Show 20 Lines | for (std::set<CTxDestination> *uniqueGrouping : uniqueGroupings) { | ||||
ret.insert(*uniqueGrouping); | ret.insert(*uniqueGrouping); | ||||
delete uniqueGrouping; | delete uniqueGrouping; | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
std::set<CTxDestination> | std::set<CTxDestination> | ||||
CWallet::GetAccountAddresses(const std::string &strAccount) const { | CWallet::GetLabelAddresses(const std::string &label) const { | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
std::set<CTxDestination> result; | std::set<CTxDestination> result; | ||||
for (const std::pair<CTxDestination, CAddressBookData> &item : | for (const std::pair<CTxDestination, CAddressBookData> &item : | ||||
mapAddressBook) { | mapAddressBook) { | ||||
const CTxDestination &address = item.first; | const CTxDestination &address = item.first; | ||||
const std::string &strName = item.second.name; | const std::string &strName = item.second.name; | ||||
if (strName == strAccount) { | if (strName == label) { | ||||
result.insert(address); | result.insert(address); | ||||
} | } | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
bool CReserveKey::GetReservedKey(CPubKey &pubkey, bool internal) { | bool CReserveKey::GetReservedKey(CPubKey &pubkey, bool internal) { | ||||
▲ Show 20 Lines • Show All 586 Lines • Show Last 20 Lines |