@@ -52,16 +52,35 @@ bool AllInputsMine(const CWallet& wallet, const CTransaction& tx, const isminefi
5252}
5353
5454CAmountMap OutputGetCredit (const CWallet& wallet, const CTransaction& tx, const size_t out_index, const isminefilter& filter) {
55+ std::map<uint256, CWalletTx>::const_iterator mi = wallet.mapWallet .find (tx.GetHash ());
56+ if (mi != wallet.mapWallet .end ())
57+ {
58+ const CWalletTx& wtx = (*mi).second ;
59+ if (out_index < wtx.tx ->vout .size () && wallet.IsMine (wtx.tx ->vout [out_index]) & filter) {
60+ CAmountMap amounts;
61+ amounts[wtx.GetOutputAsset (wallet, out_index)] = std::max<CAmount>(0 , wtx.GetOutputValueOut (wallet, out_index));
62+ return amounts;
63+ }
64+ }
65+ return CAmountMap ();
66+ }
67+
68+ CAmountMap TxGetCredit (const CWallet& wallet, const CWalletTx& wtx, const isminefilter& filter) {
5569 CAmountMap nCredit;
56- if (wallet.IsMine (tx.vout [out_index]) & filter) {
57- CWalletTx wtx (MakeTransactionRef (std::move (tx)), TxStateInactive{});
58- CAmount credit = std::max<CAmount>(0 , wtx.GetOutputValueOut (wallet, out_index));
59- if (!MoneyRange (credit))
60- throw std::runtime_error (std::string (__func__) + " : value out of range" );
61-
62- nCredit[wtx.GetOutputAsset (wallet, out_index)] += credit;
63- if (!MoneyRange (nCredit))
64- throw std::runtime_error (std::string (__func__) + " : value out of range" );
70+ {
71+ LOCK (wallet.cs_wallet );
72+
73+ for (unsigned int i = 0 ; i < wtx.tx ->vout .size (); ++i) {
74+ if (wallet.IsMine (wtx.tx ->vout [i]) & filter) {
75+ CAmount credit = std::max<CAmount>(0 , wtx.GetOutputValueOut (wallet, i));
76+ if (!MoneyRange (credit))
77+ throw std::runtime_error (std::string (__func__) + " : value out of range" );
78+
79+ nCredit[wtx.GetOutputAsset (wallet, i)] += credit;
80+ if (!MoneyRange (nCredit))
81+ throw std::runtime_error (std::string (__func__) + " : value out of range" );
82+ }
83+ }
6584 }
6685 return nCredit;
6786}
@@ -126,7 +145,7 @@ static CAmountMap GetCachableAmount(const CWallet& wallet, const CWalletTx& wtx,
126145{
127146 auto & amount = wtx.m_amounts [type];
128147 if (recalculate || !amount.m_cached [filter]) {
129- amount.Set (filter, type == CWalletTx::DEBIT ? wallet.GetDebit (*wtx.tx , filter) : TxGetCredit (wallet, * wtx. tx , filter));
148+ amount.Set (filter, type == CWalletTx::DEBIT ? wallet.GetDebit (*wtx.tx , filter) : TxGetCredit (wallet, wtx, filter));
130149 wtx.m_is_cache_empty = false ;
131150 }
132151 return amount.m_value [filter];
@@ -149,26 +168,6 @@ CAmountMap CachedTxGetCredit(const CWallet& wallet, const CWalletTx& wtx, const
149168 return credit;
150169}
151170
152- CAmountMap TxGetCredit (const CWallet& wallet, const CTransaction& tx, const isminefilter& filter)
153- {
154- {
155- LOCK (wallet.cs_wallet );
156- std::map<uint256, CWalletTx>::const_iterator mi = wallet.mapWallet .find (tx.GetHash ());
157- if (mi != wallet.mapWallet .end ())
158- {
159- const CWalletTx& wtx = (*mi).second ;
160- for (size_t i = 0 ; i < wtx.tx ->vout .size (); ++i) {
161- if (wallet.IsMine (wtx.tx ->vout [i]) & filter) {
162- CAmountMap amounts;
163- amounts[wtx.GetOutputAsset (wallet, i)] = std::max<CAmount>(0 , wtx.GetOutputValueOut (wallet, i));
164- return amounts;
165- }
166- }
167- }
168- }
169- return CAmountMap ();
170- }
171-
172171CAmountMap CachedTxGetDebit (const CWallet& wallet, const CWalletTx& wtx, const isminefilter& filter)
173172 {
174173 if (wtx.tx ->vin .empty ())
0 commit comments