X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fqt%2Ftransactionrecord.cpp;h=199e6113e76d923f237b8a3900eb7541488be276;hb=5098ea454db9132aa0f576921ca9d1a69429d146;hp=8962d18566cc76ff22f22596b92567d43664bf43;hpb=cf882ecd08d63682370e8e928a63ed51b9aa6734;p=novacoin.git diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 8962d18..199e611 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -3,6 +3,8 @@ #include "wallet.h" #include "base58.h" +extern CWallet* pwalletMain; + /* Return positive answer if transaction should be shown in list. */ bool TransactionRecord::showTransaction(const CWalletTx &wtx) @@ -24,31 +26,34 @@ bool TransactionRecord::showTransaction(const CWalletTx &wtx) QList TransactionRecord::decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx) { QList parts; - int64 nTime = wtx.GetTxTime(); - int64 nCredit = wtx.GetCredit(true); - int64 nDebit = wtx.GetDebit(); - int64 nNet = nCredit - nDebit; + int64_t nTime = wtx.GetTxTime(); + int64_t nCredit = wtx.GetCredit(MINE_ALL); + int64_t nDebit = wtx.GetDebit(MINE_ALL); + int64_t nNet = nCredit - nDebit; uint256 hash = wtx.GetHash(), hashPrev = 0; std::map mapValue = wtx.mapValue; + + bool fCoinBase = wtx.IsCoinBase(), + fCoinStake = wtx.IsCoinStake(); - if (nNet > 0 || wtx.IsCoinBase() || wtx.IsCoinStake()) + if (nNet > 0 || fCoinBase || fCoinStake) { // // Credit // - BOOST_FOREACH(const CTxOut& txout, wtx.vout) + for (const CTxOut& txout : wtx.vout) { if(wallet->IsMine(txout)) { TransactionRecord sub(hash, nTime); - CTxDestination address; sub.idx = parts.size(); // sequence number sub.credit = txout.nValue; - if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*wallet, address)) + + CBitcoinAddress addressRet; + if (ExtractAddress(*pwalletMain, txout.scriptPubKey, addressRet)) { - // Received by Bitcoin Address sub.type = TransactionRecord::RecvWithAddress; - sub.address = CBitcoinAddress(address).ToString(); + sub.address = addressRet.ToString(); } else { @@ -56,21 +61,19 @@ QList TransactionRecord::decomposeTransaction(const CWallet * sub.type = TransactionRecord::RecvFromOther; sub.address = mapValue["from"]; } - if (wtx.IsCoinBase()) - { - // Generated (proof-of-work) - sub.type = TransactionRecord::Generated; - } - if (wtx.IsCoinStake()) - { - // Generated (proof-of-stake) - - if (hashPrev == hash) - continue; // last coinstake output + if (fCoinBase || fCoinStake) + { + // Generated sub.type = TransactionRecord::Generated; - sub.credit = nNet > 0 ? nNet : wtx.GetValueOut() - nDebit; - hashPrev = hash; + if (fCoinStake) + { + // proof-of-stake + if (hashPrev == hash) + continue; // last coinstake output + sub.credit = nNet > 0 ? nNet : wtx.GetValueOut() - nDebit; + hashPrev = hash; + } } parts.append(sub); @@ -80,17 +83,17 @@ QList TransactionRecord::decomposeTransaction(const CWallet * else { bool fAllFromMe = true; - BOOST_FOREACH(const CTxIn& txin, wtx.vin) + for (const CTxIn& txin : wtx.vin) fAllFromMe = fAllFromMe && wallet->IsMine(txin); bool fAllToMe = true; - BOOST_FOREACH(const CTxOut& txout, wtx.vout) + for (const CTxOut& txout : wtx.vout) fAllToMe = fAllToMe && wallet->IsMine(txout); if (fAllFromMe && fAllToMe) { // Payment to self - int64 nChange = wtx.GetChange(); + int64_t nChange = wtx.GetChange(); parts.append(TransactionRecord(hash, nTime, TransactionRecord::SendToSelf, "", -(nDebit - nChange), nCredit - nChange)); @@ -100,7 +103,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet * // // Debit // - int64 nTxFee = nDebit - wtx.GetValueOut(); + int64_t nTxFee = nDebit - wtx.GetValueOut(); for (unsigned int nOut = 0; nOut < wtx.vout.size(); nOut++) { @@ -129,7 +132,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet * sub.address = mapValue["to"]; } - int64 nValue = txout.nValue; + int64_t nValue = txout.nValue; /* Add fee to first output */ if (nTxFee > 0) { @@ -205,8 +208,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx) // For generated transactions, determine maturity if(type == TransactionRecord::Generated) { - int64 nCredit = wtx.GetCredit(true); - if (nCredit == 0) + if (wtx.GetBlocksToMaturity() > 0) { status.maturity = TransactionStatus::Immature;