Bugfix: Replace "URL" with "URI" where we aren't actually working with URLs
[novacoin.git] / src / qt / transactionrecord.cpp
index c74b48b..57210dc 100644 (file)
@@ -47,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)
-                {
-                    int64 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())
                     {
-                        std::vector<unsigned char> vchPubKey;
-                        if (ExtractPubKey(txout.scriptPubKey, wallet, vchPubKey))
-                        {
-                            sub.address = PubKeyToAddress(vchPubKey);
-                        }
-                        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
         {
@@ -127,19 +114,19 @@ 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;
-                        uint160 hash160;
-                        if (ExtractHash160(txout.scriptPubKey, hash160))
-                            sub.address = Hash160ToAddress(hash160);
+                        // Sent to IP, or other non-address transaction like OP_EVAL
+                        sub.type = TransactionRecord::SendToOther;
+                        sub.address = mapValue["to"];
                     }
 
                     int64 nValue = txout.nValue;
@@ -185,7 +172,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
 
     // Sort order, unrecorded transactions sort to the top
     status.sortKey = strprintf("%010d-%01d-%010u-%03d",
-        (pindex ? pindex->nHeight : INT_MAX),
+        (pindex ? pindex->nHeight : std::numeric_limits<int>::max()),
         (wtx.IsCoinBase() ? 1 : 0),
         wtx.nTimeReceived,
         idx);