383a3b8b02
- Replace ~290 BOOST_FOREACH with C++11 range-for across 41+ files - Replace boost::assign::map_list_of with C++11 brace initialization - Remove PAIRTYPE macro (no longer needed without BOOST_FOREACH) - Guard OpenSSL locking callbacks for 3.x (no-ops in >= 1.1.0) - Fix Qt deprecated APIs for Qt6 compat (QStyleOptionViewItemV4, setResizeMode) - Add openssl_compat.h version string wrapper - Enable C++17 in makefile.unix and triangles-qt.pro - Delete 163 dead Tor v2 source files (~150K lines removed) - Add embedded Tor scaffold (tor_embedded.h/cpp) using tor_api.h - Add build-libtor.sh helper and CODEX-TOR-GUIDE.md - Update makefile.unix and .pro with USE_TOR_EMBEDDED optional flag - Fallback to external tor_process when not compiled with libtor - IBD pipeline refill: 100 -> 1000 blocks - Send/recv buffer limits: unlimited -> 100MB/32MB - Orphan block cap: unlimited -> 750 with random eviction - Socket poll: 10ms -> 1ms during IBD - Message handler sleep: 10ms -> 1ms during IBD - Stall detection timeout: 5s -> 2s Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
169 lines
4.9 KiB
C++
169 lines
4.9 KiB
C++
#include "signmessagepage.h"
|
|
#include "ui_signmessagepage.h"
|
|
|
|
#include "addressbookpage.h"
|
|
#include "base58.h"
|
|
#include "guiutil.h"
|
|
#include "init.h"
|
|
#include "main.h"
|
|
#include "optionsmodel.h"
|
|
#include "walletmodel.h"
|
|
#include "wallet.h"
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <QClipboard>
|
|
SignMessagePage::SignMessagePage(QWidget *parent) :
|
|
QWidget(parent),
|
|
ui(new Ui::SignMessagePage),
|
|
model(0)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
#if (QT_VERSION >= 0x040700)
|
|
/* Do not move this to the XML file, Qt before 4.7 will choke on it */
|
|
ui->addressIn_SM->setPlaceholderText(tr("Enter a Triangles address (e.g. TXc7mPCNFFpinDonuSH5PNVY9S8nBcvGQm)"));
|
|
ui->signatureOut_SM->setPlaceholderText(tr("Click \"Sign Message\" to generate signature"));
|
|
#endif
|
|
|
|
GUIUtil::setupAddressWidget(ui->addressIn_SM, this);
|
|
|
|
ui->addressIn_SM->installEventFilter(this);
|
|
ui->messageIn_SM->installEventFilter(this);
|
|
ui->signatureOut_SM->installEventFilter(this);
|
|
|
|
ui->signatureOut_SM->setFont(GUIUtil::trianglesAddressFont());
|
|
|
|
// To make size minimal
|
|
ui->statusLabel_SM->setText(tr("The entered address is invalid.") + QString(" ") + tr("Please check the address and try again."));
|
|
ui->statusLabel_SM->clear();
|
|
}
|
|
|
|
SignMessagePage::~SignMessagePage()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void SignMessagePage::setModel(WalletModel *model)
|
|
{
|
|
this->model = model;
|
|
}
|
|
|
|
void SignMessagePage::setAddress_SM(const QString &address)
|
|
{
|
|
ui->addressIn_SM->setText(address);
|
|
ui->messageIn_SM->setFocus();
|
|
}
|
|
|
|
void SignMessagePage::showTab_SM(bool fShow)
|
|
{
|
|
// Reserved
|
|
}
|
|
|
|
void SignMessagePage::on_addressBookButton_SM_clicked()
|
|
{
|
|
if (model && model->getAddressTableModel())
|
|
{
|
|
AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::ReceivingTab, this);
|
|
dlg.setModel(model->getAddressTableModel());
|
|
if (dlg.exec())
|
|
{
|
|
setAddress_SM(dlg.getReturnValue());
|
|
}
|
|
}
|
|
}
|
|
|
|
void SignMessagePage::on_pasteButton_SM_clicked()
|
|
{
|
|
setAddress_SM(QApplication::clipboard()->text());
|
|
}
|
|
|
|
void SignMessagePage::on_signMessageButton_SM_clicked()
|
|
{
|
|
/* Clear old signature to ensure users don't get confused on error with an old signature displayed */
|
|
ui->signatureOut_SM->clear();
|
|
|
|
CTrianglesAddress addr(ui->addressIn_SM->text().toStdString());
|
|
if (!addr.IsValid())
|
|
{
|
|
ui->addressIn_SM->setValid(false);
|
|
ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }");
|
|
ui->statusLabel_SM->setText(tr("The entered address is invalid.") + QString(" ") + tr("Please check the address and try again."));
|
|
return;
|
|
}
|
|
CKeyID keyID;
|
|
if (!addr.GetKeyID(keyID))
|
|
{
|
|
ui->addressIn_SM->setValid(false);
|
|
ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }");
|
|
ui->statusLabel_SM->setText(tr("The entered address does not refer to a key.") + QString(" ") + tr("Please check the address and try again."));
|
|
return;
|
|
}
|
|
|
|
WalletModel::UnlockContext ctx(model->requestUnlock());
|
|
if (!ctx.isValid())
|
|
{
|
|
ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }");
|
|
ui->statusLabel_SM->setText(tr("Wallet unlock was cancelled."));
|
|
return;
|
|
}
|
|
|
|
CKey key;
|
|
if (!pwalletMain->GetKey(keyID, key))
|
|
{
|
|
ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }");
|
|
ui->statusLabel_SM->setText(tr("Private key for the entered address is not available."));
|
|
return;
|
|
}
|
|
|
|
CDataStream ss(SER_GETHASH, 0);
|
|
ss << strMessageMagic;
|
|
ss << ui->messageIn_SM->document()->toPlainText().toStdString();
|
|
|
|
std::vector<unsigned char> vchSig;
|
|
if (!key.SignCompact(Hash(ss.begin(), ss.end()), vchSig))
|
|
{
|
|
ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }");
|
|
ui->statusLabel_SM->setText(QString("<nobr>") + tr("Message signing failed.") + QString("</nobr>"));
|
|
return;
|
|
}
|
|
|
|
ui->statusLabel_SM->setStyleSheet("QLabel { color: #E22104; }");
|
|
ui->statusLabel_SM->setText(QString("<nobr>") + tr("Message signed.") + QString("</nobr>"));
|
|
|
|
ui->signatureOut_SM->setText(QString::fromStdString(EncodeBase64(&vchSig[0], vchSig.size())));
|
|
}
|
|
|
|
void SignMessagePage::on_copySignatureButton_SM_clicked()
|
|
{
|
|
QApplication::clipboard()->setText(ui->signatureOut_SM->text());
|
|
}
|
|
|
|
void SignMessagePage::on_clearButton_SM_clicked()
|
|
{
|
|
ui->addressIn_SM->clear();
|
|
ui->messageIn_SM->clear();
|
|
ui->signatureOut_SM->clear();
|
|
ui->statusLabel_SM->clear();
|
|
|
|
ui->addressIn_SM->setFocus();
|
|
}
|
|
|
|
bool SignMessagePage::eventFilter(QObject *object, QEvent *event)
|
|
{
|
|
if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::FocusIn)
|
|
{
|
|
/* Clear status message on focus change */
|
|
ui->statusLabel_SM->clear();
|
|
|
|
/* Select generated signature */
|
|
if (object == ui->signatureOut_SM)
|
|
{
|
|
ui->signatureOut_SM->selectAll();
|
|
return true;
|
|
}
|
|
}
|
|
return QWidget::eventFilter(object, event);
|
|
}
|