Add boolean HaveWatchonly and signal NotifyWatchonlyChanged
This commit is contained in:
parent
8b11d3de7a
commit
939ed97373
@ -71,3 +71,9 @@ bool CBasicKeyStore::HaveWatchOnly(const CScript &dest) const
|
|||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
return setWatchOnly.count(dest) > 0;
|
return setWatchOnly.count(dest) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CBasicKeyStore::HaveWatchOnly() const
|
||||||
|
{
|
||||||
|
LOCK(cs_KeyStore);
|
||||||
|
return (!setWatchOnly.empty());
|
||||||
|
}
|
||||||
|
@ -50,6 +50,7 @@ public:
|
|||||||
// Support for Watch-only addresses
|
// Support for Watch-only addresses
|
||||||
virtual bool AddWatchOnly(const CScript &dest) =0;
|
virtual bool AddWatchOnly(const CScript &dest) =0;
|
||||||
virtual bool HaveWatchOnly(const CScript &dest) const =0;
|
virtual bool HaveWatchOnly(const CScript &dest) const =0;
|
||||||
|
virtual bool HaveWatchOnly() const =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::map<CKeyID, CKey> KeyMap;
|
typedef std::map<CKeyID, CKey> KeyMap;
|
||||||
@ -107,6 +108,7 @@ public:
|
|||||||
|
|
||||||
virtual bool AddWatchOnly(const CScript &dest);
|
virtual bool AddWatchOnly(const CScript &dest);
|
||||||
virtual bool HaveWatchOnly(const CScript &dest) const;
|
virtual bool HaveWatchOnly(const CScript &dest) const;
|
||||||
|
virtual bool HaveWatchOnly() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<unsigned char, secure_allocator<unsigned char> > CKeyingMaterial;
|
typedef std::vector<unsigned char, secure_allocator<unsigned char> > CKeyingMaterial;
|
||||||
|
@ -160,18 +160,25 @@ void OverviewPage::setBalance(qint64 balance, qint64 unconfirmedBalance, qint64
|
|||||||
// for the non-mining users
|
// for the non-mining users
|
||||||
bool showImmature = immatureBalance != 0;
|
bool showImmature = immatureBalance != 0;
|
||||||
bool showWatchOnlyImmature = watchImmatureBalance != 0;
|
bool showWatchOnlyImmature = watchImmatureBalance != 0;
|
||||||
bool showWatchOnly = (watchOnlyBalance != 0 || watchUnconfBalance != 0 || showWatchOnlyImmature);
|
|
||||||
|
|
||||||
// for symmetry reasons also show immature label when the watch-only one is shown
|
// for symmetry reasons also show immature label when the watch-only one is shown
|
||||||
ui->labelImmature->setVisible(showImmature || showWatchOnlyImmature);
|
ui->labelImmature->setVisible(showImmature || showWatchOnlyImmature);
|
||||||
ui->labelImmatureText->setVisible(showImmature || showWatchOnlyImmature);
|
ui->labelImmatureText->setVisible(showImmature || showWatchOnlyImmature);
|
||||||
|
ui->labelWatchImmature->setVisible(showWatchOnlyImmature); // show watch-only immature balance
|
||||||
|
}
|
||||||
|
|
||||||
|
// show/hide watch-only labels
|
||||||
|
void OverviewPage::updateWatchOnlyLabels(bool showWatchOnly)
|
||||||
|
{
|
||||||
ui->labelSpendable->setVisible(showWatchOnly); // show spendable label (only when watch-only is active)
|
ui->labelSpendable->setVisible(showWatchOnly); // show spendable label (only when watch-only is active)
|
||||||
ui->labelWatchonly->setVisible(showWatchOnly); // show watch-only label
|
ui->labelWatchonly->setVisible(showWatchOnly); // show watch-only label
|
||||||
ui->lineWatchBalance->setVisible(showWatchOnly); // show watch-only balance separator line
|
ui->lineWatchBalance->setVisible(showWatchOnly); // show watch-only balance separator line
|
||||||
ui->labelWatchAvailable->setVisible(showWatchOnly); // show watch-only available balance
|
ui->labelWatchAvailable->setVisible(showWatchOnly); // show watch-only available balance
|
||||||
ui->labelWatchImmature->setVisible(showWatchOnlyImmature); // show watch-only immature balance
|
|
||||||
ui->labelWatchPending->setVisible(showWatchOnly); // show watch-only pending balance
|
ui->labelWatchPending->setVisible(showWatchOnly); // show watch-only pending balance
|
||||||
ui->labelWatchTotal->setVisible(showWatchOnly); // show watch-only total balance
|
ui->labelWatchTotal->setVisible(showWatchOnly); // show watch-only total balance
|
||||||
|
|
||||||
|
if (!showWatchOnly)
|
||||||
|
ui->labelWatchImmature->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverviewPage::setClientModel(ClientModel *model)
|
void OverviewPage::setClientModel(ClientModel *model)
|
||||||
@ -208,6 +215,9 @@ void OverviewPage::setWalletModel(WalletModel *model)
|
|||||||
connect(model, SIGNAL(balanceChanged(qint64, qint64, qint64, qint64, qint64, qint64)), this, SLOT(setBalance(qint64, qint64, qint64, qint64, qint64, qint64)));
|
connect(model, SIGNAL(balanceChanged(qint64, qint64, qint64, qint64, qint64, qint64)), this, SLOT(setBalance(qint64, qint64, qint64, qint64, qint64, qint64)));
|
||||||
|
|
||||||
connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
|
connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
|
||||||
|
|
||||||
|
updateWatchOnlyLabels(model->haveWatchOnly());
|
||||||
|
connect(model, SIGNAL(notifyWatchonlyChanged(bool)), this, SLOT(updateWatchOnlyLabels(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the display unit, to not use the default ("BTC")
|
// update the display unit, to not use the default ("BTC")
|
||||||
|
@ -58,6 +58,7 @@ private slots:
|
|||||||
void updateDisplayUnit();
|
void updateDisplayUnit();
|
||||||
void handleTransactionClicked(const QModelIndex &index);
|
void handleTransactionClicked(const QModelIndex &index);
|
||||||
void updateAlerts(const QString &warnings);
|
void updateAlerts(const QString &warnings);
|
||||||
|
void updateWatchOnlyLabels(bool showWatchOnly);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // OVERVIEWPAGE_H
|
#endif // OVERVIEWPAGE_H
|
||||||
|
@ -36,6 +36,7 @@ WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *p
|
|||||||
cachedNumBlocks(0)
|
cachedNumBlocks(0)
|
||||||
{
|
{
|
||||||
fProcessingQueuedTransactions = false;
|
fProcessingQueuedTransactions = false;
|
||||||
|
fHaveWatchOnly = wallet->HaveWatchOnly();
|
||||||
|
|
||||||
addressTableModel = new AddressTableModel(wallet, this);
|
addressTableModel = new AddressTableModel(wallet, this);
|
||||||
transactionTableModel = new TransactionTableModel(wallet, this);
|
transactionTableModel = new TransactionTableModel(wallet, this);
|
||||||
@ -81,6 +82,11 @@ qint64 WalletModel::getImmatureBalance() const
|
|||||||
return wallet->GetImmatureBalance();
|
return wallet->GetImmatureBalance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WalletModel::haveWatchOnly() const
|
||||||
|
{
|
||||||
|
return fHaveWatchOnly;
|
||||||
|
}
|
||||||
|
|
||||||
qint64 WalletModel::getWatchBalance() const
|
qint64 WalletModel::getWatchBalance() const
|
||||||
{
|
{
|
||||||
return wallet->GetWatchOnlyBalance();
|
return wallet->GetWatchOnlyBalance();
|
||||||
@ -144,9 +150,15 @@ void WalletModel::checkBalanceChanged()
|
|||||||
qint64 newBalance = getBalance();
|
qint64 newBalance = getBalance();
|
||||||
qint64 newUnconfirmedBalance = getUnconfirmedBalance();
|
qint64 newUnconfirmedBalance = getUnconfirmedBalance();
|
||||||
qint64 newImmatureBalance = getImmatureBalance();
|
qint64 newImmatureBalance = getImmatureBalance();
|
||||||
qint64 newWatchOnlyBalance = getWatchBalance();
|
qint64 newWatchOnlyBalance = 0;
|
||||||
qint64 newWatchUnconfBalance = getWatchUnconfirmedBalance();
|
qint64 newWatchUnconfBalance = 0;
|
||||||
qint64 newWatchImmatureBalance = getWatchImmatureBalance();
|
qint64 newWatchImmatureBalance = 0;
|
||||||
|
if (haveWatchOnly())
|
||||||
|
{
|
||||||
|
newWatchOnlyBalance = getWatchBalance();
|
||||||
|
newWatchUnconfBalance = getWatchUnconfirmedBalance();
|
||||||
|
newWatchImmatureBalance = getWatchImmatureBalance();
|
||||||
|
}
|
||||||
|
|
||||||
if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance || cachedImmatureBalance != newImmatureBalance ||
|
if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance || cachedImmatureBalance != newImmatureBalance ||
|
||||||
cachedWatchOnlyBalance != newWatchOnlyBalance || cachedWatchUnconfBalance != newWatchUnconfBalance || cachedWatchImmatureBalance != newWatchImmatureBalance)
|
cachedWatchOnlyBalance != newWatchOnlyBalance || cachedWatchUnconfBalance != newWatchUnconfBalance || cachedWatchImmatureBalance != newWatchImmatureBalance)
|
||||||
@ -185,6 +197,12 @@ void WalletModel::updateAddressBook(const QString &address, const QString &label
|
|||||||
addressTableModel->updateEntry(address, label, isMine, purpose, status);
|
addressTableModel->updateEntry(address, label, isMine, purpose, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WalletModel::updateWatchOnlyFlag(bool fHaveWatchonly)
|
||||||
|
{
|
||||||
|
fHaveWatchOnly = fHaveWatchonly;
|
||||||
|
emit notifyWatchonlyChanged(fHaveWatchonly);
|
||||||
|
}
|
||||||
|
|
||||||
bool WalletModel::validateAddress(const QString &address)
|
bool WalletModel::validateAddress(const QString &address)
|
||||||
{
|
{
|
||||||
CBitcoinAddress addressParsed(address.toStdString());
|
CBitcoinAddress addressParsed(address.toStdString());
|
||||||
@ -499,6 +517,12 @@ static void ShowProgress(WalletModel *walletmodel, const std::string &title, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly)
|
||||||
|
{
|
||||||
|
QMetaObject::invokeMethod(walletmodel, "updateWatchOnlyFlag", Qt::QueuedConnection,
|
||||||
|
Q_ARG(bool, fHaveWatchonly));
|
||||||
|
}
|
||||||
|
|
||||||
void WalletModel::subscribeToCoreSignals()
|
void WalletModel::subscribeToCoreSignals()
|
||||||
{
|
{
|
||||||
// Connect signals to wallet
|
// Connect signals to wallet
|
||||||
@ -506,6 +530,7 @@ void WalletModel::subscribeToCoreSignals()
|
|||||||
wallet->NotifyAddressBookChanged.connect(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5, _6));
|
wallet->NotifyAddressBookChanged.connect(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5, _6));
|
||||||
wallet->NotifyTransactionChanged.connect(boost::bind(NotifyTransactionChanged, this, _1, _2, _3));
|
wallet->NotifyTransactionChanged.connect(boost::bind(NotifyTransactionChanged, this, _1, _2, _3));
|
||||||
wallet->ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
|
wallet->ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
|
||||||
|
wallet->NotifyWatchonlyChanged.connect(boost::bind(NotifyWatchonlyChanged, this, _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WalletModel::unsubscribeFromCoreSignals()
|
void WalletModel::unsubscribeFromCoreSignals()
|
||||||
@ -515,6 +540,7 @@ void WalletModel::unsubscribeFromCoreSignals()
|
|||||||
wallet->NotifyAddressBookChanged.disconnect(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5, _6));
|
wallet->NotifyAddressBookChanged.disconnect(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5, _6));
|
||||||
wallet->NotifyTransactionChanged.disconnect(boost::bind(NotifyTransactionChanged, this, _1, _2, _3));
|
wallet->NotifyTransactionChanged.disconnect(boost::bind(NotifyTransactionChanged, this, _1, _2, _3));
|
||||||
wallet->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
|
wallet->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
|
||||||
|
wallet->NotifyWatchonlyChanged.disconnect(boost::bind(NotifyWatchonlyChanged, this, _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// WalletModel::UnlockContext implementation
|
// WalletModel::UnlockContext implementation
|
||||||
|
@ -128,6 +128,7 @@ public:
|
|||||||
qint64 getBalance(const CCoinControl *coinControl = NULL) const;
|
qint64 getBalance(const CCoinControl *coinControl = NULL) const;
|
||||||
qint64 getUnconfirmedBalance() const;
|
qint64 getUnconfirmedBalance() const;
|
||||||
qint64 getImmatureBalance() const;
|
qint64 getImmatureBalance() const;
|
||||||
|
bool haveWatchOnly() const;
|
||||||
qint64 getWatchBalance() const;
|
qint64 getWatchBalance() const;
|
||||||
qint64 getWatchUnconfirmedBalance() const;
|
qint64 getWatchUnconfirmedBalance() const;
|
||||||
qint64 getWatchImmatureBalance() const;
|
qint64 getWatchImmatureBalance() const;
|
||||||
@ -198,6 +199,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
CWallet *wallet;
|
CWallet *wallet;
|
||||||
bool fProcessingQueuedTransactions;
|
bool fProcessingQueuedTransactions;
|
||||||
|
bool fHaveWatchOnly;
|
||||||
|
|
||||||
// Wallet has an options model for wallet-specific options
|
// Wallet has an options model for wallet-specific options
|
||||||
// (transaction fee, for example)
|
// (transaction fee, for example)
|
||||||
@ -249,6 +251,9 @@ signals:
|
|||||||
// Show progress dialog e.g. for rescan
|
// Show progress dialog e.g. for rescan
|
||||||
void showProgress(const QString &title, int nProgress);
|
void showProgress(const QString &title, int nProgress);
|
||||||
|
|
||||||
|
// Watch-only address added
|
||||||
|
void notifyWatchonlyChanged(bool fHaveWatchonly);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/* Wallet status might have changed */
|
/* Wallet status might have changed */
|
||||||
void updateStatus();
|
void updateStatus();
|
||||||
@ -256,6 +261,8 @@ public slots:
|
|||||||
void updateTransaction(const QString &hash, int status);
|
void updateTransaction(const QString &hash, int status);
|
||||||
/* New, updated or removed address book entry */
|
/* New, updated or removed address book entry */
|
||||||
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status);
|
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status);
|
||||||
|
/* Watchonly added */
|
||||||
|
void updateWatchOnlyFlag(bool fHaveWatchonly);
|
||||||
/* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */
|
/* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */
|
||||||
void pollBalanceChanged();
|
void pollBalanceChanged();
|
||||||
/* Needed to update fProcessingQueuedTransactions through a QueuedConnection */
|
/* Needed to update fProcessingQueuedTransactions through a QueuedConnection */
|
||||||
|
@ -153,6 +153,7 @@ bool CWallet::AddWatchOnly(const CScript &dest)
|
|||||||
if (!CCryptoKeyStore::AddWatchOnly(dest))
|
if (!CCryptoKeyStore::AddWatchOnly(dest))
|
||||||
return false;
|
return false;
|
||||||
nTimeFirstKey = 1; // No birthday information for watch-only keys.
|
nTimeFirstKey = 1; // No birthday information for watch-only keys.
|
||||||
|
NotifyWatchonlyChanged(true);
|
||||||
if (!fFileBacked)
|
if (!fFileBacked)
|
||||||
return true;
|
return true;
|
||||||
return CWalletDB(strWalletFile).WriteWatchOnly(dest);
|
return CWalletDB(strWalletFile).WriteWatchOnly(dest);
|
||||||
|
@ -408,6 +408,9 @@ public:
|
|||||||
|
|
||||||
/** Show progress e.g. for rescan */
|
/** Show progress e.g. for rescan */
|
||||||
boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
|
boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
|
||||||
|
|
||||||
|
/** Watch-only address added */
|
||||||
|
boost::signals2::signal<void (bool fHaveWatchOnly)> NotifyWatchonlyChanged;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A key allocated from the key pool. */
|
/** A key allocated from the key pool. */
|
||||||
|
Loading…
Reference in New Issue
Block a user