X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fqt%2Fwalletmodel.cpp;h=b6bf5b1833d71faa56470f7a660ffd181eaa9b01;hb=e0e4beec1d93de51c01b180993372498688e330e;hp=54f806aa9d0ffb60a0214dd4369f7f4b28d2c1ac;hpb=77a43545b4491b9703d803765da9059d2bdd5aaa;p=novacoin.git diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 54f806a..b6bf5b1 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -5,7 +5,7 @@ #include "mintingtablemodel.h" #include "transactiontablemodel.h" -#include "ui_interface.h" +#include "interface.h" #include "wallet.h" #include "walletdb.h" // for BackupWallet #include "base58.h" @@ -21,6 +21,8 @@ WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *p cachedEncryptionStatus(Unencrypted), cachedNumBlocks(0) { + fHaveWatchOnly = wallet->HaveWatchOnly(); + addressTableModel = new AddressTableModel(wallet, this); mintingTableModel = new MintingTableModel(wallet, this); transactionTableModel = new TransactionTableModel(wallet, this); @@ -38,6 +40,11 @@ WalletModel::~WalletModel() unsubscribeFromCoreSignals(); } +bool WalletModel::haveWatchOnly() const +{ + return fHaveWatchOnly; +} + qint64 WalletModel::getBalance() const { return wallet->GetBalance(); @@ -68,7 +75,7 @@ int WalletModel::getNumTransactions() const int numTransactions = 0; { LOCK(wallet->cs_wallet); - numTransactions = wallet->mapWallet.size(); + numTransactions = (int)(wallet->mapWallet.size()); } return numTransactions; } @@ -130,6 +137,12 @@ void WalletModel::updateAddressBook(const QString &address, const QString &label addressTableModel->updateEntry(address, label, isMine, status); } +void WalletModel::updateWatchOnlyFlag(bool fHaveWatchonly) +{ + fHaveWatchOnly = fHaveWatchonly; + emit notifyWatchonlyChanged(fHaveWatchonly); +} + bool WalletModel::validateAddress(const QString &address) { CBitcoinAddress addressParsed(address.toStdString()); @@ -194,7 +207,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(const QListcs_wallet); - std::map::iterator mi = wallet->mapAddressBook.find(dest); + std::map::iterator mi = wallet->mapAddressBook.find(addr); // Check if we have a new address or an updated label if (mi == wallet->mapAddressBook.end() || mi->second != strLabel) { - wallet->SetAddressBookName(dest, strLabel); + wallet->SetAddressBookName(addr, strLabel); } } } @@ -289,8 +302,8 @@ bool WalletModel::setWalletEncrypted(bool encrypted, const SecureString &passphr } else { - // Decrypt -- TODO; not supported yet - return false; + // Decrypt + return wallet->DecryptWallet(passphrase); } } @@ -319,11 +332,6 @@ bool WalletModel::changePassphrase(const SecureString &oldPass, const SecureStri return retval; } -void WalletModel::getStakeStats(float &nKernelsRate, float &nCoinDaysRate) -{ - wallet->GetStakeStats(nKernelsRate, nCoinDaysRate); -} - void WalletModel::getStakeWeightFromValue(const int64_t& nTime, const int64_t& nValue, uint64_t& nWeight) { wallet->GetStakeWeightFromValue(nTime, nValue, nWeight); @@ -351,11 +359,11 @@ static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel, CCryptoKeyStor QMetaObject::invokeMethod(walletmodel, "updateStatus", Qt::QueuedConnection); } -static void NotifyAddressBookChanged(WalletModel *walletmodel, CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, ChangeType status) +static void NotifyAddressBookChanged(WalletModel *walletmodel, CWallet *wallet, const CBitcoinAddress &address, const std::string &label, bool isMine, ChangeType status) { - OutputDebugStringF("NotifyAddressBookChanged %s %s isMine=%i status=%i\n", CBitcoinAddress(address).ToString().c_str(), label.c_str(), isMine, status); + OutputDebugStringF("NotifyAddressBookChanged %s %s isMine=%i status=%i\n", address.ToString().c_str(), label.c_str(), isMine, status); QMetaObject::invokeMethod(walletmodel, "updateAddressBook", Qt::QueuedConnection, - Q_ARG(QString, QString::fromStdString(CBitcoinAddress(address).ToString())), + Q_ARG(QString, QString::fromStdString(address.ToString())), Q_ARG(QString, QString::fromStdString(label)), Q_ARG(bool, isMine), Q_ARG(int, status)); @@ -369,32 +377,40 @@ static void NotifyTransactionChanged(WalletModel *walletmodel, CWallet *wallet, Q_ARG(int, status)); } +static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly) +{ + QMetaObject::invokeMethod(walletmodel, "updateWatchOnlyFlag", Qt::QueuedConnection, + Q_ARG(bool, fHaveWatchonly)); +} + void WalletModel::subscribeToCoreSignals() { // Connect signals to wallet - wallet->NotifyStatusChanged.connect(boost::bind(&NotifyKeyStoreStatusChanged, this, _1)); - wallet->NotifyAddressBookChanged.connect(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5)); - wallet->NotifyTransactionChanged.connect(boost::bind(NotifyTransactionChanged, this, _1, _2, _3)); + wallet->NotifyStatusChanged.connect(boost::bind(&NotifyKeyStoreStatusChanged, this, boost::placeholders::_1)); + wallet->NotifyAddressBookChanged.connect(boost::bind(NotifyAddressBookChanged, this, boost::placeholders::_1, boost::placeholders::_2, boost::placeholders::_3, boost::placeholders::_4, boost::placeholders::_5)); + wallet->NotifyTransactionChanged.connect(boost::bind(NotifyTransactionChanged, this, boost::placeholders::_1, boost::placeholders::_2, boost::placeholders::_3)); + wallet->NotifyWatchonlyChanged.connect(boost::bind(NotifyWatchonlyChanged, this, boost::placeholders::_1)); } void WalletModel::unsubscribeFromCoreSignals() { // Disconnect signals from wallet - wallet->NotifyStatusChanged.disconnect(boost::bind(&NotifyKeyStoreStatusChanged, this, _1)); - wallet->NotifyAddressBookChanged.disconnect(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5)); - wallet->NotifyTransactionChanged.disconnect(boost::bind(NotifyTransactionChanged, this, _1, _2, _3)); + wallet->NotifyStatusChanged.disconnect(boost::bind(&NotifyKeyStoreStatusChanged, this, boost::placeholders::_1)); + wallet->NotifyAddressBookChanged.disconnect(boost::bind(NotifyAddressBookChanged, this, boost::placeholders::_1, boost::placeholders::_2, boost::placeholders::_3, boost::placeholders::_4, boost::placeholders::_5)); + wallet->NotifyTransactionChanged.disconnect(boost::bind(NotifyTransactionChanged, this, boost::placeholders::_1, boost::placeholders::_2, boost::placeholders::_3)); + wallet->NotifyWatchonlyChanged.disconnect(boost::bind(NotifyWatchonlyChanged, this, boost::placeholders::_1)); } // WalletModel::UnlockContext implementation WalletModel::UnlockContext WalletModel::requestUnlock() { bool was_locked = getEncryptionStatus() == Locked; - + bool mintflag = fWalletUnlockMintOnly; + if ((!was_locked) && fWalletUnlockMintOnly) { - setWalletLocked(true); - was_locked = getEncryptionStatus() == Locked; - + setWalletLocked(true); + was_locked = getEncryptionStatus() == Locked; } if(was_locked) { @@ -404,13 +420,14 @@ WalletModel::UnlockContext WalletModel::requestUnlock() // If wallet is still locked, unlock was failed or cancelled, mark context as invalid bool valid = getEncryptionStatus() != Locked; - return UnlockContext(this, valid, was_locked && !fWalletUnlockMintOnly); + return UnlockContext(this, valid, was_locked, mintflag); } -WalletModel::UnlockContext::UnlockContext(WalletModel *wallet, bool valid, bool relock): +WalletModel::UnlockContext::UnlockContext(WalletModel *wallet, bool valid, bool relock, bool mintflag): wallet(wallet), valid(valid), - relock(relock) + relock(relock), + mintflag(mintflag) { } @@ -418,7 +435,14 @@ WalletModel::UnlockContext::~UnlockContext() { if(valid && relock) { + if (mintflag) + { + // Restore unlock minting flag + fWalletUnlockMintOnly = mintflag; + return; + } wallet->setWalletLocked(true); + } } @@ -431,7 +455,7 @@ void WalletModel::UnlockContext::CopyFrom(const UnlockContext& rhs) bool WalletModel::getPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const { - return wallet->GetPubKey(address, vchPubKeyOut); + return wallet->GetPubKey(address, vchPubKeyOut); } // returns a list of COutputs from COutPoints @@ -457,7 +481,8 @@ void WalletModel::listCoins(std::map >& mapCoins) { if (!wallet->mapWallet.count(outpoint.hash)) continue; COutput out(&wallet->mapWallet[outpoint.hash], outpoint.n, wallet->mapWallet[outpoint.hash].GetDepthInMainChain(), true); - vCoins.push_back(out); + if (outpoint.n < out.tx->vout.size() && wallet->IsMine(out.tx->vout[outpoint.n]) == MINE_SPENDABLE) + vCoins.push_back(out); } BOOST_FOREACH(const COutput& out, vCoins) @@ -470,10 +495,11 @@ void WalletModel::listCoins(std::map >& mapCoins) cout = COutput(&wallet->mapWallet[cout.tx->vin[0].prevout.hash], cout.tx->vin[0].prevout.n, 0, true); } - CTxDestination address; - if(!out.fSpendable || !ExtractDestination(cout.tx->vout[cout.i].scriptPubKey, address)) + CBitcoinAddress addressRet; + if(!out.fSpendable || !ExtractAddress(*wallet, cout.tx->vout[cout.i].scriptPubKey, addressRet)) continue; - mapCoins[CBitcoinAddress(address).ToString().c_str()].push_back(out); + + mapCoins[addressRet.ToString().c_str()].push_back(out); } } @@ -505,4 +531,4 @@ void WalletModel::clearOrphans() CWallet* WalletModel::getWallet() { return wallet; -} \ No newline at end of file +}