14 std::map<uint256, CWalletTx>::const_iterator mi =
wallet.mapWallet.find(txin.
prevout.
hash);
15 if (mi !=
wallet.mapWallet.end())
31 if (mi ==
wallet.mapWallet.end())
48 throw std::runtime_error(std::string(__func__) +
": value out of range");
50 return ((
wallet.IsMine(txout) & filter) ? txout.
nValue : 0);
60 throw std::runtime_error(std::string(__func__) +
": value out of range");
80 if (!
wallet.FindAddressBookEntry(address)) {
96 throw std::runtime_error(std::string(__func__) +
": value out of range");
108 throw std::runtime_error(std::string(__func__) +
": value out of range");
116 if (recalculate || !amount.m_cached[filter]) {
120 return amount.m_value[filter];
126 if (
wallet.IsTxImmatureCoinBase(wtx))
142 if (wtx.
tx->vin.empty())
166 if (
wallet.IsTxImmatureCoinBase(wtx) &&
wallet.IsTxInMainChain(wtx)) {
175 if (
wallet.IsTxImmatureCoinBase(wtx) &&
wallet.IsTxInMainChain(wtx)) {
188 if (
wallet.IsTxImmatureCoinBase(wtx))
198 for (
unsigned int i = 0; i < wtx.
tx->vout.size(); i++)
200 if (!
wallet.IsSpent(hashTx, i) && (allow_used_addresses || !
wallet.IsSpentKey(hashTx, i))) {
201 const CTxOut &txout = wtx.
tx->vout[i];
204 throw std::runtime_error(std::string(__func__) +
" : value out of range");
217 std::list<COutputEntry>& listReceived,
221 listReceived.clear();
228 CAmount nValueOut = wtx.
tx->GetValueOut();
229 nFee = nDebit - nValueOut;
234 for (
unsigned int i = 0; i < wtx.
tx->vout.size(); ++i)
236 const CTxOut& txout = wtx.
tx->vout[i];
247 else if (!(fIsMine & filter))
255 wallet.WalletLogPrintf(
"CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n",
264 listSent.push_back(output);
267 if (fIsMine & filter)
268 listReceived.push_back(output);
282 if (!
wallet.chain().checkFinalTx(*wtx.
tx))
return false;
283 int nDepth =
wallet.GetTxDepthInMainChain(wtx);
284 if (nDepth >= 1)
return true;
285 if (nDepth < 0)
return false;
293 for (
const CTxIn& txin : wtx.
tx->vin)
297 if (parent ==
nullptr)
return false;
302 if (trusted_parents.count(parent->
GetHash()))
continue;
305 trusted_parents.insert(parent->
GetHash());
312 std::set<uint256> trusted_parents;
323 std::set<uint256> trusted_parents;
324 for (
const auto& entry :
wallet.mapWallet)
328 const int tx_depth{
wallet.GetTxDepthInMainChain(wtx)};
331 if (is_trusted && tx_depth >= min_depth) {
335 if (!is_trusted && tx_depth == 0 && wtx.
InMempool()) {
348 std::map<CTxDestination, CAmount> balances;
352 std::set<uint256> trusted_parents;
353 for (
const auto& walletEntry :
wallet.mapWallet)
355 const CWalletTx& wtx = walletEntry.second;
360 if (
wallet.IsTxImmatureCoinBase(wtx))
363 int nDepth =
wallet.GetTxDepthInMainChain(wtx);
367 for (
unsigned int i = 0; i < wtx.
tx->vout.size(); i++)
370 if (!
wallet.IsMine(wtx.
tx->vout[i]))
375 CAmount n =
wallet.IsSpent(walletEntry.first, i) ? 0 : wtx.
tx->vout[i].nValue;
387 std::set< std::set<CTxDestination> > groupings;
388 std::set<CTxDestination> grouping;
390 for (
const auto& walletEntry :
wallet.mapWallet)
392 const CWalletTx& wtx = walletEntry.second;
394 if (wtx.
tx->vin.size() > 0)
396 bool any_mine =
false;
398 for (
const CTxIn& txin : wtx.
tx->vin)
405 grouping.insert(address);
412 for (
const CTxOut& txout : wtx.
tx->vout)
418 grouping.insert(txoutAddr);
421 if (grouping.size() > 0)
423 groupings.insert(grouping);
429 for (
const auto& txout : wtx.
tx->vout)
435 grouping.insert(address);
436 groupings.insert(grouping);
441 std::set< std::set<CTxDestination>* > uniqueGroupings;
442 std::map< CTxDestination, std::set<CTxDestination>* > setmap;
443 for (std::set<CTxDestination> _grouping : groupings)
446 std::set< std::set<CTxDestination>* > hits;
447 std::map< CTxDestination, std::set<CTxDestination>* >::iterator it;
449 if ((it = setmap.find(address)) != setmap.end())
450 hits.insert((*it).second);
453 std::set<CTxDestination>* merged =
new std::set<CTxDestination>(_grouping);
454 for (std::set<CTxDestination>* hit : hits)
456 merged->insert(hit->begin(), hit->end());
457 uniqueGroupings.erase(hit);
460 uniqueGroupings.insert(merged);
464 setmap[element] = merged;
467 std::set< std::set<CTxDestination> > ret;
468 for (
const std::set<CTxDestination>* uniqueGrouping : uniqueGroupings)
470 ret.insert(*uniqueGrouping);
471 delete uniqueGrouping;
bool MoneyRange(const CAmount &nValue)
int64_t CAmount
Amount in satoshis (Can be negative)
Serialized script, used inside transaction inputs and outputs.
bool IsUnspendable() const
Returns whether the script is guaranteed to fail at execution, regardless of the initial stack.
The basic transaction that is broadcasted on the network and contained in blocks.
const std::vector< CTxOut > vout
const std::vector< CTxIn > vin
An input of a transaction.
An output of a transaction.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
A transaction with a bunch of additional info that only the owner cares about.
const uint256 & GetHash() const
CachableAmount m_amounts[AMOUNTTYPE_ENUM_ELEMENTS]
bool m_is_cache_empty
This flag is true if all m_amounts caches are empty.
std::string ToString() const
isminetype
IsMine() return codes, which depend on ScriptPubKeyMan implementation.
bool CachedTxIsFromMe(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
std::set< std::set< CTxDestination > > GetAddressGroupings(const CWallet &wallet)
CAmount OutputGetCredit(const CWallet &wallet, const CTxOut &txout, const isminefilter &filter)
CAmount TxGetCredit(const CWallet &wallet, const CTransaction &tx, const isminefilter &filter)
CAmount TxGetChange(const CWallet &wallet, const CTransaction &tx)
std::map< CTxDestination, CAmount > GetAddressBalances(const CWallet &wallet)
bool ScriptIsChange(const CWallet &wallet, const CScript &script)
CAmount CachedTxGetAvailableCredit(const CWallet &wallet, const CWalletTx &wtx, bool fUseCache, const isminefilter &filter)
void CachedTxGetAmounts(const CWallet &wallet, const CWalletTx &wtx, std::list< COutputEntry > &listReceived, std::list< COutputEntry > &listSent, CAmount &nFee, const isminefilter &filter)
CAmount CachedTxGetImmatureWatchOnlyCredit(const CWallet &wallet, const CWalletTx &wtx, const bool fUseCache)
CAmount CachedTxGetImmatureCredit(const CWallet &wallet, const CWalletTx &wtx, bool fUseCache)
static CAmount GetCachableAmount(const CWallet &wallet, const CWalletTx &wtx, CWalletTx::AmountType type, const isminefilter &filter, bool recalculate=false)
bool AllInputsMine(const CWallet &wallet, const CTransaction &tx, const isminefilter &filter)
Returns whether all of the inputs match the filter.
bool OutputIsChange(const CWallet &wallet, const CTxOut &txout)
CAmount OutputGetChange(const CWallet &wallet, const CTxOut &txout)
CAmount CachedTxGetDebit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
filter decides which addresses will count towards the debit
CAmount CachedTxGetChange(const CWallet &wallet, const CWalletTx &wtx)
CAmount CachedTxGetCredit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
bool CachedTxIsTrusted(const CWallet &wallet, const CWalletTx &wtx, std::set< uint256 > &trusted_parents)
isminetype InputIsMine(const CWallet &wallet, const CTxIn &txin)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
CAmount m_mine_immature
Immature coinbases in the main chain.
CAmount m_watchonly_untrusted_pending
CAmount m_mine_trusted
Trusted, at depth=GetBalance.min_depth or more.
CAmount m_watchonly_immature
CAmount m_watchonly_trusted
CAmount m_mine_untrusted_pending
Untrusted, but in mempool (pending)
void Set(isminefilter filter, CAmount value)
CAmount m_value[ISMINE_ENUM_ELEMENTS]
std::bitset< ISMINE_ENUM_ELEMENTS > m_cached
@ WALLET_FLAG_AVOID_REUSE