* Decompose CWallet transaction to model transaction records. */
| 25 | * Decompose CWallet transaction to model transaction records. |
| 26 | */ |
| 27 | QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interfaces::WalletTx& wtx) |
| 28 | { |
| 29 | QList<TransactionRecord> parts; |
| 30 | int64_t nTime = wtx.time; |
| 31 | CAmount nCredit = wtx.credit; |
| 32 | CAmount nDebit = wtx.debit; |
| 33 | CAmount nNet = nCredit - nDebit; |
| 34 | Txid hash = wtx.tx->GetHash(); |
| 35 | std::map<std::string, std::string> mapValue = wtx.value_map; |
| 36 | |
| 37 | bool all_from_me = true; |
| 38 | bool any_from_me = false; |
| 39 | if (wtx.is_coinbase) { |
| 40 | all_from_me = false; |
| 41 | } else { |
| 42 | for (const bool mine : wtx.txin_is_mine) |
| 43 | { |
| 44 | all_from_me = all_from_me && mine; |
| 45 | if (mine) any_from_me = true; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | if (all_from_me || !any_from_me) { |
| 50 | CAmount nTxFee = nDebit - wtx.tx->GetValueOut(); |
| 51 | |
| 52 | for(unsigned int i = 0; i < wtx.tx->vout.size(); i++) |
| 53 | { |
| 54 | const CTxOut& txout = wtx.tx->vout[i]; |
| 55 | |
| 56 | if (all_from_me) { |
| 57 | // Change is only really possible if we're the sender |
| 58 | // Otherwise, someone just sent bitcoins to a change address, which should be shown |
| 59 | if (wtx.txout_is_change[i]) { |
| 60 | continue; |
| 61 | } |
| 62 | |
| 63 | // |
| 64 | // Debit |
| 65 | // |
| 66 | |
| 67 | TransactionRecord sub(hash, nTime); |
| 68 | sub.idx = i; |
| 69 | |
| 70 | if (!std::get_if<CNoDestination>(&wtx.txout_address[i])) |
| 71 | { |
| 72 | // Sent to Bitcoin Address |
| 73 | sub.type = TransactionRecord::SendToAddress; |
| 74 | sub.address = EncodeDestination(wtx.txout_address[i]); |
| 75 | } |
| 76 | else |
| 77 | { |
| 78 | // Sent to IP, or other non-address transaction like OP_EVAL |
| 79 | sub.type = TransactionRecord::SendToOther; |
| 80 | sub.address = mapValue["to"]; |
| 81 | } |
| 82 | |
| 83 | CAmount nValue = txout.nValue; |
| 84 | /* Add fee to first output */ |
nothing calls this directly
no test coverage detected