<commit_before>#include "sigmapage.h"
#include "ui_sigmapage.h"

#include "bitcoinunits.h"
#include "guiutil.h"
#include "manualmintdialog.h"
#include "optionsmodel.h"
#include "platformstyle.h"
#include "sendcoinsdialog.h"
#include "sendcoinsentry.h"
#include "walletmodel.h"

#include "../zerocoin_v3.h"
#include "../wallet/wallet.h"
#include "../wallet/walletdb.h"
#include "../sigma/coin.h"

#include <QMessageBox>
#include <QScrollBar>
#include <QTextDocument>
#include <QTimer>

#include <unordered_map>

#define SEND_CONFIRM_DELAY   3

SigmaPage::SigmaPage(const PlatformStyle *platformStyle, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SigmaPage),
    clientModel(0),
    walletModel(0),
    isNewRecipientAllowed(true),
    platformStyle(platformStyle)
{
    ui->setupUi(this);
    setWindowTitle(tr("Sigma"));

    ui->scrollArea->setBackgroundRole(QPalette::Base);

    if (platformStyle->getImagesOnButtons()) {
        ui->sendButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
        ui->clearButton->setIcon(platformStyle->SingleColorIcon(":/icons/quit"));
        ui->addButton->setIcon(platformStyle->SingleColorIcon(":/icons/add"));

        ui->mintButton->setIcon(platformStyle->SingleColorIcon(":/icons/add"));
        ui->selectDenomsButton->setIcon(platformStyle->SingleColorIcon(":/icons/edit"));
    } else {
        ui->sendButton->setIcon(QIcon());
        ui->clearButton->setIcon(QIcon());
        ui->addButton->setIcon(QIcon());

        ui->mintButton->setIcon(QIcon());
        ui->selectDenomsButton->setIcon(QIcon());
    }

    addEntry();

    // spend
    connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addEntry()));
    connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear()));

    ui->amountToMint->setLocale(QLocale::c());
}

void SigmaPage::setClientModel(ClientModel *model)
{
    this->clientModel = model;

    if (model) {
        bool sigmaAllowed = IsSigmaAllowed(model->getNumBlocks());

        connect(model, SIGNAL(numBlocksChanged(int, const QDateTime&, double, bool)), this, SLOT(numBlocksChanged(int, const QDateTime&, double, bool)));

        ui->mintButton->setEnabled(sigmaAllowed);
        ui->sendButton->setEnabled(sigmaAllowed);
    }
}

void SigmaPage::setWalletModel(WalletModel *model)
{
    this->walletModel = model;

    if (model && model->getOptionsModel()) {
        connect(model, SIGNAL(balanceChanged(CAmount, CAmount, CAmount, CAmount, CAmount, CAmount)),
            this, SLOT(updateAvailableToMintBalance(CAmount)));
        updateAvailableToMintBalance(model->getBalance());
        connect(model, SIGNAL(notifySigmaChanged(const std::vector<CZerocoinEntryV3>, const std::vector<CZerocoinEntryV3>)),
            this, SLOT(updateCoins(const std::vector<CZerocoinEntryV3>, const std::vector<CZerocoinEntryV3>)));
        model->checkSigmaAmount(true);
        for (int i = 0; i < ui->entries->count(); ++i) {
            SendCoinsEntry *entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget());
            if (entry) {
                entry->setModel(model);
            }
        }
    }
}

SigmaPage::~SigmaPage()
{
    delete ui;
}

void SigmaPage::numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, bool header)
{
    if (!header) {
        bool sigmaAllowed = IsSigmaAllowed(count);

        ui->mintButton->setEnabled(sigmaAllowed);
        ui->sendButton->setEnabled(sigmaAllowed);
    }
}

void SigmaPage::on_mintButton_clicked()
{
    auto rawAmount = ui->amountToMint->value();
    CAmount amount(rawAmount * COIN);

    // round any thing smaller than 0.1
    // if more than or equal 0.05 round to 0.1 otherwise round to 0.0
    amount = amount / CENT * CENT + ((amount % CENT >= CENT / 2) ? CENT : 0);

    try {
        walletModel->sigmaMint(amount);
    } catch (const std::runtime_error& e) {
        QMessageBox::critical(this, tr("Error"),
            tr("You cannot mint Sigma because %1").arg(tr(e.what())),
            QMessageBox::Ok, QMessageBox::Ok);
        return;
    }

    QMessageBox::information(this, tr("Success"),
        tr("Sigma successfully minted"),
        QMessageBox::Ok, QMessageBox::Ok);

    ui->amountToMint->setValue(0);
}
<commit_msg>Ask for passphrase at Mint dialog<commit_after>#include "sigmapage.h"
#include "ui_sigmapage.h"

#include "bitcoinunits.h"
#include "guiutil.h"
#include "manualmintdialog.h"
#include "optionsmodel.h"
#include "platformstyle.h"
#include "sendcoinsdialog.h"
#include "sendcoinsentry.h"
#include "walletmodel.h"

