small bugfixes

This commit is contained in:
Aditya Kulkarni
2018-10-25 22:34:42 -07:00
parent e8555ea906
commit 71abf92280
7 changed files with 134 additions and 36 deletions

View File

@@ -68,12 +68,6 @@ MainWindow::MainWindow(QWidget *parent) :
} }
void MainWindow::setupTurnstileDialog() { void MainWindow::setupTurnstileDialog() {
//Turnstile t(this);
// t.planMigration(
// "ztsKtGwc7JTEHxQq1xiRWyU9o1sheA3tYjcaFTBfVtp4RKJ782U6pH9STEYUoWQiGn1epfRMmFhkWCUyCSCqByNj9HKnzKU",
// "ztbGDqgkmXQjheivgeirwEvJLD4SUNqsWCGwxwVg4YpGz1ARR8P2rXaptkT14z3NDKamcxNmQuvmvktyokMs7HkutRNSx1D"
// );
//t.executeMigrationStep();
// Turnstile migration // Turnstile migration
QObject::connect(ui->actionTurnstile_Migration, &QAction::triggered, [=] () { QObject::connect(ui->actionTurnstile_Migration, &QAction::triggered, [=] () {
@@ -117,18 +111,39 @@ void MainWindow::setupTurnstileDialog() {
turnstile.fromBalance->setText(Settings::getInstance()->getZECUSDDisplayFormat(bal)); turnstile.fromBalance->setText(Settings::getInstance()->getZECUSDDisplayFormat(bal));
}); });
turnstile.privLevel->addItem("Good - 3 tx over 3 days"); // Privacy level combobox
turnstile.privLevel->addItem("Excellent - 5 tx over 5 days"); // Num tx over num blocks
turnstile.privLevel->addItem("Paranoid - 10 tx over 7 days"); QList<QPair<int, int>> privOptions;
privOptions.push_back(QPair<double, double>(3, 3));
privOptions.push_back(QPair<double, double>(5, 5));
privOptions.push_back(QPair<double, double>(10, 7));
QObject::connect(turnstile.privLevel, QOverload<int>::of(&QComboBox::currentIndexChanged), [=] (auto idx) {
// Update the fees
turnstile.minerFee->setText(
Settings::getInstance()->getZECUSDDisplayFormat(privOptions[idx].first * Utils::getMinerFee()));
});
turnstile.privLevel->addItem("Good - 3 tx over 3 blocks");
turnstile.privLevel->addItem("Excellent - 5 tx over 5 blocks");
turnstile.privLevel->addItem("Paranoid - 10 tx over 7 blocks");
turnstile.buttonBox->button(QDialogButtonBox::Ok)->setText("Start"); turnstile.buttonBox->button(QDialogButtonBox::Ok)->setText("Start");
if (d.exec() == QDialog::Accepted) { if (d.exec() == QDialog::Accepted) {
auto privLevel = privOptions[turnstile.privLevel->currentIndex()];
rpc->getTurnstile()->planMigration( rpc->getTurnstile()->planMigration(
turnstile.migrateZaddList->currentText(), turnstile.migrateTo->currentText()); turnstile.migrateZaddList->currentText(),
turnstile.migrateTo->currentText(),
privLevel.first, privLevel.second);
QMessageBox::information(this, "Backup your wallet.dat",
"The migration will now start. You can check progress in the File -> Turnstile Migration menu.\n\nYOU MUST BACKUP YOUR wallet.dat NOW!.\n\nNew Addresses have been added to your wallet which will be used for the migration.",
QMessageBox::Ok);
} }
}); });
// Progress update button
QObject::connect(ui->actionProgress, &QAction::triggered, [=] () { QObject::connect(ui->actionProgress, &QAction::triggered, [=] () {
Ui_TurnstileProgress progress; Ui_TurnstileProgress progress;
QDialog d(this); QDialog d(this);
@@ -138,6 +153,37 @@ void MainWindow::setupTurnstileDialog() {
progress.msgIcon->setPixmap(icon.pixmap(64, 64)); progress.msgIcon->setPixmap(icon.pixmap(64, 64));
progress.buttonBox->button(QDialogButtonBox::Cancel)->setText("Abort"); progress.buttonBox->button(QDialogButtonBox::Cancel)->setText("Abort");
auto fnUpdateProgressUI = [=] () {
// Get the plan progress
if (rpc->getTurnstile()->isMigrationActive()) {
auto curProgress = rpc->getTurnstile()->getPlanProgress();
progress.progressTxt->setText(QString::number(curProgress.step) % QString(" / ") % QString::number(curProgress.totalSteps));
progress.progressBar->setValue(100 * curProgress.step / curProgress.totalSteps);
auto nextTxBlock = curProgress.nextBlock - Settings::getInstance()->getBlockNumber();
if (curProgress.step == curProgress.totalSteps) {
progress.nextTx->setText("Turnstile migration finished");
} else {
progress.nextTx->setText(QString("Next transaction in ")
% QString::number(nextTxBlock < 0 ? 0 : nextTxBlock)
% " blocks");
}
} else {
progress.progressTxt->setText("");
progress.progressBar->setValue(0);
progress.nextTx->setText("No turnstile migration is in progress");
}
};
QTimer progressTimer(this);
QObject::connect(&progressTimer, &QTimer::timeout, fnUpdateProgressUI);
progressTimer.start(Utils::updateSpeed);
fnUpdateProgressUI();
d.exec(); d.exec();
}); });
} }

