* Decompose CWallet transaction to model transaction records. */
| 26 | * Decompose CWallet transaction to model transaction records. |
| 27 | */ |
| 28 | QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interfaces::WalletTx& wtx) |
| 29 | { |
| 30 | QList<TransactionRecord> parts; |
| 31 | int64_t nTime = wtx.time; |
| 32 | CAmount nCredit = wtx.credit; |
| 33 | CAmount nDebit = wtx.debit; |
| 34 | CAmount nNet = nCredit - nDebit; |
| 35 | uint256 hash = wtx.tx->GetHash(); |
| 36 | std::map<std::string, std::string> mapValue = wtx.value_map; |
| 37 | |
| 38 | if (nNet > 0 || wtx.is_coinbase) |
| 39 | { |
| 40 | // |
| 41 | // Credit |
| 42 | // |
| 43 | for(unsigned int i = 0; i < wtx.tx->vout.size(); i++) |
| 44 | { |
| 45 | const CTxOut& txout = wtx.tx->vout[i]; |
| 46 | isminetype mine = wtx.txout_is_mine[i]; |
| 47 | if(mine) |
| 48 | { |
| 49 | TransactionRecord sub(hash, nTime); |
| 50 | CTxDestination address; |
| 51 | sub.idx = i; // vout index |
| 52 | sub.credit = txout.nValue; |
| 53 | sub.involvesWatchAddress = mine & ISMINE_WATCH_ONLY; |
| 54 | if (wtx.txout_address_is_mine[i]) |
| 55 | { |
| 56 | // Received by Bitcoin Address |
| 57 | sub.type = TransactionRecord::RecvWithAddress; |
| 58 | sub.address = EncodeDestination(wtx.txout_address[i]); |
| 59 | } |
| 60 | else |
| 61 | { |
| 62 | // Received by IP connection (deprecated features), or a multisignature or other non-simple transaction |
| 63 | sub.type = TransactionRecord::RecvFromOther; |
| 64 | sub.address = mapValue["from"]; |
| 65 | } |
| 66 | if (wtx.is_coinbase) |
| 67 | { |
| 68 | // Generated |
| 69 | sub.type = TransactionRecord::Generated; |
| 70 | } |
| 71 | |
| 72 | parts.append(sub); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | else |
| 77 | { |
| 78 | bool involvesWatchAddress = false; |
| 79 | isminetype fAllFromMe = ISMINE_SPENDABLE; |
| 80 | for (isminetype mine : wtx.txin_is_mine) |
| 81 | { |
| 82 | if(mine & ISMINE_WATCH_ONLY) involvesWatchAddress = true; |
| 83 | if(fAllFromMe > mine) fAllFromMe = mine; |
| 84 | } |
| 85 |
nothing calls this directly
no test coverage detected