Revert "Use standard C99 (and Qt) types for 64-bit integers"
[novacoin.git] / src / qt / transactionrecord.cpp
index 34f30d5..53cd35b 100644 (file)
@@ -1,5 +1,6 @@
 #include "transactionrecord.h"
 
+#include "headers.h"
 
 /* Return positive answer if transaction should be shown in list.
  */
@@ -29,7 +30,7 @@ bool TransactionRecord::showTransaction(const CWalletTx &wtx)
 /*
  * Decompose CWallet transaction to model transaction records.
  */
-QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWalletTx &wtx)
+QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx)
 {
     QList<TransactionRecord> parts;
     int64 nTime = wtx.nTimeDisplayed = wtx.GetTxTime();
@@ -59,7 +60,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWalletTx
                 {
                     int64 nUnmatured = 0;
                     BOOST_FOREACH(const CTxOut& txout, wtx.vout)
-                        nUnmatured += txout.GetCredit();
+                        nUnmatured += wallet->GetCredit(txout);
                     sub.credit = nUnmatured;
                 }
             }
@@ -76,12 +77,12 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWalletTx
                 sub.type = TransactionRecord::RecvWithAddress;
                 BOOST_FOREACH(const CTxOut& txout, wtx.vout)
                 {
-                    if (txout.IsMine())
+                    if(wallet->IsMine(txout))
                     {
-                        std::vector<unsigned char> vchPubKey;
-                        if (ExtractPubKey(txout.scriptPubKey, true, vchPubKey))
+                        CBitcoinAddress address;
+                        if (ExtractAddress(txout.scriptPubKey, wallet, address))
                         {
-                            sub.address = PubKeyToAddress(vchPubKey);
+                            sub.address = address.ToString();
                         }
                         break;
                     }
@@ -93,11 +94,11 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWalletTx
         {
             bool fAllFromMe = true;
             BOOST_FOREACH(const CTxIn& txin, wtx.vin)
-                fAllFromMe = fAllFromMe && txin.IsMine();
+                fAllFromMe = fAllFromMe && wallet->IsMine(txin);
 
             bool fAllToMe = true;
             BOOST_FOREACH(const CTxOut& txout, wtx.vout)
-                fAllToMe = fAllToMe && txout.IsMine();
+                fAllToMe = fAllToMe && wallet->IsMine(txout);
 
             if (fAllFromMe && fAllToMe)
             {
@@ -120,13 +121,13 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWalletTx
                     TransactionRecord sub(hash, nTime);
                     sub.idx = parts.size();
 
-                    if (txout.IsMine())
+                    if(wallet->IsMine(txout))
                     {
                         // Ignore parts sent to self, as this is usually the change
                         // from a transaction sent back to our own address.
                         continue;
                     }
-                    else if (!mapValue["to"].empty())
+                    else if(!mapValue["to"].empty())
                     {
                         // Sent to IP
                         sub.type = TransactionRecord::SendToIP;
@@ -136,9 +137,11 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWalletTx
                     {
                         // Sent to Bitcoin Address
                         sub.type = TransactionRecord::SendToAddress;
-                        uint160 hash160;
-                        if (ExtractHash160(txout.scriptPubKey, hash160))
-                            sub.address = Hash160ToAddress(hash160);
+                        CBitcoinAddress address;
+                        if (ExtractAddress(txout.scriptPubKey, 0, address))
+                        {
+                            sub.address = address.ToString();
+                        }
                     }
 
                     int64 nValue = txout.nValue;
@@ -160,9 +163,9 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWalletTx
                 //
                 bool fAllMine = true;
                 BOOST_FOREACH(const CTxOut& txout, wtx.vout)
-                    fAllMine = fAllMine && txout.IsMine();
+                    fAllMine = fAllMine && wallet->IsMine(txout);
                 BOOST_FOREACH(const CTxIn& txin, wtx.vin)
-                    fAllMine = fAllMine && txin.IsMine();
+                    fAllMine = fAllMine && wallet->IsMine(txin);
 
                 parts.append(TransactionRecord(hash, nTime, TransactionRecord::Other, "", nNet, 0));
             }
@@ -184,7 +187,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);
@@ -194,7 +197,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
 
     if (!wtx.IsFinal())
     {
-        if (wtx.nLockTime < 500000000)
+        if (wtx.nLockTime < LOCKTIME_THRESHOLD)
         {
             status.status = TransactionStatus::OpenUntilBlock;
             status.open_for = nBestHeight - wtx.nLockTime;
@@ -211,7 +214,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
         {
             status.status = TransactionStatus::Offline;
         }
-        else if (status.depth < 6)
+        else if (status.depth < NumConfirmations)
         {
             status.status = TransactionStatus::Unconfirmed;
         }
@@ -253,3 +256,9 @@ bool TransactionRecord::statusUpdateNeeded()
 {
     return status.cur_num_blocks != nBestHeight;
 }
+
+std::string TransactionRecord::getTxID()
+{
+    return hash.ToString() + strprintf("-%03d", idx);
+}
+