Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 791 Lines • ▼ Show 20 Lines | |||||
void CWallet::MarkDirty() { | void CWallet::MarkDirty() { | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
for (std::pair<const TxId, CWalletTx> &item : mapWallet) { | for (std::pair<const TxId, CWalletTx> &item : mapWallet) { | ||||
item.second.MarkDirty(); | item.second.MarkDirty(); | ||||
} | } | ||||
} | } | ||||
void CWallet::SetUsedDestinationState( | void CWallet::SetSpentKeyState(WalletBatch &batch, const TxId &txid, | ||||
WalletBatch &batch, const TxId &txid, unsigned int n, bool used, | unsigned int n, bool used, | ||||
std::set<CTxDestination> &tx_destinations) { | std::set<CTxDestination> &tx_destinations) { | ||||
AssertLockHeld(cs_wallet); | AssertLockHeld(cs_wallet); | ||||
const CWalletTx *srctx = GetWalletTx(txid); | const CWalletTx *srctx = GetWalletTx(txid); | ||||
if (!srctx) { | if (!srctx) { | ||||
return; | return; | ||||
} | } | ||||
CTxDestination dst; | CTxDestination dst; | ||||
if (ExtractDestination(srctx->tx->vout[n].scriptPubKey, dst)) { | if (ExtractDestination(srctx->tx->vout[n].scriptPubKey, dst)) { | ||||
if (IsMine(dst)) { | if (IsMine(dst)) { | ||||
if (used && !GetDestData(dst, "used", nullptr)) { | if (used && !GetDestData(dst, "used", nullptr)) { | ||||
// p for "present", opposite of absent (null) | // p for "present", opposite of absent (null) | ||||
if (AddDestData(batch, dst, "used", "p")) { | if (AddDestData(batch, dst, "used", "p")) { | ||||
tx_destinations.insert(dst); | tx_destinations.insert(dst); | ||||
} | } | ||||
} else if (!used && GetDestData(dst, "used", nullptr)) { | } else if (!used && GetDestData(dst, "used", nullptr)) { | ||||
EraseDestData(batch, dst, "used"); | EraseDestData(batch, dst, "used"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
bool CWallet::IsUsedDestination(const TxId &txid, unsigned int n) const { | bool CWallet::IsSpentKey(const TxId &txid, unsigned int n) const { | ||||
AssertLockHeld(cs_wallet); | AssertLockHeld(cs_wallet); | ||||
CTxDestination dst; | CTxDestination dst; | ||||
const CWalletTx *srctx = GetWalletTx(txid); | const CWalletTx *srctx = GetWalletTx(txid); | ||||
if (srctx) { | if (srctx) { | ||||
assert(srctx->tx->vout.size() > n); | assert(srctx->tx->vout.size() > n); | ||||
CTxDestination dest; | CTxDestination dest; | ||||
if (!ExtractDestination(srctx->tx->vout[n].scriptPubKey, dest)) { | if (!ExtractDestination(srctx->tx->vout[n].scriptPubKey, dest)) { | ||||
return false; | return false; | ||||
Show All 24 Lines | bool CWallet::AddToWallet(const CWalletTx &wtxIn, bool fFlushOnClose) { | ||||
const TxId &txid = wtxIn.GetId(); | const TxId &txid = wtxIn.GetId(); | ||||
if (IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE)) { | if (IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE)) { | ||||
// Mark used destinations | // Mark used destinations | ||||
std::set<CTxDestination> tx_destinations; | std::set<CTxDestination> tx_destinations; | ||||
for (const CTxIn &txin : wtxIn.tx->vin) { | for (const CTxIn &txin : wtxIn.tx->vin) { | ||||
const COutPoint &op = txin.prevout; | const COutPoint &op = txin.prevout; | ||||
SetUsedDestinationState(batch, op.GetTxId(), op.GetN(), true, | SetSpentKeyState(batch, op.GetTxId(), op.GetN(), true, | ||||
tx_destinations); | tx_destinations); | ||||
} | } | ||||
MarkDestinationsDirty(tx_destinations); | MarkDestinationsDirty(tx_destinations); | ||||
} | } | ||||
// Inserts only if not already there, returns tx inserted or tx found. | // Inserts only if not already there, returns tx inserted or tx found. | ||||
std::pair<std::map<TxId, CWalletTx>::iterator, bool> ret = | std::pair<std::map<TxId, CWalletTx>::iterator, bool> ret = | ||||
mapWallet.insert(std::make_pair(txid, wtxIn)); | mapWallet.insert(std::make_pair(txid, wtxIn)); | ||||
▲ Show 20 Lines • Show All 1,185 Lines • ▼ Show 20 Lines | Amount CWalletTx::GetAvailableCredit(bool fUseCache, | ||||
bool allow_used_addresses = | bool allow_used_addresses = | ||||
(filter & ISMINE_USED) || | (filter & ISMINE_USED) || | ||||
!pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE); | !pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE); | ||||
Amount nCredit = Amount::zero(); | Amount nCredit = Amount::zero(); | ||||
const TxId &txid = GetId(); | const TxId &txid = GetId(); | ||||
for (uint32_t i = 0; i < tx->vout.size(); i++) { | for (uint32_t i = 0; i < tx->vout.size(); i++) { | ||||
if (!pwallet->IsSpent(COutPoint(txid, i)) && | if (!pwallet->IsSpent(COutPoint(txid, i)) && | ||||
(allow_used_addresses || !pwallet->IsUsedDestination(txid, i))) { | (allow_used_addresses || !pwallet->IsSpentKey(txid, i))) { | ||||
const CTxOut &txout = tx->vout[i]; | const CTxOut &txout = tx->vout[i]; | ||||
nCredit += pwallet->GetCredit(txout, filter); | nCredit += pwallet->GetCredit(txout, filter); | ||||
if (!MoneyRange(nCredit)) { | if (!MoneyRange(nCredit)) { | ||||
throw std::runtime_error(std::string(__func__) + | throw std::runtime_error(std::string(__func__) + | ||||
" : value out of range"); | " : value out of range"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 328 Lines • ▼ Show 20 Lines | for (const auto &entry : mapWallet) { | ||||
} | } | ||||
isminetype mine = IsMine(wtx.tx->vout[i]); | isminetype mine = IsMine(wtx.tx->vout[i]); | ||||
if (mine == ISMINE_NO) { | if (mine == ISMINE_NO) { | ||||
continue; | continue; | ||||
} | } | ||||
if (!allow_used_addresses && IsUsedDestination(wtxid, i)) { | if (!allow_used_addresses && IsSpentKey(wtxid, i)) { | ||||
continue; | continue; | ||||
} | } | ||||
std::unique_ptr<SigningProvider> provider = | std::unique_ptr<SigningProvider> provider = | ||||
GetSolvingProvider(wtx.tx->vout[i].scriptPubKey); | GetSolvingProvider(wtx.tx->vout[i].scriptPubKey); | ||||
bool solvable = | bool solvable = | ||||
provider ? IsSolvable(*provider, wtx.tx->vout[i].scriptPubKey) | provider ? IsSolvable(*provider, wtx.tx->vout[i].scriptPubKey) | ||||
▲ Show 20 Lines • Show All 2,633 Lines • Show Last 20 Lines |