From 3a64318bd2c3ccbe46a2941d17f27bb187345c25 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sun, 8 Feb 2015 17:10:01 +0300 Subject: [PATCH] update tx types in UI / fix tx decomposition / use wallet db ds flag in UI --- src/qt/transactionrecord.cpp | 91 ++++++++++++++++++++------------ src/qt/transactionrecord.h | 3 +- src/qt/transactiontablemodel.cpp | 6 ++- src/qt/transactionview.cpp | 3 ++ 4 files changed, 67 insertions(+), 36 deletions(-) diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 08f877c6a5..a7918d99f0 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -76,37 +76,76 @@ QList TransactionRecord::decomposeTransaction(const CWallet * else { bool fAllFromMe = true; + bool fAllFromMeDenom = true; + int nFromMe = 0; BOOST_FOREACH(const CTxIn& txin, wtx.vin) + { fAllFromMe = fAllFromMe && wallet->IsMine(txin); + if(wallet->IsMine(txin)) { + fAllFromMeDenom = fAllFromMeDenom && wallet->IsDenominated(txin); + nFromMe++; + } + } bool fAllToMe = true; - BOOST_FOREACH(const CTxOut& txout, wtx.vout) + bool fAllToMeDenom = true; + int nToMe = 0; + BOOST_FOREACH(const CTxOut& txout, wtx.vout) { fAllToMe = fAllToMe && wallet->IsMine(txout); + if(wallet->IsMine(txout)) { + fAllToMeDenom = fAllToMeDenom && wallet->IsDenominatedAmount(txout.nValue); + nToMe++; + } + } - if (fAllFromMe && fAllToMe) + if(fAllFromMeDenom && fAllToMeDenom && nFromMe * nToMe) { + TransactionRecord sub(hash, nTime); + sub.type = TransactionRecord::DarksendDenominate; + parts.append(TransactionRecord(hash, nTime, sub.type, "", -nDebit, nCredit)); + } + else if (fAllFromMe && fAllToMe) { + // TODO: this section still not accurate but covers most cases, + // might need some additional work however - for (unsigned int nOut = 0; nOut < wtx.vout.size(); nOut++) + TransactionRecord sub(hash, nTime); + // Payment to self by default + sub.type = TransactionRecord::SendToSelf; + sub.address = ""; + + if(mapValue["DS"] == "1") { - const CTxOut& txout = wtx.vout[nOut]; - TransactionRecord sub(hash, nTime); - sub.idx = parts.size(); + sub.type = TransactionRecord::Darksent; + CTxDestination address; + if (ExtractDestination(wtx.vout[0].scriptPubKey, address)) + { + // Sent to Darkcoin Address + sub.address = CBitcoinAddress(address).ToString(); + } + else + { + // Sent to IP, or other non-address transaction like OP_EVAL + sub.address = mapValue["to"]; + } + } + else + { + for (unsigned int nOut = 0; nOut < wtx.vout.size(); nOut++) + { + const CTxOut& txout = wtx.vout[nOut]; + sub.idx = parts.size(); - if(txout.nValue == (DARKSEND_COLLATERAL*2)+DARKSEND_FEE || - txout.nValue == (DARKSEND_COLLATERAL*2)+DARKSEND_FEE || - txout.nValue == (DARKSEND_COLLATERAL*3)+DARKSEND_FEE || - txout.nValue == (DARKSEND_COLLATERAL*4)+DARKSEND_FEE || - txout.nValue == (DARKSEND_COLLATERAL*5)+DARKSEND_FEE - ) { - sub.type = TransactionRecord::DarksendSplitUpLarge; + if(wallet->IsCollateralAmount(txout.nValue)) sub.type = TransactionRecord::DarksendMakeCollaterals; + if(wallet->IsDenominatedAmount(txout.nValue)) sub.type = TransactionRecord::DarksendCreateDenominations; + if(nDebit - wtx.GetValueOut() == DARKSEND_COLLATERAL) sub.type = TransactionRecord::DarksendCollateralPayment; } } - // Payment to self int64_t nChange = wtx.GetChange(); - parts.append(TransactionRecord(hash, nTime, TransactionRecord::SendToSelf, "", - -(nDebit - nChange), nCredit - nChange)); + sub.debit = -(nDebit - nChange); + sub.credit = nCredit - nChange; + parts.append(sub); } else if (fAllFromMe) { @@ -142,17 +181,11 @@ QList TransactionRecord::decomposeTransaction(const CWallet * sub.address = mapValue["to"]; } - if(wtx.IsDenominated()){ + if(mapValue["DS"] == "1") + { sub.type = TransactionRecord::Darksent; } - if(txout.nValue == DARKSEND_COLLATERAL){ - sub.type = TransactionRecord::DarksendCollateralPayment; - } - if(txout.nValue == DARKSEND_COLLATERAL*5){ - sub.type = TransactionRecord::DarksendSplitUpLarge; - } - int64_t nValue = txout.nValue; /* Add fee to first output */ if (nTxFee > 0) @@ -170,16 +203,8 @@ QList TransactionRecord::decomposeTransaction(const CWallet * // // Mixed debit transaction, can't break down payees // - bool isDarksent = false; - for (unsigned int nOut = 0; nOut < wtx.vout.size(); nOut++) - { - const CTxOut& txout = wtx.vout[nOut]; - isDarksent = wallet->IsDenominatedAmount(txout.nValue); - if(isDarksent) break; // no need to loop more - } - - parts.append(TransactionRecord(hash, nTime, isDarksent ? TransactionRecord::DarksendDenominate : TransactionRecord::Other, "", nNet, 0)); + parts.append(TransactionRecord(hash, nTime, TransactionRecord::Other, "", nNet, 0)); } } diff --git a/src/qt/transactionrecord.h b/src/qt/transactionrecord.h index e7d008dcf9..fe6eabb285 100644 --- a/src/qt/transactionrecord.h +++ b/src/qt/transactionrecord.h @@ -79,7 +79,8 @@ public: RecvWithDarksend, DarksendDenominate, DarksendCollateralPayment, - DarksendSplitUpLarge, + DarksendMakeCollaterals, + DarksendCreateDenominations, Darksent }; diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index dff083c1ed..05d57f2716 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -370,8 +370,10 @@ QString TransactionTableModel::formatTxType(const TransactionRecord *wtx) const return tr("Darksend Denominate"); case TransactionRecord::DarksendCollateralPayment: return tr("Darksend Collateral Payment"); - case TransactionRecord::DarksendSplitUpLarge: - return tr("Darksend Split Up Large Inputs"); + case TransactionRecord::DarksendMakeCollaterals: + return tr("Darksend Make Collateral Inputs"); + case TransactionRecord::DarksendCreateDenominations: + return tr("Darksend Create Denominations"); case TransactionRecord::Darksent: return tr("Darksent"); diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 46316773bb..d63af3a9e8 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -79,7 +79,10 @@ TransactionView::TransactionView(QWidget *parent) : typeWidget->addItem(tr("Sent to"), TransactionFilterProxy::TYPE(TransactionRecord::SendToAddress) | TransactionFilterProxy::TYPE(TransactionRecord::SendToOther)); typeWidget->addItem(tr("Darksent"), TransactionFilterProxy::TYPE(TransactionRecord::Darksent)); + typeWidget->addItem(tr("Darksend Make Collateral Inputs"), TransactionFilterProxy::TYPE(TransactionRecord::DarksendMakeCollaterals)); + typeWidget->addItem(tr("Darksend Create Denominations"), TransactionFilterProxy::TYPE(TransactionRecord::DarksendCreateDenominations)); typeWidget->addItem(tr("Darksend Denominate"), TransactionFilterProxy::TYPE(TransactionRecord::DarksendDenominate)); + typeWidget->addItem(tr("Darksend Collateral Payment"), TransactionFilterProxy::TYPE(TransactionRecord::DarksendCollateralPayment)); typeWidget->addItem(tr("To yourself"), TransactionFilterProxy::TYPE(TransactionRecord::SendToSelf)); typeWidget->addItem(tr("Mined"), TransactionFilterProxy::TYPE(TransactionRecord::Generated)); typeWidget->addItem(tr("Other"), TransactionFilterProxy::TYPE(TransactionRecord::Other));