Bugfix: Replace "URL" with "URI" where we aren't actually working with URLs
[novacoin.git] / src / qt / transactionrecord.cpp
index 8a1f1b6..57210dc 100644 (file)
@@ -1,5 +1,3 @@
-#include <QtGlobal>
-
 #include "transactionrecord.h"
 
 #include "headers.h"
@@ -35,10 +33,10 @@ bool TransactionRecord::showTransaction(const CWalletTx &wtx)
 QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx)
 {
     QList<TransactionRecord> parts;
-    qint64 nTime = wtx.nTimeDisplayed = wtx.GetTxTime();
-    qint64 nCredit = wtx.GetCredit(true);
-    qint64 nDebit = wtx.GetDebit();
-    qint64 nNet = nCredit - nDebit;
+    int64 nTime = wtx.nTimeDisplayed = wtx.GetTxTime();
+    int64 nCredit = wtx.GetCredit(true);
+    int64 nDebit = wtx.GetDebit();
+    int64 nNet = nCredit - nDebit;
     uint256 hash = wtx.GetHash();
     std::map<std::string, std::string> mapValue = wtx.mapValue;
 
@@ -49,48 +47,35 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
             //
             // Credit
             //
-            TransactionRecord sub(hash, nTime);
-
-            sub.credit = nNet;
-
-            if (wtx.IsCoinBase())
-            {
-                // Generated
-                sub.type = TransactionRecord::Generated;
-
-                if (nCredit == 0)
-                {
-                    qint64 nUnmatured = 0;
-                    BOOST_FOREACH(const CTxOut& txout, wtx.vout)
-                        nUnmatured += wallet->GetCredit(txout);
-                    sub.credit = nUnmatured;
-                }
-            }
-            else if (!mapValue["from"].empty() || !mapValue["message"].empty())
-            {
-                // Received by IP connection
-                sub.type = TransactionRecord::RecvFromIP;
-                if (!mapValue["from"].empty())
-                    sub.address = mapValue["from"];
-            }
-            else
+            BOOST_FOREACH(const CTxOut& txout, wtx.vout)
             {
-                // Received by Bitcoin Address
-                sub.type = TransactionRecord::RecvWithAddress;
-                BOOST_FOREACH(const CTxOut& txout, wtx.vout)
+                if(wallet->IsMine(txout))
                 {
-                    if(wallet->IsMine(txout))
+                    TransactionRecord sub(hash, nTime);
+                    CBitcoinAddress address;
+                    sub.idx = parts.size(); // sequence number
+                    sub.credit = txout.nValue;
+                    if (wtx.IsCoinBase())
                     {
-                        CBitcoinAddress address;
-                        if (ExtractAddress(txout.scriptPubKey, wallet, address))
-                        {
-                            sub.address = address.ToString();
-                        }
-                        break;
+                        // Generated
+                        sub.type = TransactionRecord::Generated;
                     }
+                    else if (ExtractAddress(txout.scriptPubKey, address) && wallet->HaveKey(address))
+                    {
+                        // Received by Bitcoin Address
+                        sub.type = TransactionRecord::RecvWithAddress;
+                        sub.address = address.ToString();
+                    }
+                    else
+                    {
+                        // Received by IP connection (deprecated features), or a multisignature or other non-simple transaction
+                        sub.type = TransactionRecord::RecvFromOther;
+                        sub.address = mapValue["from"];
+                    }
+
+                    parts.append(sub);
                 }
             }
-            parts.append(sub);
         }
         else
         {
@@ -105,7 +90,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
             if (fAllFromMe && fAllToMe)
             {
                 // Payment to self
-                qint64 nChange = wtx.GetChange();
+                int64 nChange = wtx.GetChange();
 
                 parts.append(TransactionRecord(hash, nTime, TransactionRecord::SendToSelf, "",
                                 -(nDebit - nChange), nCredit - nChange));
@@ -115,7 +100,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
                 //
                 // Debit
                 //
-                qint64 nTxFee = nDebit - wtx.GetValueOut();
+                int64 nTxFee = nDebit - wtx.GetValueOut();
 
                 for (int nOut = 0; nOut < wtx.vout.size(); nOut++)
                 {
@@ -129,24 +114,22 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
                         // from a transaction sent back to our own address.
                         continue;
                     }
-                    else if(!mapValue["to"].empty())
+
+                    CBitcoinAddress address;
+                    if (ExtractAddress(txout.scriptPubKey, address))
                     {
-                        // Sent to IP
-                        sub.type = TransactionRecord::SendToIP;
-                        sub.address = mapValue["to"];
+                        // Sent to Bitcoin Address
+                        sub.type = TransactionRecord::SendToAddress;
+                        sub.address = address.ToString();
                     }
                     else
                     {
-                        // Sent to Bitcoin Address
-                        sub.type = TransactionRecord::SendToAddress;
-                        CBitcoinAddress address;
-                        if (ExtractAddress(txout.scriptPubKey, 0, address))
-                        {
-                            sub.address = address.ToString();
-                        }
+                        // Sent to IP, or other non-address transaction like OP_EVAL
+                        sub.type = TransactionRecord::SendToOther;
+                        sub.address = mapValue["to"];
                     }
 
-                    qint64 nValue = txout.nValue;
+                    int64 nValue = txout.nValue;
                     /* Add fee to first output */
                     if (nTxFee > 0)
                     {
@@ -229,7 +212,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
     // For generated transactions, determine maturity
     if(type == TransactionRecord::Generated)
     {
-        qint64 nCredit = wtx.GetCredit(true);
+        int64 nCredit = wtx.GetCredit(true);
         if (nCredit == 0)
         {
             status.maturity = TransactionStatus::Immature;