X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fqt%2Fclientmodel.cpp;h=5a0b4aa83ca99b46791747e19c5337fc6424dc57;hb=7ca47cece7854a4efb4a8dcb68b93edbde1a76fb;hp=86fc8b32d3a14862e9f02803675d77434ad5b395;hpb=6cab66354d5523ec3f977cfe8c4028a4c42a693d;p=novacoin.git diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index 86fc8b3..5a0b4aa 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -1,15 +1,17 @@ #include "clientmodel.h" -#include "main.h" #include "guiconstants.h" #include "optionsmodel.h" #include "addresstablemodel.h" #include "transactiontablemodel.h" +#include "headers.h" + #include +#include -ClientModel::ClientModel(QObject *parent) : - QObject(parent), optionsModel(0), addressTableModel(0), - transactionTableModel(0) +ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) : + QObject(parent), optionsModel(optionsModel), + cachedNumConnections(0), cachedNumBlocks(0) { // Until signal notifications is built into the bitcoin core, // simply update everything after polling using a timer. @@ -17,27 +19,7 @@ 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); -} - -qint64 ClientModel::getBalance() const -{ - return GetBalance(); -} - -QString ClientModel::getAddress() const -{ - std::vector vchPubKey; - if (CWalletDB("r").ReadDefaultKey(vchPubKey)) - { - return QString::fromStdString(PubKeyToAddress(vchPubKey)); - } - else - { - return QString(); - } + numBlocksAtStartup = -1; } int ClientModel::getNumConnections() const @@ -50,92 +32,34 @@ int ClientModel::getNumBlocks() const return nBestHeight; } -int ClientModel::getNumTransactions() const +int ClientModel::getNumBlocksAtStartup() { - int numTransactions = 0; - CRITICAL_BLOCK(cs_mapWallet) - { - numTransactions = mapWallet.size(); - } - return numTransactions; + if (numBlocksAtStartup == -1) numBlocksAtStartup = getNumBlocks(); + return numBlocksAtStartup; } -void ClientModel::update() +QDateTime ClientModel::getLastBlockDate() const { - // Plainly emit all signals for now. To be more efficient this should check - // whether the values actually changed first. - emit balanceChanged(getBalance()); - emit addressChanged(getAddress()); - emit numConnectionsChanged(getNumConnections()); - emit numBlocksChanged(getNumBlocks()); - emit numTransactionsChanged(getNumTransactions()); + return QDateTime::fromTime_t(pindexBest->GetBlockTime()); } -void ClientModel::setAddress(const QString &defaultAddress) +void ClientModel::update() { - uint160 hash160; - std::string strAddress = defaultAddress.toStdString(); - if (!AddressToHash160(strAddress, hash160)) - return; - if (!mapPubKeys.count(hash160)) - return; - CWalletDB().WriteDefaultKey(mapPubKeys[hash160]); + int newNumConnections = getNumConnections(); + int newNumBlocks = getNumBlocks(); + + if(cachedNumConnections != newNumConnections) + emit numConnectionsChanged(newNumConnections); + if(cachedNumBlocks != newNumBlocks) + emit numBlocksChanged(newNumBlocks); + + cachedNumConnections = newNumConnections; + cachedNumBlocks = newNumBlocks; } -ClientModel::StatusCode ClientModel::sendCoins(const QString &payTo, qint64 payAmount) +bool ClientModel::isTestNet() const { - uint160 hash160 = 0; - bool valid = false; - - if(!AddressToHash160(payTo.toUtf8().constData(), hash160)) - { - return InvalidAddress; - } - - if(payAmount <= 0) - { - return InvalidAmount; - } - - if(payAmount > getBalance()) - { - return AmountExceedsBalance; - } - - if((payAmount + nTransactionFee) > getBalance()) - { - return AmountWithFeeExceedsBalance; - } - - CRITICAL_BLOCK(cs_main) - { - // Send to bitcoin address - CWalletTx wtx; - CScript scriptPubKey; - scriptPubKey << OP_DUP << OP_HASH160 << hash160 << OP_EQUALVERIFY << OP_CHECKSIG; - - std::string strError = SendMoney(scriptPubKey, payAmount, wtx, true); - if (strError == "") - { - return OK; - } - else if (strError == "ABORTED") - { - return Aborted; - } - else - { - emit error(tr("Sending..."), QString::fromStdString(strError)); - return MiscError; - } - } - // 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, ""); - - return OK; + return fTestNet; } bool ClientModel::inInitialBlockDownload() const @@ -143,23 +67,22 @@ bool ClientModel::inInitialBlockDownload() const return IsInitialBlockDownload(); } -int ClientModel::getTotalBlocksEstimate() const +int ClientModel::getNumBlocksOfPeers() const { - return GetTotalBlocksEstimate(); + return GetNumBlocksOfPeers(); } - -OptionsModel *ClientModel::getOptionsModel() +QString ClientModel::getStatusBarWarnings() const { - return optionsModel; + return QString::fromStdString(GetWarnings("statusbar")); } -AddressTableModel *ClientModel::getAddressTableModel() +OptionsModel *ClientModel::getOptionsModel() { - return addressTableModel; + return optionsModel; } -TransactionTableModel *ClientModel::getTransactionTableModel() +QString ClientModel::formatFullVersion() const { - return transactionTableModel; + return QString::fromStdString(FormatFullVersion()); }