View File

@@ -80,10 +80,10 @@ QList<TurnstileMigrationItem> Turnstile::readMigrationPlan() {
return plan; return plan;
} }
void Turnstile::planMigration(QString zaddr, QString destAddr) { void Turnstile::planMigration(QString zaddr, QString destAddr, int numsplits, int numBlocks) {
// First, get the balance and split up the amounts // First, get the balance and split up the amounts
auto bal = rpc->getAllBalances()->value(zaddr); auto bal = rpc->getAllBalances()->value(zaddr);
auto splits = splitAmount(bal, 5); auto splits = splitAmount(bal, numsplits);
// Then, generate an intermediate t-Address for each part using getBatchRPC // Then, generate an intermediate t-Address for each part using getBatchRPC
rpc->getBatchRPC<double>(splits, rpc->getBatchRPC<double>(splits,
@@ -98,7 +98,7 @@ void Turnstile::planMigration(QString zaddr, QString destAddr) {
[=] (QMap<double, json>* newAddrs) { [=] (QMap<double, json>* newAddrs) {
// Get block numbers // Get block numbers
auto curBlock = Settings::getInstance()->getBlockNumber(); auto curBlock = Settings::getInstance()->getBlockNumber();
auto blockNumbers = getBlockNumbers(curBlock, curBlock + 3, splits.size()); auto blockNumbers = getBlockNumbers(curBlock, curBlock + numBlocks, splits.size());
// Assign the amounts to the addresses. // Assign the amounts to the addresses.
QList<TurnstileMigrationItem> migItems; QList<TurnstileMigrationItem> migItems;
@@ -195,6 +195,47 @@ void Turnstile::fillAmounts(QList<double>& amounts, double amount, int count) {
fillAmounts(amounts, amount - curAmount, count - 1); fillAmounts(amounts, amount - curAmount, count - 1);
} }
QList<TurnstileMigrationItem>::Iterator
Turnstile::getNextStep(QList<TurnstileMigrationItem>& plan) {
// Get to the next unexecuted step
auto fnIsEligibleItem = [&] (auto item) {
return item.status == TurnstileMigrationItemStatus::NotStarted ||
item.status == TurnstileMigrationItemStatus::SentToT;
};
// // Fn to find if there are any unconfirmed funds for this address.
// auto fnHasUnconfirmed = [=] (QString addr) {
// auto utxoset = rpc->getUTXOs();
// return std::find_if(utxoset->begin(), utxoset->end(), [=] (auto utxo) {
// return utxo.address == addr && utxo.confirmations == 0;
// }) != utxoset->end();
// };
// Find the next step
auto nextStep = std::find_if(plan.begin(), plan.end(), fnIsEligibleItem);
return nextStep;
}
bool Turnstile::isMigrationActive() {
auto plan = readMigrationPlan();
if (plan.isEmpty()) return false;
return true;
}
ProgressReport Turnstile::getPlanProgress() {
auto plan = readMigrationPlan();
auto nextStep = getNextStep(plan);
auto step = std::distance(plan.begin(), nextStep);
auto total = plan.size();
auto nextBlock = nextStep == plan.end() ? 0 : nextStep->blockNumber;
return ProgressReport{(int)step*2, total*2, nextBlock};
}
void Turnstile::executeMigrationStep() { void Turnstile::executeMigrationStep() {
auto plan = readMigrationPlan(); auto plan = readMigrationPlan();

View File

@@ -23,13 +23,19 @@ enum TurnstileMigrationItemStatus {
UnknownError UnknownError
}; };
struct ProgressReport {
int step;
int totalSteps;
int nextBlock;
};
class Turnstile class Turnstile
{ {
public: public:
Turnstile(RPC* _rpc); Turnstile(RPC* _rpc);
~Turnstile(); ~Turnstile();
void planMigration(QString zaddr, QString destAddr); void planMigration(QString zaddr, QString destAddr, int splits, int numBlocks);
QList<double> splitAmount(double amount, int parts); QList<double> splitAmount(double amount, int parts);
void fillAmounts(QList<double>& amounts, double amount, int count); void fillAmounts(QList<double>& amounts, double amount, int count);
@@ -37,6 +43,8 @@ public:
void writeMigrationPlan(QList<TurnstileMigrationItem> plan); void writeMigrationPlan(QList<TurnstileMigrationItem> plan);
void executeMigrationStep(); void executeMigrationStep();
ProgressReport getPlanProgress();
bool isMigrationActive();
private: private:
QList<int> getBlockNumbers(int start, int end, int count); QList<int> getBlockNumbers(int start, int end, int count);
@@ -44,6 +52,9 @@ private:
void doSendTx(Tx tx, std::function<void(void)> cb); void doSendTx(Tx tx, std::function<void(void)> cb);
QList<TurnstileMigrationItem>::Iterator getNextStep(QList<TurnstileMigrationItem>& plan);
RPC* rpc; RPC* rpc;
}; };

View File

@@ -151,7 +151,7 @@
</widget> </widget>
</item> </item>
<item row="6" column="1" colspan="2"> <item row="6" column="1" colspan="2">
<widget class="QLabel" name="label_7"> <widget class="QLabel" name="minerFee">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred"> <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>

View File

@@ -45,14 +45,14 @@
</widget> </widget>
</item> </item>
<item row="5" column="0" colspan="3"> <item row="5" column="0" colspan="3">
<widget class="QLabel" name="label"> <widget class="QLabel" name="nextTx">
<property name="text"> <property name="text">
<string>Next Transaction in 4 hours</string> <string>Next Transaction in 4 hours</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="2"> <item row="2" column="2">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="progressTxt">
<property name="text"> <property name="text">
<string>4 / 12</string> <string>4 / 12</string>
</property> </property>

View File

@@ -42,7 +42,7 @@ public:
QLabel *fromBalance; QLabel *fromBalance;
QSpacerItem *verticalSpacer; QSpacerItem *verticalSpacer;
QLabel *label_5; QLabel *label_5;
QLabel *label_7; QLabel *minerFee;
QLabel *label_3; QLabel *label_3;
QDialogButtonBox *buttonBox; QDialogButtonBox *buttonBox;
@@ -141,16 +141,16 @@ public:
gridLayout->addWidget(label_5, 6, 0, 1, 1); gridLayout->addWidget(label_5, 6, 0, 1, 1);
label_7 = new QLabel(groupBox); minerFee = new QLabel(groupBox);
label_7->setObjectName(QStringLiteral("label_7")); minerFee->setObjectName(QStringLiteral("minerFee"));
QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Preferred); QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Preferred);
sizePolicy2.setHorizontalStretch(0); sizePolicy2.setHorizontalStretch(0);
sizePolicy2.setVerticalStretch(0); sizePolicy2.setVerticalStretch(0);
sizePolicy2.setHeightForWidth(label_7->sizePolicy().hasHeightForWidth()); sizePolicy2.setHeightForWidth(minerFee->sizePolicy().hasHeightForWidth());
label_7->setSizePolicy(sizePolicy2); minerFee->setSizePolicy(sizePolicy2);
label_7->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter); minerFee->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter);
gridLayout->addWidget(label_7, 6, 1, 1, 2); gridLayout->addWidget(minerFee, 6, 1, 1, 2);
label_3 = new QLabel(groupBox); label_3 = new QLabel(groupBox);
label_3->setObjectName(QStringLiteral("label_3")); label_3->setObjectName(QStringLiteral("label_3"));
@@ -190,7 +190,7 @@ public:
label_9->setText(QApplication::translate("Turnstile", "To", nullptr)); label_9->setText(QApplication::translate("Turnstile", "To", nullptr));
fromBalance->setText(QApplication::translate("Turnstile", "Balance", nullptr)); fromBalance->setText(QApplication::translate("Turnstile", "Balance", nullptr));
label_5->setText(QApplication::translate("Turnstile", "Miner Fees", nullptr)); label_5->setText(QApplication::translate("Turnstile", "Miner Fees", nullptr));
label_7->setText(QApplication::translate("Turnstile", "0.0004 ZEC $0.04", nullptr)); minerFee->setText(QApplication::translate("Turnstile", "0.0004 ZEC $0.04", nullptr));
label_3->setText(QApplication::translate("Turnstile", "Total Balance", nullptr)); label_3->setText(QApplication::translate("Turnstile", "Total Balance", nullptr));
} // retranslateUi } // retranslateUi

View File

@@ -28,8 +28,8 @@ public:
QProgressBar *progressBar; QProgressBar *progressBar;
QLabel *label_4; QLabel *label_4;
QFrame *line; QFrame *line;
QLabel *label; QLabel *nextTx;
QLabel *label_3; QLabel *progressTxt;
QLabel *label_2; QLabel *label_2;
QLabel *msgIcon; QLabel *msgIcon;
QDialogButtonBox *buttonBox; QDialogButtonBox *buttonBox;
@@ -67,16 +67,16 @@ public:
gridLayout->addWidget(line, 4, 0, 1, 3); gridLayout->addWidget(line, 4, 0, 1, 3);
label = new QLabel(TurnstileProgress); nextTx = new QLabel(TurnstileProgress);
label->setObjectName(QStringLiteral("label")); nextTx->setObjectName(QStringLiteral("nextTx"));
gridLayout->addWidget(label, 5, 0, 1, 3); gridLayout->addWidget(nextTx, 5, 0, 1, 3);
label_3 = new QLabel(TurnstileProgress); progressTxt = new QLabel(TurnstileProgress);
label_3->setObjectName(QStringLiteral("label_3")); progressTxt->setObjectName(QStringLiteral("progressTxt"));
label_3->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); progressTxt->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
gridLayout->addWidget(label_3, 2, 2, 1, 1); gridLayout->addWidget(progressTxt, 2, 2, 1, 1);
label_2 = new QLabel(TurnstileProgress); label_2 = new QLabel(TurnstileProgress);
label_2->setObjectName(QStringLiteral("label_2")); label_2->setObjectName(QStringLiteral("label_2"));
@@ -124,8 +124,8 @@ public:
{ {
TurnstileProgress->setWindowTitle(QApplication::translate("TurnstileProgress", "Dialog", nullptr)); TurnstileProgress->setWindowTitle(QApplication::translate("TurnstileProgress", "Dialog", nullptr));
label_4->setText(QApplication::translate("TurnstileProgress", "Please Ensure you have your wallet.dat backed up!", nullptr)); label_4->setText(QApplication::translate("TurnstileProgress", "Please Ensure you have your wallet.dat backed up!", nullptr));
label->setText(QApplication::translate("TurnstileProgress", "Next Transaction in 4 hours", nullptr)); nextTx->setText(QApplication::translate("TurnstileProgress", "Next Transaction in 4 hours", nullptr));
label_3->setText(QApplication::translate("TurnstileProgress", "4 / 12", nullptr)); progressTxt->setText(QApplication::translate("TurnstileProgress", "4 / 12", nullptr));
label_2->setText(QApplication::translate("TurnstileProgress", "Migration Progress", nullptr)); label_2->setText(QApplication::translate("TurnstileProgress", "Migration Progress", nullptr));
msgIcon->setText(QApplication::translate("TurnstileProgress", "TextLabel", nullptr)); msgIcon->setText(QApplication::translate("TurnstileProgress", "TextLabel", nullptr));
} // retranslateUi } // retranslateUi