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) {
152 if (
wallet.IsTxImmatureCoinBase(wtx) &&
wallet.IsTxInMainChain(wtx)) {
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);
259 int nDepth =
wallet.GetTxDepthInMainChain(wtx);
260 if (nDepth >= 1)
return true;
261 if (nDepth < 0)
return false;
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;
isminetype InputIsMine(const CWallet &wallet, const CTxIn &txin)
bool OutputIsChange(const CWallet &wallet, const CTxOut &txout)
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.
static CAmount GetCachableAmount(const CWallet &wallet, const CWalletTx &wtx, CWalletTx::AmountType type, const isminefilter &filter)
CAmount TxGetCredit(const CWallet &wallet, const CTransaction &tx, const isminefilter &filter)
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
CAmount CachedTxGetChange(const CWallet &wallet, const CWalletTx &wtx)
CAmount m_value[ISMINE_ENUM_ELEMENTS]
const std::vector< CTxIn > vin
bool IsUnspendable() const
Returns whether the script is guaranteed to fail at execution, regardless of the initial stack...
void CachedTxGetAmounts(const CWallet &wallet, const CWalletTx &wtx, std::list< COutputEntry > &listReceived, std::list< COutputEntry > &listSent, CAmount &nFee, const isminefilter &filter, bool include_change)
int64_t CAmount
Amount in satoshis (Can be negative)
A transaction with a bunch of additional info that only the owner cares about.
std::underlying_type< isminetype >::type isminefilter
used for bitflags of isminetype
CAmount CachedTxGetCredit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
std::bitset< ISMINE_ENUM_ELEMENTS > m_cached
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
An input of a transaction.
bool CachedTxIsTrusted(const CWallet &wallet, const CWalletTx &wtx, std::set< uint256 > &trusted_parents)
isminetype
IsMine() return codes, which depend on ScriptPubKeyMan implementation.
const std::vector< CTxOut > vout
CAmount CachedTxGetImmatureCredit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
An output of a transaction.
std::string ToString() const
An outpoint - a combination of a transaction hash and an index n into its vout.
std::set< std::set< CTxDestination > > GetAddressGroupings(const CWallet &wallet)
bool ScriptIsChange(const CWallet &wallet, const CScript &script)
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
CAmount CachedTxGetAvailableCredit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
Serialized script, used inside transaction inputs and outputs.
CAmount OutputGetChange(const CWallet &wallet, const CTxOut &txout)
const uint256 & GetHash() const
CachableAmount m_amounts[AMOUNTTYPE_ENUM_ELEMENTS]
The basic transaction that is broadcasted on the network and contained in blocks. ...
void Set(isminefilter filter, CAmount value)
bool AllInputsMine(const CWallet &wallet, const CTransaction &tx, const isminefilter &filter)
Returns whether all of the inputs match the filter.
CAmount TxGetChange(const CWallet &wallet, const CTransaction &tx)
CAmount OutputGetCredit(const CWallet &wallet, const CTxOut &txout, const isminefilter &filter)
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