13 std::map<TxId, CWalletTx>::const_iterator mi =
15 if (mi !=
wallet.mapWallet.end()) {
31 if (mi ==
wallet.mapWallet.end()) {
54 throw std::runtime_error(std::string(__func__) +
55 ": value out of range");
67 throw std::runtime_error(std::string(__func__) +
68 ": value out of range");
85 if (
wallet.IsMine(script)) {
90 if (!
wallet.FindAddressBookEntry(address)) {
105 throw std::runtime_error(std::string(__func__) +
106 ": value out of range");
117 throw std::runtime_error(std::string(__func__) +
118 ": value out of range");
128 bool recalculate =
false) {
130 if (recalculate || !amount.m_cached[filter]) {
136 return amount.m_value[filter];
145 if (
wallet.IsTxImmatureCoinBase(wtx)) {
166 if (wtx.
tx->vin.empty()) {
196 if (
wallet.IsTxImmatureCoinBase(wtx) &&
wallet.IsTxInMainChain(wtx)) {
206 const bool fUseCache) {
209 if (
wallet.IsTxImmatureCoinBase(wtx) &&
wallet.IsTxInMainChain(wtx)) {
228 if (
wallet.IsTxImmatureCoinBase(wtx)) {
232 if (fUseCache && allow_cache &&
237 bool allow_used_addresses =
242 for (uint32_t i = 0; i < wtx.
tx->vout.size(); i++) {
244 (allow_used_addresses || !
wallet.IsSpentKey(txid, i))) {
245 const CTxOut &txout = wtx.
tx->vout[i];
248 throw std::runtime_error(std::string(__func__) +
249 " : value out of range");
263 std::list<COutputEntry> &listReceived,
264 std::list<COutputEntry> &listSent,
Amount &nFee,
267 listReceived.clear();
274 Amount nValueOut = wtx.
tx->GetValueOut();
275 nFee = nDebit - nValueOut;
280 for (
unsigned int i = 0; i < wtx.
tx->vout.size(); ++i) {
281 const CTxOut &txout = wtx.
tx->vout[i];
291 }
else if (!(fIsMine & filter)) {
300 wallet.WalletLogPrintf(
"CWalletTx::GetAmounts: Unknown transaction "
301 "type found, txid %s\n",
311 listSent.push_back(output);
315 if (fIsMine & filter) {
316 listReceived.push_back(output);
327 std::set<TxId> &trusted_parents) {
330 int nDepth =
wallet.GetTxDepthInMainChain(wtx);
340 if (!
wallet.m_spend_zero_conf_change ||
352 for (
const CTxIn &txin : wtx.
tx->vin) {
355 if (parent ==
nullptr) {
365 if (trusted_parents.count(parent->
GetId())) {
372 trusted_parents.insert(parent->
GetId());
379 std::set<TxId> trusted_parents;
389 std::set<TxId> trusted_parents;
390 for (
const auto &entry :
wallet.mapWallet) {
393 const int tx_depth{
wallet.GetTxDepthInMainChain(wtx)};
398 if (is_trusted && tx_depth >= min_depth) {
402 if (!is_trusted && tx_depth == 0 && wtx.
InMempool()) {
414 std::map<CTxDestination, Amount> balances;
417 std::set<TxId> trusted_parents;
418 for (
const auto &walletEntry :
wallet.mapWallet) {
419 const CWalletTx &wtx = walletEntry.second;
425 if (
wallet.IsTxImmatureCoinBase(wtx)) {
429 int nDepth =
wallet.GetTxDepthInMainChain(wtx);
434 for (uint32_t i = 0; i < wtx.
tx->vout.size(); i++) {
436 if (!
wallet.IsMine(wtx.
tx->vout[i])) {
445 : wtx.
tx->vout[i].nValue;
455 std::set<std::set<CTxDestination>> groupings;
456 std::set<CTxDestination> grouping;
458 for (
const auto &walletEntry :
wallet.mapWallet) {
459 const CWalletTx &wtx = walletEntry.second;
461 if (wtx.
tx->vin.size() > 0) {
462 bool any_mine =
false;
464 for (
const auto &txin : wtx.
tx->vin) {
472 wallet.mapWallet.at(txin.prevout.GetTxId())
473 .tx->vout[txin.prevout.GetN()]
479 grouping.insert(address);
485 for (
const auto &txout : wtx.
tx->vout) {
493 grouping.insert(txoutAddr);
498 if (grouping.size() > 0) {
499 groupings.insert(grouping);
505 for (
const auto &txout : wtx.
tx->vout) {
506 if (
wallet.IsMine(txout)) {
512 grouping.insert(address);
513 groupings.insert(grouping);
520 std::set<std::set<CTxDestination> *> uniqueGroupings;
522 std::map<CTxDestination, std::set<CTxDestination> *> setmap;
523 for (std::set<CTxDestination> _grouping : groupings) {
525 std::set<std::set<CTxDestination> *> hits;
526 std::map<CTxDestination, std::set<CTxDestination> *>::iterator it;
528 if ((it = setmap.find(address)) != setmap.end()) {
529 hits.insert((*it).second);
534 std::set<CTxDestination> *merged =
535 new std::set<CTxDestination>(_grouping);
536 for (std::set<CTxDestination> *hit : hits) {
537 merged->insert(hit->begin(), hit->end());
538 uniqueGroupings.erase(hit);
541 uniqueGroupings.insert(merged);
545 setmap[element] = merged;
549 std::set<std::set<CTxDestination>> ret;
550 for (
const std::set<CTxDestination> *uniqueGrouping : uniqueGroupings) {
551 ret.insert(*uniqueGrouping);
552 delete uniqueGrouping;
bool MoneyRange(const Amount nValue)
An outpoint - a combination of a transaction hash and an index n into its vout.
const TxId & GetTxId() const
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.
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.
Amount CachedTxGetImmatureCredit(const CWallet &wallet, const CWalletTx &wtx, bool fUseCache)
std::set< std::set< CTxDestination > > GetAddressGroupings(const CWallet &wallet)
bool CachedTxIsFromMe(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
Amount OutputGetChange(const CWallet &wallet, const CTxOut &txout)
Amount CachedTxGetAvailableCredit(const CWallet &wallet, const CWalletTx &wtx, bool fUseCache, const isminefilter &filter)
Amount CachedTxGetChange(const CWallet &wallet, const CWalletTx &wtx)
Amount CachedTxGetDebit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
filter decides which addresses will count towards the debit
bool ScriptIsChange(const CWallet &wallet, const CScript &script)
Amount TxGetCredit(const CWallet &wallet, const CTransaction &tx, const isminefilter &filter)
Amount CachedTxGetImmatureWatchOnlyCredit(const CWallet &wallet, const CWalletTx &wtx, const bool fUseCache)
std::map< CTxDestination, Amount > GetAddressBalances(const CWallet &wallet)
void CachedTxGetAmounts(const CWallet &wallet, const CWalletTx &wtx, std::list< COutputEntry > &listReceived, std::list< COutputEntry > &listSent, Amount &nFee, const isminefilter &filter)
Amount OutputGetCredit(const CWallet &wallet, const CTxOut &txout, const isminefilter &filter)
Amount TxGetChange(const CWallet &wallet, const CTransaction &tx)
bool AllInputsMine(const CWallet &wallet, const CTransaction &tx, const isminefilter &filter)
Returns whether all of the inputs match the filter.
Amount CachedTxGetCredit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
bool OutputIsChange(const CWallet &wallet, const CTxOut &txout)
bool CachedTxIsTrusted(const CWallet &wallet, const CWalletTx &wtx, std::set< TxId > &trusted_parents)
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
static Amount GetCachableAmount(const CWallet &wallet, const CWalletTx &wtx, CWalletTx::AmountType type, const isminefilter &filter, bool recalculate=false)
isminetype InputIsMine(const CWallet &wallet, const CTxIn &txin)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
boost::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
static constexpr Amount zero() noexcept
Amount m_mine_immature
Immature coinbases in the main chain.
Amount m_watchonly_trusted
Amount m_mine_untrusted_pending
Untrusted, but in mempool (pending)
Amount m_watchonly_immature
Amount m_watchonly_untrusted_pending
Amount m_mine_trusted
Trusted, at depth=GetBalance.min_depth or more.
Amount m_value[ISMINE_ENUM_ELEMENTS]
void Set(isminefilter filter, Amount value)
std::bitset< ISMINE_ENUM_ELEMENTS > m_cached
A TxId is the identifier of a transaction.
@ WALLET_FLAG_AVOID_REUSE