MCPcopy Create free account
hub / github.com/ElementsProject/elements / CachedTxGetAmounts

Function CachedTxGetAmounts

src/wallet/receive.cpp:257–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255}
256
257void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx,
258 std::list<COutputEntry>& listReceived,
259 std::list<COutputEntry>& listSent, CAmount& nFee, const isminefilter& filter)
260{
261 nFee = 0;
262 listReceived.clear();
263 listSent.clear();
264
265 // Compute fee:
266 CAmountMap mapDebit = CachedTxGetDebit(wallet, wtx, filter);
267 if (mapDebit > CAmountMap()) // debit>0 means we signed/sent this transaction
268 {
269 nFee = -GetFeeMap(*wtx.tx)[::policyAsset];
270 }
271
272 LOCK(wallet.cs_wallet);
273 // Sent/received.
274 for (unsigned int i = 0; i < wtx.tx->vout.size(); ++i)
275 {
276 const CTxOut& txout = wtx.tx->vout[i];
277 CAmount output_value = wtx.GetOutputValueOut(wallet, i);
278 // Don't list unknown assets
279 isminetype fIsMine = output_value != -1 ? wallet.IsMine(txout) : ISMINE_NO;
280 // Only need to handle txouts if AT LEAST one of these is true:
281 // 1) they debit from us (sent)
282 // 2) the output is to us (received)
283 if (mapDebit > CAmountMap())
284 {
285 // Don't report 'change' txouts
286 if (OutputIsChange(wallet, txout))
287 continue;
288 }
289 else if (!(fIsMine & filter))
290 continue;
291
292 // In either case, we need to get the destination address
293 CTxDestination address;
294
295 if (!ExtractDestination(txout.scriptPubKey, address) && !txout.scriptPubKey.IsUnspendable())
296 {
297 wallet.WalletLogPrintf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n",
298 wtx.GetHash().ToString());
299 address = CNoDestination();
300 }
301
302 COutputEntry output = {address, output_value, (int)i, wtx.GetOutputAsset(wallet, i), wtx.GetOutputAmountBlindingFactor(wallet, i), wtx.GetOutputAssetBlindingFactor(wallet, i)};
303
304 // If we are debited by the transaction, add the output as a "sent" entry
305 if (mapDebit > CAmountMap() && !txout.IsFee())
306 listSent.push_back(output);
307
308 // If we are receiving the output, add it as a "received" entry
309 if (fIsMine & filter)
310 listReceived.push_back(output);
311 }
312
313}
314

Callers 1

transactions.cppFile · 0.85

Calls 15

CachedTxGetDebitFunction · 0.85
GetFeeMapFunction · 0.85
OutputIsChangeFunction · 0.85
ExtractDestinationFunction · 0.85
CNoDestinationClass · 0.85
GetOutputValueOutMethod · 0.80
IsUnspendableMethod · 0.80
GetOutputAssetMethod · 0.80
IsFeeMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected