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);
269 for (
const CTxIn& txin : wtx.
tx->vin)
273 if (parent ==
nullptr)
return false;
278 if (trusted_parents.count(parent->
GetHash()))
continue;
281 trusted_parents.insert(parent->
GetHash());
288 std::set<uint256> trusted_parents;
299 std::set<uint256> trusted_parents;
300 for (
const auto& entry :
wallet.mapWallet)
304 const int tx_depth{
wallet.GetTxDepthInMainChain(wtx)};
307 if (is_trusted && tx_depth >= min_depth) {
308 ret.m_mine_trusted += tx_credit_mine;
309 ret.m_watchonly_trusted += tx_credit_watchonly;
311 if (!is_trusted && tx_depth == 0 && wtx.
InMempool()) {
312 ret.m_mine_untrusted_pending += tx_credit_mine;
313 ret.m_watchonly_untrusted_pending += tx_credit_watchonly;
324 std::map<CTxDestination, CAmount> balances;
328 std::set<uint256> trusted_parents;
329 for (
const auto& walletEntry :
wallet.mapWallet)
331 const CWalletTx& wtx = walletEntry.second;
336 if (
wallet.IsTxImmatureCoinBase(wtx))
339 int nDepth =
wallet.GetTxDepthInMainChain(wtx);
343 for (
unsigned int i = 0; i < wtx.
tx->vout.size(); i++) {
344 const auto& output = wtx.
tx->vout[i];
346 if (!
wallet.IsMine(output))
363 std::set< std::set<CTxDestination> > groupings;
364 std::set<CTxDestination> grouping;
366 for (
const auto& walletEntry :
wallet.mapWallet)
368 const CWalletTx& wtx = walletEntry.second;
370 if (wtx.
tx->vin.size() > 0)
372 bool any_mine =
false;
374 for (
const CTxIn& txin : wtx.
tx->vin)
381 grouping.insert(address);
388 for (
const CTxOut& txout : wtx.
tx->vout)
394 grouping.insert(txoutAddr);
397 if (grouping.size() > 0)
399 groupings.insert(grouping);
405 for (
const auto& txout : wtx.
tx->vout)
411 grouping.insert(address);
412 groupings.insert(grouping);
417 std::set< std::set<CTxDestination>* > uniqueGroupings;
418 std::map< CTxDestination, std::set<CTxDestination>* > setmap;
419 for (
const std::set<CTxDestination>& _grouping : groupings)
422 std::set< std::set<CTxDestination>* > hits;
423 std::map< CTxDestination, std::set<CTxDestination>* >::iterator it;
425 if ((it = setmap.find(address)) != setmap.end())
426 hits.insert((*it).second);
429 std::set<CTxDestination>* merged =
new std::set<CTxDestination>(_grouping);
430 for (std::set<CTxDestination>* hit : hits)
432 merged->insert(hit->begin(), hit->end());
433 uniqueGroupings.erase(hit);
436 uniqueGroupings.insert(merged);
440 setmap[element] = merged;
443 std::set< std::set<CTxDestination> >
ret;
444 for (
const std::set<CTxDestination>* uniqueGrouping : uniqueGroupings)
446 ret.insert(*uniqueGrouping);
447 delete uniqueGrouping;
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, 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