From 8e0b118cc673189999f303967d6fdb3b7354bd6a Mon Sep 17 00:00:00 2001 From: adityapk00 Date: Wed, 24 Oct 2018 21:06:03 -0700 Subject: [PATCH] intermediate checkin --- src/main.cpp | 8 ++++++++ src/precompiled.h | 2 ++ src/turnstile.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/turnstile.h | 11 +++++++++++ zec-qt-wallet.pro | 2 ++ 5 files changed, 60 insertions(+) create mode 100644 src/turnstile.cpp create mode 100644 src/turnstile.h diff --git a/src/main.cpp b/src/main.cpp index 76b6873..f96df19 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,7 @@ #include "mainwindow.h" #include "settings.h" +#include "turnstile.h" + #include "precompiled.h" int main(int argc, char *argv[]) @@ -16,6 +18,8 @@ int main(int argc, char *argv[]) qApp->setFont(QFont("Ubuntu", 11, QFont::Normal, false)); #endif + std::srand(std::time(nullptr)); + QCoreApplication::setOrganizationName("zec-qt-wallet-org"); QCoreApplication::setApplicationName("zec-qt-wallet"); @@ -24,6 +28,10 @@ int main(int argc, char *argv[]) MainWindow w; w.setWindowTitle("zec-qt-wallet v" + QString(APP_VERSION)); w.show(); + + // Temp + Turnstile t; + qDebug() << t.splitAmount(1245.2294371, 3); return QApplication::exec(); } diff --git a/src/precompiled.h b/src/precompiled.h index c3e837b..976fba1 100644 --- a/src/precompiled.h +++ b/src/precompiled.h @@ -2,6 +2,8 @@ /* Add C++ includes here */ #include +#include +#include #include #include diff --git a/src/turnstile.cpp b/src/turnstile.cpp new file mode 100644 index 0000000..c442d70 --- /dev/null +++ b/src/turnstile.cpp @@ -0,0 +1,37 @@ +#include "precompiled.h" +#include "turnstile.h" + + +Turnstile::Turnstile() { +} + + +Turnstile::~Turnstile() { +} + +QList Turnstile::splitAmount(double amount, int parts) { + QList amounts; + fillAmounts(amounts, amount, parts); + + // Ensure they all add up! + double sumofparts = 0; + for (auto a : amounts) { + sumofparts += a.toDouble(); + } + + Q_ASSERT(sumofparts == amount); + return amounts; +} + +void Turnstile::fillAmounts(QList& amounts, double amount, int count) { + if (count == 1 || amount < 1) { + amounts.push_back(QString::number(amount, 'g', 8)); + return; + } + + // Get a random amount off the amount and call recursively. + auto curAmount = std::rand() % (int)std::floor(amount); + amounts.push_back(QString::number(curAmount, 'g', 8)); + + fillAmounts(amounts, amount - curAmount, count - 1); +} \ No newline at end of file diff --git a/src/turnstile.h b/src/turnstile.h new file mode 100644 index 0000000..0da7098 --- /dev/null +++ b/src/turnstile.h @@ -0,0 +1,11 @@ +#pragma once +class Turnstile +{ +public: + Turnstile(); + ~Turnstile(); + + QList Turnstile::splitAmount(double amount, int parts); + void fillAmounts(QList& amounts, double amount, int count); +}; + diff --git a/zec-qt-wallet.pro b/zec-qt-wallet.pro index 710aafa..1b40335 100644 --- a/zec-qt-wallet.pro +++ b/zec-qt-wallet.pro @@ -50,6 +50,7 @@ SOURCES += \ src/sendtab.cpp \ src/senttxstore.cpp \ src/txtablemodel.cpp \ + src/turnstile.cpp \ src/utils.cpp HEADERS += \ @@ -65,6 +66,7 @@ HEADERS += \ src/settings.h \ src/txtablemodel.h \ src/senttxstore.h \ + src/turnstile.h \ src/utils.h FORMS += \