16 if (prev && txin.
prevout.
n < prev->
tx->vout.size()) {
34 throw std::runtime_error(std::string(__func__) +
": value out of range");
36 return ((
wallet.IsMine(txout) & filter) ? txout.
nValue : 0);
46 throw std::runtime_error(std::string(__func__) +
": value out of range");
66 if (!
wallet.FindAddressBookEntry(address)) {
82 throw std::runtime_error(std::string(__func__) +
": value out of range");
94 throw std::runtime_error(std::string(__func__) +
": value out of range");
102 if (!amount.m_cached[filter]) {
106 return amount.m_value[filter];
114 if (
wallet.IsTxImmatureCoinBase(wtx))
119 if (get_amount_filter) {
128 if (wtx.
tx->vin.empty())
133 if (get_amount_filter) {
167 if (
wallet.IsTxImmatureCoinBase(wtx))
177 for (
unsigned int i = 0; i < wtx.
tx->vout.size(); i++) {
178 const CTxOut& txout = wtx.
tx->vout[i];
182 throw std::runtime_error(std::string(__func__) +
" : value out of range");
195 std::list<COutputEntry>& listReceived,
200 listReceived.clear();
207 CAmount nValueOut = wtx.
tx->GetValueOut();
208 nFee = nDebit - nValueOut;
213 for (
unsigned int i = 0; i < wtx.
tx->vout.size(); ++i)
215 const CTxOut& txout = wtx.
tx->vout[i];
225 else if (!(fIsMine & filter))
233 wallet.WalletLogPrintf(
"CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n",
242 listSent.push_back(output);
245 if (fIsMine & filter)
246 listReceived.push_back(output);
268 for (
const CTxIn& txin : wtx.
tx->vin)
272 if (parent ==
nullptr)
return false;
277 if (trusted_parents.count(parent->
GetHash()))
continue;
280 trusted_parents.insert(parent->
GetHash());
287 std::set<uint256> trusted_parents;
298 std::set<uint256> trusted_parents;
299 for (
const auto& entry :
wallet.mapWallet)
303 const int tx_depth{
wallet.GetTxDepthInMainChain(wtx)};
306 if (is_trusted && tx_depth >= min_depth) {
307 ret.m_mine_trusted += tx_credit_mine;
308 ret.m_watchonly_trusted += tx_credit_watchonly;
310 if (!is_trusted && tx_depth == 0 && wtx.
InMempool()) {
311 ret.m_mine_untrusted_pending += tx_credit_mine;
312 ret.m_watchonly_untrusted_pending += tx_credit_watchonly;
323 std::map<CTxDestination, CAmount> balances;
327 std::set<uint256> trusted_parents;
328 for (
const auto& walletEntry :
wallet.mapWallet)
330 const CWalletTx& wtx = walletEntry.second;
335 if (
wallet.IsTxImmatureCoinBase(wtx))
338 int nDepth =
wallet.GetTxDepthInMainChain(wtx);
342 for (
unsigned int i = 0; i < wtx.
tx->vout.size(); i++) {
343 const auto& output = wtx.
tx->vout[i];
345 if (!
wallet.IsMine(output))
362 std::set< std::set<CTxDestination> > groupings;
363 std::set<CTxDestination> grouping;
365 for (
const auto& walletEntry :
wallet.mapWallet)
367 const CWalletTx& wtx = walletEntry.second;
369 if (wtx.
tx->vin.size() > 0)
371 bool any_mine =
false;
373 for (
const CTxIn& txin : wtx.
tx->vin)
380 grouping.insert(address);
387 for (
const CTxOut& txout : wtx.
tx->vout)
393 grouping.insert(txoutAddr);
396 if (grouping.size() > 0)
398 groupings.insert(grouping);
404 for (
const auto& txout : wtx.
tx->vout)
410 grouping.insert(address);
411 groupings.insert(grouping);
416 std::set< std::set<CTxDestination>* > uniqueGroupings;
417 std::map< CTxDestination, std::set<CTxDestination>* > setmap;
418 for (
const std::set<CTxDestination>& _grouping : groupings)
421 std::set< std::set<CTxDestination>* > hits;
422 std::map< CTxDestination, std::set<CTxDestination>* >::iterator it;
424 if ((it = setmap.find(address)) != setmap.end())
425 hits.insert((*it).second);
428 std::set<CTxDestination>* merged =
new std::set<CTxDestination>(_grouping);
429 for (std::set<CTxDestination>* hit : hits)
431 merged->insert(hit->begin(), hit->end());
432 uniqueGroupings.erase(hit);
435 uniqueGroupings.insert(merged);
439 setmap[element] = merged;
442 std::set< std::set<CTxDestination> >
ret;
443 for (
const std::set<CTxDestination>* uniqueGrouping : uniqueGroupings)
445 ret.insert(*uniqueGrouping);
446 delete uniqueGrouping;
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
bool MoneyRange(const CAmount &nValue)
int64_t CAmount
Amount in satoshis (Can be negative)
An outpoint - a combination of a transaction hash and an index n into its vout.
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.
std::string ToString() const
static transaction_identifier FromUint256(const uint256 &id)
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.
bool isBlockConflicted() const
const Txid & GetHash() const LIFETIMEBOUND
CachableAmount m_amounts[AMOUNTTYPE_ENUM_ELEMENTS]
bool m_is_cache_empty
This flag is true if all m_amounts caches are empty.
bool OutputIsChange(const CWallet &wallet, const CTxOut &txout)
CAmount CachedTxGetAvailableCredit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
CAmount TxGetChange(const CWallet &wallet, const CTransaction &tx)
bool ScriptIsChange(const CWallet &wallet, const CScript &script)
bool CachedTxIsFromMe(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
CAmount CachedTxGetDebit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
filter decides which addresses will count towards the debit
void CachedTxGetAmounts(const CWallet &wallet, const CWalletTx &wtx, std::list< COutputEntry > &listReceived, std::list< COutputEntry > &listSent, CAmount &nFee, const isminefilter &filter, bool include_change)
CAmount OutputGetCredit(const CWallet &wallet, const CTxOut &txout, const isminefilter &filter)
CAmount CachedTxGetCredit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
bool CachedTxIsTrusted(const CWallet &wallet, const CWalletTx &wtx, std::set< uint256 > &trusted_parents)
CAmount TxGetCredit(const CWallet &wallet, const CTransaction &tx, const isminefilter &filter)
std::underlying_type< isminetype >::type isminefilter
used for bitflags of isminetype
CAmount OutputGetChange(const CWallet &wallet, const CTxOut &txout)
isminetype
IsMine() return codes, which depend on ScriptPubKeyMan implementation.
CAmount CachedTxGetChange(const CWallet &wallet, const CWalletTx &wtx)
bool AllInputsMine(const CWallet &wallet, const CTransaction &tx, const isminefilter &filter)
Returns whether all of the inputs match the filter.
isminetype InputIsMine(const CWallet &wallet, const CTxIn &txin)
static CAmount GetCachableAmount(const CWallet &wallet, const CWalletTx &wtx, CWalletTx::AmountType type, const isminefilter &filter)
CAmount CachedTxGetImmatureCredit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
std::map< CTxDestination, CAmount > GetAddressBalances(const CWallet &wallet)
@ WALLET_FLAG_AVOID_REUSE
std::set< std::set< CTxDestination > > GetAddressGroupings(const CWallet &wallet)
void Set(isminefilter filter, CAmount value)
CAmount m_value[ISMINE_ENUM_ELEMENTS]
std::bitset< ISMINE_ENUM_ELEMENTS > m_cached