Add IsLegacy to CWallet so that the GUI knows whether to show watchonly
This commit is contained in:
parent
1cb42b22b1
commit
ce24a94494
7 changed files with 34 additions and 11 deletions
|
@ -464,6 +464,7 @@ public:
|
||||||
{
|
{
|
||||||
RemoveWallet(m_wallet);
|
RemoveWallet(m_wallet);
|
||||||
}
|
}
|
||||||
|
bool isLegacy() override { return m_wallet->IsLegacy(); }
|
||||||
std::unique_ptr<Handler> handleUnload(UnloadFn fn) override
|
std::unique_ptr<Handler> handleUnload(UnloadFn fn) override
|
||||||
{
|
{
|
||||||
return MakeHandler(m_wallet->NotifyUnload.connect(fn));
|
return MakeHandler(m_wallet->NotifyUnload.connect(fn));
|
||||||
|
|
|
@ -266,6 +266,9 @@ public:
|
||||||
// Remove wallet.
|
// Remove wallet.
|
||||||
virtual void remove() = 0;
|
virtual void remove() = 0;
|
||||||
|
|
||||||
|
//! Return whether is a legacy wallet
|
||||||
|
virtual bool isLegacy() = 0;
|
||||||
|
|
||||||
//! Register handler for unload message.
|
//! Register handler for unload message.
|
||||||
using UnloadFn = std::function<void()>;
|
using UnloadFn = std::function<void()>;
|
||||||
virtual std::unique_ptr<Handler> handleUnload(UnloadFn fn) = 0;
|
virtual std::unique_ptr<Handler> handleUnload(UnloadFn fn) = 0;
|
||||||
|
|
|
@ -161,20 +161,27 @@ void OverviewPage::setBalance(const interfaces::WalletBalances& balances)
|
||||||
{
|
{
|
||||||
int unit = walletModel->getOptionsModel()->getDisplayUnit();
|
int unit = walletModel->getOptionsModel()->getDisplayUnit();
|
||||||
m_balances = balances;
|
m_balances = balances;
|
||||||
if (walletModel->wallet().privateKeysDisabled()) {
|
if (walletModel->wallet().isLegacy()) {
|
||||||
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance, false, BitcoinUnits::separatorAlways));
|
if (walletModel->wallet().privateKeysDisabled()) {
|
||||||
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, balances.unconfirmed_watch_only_balance, false, BitcoinUnits::separatorAlways));
|
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance, false, BitcoinUnits::separatorAlways));
|
||||||
ui->labelImmature->setText(BitcoinUnits::formatWithUnit(unit, balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways));
|
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, balances.unconfirmed_watch_only_balance, false, BitcoinUnits::separatorAlways));
|
||||||
ui->labelTotal->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance + balances.unconfirmed_watch_only_balance + balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways));
|
ui->labelImmature->setText(BitcoinUnits::formatWithUnit(unit, balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways));
|
||||||
|
ui->labelTotal->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance + balances.unconfirmed_watch_only_balance + balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways));
|
||||||
|
} else {
|
||||||
|
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balances.balance, false, BitcoinUnits::separatorAlways));
|
||||||
|
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, balances.unconfirmed_balance, false, BitcoinUnits::separatorAlways));
|
||||||
|
ui->labelImmature->setText(BitcoinUnits::formatWithUnit(unit, balances.immature_balance, false, BitcoinUnits::separatorAlways));
|
||||||
|
ui->labelTotal->setText(BitcoinUnits::formatWithUnit(unit, balances.balance + balances.unconfirmed_balance + balances.immature_balance, false, BitcoinUnits::separatorAlways));
|
||||||
|
ui->labelWatchAvailable->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance, false, BitcoinUnits::separatorAlways));
|
||||||
|
ui->labelWatchPending->setText(BitcoinUnits::formatWithUnit(unit, balances.unconfirmed_watch_only_balance, false, BitcoinUnits::separatorAlways));
|
||||||
|
ui->labelWatchImmature->setText(BitcoinUnits::formatWithUnit(unit, balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways));
|
||||||
|
ui->labelWatchTotal->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance + balances.unconfirmed_watch_only_balance + balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balances.balance, false, BitcoinUnits::separatorAlways));
|
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balances.balance, false, BitcoinUnits::separatorAlways));
|
||||||
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, balances.unconfirmed_balance, false, BitcoinUnits::separatorAlways));
|
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, balances.unconfirmed_balance, false, BitcoinUnits::separatorAlways));
|
||||||
ui->labelImmature->setText(BitcoinUnits::formatWithUnit(unit, balances.immature_balance, false, BitcoinUnits::separatorAlways));
|
ui->labelImmature->setText(BitcoinUnits::formatWithUnit(unit, balances.immature_balance, false, BitcoinUnits::separatorAlways));
|
||||||
ui->labelTotal->setText(BitcoinUnits::formatWithUnit(unit, balances.balance + balances.unconfirmed_balance + balances.immature_balance, false, BitcoinUnits::separatorAlways));
|
ui->labelTotal->setText(BitcoinUnits::formatWithUnit(unit, balances.balance + balances.unconfirmed_balance + balances.immature_balance, false, BitcoinUnits::separatorAlways));
|
||||||
ui->labelWatchAvailable->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance, false, BitcoinUnits::separatorAlways));
|
|
||||||
ui->labelWatchPending->setText(BitcoinUnits::formatWithUnit(unit, balances.unconfirmed_watch_only_balance, false, BitcoinUnits::separatorAlways));
|
|
||||||
ui->labelWatchImmature->setText(BitcoinUnits::formatWithUnit(unit, balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways));
|
|
||||||
ui->labelWatchTotal->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance + balances.unconfirmed_watch_only_balance + balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways));
|
|
||||||
}
|
}
|
||||||
// only show immature (newly mined) balance if it's non-zero, so as not to complicate things
|
// only show immature (newly mined) balance if it's non-zero, so as not to complicate things
|
||||||
// for the non-mining users
|
// for the non-mining users
|
||||||
|
|
|
@ -1851,7 +1851,7 @@ static UniValue keypoolrefill(const JSONRPCRequest& request)
|
||||||
},
|
},
|
||||||
}.Check(request);
|
}.Check(request);
|
||||||
|
|
||||||
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
|
if (pwallet->IsLegacy() && pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Private keys are disabled for this wallet");
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Private keys are disabled for this wallet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4412,3 +4412,12 @@ void CWallet::SetActiveScriptPubKeyMan(uint256 id, OutputType type, bool interna
|
||||||
}
|
}
|
||||||
NotifyCanGetAddressesChanged();
|
NotifyCanGetAddressesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CWallet::IsLegacy() const
|
||||||
|
{
|
||||||
|
if (m_internal_spk_managers.count(OutputType::LEGACY) == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto spk_man = dynamic_cast<LegacyScriptPubKeyMan*>(m_internal_spk_managers.at(OutputType::LEGACY));
|
||||||
|
return spk_man != nullptr;
|
||||||
|
}
|
||||||
|
|
|
@ -1165,6 +1165,9 @@ public:
|
||||||
returns false if unknown, non-tolerable flags are present */
|
returns false if unknown, non-tolerable flags are present */
|
||||||
bool SetWalletFlags(uint64_t overwriteFlags, bool memOnly);
|
bool SetWalletFlags(uint64_t overwriteFlags, bool memOnly);
|
||||||
|
|
||||||
|
/** Determine if we are a legacy wallet */
|
||||||
|
bool IsLegacy() const;
|
||||||
|
|
||||||
/** Returns a bracketed wallet name for displaying in logs, will return [default wallet] if the wallet has no name */
|
/** Returns a bracketed wallet name for displaying in logs, will return [default wallet] if the wallet has no name */
|
||||||
const std::string GetDisplayName() const override {
|
const std::string GetDisplayName() const override {
|
||||||
std::string wallet_name = GetName().length() == 0 ? "default wallet" : GetName();
|
std::string wallet_name = GetName().length() == 0 ? "default wallet" : GetName();
|
||||||
|
|
|
@ -699,7 +699,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
|
||||||
wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys, wss.m_unknown_records);
|
wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys, wss.m_unknown_records);
|
||||||
|
|
||||||
// nTimeFirstKey is only reliable if all keys have metadata
|
// nTimeFirstKey is only reliable if all keys have metadata
|
||||||
if ((wss.nKeys + wss.nCKeys + wss.nWatchKeys) != wss.nKeyMeta) {
|
if (pwallet->IsLegacy() && (wss.nKeys + wss.nCKeys + wss.nWatchKeys) != wss.nKeyMeta) {
|
||||||
auto spk_man = pwallet->GetOrCreateLegacyScriptPubKeyMan();
|
auto spk_man = pwallet->GetOrCreateLegacyScriptPubKeyMan();
|
||||||
if (spk_man) {
|
if (spk_man) {
|
||||||
LOCK(spk_man->cs_KeyStore);
|
LOCK(spk_man->cs_KeyStore);
|
||||||
|
|
Loading…
Reference in a new issue