#include "../zerocoin_v3.h"
#include "../wallet/wallet.h"
#include "../wallet/walletdb.h"
#include "../sigma/coin.h"

#include <QMessageBox>
#include <QScrollBar>
#include <QTextDocument>
#include <QTimer>

#include <unordered_map>

#define SEND_CONFIRM_DELAY   3

SigmaPage::SigmaPage(const PlatformStyle *platformStyle, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SigmaPage),
    clientModel(0),
    walletModel(0),
    isNewRecipientAllowed(true),
    platformStyle(platformStyle)
{
    ui->setupUi(this);
    setWindowTitle(tr("Sigma"));

    ui->scrollArea->setBackgroundRole(QPalette::Base);

    if (platformStyle->getImagesOnButtons()) {
        ui->sendButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
        ui->clearButton->setIcon(platformStyle->SingleColorIcon(":/icons/quit"));
        ui->addButton->setIcon(platformStyle->SingleColorIcon(":/icons/add"));

        ui->mintButton->setIcon(platformStyle->SingleColorIcon(":/icons/add"));
        ui->selectDenomsButton->setIcon(platformStyle->SingleColorIcon(":/icons/edit"));
    } else {
        ui->sendButton->setIcon(QIcon());
        ui->clearButton->setIcon(QIcon());
        ui->addButton->setIcon(QIcon());

        ui->mintButton->setIcon(QIcon());
        ui->selectDenomsButton->setIcon(QIcon());
    }

    addEntry();

    // spend
    connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addEntry()));
    connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear()));

    ui->amountToMint->setLocale(QLocale::c());
}

void SigmaPage::setClientModel(ClientModel *model)
{
    this->clientModel = model;

    if (model) {
        bool sigmaAllowed = IsSigmaAllowed(model->getNumBlocks());

        connect(model, SIGNAL(numBlocksChanged(int, const QDateTime&, double, bool)), this, SLOT(numBlocksChanged(int, const QDateTime&, double, bool)));

        ui->mintButton->setEnabled(sigmaAllowed);
        ui->sendButton->setEnabled(sigmaAllowed);
    }
}

void SigmaPage::setWalletModel(WalletModel *model)
{
    this->walletModel = model;

    if (model && model->getOptionsModel()) {
        connect(model, SIGNAL(balanceChanged(CAmount, CAmount, CAmount, CAmount, CAmount, CAmount)),
            this, SLOT(updateAvailableToMintBalance(CAmount)));
        updateAvailableToMintBalance(model->getBalance());
        connect(model, SIGNAL(notifySigmaChanged(const std::vector<CZerocoinEntryV3>, const std::vector<CZerocoinEntryV3>)),
            this, SLOT(updateCoins(const std::vector<CZerocoinEntryV3>, const std::vector<CZerocoinEntryV3>)));
        model->checkSigmaAmount(true);
        for (int i = 0; i < ui->entries->count(); ++i) {
            SendCoinsEntry *entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget());
            if (entry) {
                entry->setModel(model);
            }
        }
    }
}

SigmaPage::~SigmaPage()
{
    delete ui;
}

void SigmaPage::numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, bool header)
{
    if (!header) {
        bool sigmaAllowed = IsSigmaAllowed(count);

        ui->mintButton->setEnabled(sigmaAllowed);
        ui->sendButton->setEnabled(sigmaAllowed);
    }
}

void SigmaPage::on_mintButton_clicked()
{
    auto rawAmount = ui->amountToMint->value();
    CAmount amount(rawAmount * COIN);

    // round any thing smaller than 0.1
    // if more than or equal 0.05 round to 0.1 otherwise round to 0.0
    amount = amount / CENT * CENT + ((amount % CENT >= CENT / 2) ? CENT : 0);

    try {
        WalletModel::UnlockContext ctx(walletModel->requestUnlock());
        if (!ctx.isValid()) {
            return;
        }
        walletModel->sigmaMint(amount);
    } catch (const std::runtime_error& e) {
        QMessageBox::critical(this, tr("Error"),
            tr("You cannot mint Sigma because %1").arg(tr(e.what())),
            QMessageBox::Ok, QMessageBox::Ok);
        return;
    }

    QMessageBox::information(this, tr("Success"),
        tr("Sigma successfully minted"),
        QMessageBox::Ok, QMessageBox::Ok);

    ui->amountToMint->setValue(0);
}

{'fraction_non_alphanumeric': 0.1553913645809282, 'fraction_numerical': 0.005079658277534056, 'mean_word_length': 3.736468015308912, 'pattern_counts': {'":': 10, '<': 25, '<?xml version=': 0, '>': 142, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3701947', 'n_tokens_mistral': 2801, 'n_tokens_neox': 2766, 'n_words': 468}