MWEB: UI: Don't allow sending to MWEB addresses until after activation.

This commit is contained in:
David Burkett 2022-01-30 21:52:17 -05:00 committed by Loshan T
parent 493e8288ab
commit 2a33f5b322
8 changed files with 40 additions and 0 deletions

View File

@ -196,6 +196,7 @@ public:
return GuessVerificationProgress(Params().TxData(), tip);
}
bool isInitialBlockDownload() override { return ::ChainstateActive().IsInitialBlockDownload(); }
bool isMWEBActive() override { return ::ChainstateActive().IsMWEBActive(); }
bool getReindex() override { return ::fReindex; }
bool getImporting() override { return ::fImporting; }
void setNetworkActive(bool active) override

View File

@ -139,6 +139,9 @@ public:
//! Is initial block download.
virtual bool isInitialBlockDownload() = 0;
//! Is MWEB activated.
virtual bool isMWEBActive() = 0;
//! Get reindex.
virtual bool getReindex() = 0;

View File

@ -212,6 +212,16 @@ bool isDust(interfaces::Node& node, const QString& address, const CAmount& amoun
return IsDust(txOut, node.getDustRelayFee());
}
bool isMWEBAddressBeforeActivated(interfaces::Node& node, const QString& address)
{
CTxDestination dest = DecodeDestination(address.toStdString());
if (dest.type() == typeid(StealthAddress)) {
return !node.isMWEBActive();
}
return false;
}
QString HtmlEscape(const QString& str, bool fMultiLine)
{
QString escaped = str.toHtmlEscaped();

View File

@ -61,6 +61,9 @@ namespace GUIUtil
// Returns true if given address+amount meets "dust" definition
bool isDust(interfaces::Node& node, const QString& address, const CAmount& amount);
// Returns true if address is of type StealthAddress and MWEB has not yet been activated.
bool isMWEBAddressBeforeActivated(interfaces::Node& node, const QString& address);
// HTML escaping for rich text controls
QString HtmlEscape(const QString& str, bool fMultiLine=false);
QString HtmlEscape(const std::string& str, bool fMultiLine=false);

View File

@ -175,6 +175,10 @@ void SendCoinsDialog::setModel(WalletModel *_model)
connect(_model->getOptionsModel(), &OptionsModel::mwebFeaturesChanged, this, &SendCoinsDialog::mwebFeatureChanged);
ui->frameMWEBFeatures->setVisible(_model->getOptionsModel()->getMWEBFeatures());
bool mweb_active = model->node().isMWEBActive();
ui->pushButtonMWEBPegIn->setEnabled(mweb_active);
ui->pushButtonMWEBPegIn->setToolTip(mweb_active ? "" : "Pegin is not available until MWEB activation");
// fee section
for (const int n : confTargets) {
ui->confTargetSelector->addItem(tr("%1 (%2 blocks)").arg(GUIUtil::formatNiceTimeOffset(n*Params().GetConsensus().nPowTargetSpacing)).arg(n));

View File

@ -167,6 +167,17 @@ bool SendCoinsEntry::validate(interfaces::Node& node)
retval = false;
}
if (retval && GUIUtil::isMWEBAddressBeforeActivated(node, ui->payTo->text())) {
ui->payTo->setValid(false);
retval = false;
QMessageBox msgBox;
msgBox.setInformativeText("You cannot send to an MWEB address until after the feature has been activated.");
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
}
return retval;
}

View File

@ -1353,6 +1353,11 @@ bool CChainState::IsInitialBlockDownload() const
return false;
}
bool CChainState::IsMWEBActive() const
{
return m_chain.Tip() != nullptr && IsMWEBEnabled(m_chain.Tip(), Params().GetConsensus());
}
static CBlockIndex *pindexBestForkTip = nullptr, *pindexBestForkBase = nullptr;
static void AlertNotify(const std::string& strMessage)

View File

@ -695,6 +695,9 @@ public:
/** Check whether we are doing an initial block download (synchronizing from disk or network) */
bool IsInitialBlockDownload() const;
/** Check whether MWEB has been activated */
bool IsMWEBActive() const;
/**
* Make various assertions about the state of the block index.
*