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

Method decomposeTransaction

src/qt/transactionrecord.cpp:35–209  ·  view source on GitHub ↗

* Decompose CWallet transaction to model transaction records. */

Source from the content-addressed store, hash-verified

33 * Decompose CWallet transaction to model transaction records.
34 */
35QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interfaces::WalletTx& wtx)
36{
37 QList<TransactionRecord> parts;
38 int64_t nTime = wtx.time;
39 CAmount nCredit = valueFor(wtx.credit, ::policyAsset);
40 CAmount nDebit = valueFor(wtx.debit, ::policyAsset);
41 CAmount nNet = nCredit - nDebit;
42 uint256 hash = wtx.tx->GetHash();
43 std::map<std::string, std::string> mapValue = wtx.value_map;
44
45 bool involvesWatchAddress = false;
46 isminetype fAllFromMe = ISMINE_SPENDABLE;
47 bool any_from_me = false;
48 std::set<CAsset> assets_issued_to_me_only;
49 if (wtx.is_coinbase) {
50 fAllFromMe = ISMINE_NO;
51 }
52 else
53 {
54 CAmountMap assets_received_by_me_only;
55 for (unsigned int i = 0; i < wtx.tx->vout.size(); i++)
56 {
57 if (wtx.tx->vout[i].IsFee()) {
58 continue;
59 }
60 const CAsset& asset = wtx.txout_assets[i];
61 if (assets_received_by_me_only.count(asset) && assets_received_by_me_only.at(asset) < 0) {
62 // Already known to be received by not-me
63 continue;
64 }
65 isminetype mine = wtx.txout_address_is_mine[i];
66 if (!mine) {
67 assets_received_by_me_only[asset] = -1;
68 } else {
69 assets_received_by_me_only[asset] += wtx.txout_amounts[i];
70 }
71 }
72
73 any_from_me = false;
74 for (size_t i = 0; i < wtx.tx->vin.size(); ++i)
75 {
76 /* Issuance detection */
77 isminetype mine = wtx.txin_is_mine[i];
78 if(mine & ISMINE_WATCH_ONLY) involvesWatchAddress = true;
79 if(fAllFromMe > mine) fAllFromMe = mine;
80 if (mine) any_from_me = true;
81 CAmountMap assets;
82 assets[wtx.txin_issuance_asset[i]] = wtx.txin_issuance_asset_amount[i];
83 assets[wtx.txin_issuance_token[i]] = wtx.txin_issuance_token_amount[i];
84 for (const auto& asset : assets) {
85 if (!asset.first.IsNull()) {
86 if (assets_received_by_me_only.count(asset.first) == 0) {
87 continue;
88 }
89 if (asset.second == assets_received_by_me_only.at(asset.first)) {
90 // Special case: collapse the chain of issue, send, receive to just an issue
91 assets_issued_to_me_only.insert(asset.first);
92 continue;

Callers

nothing calls this directly

Calls 11

valueForFunction · 0.85
EncodeDestinationFunction · 0.85
GetFeeMapFunction · 0.85
CAssetClass · 0.85
IsFeeMethod · 0.80
countMethod · 0.80
TransactionRecordClass · 0.70
GetHashMethod · 0.45
sizeMethod · 0.45
IsNullMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected