コード例 #1
0
ファイル: Namecoin.cpp プロジェクト: Paul4/Moneychanger
/**
 * Try to unlock the wallet.  If a passphrase is needed, a dialog is shown
 * until the correct one is entered or the user cancels the action.  In the
 * latter case, UnlockFailure is thrown.
 * @throws UnlockFailure if the user cancels the unlock.
 */
void
NMC_WalletUnlocker::unlock ()
{
  std::string pwd;

  qDebug () << "Trying to unlock the Namecoin wallet.";

  /* If we need a password, show the dialog.  */
  if (nc.needWalletPassphrase ())
    {
      OTPassword otPwd;

      MTDlgPassword dlg (nullptr, otPwd);
      dlg.setDisplay ("Your Namecoin wallet is locked.  For the operations to"
                      " proceed, please enter the passphrase to temporarily"
                      " unlock the wallet.");
      const int res = dlg.exec ();

      /* Return code is 0 for cancel button or closing the window.
         It is 1 in case of ok.  */
      if (res == 0)
        {
          qDebug () << "Wallet unlock was cancelled.";
          throw UnlockFailure("Wallet unlock was cancelled.");
        }

      dlg.extractPassword ();
      pwd = otPwd.getPassword ();
    }

  /* Now try to unlock.  If the passphrase is wrong, retry by a tail-recursive
     call to unlock().  */
  try
    {
      unlocker.unlock (pwd);
      qDebug () << "Unlock successful (or not necessary).";
    }
  catch (const nmcrpc::NamecoinInterface::UnlockFailure& exc)
    {
      qDebug () << "Wrong passphrase, retrying.";
      unlock ();
    }
  catch (const nmcrpc::JsonRpc::RpcError& exc)
    {
      qDebug () << "NMC RPC Error " << exc.getErrorCode ()
                << ": " << exc.getErrorMessage ().c_str ();
    }
  catch (const std::exception& exc)
    {
      qDebug () << "Error: " << exc.what ();
    }
}
コード例 #2
0
void MTPasswordCallback::runOne(const char * szDisplay, OTPassword & theOutput)
{
    if (NULL == szDisplay)
    {
        qDebug() << QString("MTPasswordCallback::runOne: Failure: szDisplay (telling you why to enter password) is NULL!");
        return;
    }

//    MTDlgPassword * pDlg = new MTDlgPassword(NULL, theOutput);
    MTDlgPassword * pDlg = new MTDlgPassword(Moneychanger::It(), theOutput);

    pDlg->setAttribute(Qt::WA_DeleteOnClose);

    QString qstrDisplay(szDisplay);
    pDlg->setDisplay(qstrDisplay);

    pDlg->exec();
}