aboutsummaryrefslogtreecommitdiff
path: root/src/qt
diff options
context:
space:
mode:
Diffstat (limited to 'src/qt')
-rw-r--r--src/qt/addresstablemodel.cpp76
-rw-r--r--src/qt/addresstablemodel.h4
-rw-r--r--src/qt/bitcoin.cpp7
-rw-r--r--src/qt/bitcoingui.cpp2
-rw-r--r--src/qt/clientmodel.cpp29
-rw-r--r--src/qt/clientmodel.h5
-rw-r--r--src/qt/optionsmodel.cpp11
-rw-r--r--src/qt/optionsmodel.h7
-rw-r--r--src/qt/transactiondesc.cpp54
-rw-r--r--src/qt/transactiondesc.h3
-rw-r--r--src/qt/transactionrecord.cpp21
-rw-r--r--src/qt/transactionrecord.h4
-rw-r--r--src/qt/transactiontablemodel.cpp58
-rw-r--r--src/qt/transactiontablemodel.h5
14 files changed, 148 insertions, 138 deletions
diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp
index 1cd82b7626..eece092f0d 100644
--- a/src/qt/addresstablemodel.cpp
+++ b/src/qt/addresstablemodel.cpp
@@ -1,6 +1,7 @@
#include "addresstablemodel.h"
#include "guiutil.h"
-#include "main.h"
+
+#include "headers.h"
#include <QFont>
#include <QColor>
@@ -22,31 +23,25 @@ struct AddressTableEntry
AddressTableEntry() {}
AddressTableEntry(Type type, const QString &label, const QString &address):
type(type), label(label), address(address) {}
-
- bool isDefaultAddress() const
- {
- std::vector<unsigned char> vchPubKey;
- if (CWalletDB("r").ReadDefaultKey(vchPubKey))
- {
- return address == QString::fromStdString(PubKeyToAddress(vchPubKey));
- }
- return false;
- }
};
// Private implementation
struct AddressTablePriv
{
+ CWallet *wallet;
QList<AddressTableEntry> cachedAddressTable;
+ AddressTablePriv(CWallet *wallet):
+ wallet(wallet) {}
+
void refreshAddressTable()
{
cachedAddressTable.clear();
- CRITICAL_BLOCK(cs_mapKeys)
- CRITICAL_BLOCK(cs_mapAddressBook)
+ CRITICAL_BLOCK(wallet->cs_mapKeys)
+ CRITICAL_BLOCK(wallet->cs_mapAddressBook)
{
- BOOST_FOREACH(const PAIRTYPE(std::string, std::string)& item, mapAddressBook)
+ BOOST_FOREACH(const PAIRTYPE(std::string, std::string)& item, wallet->mapAddressBook)
{
std::string strAddress = item.first;
std::string strName = item.second;
@@ -75,13 +70,18 @@ struct AddressTablePriv
return 0;
}
}
+
+ bool isDefaultAddress(const AddressTableEntry *rec)
+ {
+ return rec->address == QString::fromStdString(wallet->GetDefaultAddress());
+ }
};
-AddressTableModel::AddressTableModel(QObject *parent) :
- QAbstractTableModel(parent),priv(0)
+AddressTableModel::AddressTableModel(CWallet *wallet, QObject *parent) :
+ QAbstractTableModel(parent),wallet(wallet),priv(0)
{
columns << tr("Label") << tr("Address");
- priv = new AddressTablePriv();
+ priv = new AddressTablePriv(wallet);
priv->refreshAddressTable();
}
@@ -118,7 +118,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
case Address:
return rec->address;
case IsDefaultAddress:
- return rec->isDefaultAddress();
+ return priv->isDefaultAddress(rec);
}
}
else if (role == Qt::FontRole)
@@ -128,7 +128,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
{
font = GUIUtil::bitcoinAddressFont();
}
- if(rec->isDefaultAddress())
+ if(priv->isDefaultAddress(rec))
{
font.setBold(true);
}
@@ -137,14 +137,14 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
else if (role == Qt::ForegroundRole)
{
// Show default address in alternative color
- if(rec->isDefaultAddress())
+ if(priv->isDefaultAddress(rec))
{
return QColor(0,0,255);
}
}
else if (role == Qt::ToolTipRole)
{
- if(rec->isDefaultAddress())
+ if(priv->isDefaultAddress(rec))
{
return tr("Default receiving address");
}
@@ -174,7 +174,7 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu
switch(index.column())
{
case Label:
- SetAddressBookName(rec->address.toStdString(), value.toString().toStdString());
+ wallet->SetAddressBookName(rec->address.toStdString(), value.toString().toStdString());
rec->label = value.toString();
break;
case Address:
@@ -182,9 +182,9 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu
if(rec->type == AddressTableEntry::Sending)
{
// Remove old entry
- CWalletDB().EraseName(rec->address.toStdString());
+ wallet->EraseAddressBookName(rec->address.toStdString());
// Add new entry with new address
- SetAddressBookName(value.toString().toStdString(), rec->label.toStdString());
+ wallet->SetAddressBookName(value.toString().toStdString(), rec->label.toStdString());
rec->address = value.toString();
}
@@ -245,9 +245,9 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
if(type == Send)
{
// Check for duplicate
- CRITICAL_BLOCK(cs_mapAddressBook)
+ CRITICAL_BLOCK(wallet->cs_mapAddressBook)
{
- if(mapAddressBook.count(strAddress))
+ if(wallet->mapAddressBook.count(strAddress))
{
return QString();
}
@@ -257,7 +257,7 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
{
// Generate a new address to associate with given label, optionally
// set as default receiving address.
- strAddress = PubKeyToAddress(GetKeyFromKeyPool());
+ strAddress = PubKeyToAddress(wallet->GetKeyFromKeyPool());
if(setAsDefault)
{
setDefaultAddress(QString::fromStdString(strAddress));
@@ -268,7 +268,7 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
return QString();
}
// Add entry and update list
- SetAddressBookName(strAddress, strLabel);
+ wallet->SetAddressBookName(strAddress, strLabel);
updateList();
return QString::fromStdString(strAddress);
}
@@ -283,33 +283,19 @@ bool AddressTableModel::removeRows(int row, int count, const QModelIndex & paren
// Also refuse to remove receiving addresses.
return false;
}
- CWalletDB().EraseName(rec->address.toStdString());
+ wallet->EraseAddressBookName(rec->address.toStdString());
updateList();
return true;
}
QString AddressTableModel::getDefaultAddress() const
{
- std::vector<unsigned char> vchPubKey;
- if (CWalletDB("r").ReadDefaultKey(vchPubKey))
- {
- return QString::fromStdString(PubKeyToAddress(vchPubKey));
- }
- else
- {
- return QString();
- }
+ return QString::fromStdString(wallet->GetDefaultAddress());
}
void AddressTableModel::setDefaultAddress(const QString &defaultAddress)
{
- uint160 hash160;
- std::string strAddress = defaultAddress.toStdString();
- if (!AddressToHash160(strAddress, hash160))
- return;
- if (!mapPubKeys.count(hash160))
- return;
- CWalletDB().WriteDefaultKey(mapPubKeys[hash160]);
+ wallet->SetDefaultAddress(defaultAddress.toStdString());
}
void AddressTableModel::update()
diff --git a/src/qt/addresstablemodel.h b/src/qt/addresstablemodel.h
index 32dd4d9f1d..d8465853b2 100644
--- a/src/qt/addresstablemodel.h
+++ b/src/qt/addresstablemodel.h
@@ -5,12 +5,13 @@
#include <QStringList>
class AddressTablePriv;
+class CWallet;
class AddressTableModel : public QAbstractTableModel
{
Q_OBJECT
public:
- explicit AddressTableModel(QObject *parent = 0);
+ explicit AddressTableModel(CWallet *wallet, QObject *parent = 0);
~AddressTableModel();
enum ColumnIndex {
@@ -49,6 +50,7 @@ public:
void updateList();
private:
+ CWallet *wallet;
AddressTablePriv *priv;
QStringList columns;
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index 7d5712f4aa..c31be1b606 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -3,10 +3,9 @@
*/
#include "bitcoingui.h"
#include "clientmodel.h"
-#include "util.h"
+
+#include "headers.h"
#include "init.h"
-#include "main.h"
-#include "qtui.h"
#include <QApplication>
#include <QMessageBox>
@@ -114,7 +113,7 @@ int main(int argc, char *argv[])
if(AppInit2(argc, argv))
{
BitcoinGUI window;
- ClientModel model;
+ ClientModel model(pwalletMain);
guiref = &window;
window.setModel(&model);
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index 1b4e13c420..76ae3ddb3f 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -16,7 +16,7 @@
#include "transactiondescdialog.h"
#include "addresstablemodel.h"
-#include "main.h"
+#include "headers.h"
#include <QApplication>
#include <QMainWindow>
diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp
index e39bb7ecb1..b70b71ee4f 100644
--- a/src/qt/clientmodel.cpp
+++ b/src/qt/clientmodel.cpp
@@ -1,14 +1,15 @@
#include "clientmodel.h"
-#include "main.h"
#include "guiconstants.h"
#include "optionsmodel.h"
#include "addresstablemodel.h"
#include "transactiontablemodel.h"
+#include "headers.h"
+
#include <QTimer>
-ClientModel::ClientModel(QObject *parent) :
- QObject(parent), optionsModel(0), addressTableModel(0),
+ClientModel::ClientModel(CWallet *wallet, QObject *parent) :
+ QObject(parent), wallet(wallet), optionsModel(0), addressTableModel(0),
transactionTableModel(0)
{
// Until signal notifications is built into the bitcoin core,
@@ -17,14 +18,14 @@ ClientModel::ClientModel(QObject *parent) :
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(MODEL_UPDATE_DELAY);
- optionsModel = new OptionsModel(this);
- addressTableModel = new AddressTableModel(this);
- transactionTableModel = new TransactionTableModel(this);
+ optionsModel = new OptionsModel(wallet, this);
+ addressTableModel = new AddressTableModel(wallet, this);
+ transactionTableModel = new TransactionTableModel(wallet, this);
}
qint64 ClientModel::getBalance() const
{
- return GetBalance();
+ return wallet->GetBalance();
}
int ClientModel::getNumConnections() const
@@ -40,9 +41,9 @@ int ClientModel::getNumBlocks() const
int ClientModel::getNumTransactions() const
{
int numTransactions = 0;
- CRITICAL_BLOCK(cs_mapWallet)
+ CRITICAL_BLOCK(wallet->cs_mapWallet)
{
- numTransactions = mapWallet.size();
+ numTransactions = wallet->mapWallet.size();
}
return numTransactions;
}
@@ -92,7 +93,7 @@ ClientModel::StatusCode ClientModel::sendCoins(const QString &payTo, qint64 payA
CScript scriptPubKey;
scriptPubKey << OP_DUP << OP_HASH160 << hash160 << OP_EQUALVERIFY << OP_CHECKSIG;
- std::string strError = SendMoney(scriptPubKey, payAmount, wtx, true);
+ std::string strError = wallet->SendMoney(scriptPubKey, payAmount, wtx, true);
if (strError == "")
{
// OK
@@ -110,9 +111,11 @@ ClientModel::StatusCode ClientModel::sendCoins(const QString &payTo, qint64 payA
// Add addresses that we've sent to to the address book
std::string strAddress = payTo.toStdString();
- CRITICAL_BLOCK(cs_mapAddressBook)
- if (!mapAddressBook.count(strAddress))
- SetAddressBookName(strAddress, addToAddressBookAs.toStdString());
+ CRITICAL_BLOCK(wallet->cs_mapAddressBook)
+ {
+ if (!wallet->mapAddressBook.count(strAddress))
+ wallet->SetAddressBookName(strAddress, addToAddressBookAs.toStdString());
+ }
return OK;
}
diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h
index da3e52e20e..9c23a14a0a 100644
--- a/src/qt/clientmodel.h
+++ b/src/qt/clientmodel.h
@@ -6,12 +6,13 @@
class OptionsModel;
class AddressTableModel;
class TransactionTableModel;
+class CWallet;
class ClientModel : public QObject
{
Q_OBJECT
public:
- explicit ClientModel(QObject *parent = 0);
+ explicit ClientModel(CWallet *wallet, QObject *parent = 0);
enum StatusCode
{
@@ -41,6 +42,8 @@ public:
/* Send coins */
StatusCode sendCoins(const QString &payTo, qint64 payAmount, const QString &addToAddressBookAs=QString());
private:
+ CWallet *wallet;
+
OptionsModel *optionsModel;
AddressTableModel *addressTableModel;
TransactionTableModel *transactionTableModel;
diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp
index 3788f9fd7c..8f285c6446 100644
--- a/src/qt/optionsmodel.cpp
+++ b/src/qt/optionsmodel.cpp
@@ -1,11 +1,12 @@
#include "optionsmodel.h"
-#include "main.h"
-#include "net.h"
+
+#include "headers.h"
#include <QDebug>
-OptionsModel::OptionsModel(QObject *parent) :
- QAbstractListModel(parent)
+OptionsModel::OptionsModel(CWallet *wallet, QObject *parent) :
+ QAbstractListModel(parent),
+ wallet(wallet)
{
}
@@ -48,7 +49,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
bool successful = true; /* set to false on parse error */
if(role == Qt::EditRole)
{
- CWalletDB walletdb;
+ CWalletDB walletdb(wallet->strWalletFile);
switch(index.row())
{
case StartAtStartup:
diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h
index 0124e2ab47..bdb797a2de 100644
--- a/src/qt/optionsmodel.h
+++ b/src/qt/optionsmodel.h
@@ -3,6 +3,8 @@
#include <QAbstractListModel>
+class CWallet;
+
/* Interface from QT to configuration data structure for bitcoin client.
To QT, the options are presented as a list with the different options
laid out vertically.
@@ -13,7 +15,7 @@ class OptionsModel : public QAbstractListModel
{
Q_OBJECT
public:
- explicit OptionsModel(QObject *parent = 0);
+ explicit OptionsModel(CWallet *wallet, QObject *parent = 0);
enum OptionID {
StartAtStartup,
@@ -35,6 +37,9 @@ public:
qint64 getTransactionFee();
bool getMinimizeToTray();
bool getMinimizeOnClose();
+private:
+ // Wallet stores persistent options
+ CWallet *wallet;
signals:
public slots:
diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp
index 84b617b7c4..bb2537a479 100644
--- a/src/qt/transactiondesc.cpp
+++ b/src/qt/transactiondesc.cpp
@@ -70,10 +70,10 @@ static string FormatTxStatus(const CWalletTx& wtx)
}
}
-string TransactionDesc::toHTML(CWalletTx &wtx)
+string TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
{
string strHTML;
- CRITICAL_BLOCK(cs_mapAddressBook)
+ CRITICAL_BLOCK(wallet->cs_mapAddressBook)
{
strHTML.reserve(4000);
strHTML += "<html><font face='verdana, arial, helvetica, sans-serif'>";
@@ -122,19 +122,19 @@ string TransactionDesc::toHTML(CWalletTx &wtx)
// Credit
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
{
- if (txout.IsMine())
+ if (wallet->IsMine(txout))
{
vector<unsigned char> vchPubKey;
- if (ExtractPubKey(txout.scriptPubKey, true, vchPubKey))
+ if (ExtractPubKey(txout.scriptPubKey, wallet, vchPubKey))
{
string strAddress = PubKeyToAddress(vchPubKey);
- if (mapAddressBook.count(strAddress))
+ if (wallet->mapAddressBook.count(strAddress))
{
strHTML += string() + _("<b>From:</b> ") + _("unknown") + "<br>";
strHTML += _("<b>To:</b> ");
strHTML += HtmlEscape(strAddress);
- if (!mapAddressBook[strAddress].empty())
- strHTML += _(" (yours, label: ") + mapAddressBook[strAddress] + ")";
+ if (!wallet->mapAddressBook[strAddress].empty())
+ strHTML += _(" (yours, label: ") + wallet->mapAddressBook[strAddress] + ")";
else
strHTML += _(" (yours)");
strHTML += "<br>";
@@ -156,8 +156,8 @@ string TransactionDesc::toHTML(CWalletTx &wtx)
// Online transaction
strAddress = wtx.mapValue["to"];
strHTML += _("<b>To:</b> ");
- if (mapAddressBook.count(strAddress) && !mapAddressBook[strAddress].empty())
- strHTML += mapAddressBook[strAddress] + " ";
+ if (wallet->mapAddressBook.count(strAddress) && !wallet->mapAddressBook[strAddress].empty())
+ strHTML += wallet->mapAddressBook[strAddress] + " ";
strHTML += HtmlEscape(strAddress) + "<br>";
}
@@ -172,7 +172,7 @@ string TransactionDesc::toHTML(CWalletTx &wtx)
//
int64 nUnmatured = 0;
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
- nUnmatured += txout.GetCredit();
+ nUnmatured += wallet->GetCredit(txout);
strHTML += _("<b>Credit:</b> ");
if (wtx.IsInMainChain())
strHTML += strprintf(_("(%s matures in %d more blocks)"), FormatMoney(nUnmatured).c_str(), wtx.GetBlocksToMaturity());
@@ -191,11 +191,11 @@ string TransactionDesc::toHTML(CWalletTx &wtx)
{
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)
{
@@ -204,7 +204,7 @@ string TransactionDesc::toHTML(CWalletTx &wtx)
//
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
{
- if (txout.IsMine())
+ if (wallet->IsMine(txout))
continue;
if (wtx.mapValue["to"].empty())
@@ -215,8 +215,8 @@ string TransactionDesc::toHTML(CWalletTx &wtx)
{
string strAddress = Hash160ToAddress(hash160);
strHTML += _("<b>To:</b> ");
- if (mapAddressBook.count(strAddress) && !mapAddressBook[strAddress].empty())
- strHTML += mapAddressBook[strAddress] + " ";
+ if (wallet->mapAddressBook.count(strAddress) && !wallet->mapAddressBook[strAddress].empty())
+ strHTML += wallet->mapAddressBook[strAddress] + " ";
strHTML += strAddress;
strHTML += "<br>";
}
@@ -244,11 +244,11 @@ string TransactionDesc::toHTML(CWalletTx &wtx)
// Mixed debit transaction
//
BOOST_FOREACH(const CTxIn& txin, wtx.vin)
- if (txin.IsMine())
- strHTML += _("<b>Debit:</b> ") + FormatMoney(-txin.GetDebit()) + "<br>";
+ if (wallet->IsMine(txin))
+ strHTML += _("<b>Debit:</b> ") + FormatMoney(-wallet->GetDebit(txin)) + "<br>";
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
- if (txout.IsMine())
- strHTML += _("<b>Credit:</b> ") + FormatMoney(txout.GetCredit()) + "<br>";
+ if (wallet->IsMine(txout))
+ strHTML += _("<b>Credit:</b> ") + FormatMoney(wallet->GetCredit(txout)) + "<br>";
}
}
@@ -274,30 +274,30 @@ string TransactionDesc::toHTML(CWalletTx &wtx)
{
strHTML += "<hr><br>debug print<br><br>";
BOOST_FOREACH(const CTxIn& txin, wtx.vin)
- if (txin.IsMine())
- strHTML += "<b>Debit:</b> " + FormatMoney(-txin.GetDebit()) + "<br>";
+ if(wallet->IsMine(txin))
+ strHTML += "<b>Debit:</b> " + FormatMoney(-wallet->IsMine(txin)) + "<br>";
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
- if (txout.IsMine())
- strHTML += "<b>Credit:</b> " + FormatMoney(txout.GetCredit()) + "<br>";
+ if(wallet->IsMine(txout))
+ strHTML += "<b>Credit:</b> " + FormatMoney(wallet->IsMine(txout)) + "<br>";
strHTML += "<br><b>Transaction:</b><br>";
strHTML += HtmlEscape(wtx.ToString(), true);
strHTML += "<br><b>Inputs:</b><br>";
- CRITICAL_BLOCK(cs_mapWallet)
+ CRITICAL_BLOCK(wallet->cs_mapWallet)
{
BOOST_FOREACH(const CTxIn& txin, wtx.vin)
{
COutPoint prevout = txin.prevout;
- map<uint256, CWalletTx>::iterator mi = mapWallet.find(prevout.hash);
- if (mi != mapWallet.end())
+ map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(prevout.hash);
+ if (mi != wallet->mapWallet.end())
{
const CWalletTx& prev = (*mi).second;
if (prevout.n < prev.vout.size())
{
strHTML += HtmlEscape(prev.ToString(), true);
strHTML += " &nbsp;&nbsp; " + FormatTxStatus(prev) + ", ";
- strHTML = strHTML + "IsMine=" + (prev.vout[prevout.n].IsMine() ? "true" : "false") + "<br>";
+ strHTML = strHTML + "IsMine=" + (wallet->IsMine(prev.vout[prevout.n]) ? "true" : "false") + "<br>";
}
}
}
diff --git a/src/qt/transactiondesc.h b/src/qt/transactiondesc.h
index 5a85949341..fde861b6fb 100644
--- a/src/qt/transactiondesc.h
+++ b/src/qt/transactiondesc.h
@@ -3,13 +3,14 @@
#include <string>
+class CWallet;
class CWalletTx;
class TransactionDesc
{
public:
/* Provide human-readable extended HTML description of a transaction */
- static std::string toHTML(CWalletTx &wtx);
+ static std::string toHTML(CWallet *wallet, CWalletTx &wtx);
};
#endif // TRANSACTIONDESC_H
diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp
index 2f00fa8752..864dffa99e 100644
--- a/src/qt/transactionrecord.cpp
+++ b/src/qt/transactionrecord.cpp
@@ -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,10 +77,10 @@ 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))
+ if (ExtractPubKey(txout.scriptPubKey, wallet, vchPubKey))
{
sub.address = PubKeyToAddress(vchPubKey);
}
@@ -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;
@@ -160,9 +161,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));
}
diff --git a/src/qt/transactionrecord.h b/src/qt/transactionrecord.h
index a7f6537b3f..ba071dfdc9 100644
--- a/src/qt/transactionrecord.h
+++ b/src/qt/transactionrecord.h
@@ -5,6 +5,8 @@
#include <QList>
+class CWallet;
+
class TransactionStatus
{
public:
@@ -84,7 +86,7 @@ public:
/* Decompose CWallet transaction to model transaction records.
*/
static bool showTransaction(const CWalletTx &wtx);
- static QList<TransactionRecord> decomposeTransaction(const CWalletTx &wtx);
+ static QList<TransactionRecord> decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx);
/* Fixed */
uint256 hash;
diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp
index dc3ef245e0..18ab421e3c 100644
--- a/src/qt/transactiontablemodel.cpp
+++ b/src/qt/transactiontablemodel.cpp
@@ -2,9 +2,10 @@
#include "guiutil.h"
#include "transactionrecord.h"
#include "guiconstants.h"
-#include "main.h"
#include "transactiondesc.h"
+#include "headers.h"
+
#include <QLocale>
#include <QDebug>
#include <QList>
@@ -37,11 +38,12 @@ struct TxLessThan
// Private implementation
struct TransactionTablePriv
{
- TransactionTablePriv(TransactionTableModel *parent):
+ TransactionTablePriv(CWallet *wallet, TransactionTableModel *parent):
+ wallet(wallet),
parent(parent)
{
}
-
+ CWallet *wallet;
TransactionTableModel *parent;
/* Local cache of wallet.
@@ -58,11 +60,11 @@ struct TransactionTablePriv
qDebug() << "refreshWallet";
#endif
cachedWallet.clear();
- CRITICAL_BLOCK(cs_mapWallet)
+ CRITICAL_BLOCK(wallet->cs_mapWallet)
{
- for(std::map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
+ for(std::map<uint256, CWalletTx>::iterator it = wallet->mapWallet.begin(); it != wallet->mapWallet.end(); ++it)
{
- cachedWallet.append(TransactionRecord::decomposeTransaction(it->second));
+ cachedWallet.append(TransactionRecord::decomposeTransaction(wallet, it->second));
}
}
}
@@ -84,14 +86,14 @@ struct TransactionTablePriv
QList<uint256> updated_sorted = updated;
qSort(updated_sorted);
- CRITICAL_BLOCK(cs_mapWallet)
+ CRITICAL_BLOCK(wallet->cs_mapWallet)
{
for(int update_idx = updated_sorted.size()-1; update_idx >= 0; --update_idx)
{
const uint256 &hash = updated_sorted.at(update_idx);
/* Find transaction in wallet */
- std::map<uint256, CWalletTx>::iterator mi = mapWallet.find(hash);
- bool inWallet = mi != mapWallet.end();
+ std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(hash);
+ bool inWallet = mi != wallet->mapWallet.end();
/* Find bounds of this transaction in model */
QList<TransactionRecord>::iterator lower = qLowerBound(
cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan());
@@ -100,6 +102,7 @@ struct TransactionTablePriv
int lowerIndex = (lower - cachedWallet.begin());
int upperIndex = (upper - cachedWallet.begin());
+ // Determine if transaction is in model already
bool inModel = false;
if(lower != upper)
{
@@ -115,7 +118,7 @@ struct TransactionTablePriv
{
// Added -- insert at the right position
QList<TransactionRecord> toInsert =
- TransactionRecord::decomposeTransaction(mi->second);
+ TransactionRecord::decomposeTransaction(wallet, mi->second);
if(!toInsert.isEmpty()) /* only if something to insert */
{
parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex+toInsert.size()-1);
@@ -159,11 +162,11 @@ struct TransactionTablePriv
// simply re-use the cached status.
if(rec->statusUpdateNeeded())
{
- CRITICAL_BLOCK(cs_mapWallet)
+ CRITICAL_BLOCK(wallet->cs_mapWallet)
{
- std::map<uint256, CWalletTx>::iterator mi = mapWallet.find(rec->hash);
+ std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(rec->hash);
- if(mi != mapWallet.end())
+ if(mi != wallet->mapWallet.end())
{
rec->updateStatus(mi->second);
}
@@ -179,12 +182,12 @@ struct TransactionTablePriv
QString describe(TransactionRecord *rec)
{
- CRITICAL_BLOCK(cs_mapWallet)
+ CRITICAL_BLOCK(wallet->cs_mapWallet)
{
- std::map<uint256, CWalletTx>::iterator mi = mapWallet.find(rec->hash);
- if(mi != mapWallet.end())
+ std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(rec->hash);
+ if(mi != wallet->mapWallet.end())
{
- return QString::fromStdString(TransactionDesc::toHTML(mi->second));
+ return QString::fromStdString(TransactionDesc::toHTML(wallet, mi->second));
}
}
return QString("");
@@ -202,9 +205,10 @@ static int column_alignments[] = {
Qt::AlignLeft|Qt::AlignVCenter
};
-TransactionTableModel::TransactionTableModel(QObject *parent):
+TransactionTableModel::TransactionTableModel(CWallet* wallet, QObject *parent):
QAbstractTableModel(parent),
- priv(new TransactionTablePriv(this))
+ wallet(wallet),
+ priv(new TransactionTablePriv(wallet, this))
{
columns << tr("Status") << tr("Date") << tr("Description") << tr("Debit") << tr("Credit");
@@ -225,15 +229,15 @@ void TransactionTableModel::update()
QList<uint256> updated;
// Check if there are changes to wallet map
- TRY_CRITICAL_BLOCK(cs_mapWallet)
+ TRY_CRITICAL_BLOCK(wallet->cs_mapWallet)
{
- if(!vWalletUpdated.empty())
+ if(!wallet->vWalletUpdated.empty())
{
- BOOST_FOREACH(uint256 hash, vWalletUpdated)
+ BOOST_FOREACH(uint256 hash, wallet->vWalletUpdated)
{
updated.append(hash);
}
- vWalletUpdated.clear();
+ wallet->vWalletUpdated.clear();
}
}
@@ -302,13 +306,13 @@ QVariant TransactionTableModel::formatTxDate(const TransactionRecord *wtx) const
address[0:12]... (label)
otherwise just return address
*/
-std::string lookupAddress(const std::string &address)
+std::string TransactionTableModel::lookupAddress(const std::string &address) const
{
std::string description;
- CRITICAL_BLOCK(cs_mapAddressBook)
+ CRITICAL_BLOCK(wallet->cs_mapAddressBook)
{
- std::map<std::string, std::string>::iterator mi = mapAddressBook.find(address);
- if (mi != mapAddressBook.end() && !(*mi).second.empty())
+ std::map<std::string, std::string>::iterator mi = wallet->mapAddressBook.find(address);
+ if (mi != wallet->mapAddressBook.end() && !(*mi).second.empty())
{
std::string label = (*mi).second;
description += address.substr(0,12) + "... ";
diff --git a/src/qt/transactiontablemodel.h b/src/qt/transactiontablemodel.h
index 804f004e38..72a645b3db 100644
--- a/src/qt/transactiontablemodel.h
+++ b/src/qt/transactiontablemodel.h
@@ -4,6 +4,7 @@
#include <QAbstractTableModel>
#include <QStringList>
+class CWallet;
class TransactionTablePriv;
class TransactionRecord;
@@ -11,7 +12,7 @@ class TransactionTableModel : public QAbstractTableModel
{
Q_OBJECT
public:
- explicit TransactionTableModel(QObject *parent = 0);
+ explicit TransactionTableModel(CWallet* wallet, QObject *parent = 0);
~TransactionTableModel();
enum {
@@ -39,9 +40,11 @@ public:
Qt::ItemFlags flags(const QModelIndex &index) const;
QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
private:
+ CWallet* wallet;
QStringList columns;
TransactionTablePriv *priv;
+ std::string lookupAddress(const std::string &address) const;
QVariant formatTxStatus(const TransactionRecord *wtx) const;
QVariant formatTxDate(const TransactionRecord *wtx) const;
QVariant formatTxDescription(const TransactionRecord *wtx) const;