17 if (prev && txin.
prevout.
n < prev->
tx->vout.size()) {
35 throw std::runtime_error(std::string(__func__) +
": value out of range");
47 throw std::runtime_error(std::string(__func__) +
": value out of range");
67 if (!
wallet.FindAddressBookEntry(address)) {
83 throw std::runtime_error(std::string(__func__) +
": value out of range");
95 throw std::runtime_error(std::string(__func__) +
": value out of range");
103 if (!amount.IsCached(avoid_reuse)) {
107 return amount.Get(avoid_reuse);
115 if (
wallet.IsTxImmatureCoinBase(wtx))
124 if (wtx.
tx->vin.empty())
140 std::list<COutputEntry>& listReceived,
141 std::list<COutputEntry>& listSent,
CAmount& nFee,
145 listReceived.clear();
152 CAmount nValueOut = wtx.
tx->GetValueOut();
153 nFee = nDebit - nValueOut;
158 for (
unsigned int i = 0; i < wtx.
tx->vout.size(); ++i)
160 const CTxOut& txout = wtx.
tx->vout[i];
161 bool ismine =
wallet.IsMine(txout);
178 wallet.WalletLogPrintf(
"CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n",
187 listSent.push_back(output);
191 listReceived.push_back(output);
210 if (trusted_parents.contains(wtx.
GetHash()))
return true;
221 for (
const CTxIn& txin : wtx.
tx->vin)
225 if (parent ==
nullptr)
return false;
228 if (!
wallet.IsMine(parentOut))
return false;
230 if (trusted_parents.contains(parent->
GetHash()))
continue;
233 trusted_parents.insert(parent->
GetHash());
240 std::set<Txid> trusted_parents;
251 std::set<Txid> trusted_parents;
252 for (
const auto& [outpoint, txo] :
wallet.GetTXOs()) {
253 const CWalletTx& wtx = txo.GetWalletTx();
256 const int tx_depth{
wallet.GetTxDepthInMainChain(wtx)};
258 if (!
wallet.IsSpent(outpoint) && (allow_used_addresses || !
wallet.IsSpentKey(txo.GetTxOut().scriptPubKey))) {
260 CAmount credit_mine = txo.GetTxOut().nValue;
264 ret.m_mine_immature += credit_mine;
265 }
else if (is_trusted && tx_depth >= min_depth) {
266 ret.m_mine_trusted += credit_mine;
267 }
else if (!is_trusted && wtx.
InMempool()) {
268 ret.m_mine_untrusted_pending += credit_mine;
278 std::map<CTxDestination, CAmount> balances;
282 std::set<Txid> trusted_parents;
283 for (
const auto& [outpoint, txo] :
wallet.GetTXOs()) {
284 const CWalletTx& wtx = txo.GetWalletTx();
287 if (
wallet.IsTxImmatureCoinBase(wtx))
continue;
289 int nDepth =
wallet.GetTxDepthInMainChain(wtx);
296 CAmount n =
wallet.IsSpent(outpoint) ? 0 : txo.GetTxOut().nValue;
307 std::set< std::set<CTxDestination> > groupings;
308 std::set<CTxDestination> grouping;
310 for (
const auto& walletEntry :
wallet.mapWallet)
312 const CWalletTx& wtx = walletEntry.second;
314 if (wtx.
tx->vin.size() > 0)
316 bool any_mine =
false;
318 for (
const CTxIn& txin : wtx.
tx->vin)
325 grouping.insert(address);
332 for (
const CTxOut& txout : wtx.
tx->vout)
338 grouping.insert(txoutAddr);
341 if (grouping.size() > 0)
343 groupings.insert(grouping);
349 for (
const auto& txout : wtx.
tx->vout)
355 grouping.insert(address);
356 groupings.insert(grouping);
361 std::set< std::set<CTxDestination>* > uniqueGroupings;
362 std::map< CTxDestination, std::set<CTxDestination>* > setmap;
363 for (
const std::set<CTxDestination>& _grouping : groupings)
366 std::set< std::set<CTxDestination>* > hits;
367 std::map< CTxDestination, std::set<CTxDestination>* >::iterator it;
369 if ((it = setmap.find(address)) != setmap.end())
370 hits.insert((*it).second);
373 std::set<CTxDestination>* merged =
new std::set<CTxDestination>(_grouping);
374 for (std::set<CTxDestination>* hit : hits)
376 merged->insert(hit->begin(), hit->end());
377 uniqueGroupings.erase(hit);
380 uniqueGroupings.insert(merged);
384 setmap[element] = merged;
387 std::set< std::set<CTxDestination> >
ret;
388 for (
const std::set<CTxDestination>* uniqueGrouping : uniqueGroupings)
390 ret.insert(*uniqueGrouping);
391 delete uniqueGrouping;
CAmount CachedTxGetDebit(const CWallet &wallet, const CWalletTx &wtx, bool avoid_reuse)
bool CachedTxIsTrusted(const CWallet &wallet, const CWalletTx &wtx, std::set< Txid > &trusted_parents)
bool OutputIsChange(const CWallet &wallet, const CTxOut &txout)
void CachedTxGetAmounts(const CWallet &wallet, const CWalletTx &wtx, std::list< COutputEntry > &listReceived, std::list< COutputEntry > &listSent, CAmount &nFee, bool include_change)
std::map< CTxDestination, CAmount > GetAddressBalances(const CWallet &wallet)
bool MoneyRange(const CAmount &nValue)
bool m_is_cache_empty
This flag is true if all m_amounts caches are empty.
CAmount CachedTxGetCredit(const CWallet &wallet, const CWalletTx &wtx, bool avoid_reuse)
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
CAmount CachedTxGetChange(const CWallet &wallet, const CWalletTx &wtx)
bool CachedTxIsFromMe(const CWallet &wallet, const CWalletTx &wtx)
const std::vector< CTxIn > vin
bool IsUnspendable() const
Returns whether the script is guaranteed to fail at execution, regardless of the initial stack...
int64_t CAmount
Amount in satoshis (Can be negative)
A transaction with a bunch of additional info that only the owner cares about.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
An input of a transaction.
const std::vector< CTxOut > vout
std::string ToString() const
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
An output of a transaction.
bool isBlockConflicted() const
std::set< std::set< CTxDestination > > GetAddressGroupings(const CWallet &wallet)
#define Assume(val)
Assume is the identity function.
bool ScriptIsChange(const CWallet &wallet, const CScript &script)
const Txid & GetHash() const LIFETIMEBOUND
CAmount OutputGetCredit(const CWallet &wallet, const CTxOut &txout)
Serialized script, used inside transaction inputs and outputs.
CAmount OutputGetChange(const CWallet &wallet, const CTxOut &txout)
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
void Set(bool avoid_reuse, CAmount value)
CachableAmount m_amounts[AMOUNTTYPE_ENUM_ELEMENTS]
bool InputIsMine(const CWallet &wallet, const CTxIn &txin)
The basic transaction that is broadcasted on the network and contained in blocks. ...
static CAmount GetCachableAmount(const CWallet &wallet, const CWalletTx &wtx, CWalletTx::AmountType type, bool avoid_reuse)
CAmount TxGetChange(const CWallet &wallet, const CTransaction &tx)
bool AllInputsMine(const CWallet &wallet, const CTransaction &tx)
Returns whether all of the inputs belong to the wallet.
std::optional< bool > m_cached_from_me
CAmount TxGetCredit(const CWallet &wallet, const CTransaction &tx)