MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / CachedTxGetAmounts

Function CachedTxGetAmounts

src/wallet/receive.cpp:139–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137}
138
139void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx,
140 std::list<COutputEntry>& listReceived,
141 std::list<COutputEntry>& listSent, CAmount& nFee,
142 bool include_change)
143{
144 nFee = 0;
145 listReceived.clear();
146 listSent.clear();
147
148 // Compute fee:
149 CAmount nDebit = CachedTxGetDebit(wallet, wtx, /*avoid_reuse=*/false);
150 if (nDebit > 0) // debit>0 means we signed/sent this transaction
151 {
152 CAmount nValueOut = wtx.tx->GetValueOut();
153 nFee = nDebit - nValueOut;
154 }
155
156 LOCK(wallet.cs_wallet);
157 // Sent/received.
158 for (unsigned int i = 0; i < wtx.tx->vout.size(); ++i)
159 {
160 const CTxOut& txout = wtx.tx->vout[i];
161 bool ismine = wallet.IsMine(txout);
162 // Only need to handle txouts if AT LEAST one of these is true:
163 // 1) they debit from us (sent)
164 // 2) the output is to us (received)
165 if (nDebit > 0)
166 {
167 if (!include_change && OutputIsChange(wallet, txout))
168 continue;
169 }
170 else if (!ismine)
171 continue;
172
173 // In either case, we need to get the destination address
174 CTxDestination address;
175
176 if (!ExtractDestination(txout.scriptPubKey, address) && !txout.scriptPubKey.IsUnspendable())
177 {
178 wallet.WalletLogPrintf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n",
179 wtx.GetHash().ToString());
180 address = CNoDestination();
181 }
182
183 COutputEntry output = {address, txout.nValue, (int)i};
184
185 // If we are debited by the transaction, add the output as a "sent" entry
186 if (nDebit > 0)
187 listSent.push_back(output);
188
189 // If we are receiving the output, add it as a "received" entry
190 if (ismine)
191 listReceived.push_back(output);
192 }
193
194}
195
196bool CachedTxIsFromMe(const CWallet& wallet, const CWalletTx& wtx)

Callers 1

transactions.cppFile · 0.85

Calls 13

CachedTxGetDebitFunction · 0.85
OutputIsChangeFunction · 0.85
ExtractDestinationFunction · 0.85
CNoDestinationClass · 0.85
GetValueOutMethod · 0.80
IsUnspendableMethod · 0.80
clearMethod · 0.45
sizeMethod · 0.45
IsMineMethod · 0.45
WalletLogPrintfMethod · 0.45
ToStringMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected