Changeset View
Changeset View
Standalone View
Standalone View
src/qt/signverifymessagedialog.cpp
Show First 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | void SignVerifyMessageDialog::on_signMessageButton_SM_clicked() { | ||||
WalletModel::UnlockContext ctx(model->requestUnlock()); | WalletModel::UnlockContext ctx(model->requestUnlock()); | ||||
if (!ctx.isValid()) { | if (!ctx.isValid()) { | ||||
ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); | ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); | ||||
ui->statusLabel_SM->setText(tr("Wallet unlock was cancelled.")); | ui->statusLabel_SM->setText(tr("Wallet unlock was cancelled.")); | ||||
return; | return; | ||||
} | } | ||||
CKey key; | |||||
if (!model->wallet().getPrivKey(GetScriptForDestination(destination), | |||||
CKeyID(*pkhash), key)) { | |||||
ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); | |||||
ui->statusLabel_SM->setText( | |||||
tr("Private key for the entered address is not available.")); | |||||
return; | |||||
} | |||||
const std::string &message = | const std::string &message = | ||||
ui->messageIn_SM->document()->toPlainText().toStdString(); | ui->messageIn_SM->document()->toPlainText().toStdString(); | ||||
std::string signature; | std::string signature; | ||||
SigningResult res = | |||||
model->wallet().signMessage(message, *pkhash, signature); | |||||
QString error; | |||||
switch (res) { | |||||
case SigningResult::OK: | |||||
error = tr("No error"); | |||||
break; | |||||
case SigningResult::PRIVATE_KEY_NOT_AVAILABLE: | |||||
error = tr("Private key for the entered address is not available."); | |||||
break; | |||||
case SigningResult::SIGNING_FAILED: | |||||
error = tr("Message signing failed."); | |||||
break; | |||||
// no default case, so the compiler can warn about missing cases | |||||
} | |||||
if (!MessageSign(key, message, signature)) { | if (res != SigningResult::OK) { | ||||
ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); | ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); | ||||
ui->statusLabel_SM->setText(QString("<nobr>") + | ui->statusLabel_SM->setText(QString("<nobr>") + error + | ||||
tr("Message signing failed.") + | |||||
QString("</nobr>")); | QString("</nobr>")); | ||||
return; | return; | ||||
} | } | ||||
ui->statusLabel_SM->setStyleSheet("QLabel { color: green; }"); | ui->statusLabel_SM->setStyleSheet("QLabel { color: green; }"); | ||||
ui->statusLabel_SM->setText(QString("<nobr>") + tr("Message signed.") + | ui->statusLabel_SM->setText(QString("<nobr>") + tr("Message signed.") + | ||||
QString("</nobr>")); | QString("</nobr>")); | ||||
▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines |