switch to Hush as Unit

This commit is contained in:
DenioD
2019-10-25 22:35:42 +02:00
parent 505c1bfa03
commit b0db704262
12 changed files with 42 additions and 85 deletions

View File

@@ -2,12 +2,11 @@
#include "addressbook.h"
#include "settings.h"
BalancesTableModel::BalancesTableModel(QObject *parent)
: QAbstractTableModel(parent) {
}
void BalancesTableModel::setNewData(const QMap<QString, qint64> balances,
void BalancesTableModel::setNewData(const QMap<QString, double> balances,
const QList<UnspentOutput> outputs)
{
loading = false;
@@ -22,7 +21,7 @@ void BalancesTableModel::setNewData(const QMap<QString, qint64> balances,
// Process the address balances into a list
delete modeldata;
modeldata = new QList<std::tuple<QString, qint64>>();
modeldata = new QList<std::tuple<QString, double>>();
std::for_each(balances.keyBegin(), balances.keyEnd(), [=] (auto keyIt) {
if (balances.value(keyIt) > 0)
modeldata->push_back(std::make_tuple(keyIt, balances.value(keyIt)));
@@ -95,7 +94,7 @@ QVariant BalancesTableModel::data(const QModelIndex &index, int role) const
if(role == Qt::ToolTipRole) {
switch (index.column()) {
case 0: return AddressBook::addLabelToAddress(std::get<0>(modeldata->at(index.row())));
case 1: return Settings::getUSDFromhushAmount(std::get<1>(modeldata->at(index.row())));
case 1: return Settings::getUSDFormat(std::get<1>(modeldata->at(index.row())));
}
}

View File

@@ -4,13 +4,14 @@
#include "precompiled.h"
#include "datamodel.h"
class BalancesTableModel : public QAbstractTableModel
{
public:
BalancesTableModel(QObject* parent);
~BalancesTableModel();
void setNewData(const QMap<QString, qint64> balances, const QList<UnspentOutput> outputs);
void setNewData(const QMap<QString, double> balances, const QList<UnspentOutput> outputs);
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
@@ -18,7 +19,7 @@ public:
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
private:
QList<std::tuple<QString, qint64>>* modeldata = nullptr;
QList<std::tuple<QString, double>>* modeldata = nullptr;
QList<UnspentOutput>* utxos = nullptr;
bool loading = true;

View File

@@ -51,7 +51,7 @@ void ConnectionLoader::doAutoConnect() {
litelib_initialize_existing(config->dangerous, config->server.toStdString().c_str());
} else {
main->logger->write(QObject::tr("Create/restore wallet."));
createOrRestore(config->dangerous, config->server);
litelib_initialize_existing(config->dangerous, config->server.toStdString().c_str());
}
auto connection = makeConnection(config);

View File

@@ -64,7 +64,7 @@ void Controller::setConnection(Connection* c) {
this->zrpc->setConnection(c);
ui->statusBar->showMessage("Ready!");
ui->statusBar->showMessage("Your hushd is connected");
// See if we need to remove the reindex/rescan flags from the hush.conf file
auto hushConfLocation = Settings::getInstance()->gethushdConfLocation();
@@ -96,7 +96,7 @@ void Controller::fillTxJsonParams(json& allRecepients, Tx tx) {
// Construct the JSON params
json rec = json::object();
rec["address"] = toAddr.addr.toStdString();
rec["amount"] = toAddr.amount;
rec["amount"] = toAddr.amount * 10000000;
if (Settings::isZAddress(toAddr.addr) && !toAddr.memo.trimmed().isEmpty())
rec["memo"] = toAddr.memo.toStdString();
@@ -120,7 +120,7 @@ void Controller::noConnection() {
main->ui->statusBar->showMessage(QObject::tr("No Connection"), 1000);
// Clear balances table.
QMap<QString, qint64> emptyBalances;
QMap<QString, double> emptyBalances;
QList<UnspentOutput> emptyOutputs;
balancesTableModel->setNewData(emptyBalances, emptyOutputs);
@@ -251,7 +251,7 @@ void Controller::updateUI(bool anyUnconfirmed) {
};
// Function to process reply of the listunspent and z_listunspent API calls, used below.
bool Controller::processUnspent(const json& reply, QMap<QString, qint64>* balancesMap, QList<UnspentOutput>* newUtxos) {
bool Controller::processUnspent(const json& reply, QMap<QString, double>* balancesMap, QList<UnspentOutput>* newUtxos) {
bool anyUnconfirmed = false;
auto processFn = [=](const json& array) {
@@ -259,11 +259,11 @@ bool Controller::processUnspent(const json& reply, QMap<QString, qint64>* balanc
QString qsAddr = QString::fromStdString(it["address"]);
int block = it["created_in_block"].get<json::number_unsigned_t>();
QString txid = QString::fromStdString(it["created_in_txid"]);
QString amount = Settings::getDecimalString(it["value"].get<json::number_unsigned_t>());
QString amount = Settings::getDecimalString(it["value"].get<json::number_float_t>());
newUtxos->push_back(UnspentOutput{ qsAddr, txid, amount, block, true });
(*balancesMap)[qsAddr] = (*balancesMap)[qsAddr] + it["value"].get<json::number_unsigned_t>();
(*balancesMap)[qsAddr] = ((*balancesMap)[qsAddr] + it["value"].get<json::number_float_t>()) /10000000;
}
};
@@ -279,26 +279,28 @@ void Controller::refreshBalances() {
// 1. Get the Balances
zrpc->fetchBalance([=] (json reply) {
auto balT = reply["tbalance"].get<json::number_unsigned_t>();
auto balZ = reply["zbalance"].get<json::number_unsigned_t>();
auto balT = reply["tbalance"].get<json::number_float_t>();
auto balZ = reply["zbalance"].get<json::number_float_t>();
auto balTotal = balT + balZ;
AppDataModel::getInstance()->setBalances(balT, balZ);
ui->balSheilded ->setText(Settings::gethushDisplayFormat(balZ));
ui->balTransparent->setText(Settings::gethushDisplayFormat(balT));
ui->balTotal ->setText(Settings::gethushDisplayFormat(balTotal));
ui->balSheilded ->setText(Settings::gethushDisplayFormat(balZ /10000000));
ui->balTransparent->setText(Settings::gethushDisplayFormat(balT /10000000));
ui->balTotal ->setText(Settings::gethushDisplayFormat(balTotal /10000000));
ui->balSheilded ->setToolTip(Settings::gethushDisplayFormat(balZ));
ui->balTransparent->setToolTip(Settings::gethushDisplayFormat(balT));
ui->balTotal ->setToolTip(Settings::gethushDisplayFormat(balTotal));
ui->balSheilded ->setToolTip(Settings::gethushDisplayFormat(balZ /10000000));
ui->balTransparent->setToolTip(Settings::gethushDisplayFormat(balT /10000000));
ui->balTotal ->setToolTip(Settings::gethushDisplayFormat(balTotal /10000000));
});
// 2. Get the UTXOs
// First, create a new UTXO list. It will be replacing the existing list when everything is processed.
auto newUtxos = new QList<UnspentOutput>();
auto newBalances = new QMap<QString, qint64>();
auto newBalances = new QMap<QString, double>();
// Call the Transparent and Z unspent APIs serially and then, once they're done, update the UI
zrpc->fetchUnspent([=] (json reply) {
@@ -323,7 +325,7 @@ void Controller::refreshTransactions() {
for (auto& it : reply.get<json::array_t>()) {
QString address;
qint64 total_amount;
double total_amount;
QList<TransactionItemDetail> items;
// First, check if there's outgoing metadata
@@ -331,7 +333,7 @@ void Controller::refreshTransactions() {
for (auto o: it["outgoing_metadata"].get<json::array_t>()) {
QString address = QString::fromStdString(o["address"]);
qint64 amount = -1 * o["value"].get<json::number_integer_t>(); // Sent items are -ve
double amount = -1 * o["value"].get<json::number_float_t>() /10000000;// Sent items are -ve
QString memo;
if (!o["memo"].is_null()) {
@@ -353,7 +355,7 @@ void Controller::refreshTransactions() {
it["datetime"].get<json::number_unsigned_t>(),
address,
QString::fromStdString(it["txid"]),
model->getLatestBlock() - it["block_height"].get<json::number_unsigned_t>(),
model->getLatestBlock() - it["block_height"].get<json::number_unsigned_t>(),
items
});
} else {
@@ -363,7 +365,7 @@ void Controller::refreshTransactions() {
items.push_back(TransactionItemDetail{
address,
it["amount"].get<json::number_integer_t>(),
it["amount"].get<json::number_float_t>(),
""
});
@@ -509,7 +511,7 @@ void Controller::refreshhushPrice() {
return noConnection();
// TODO: use/render all this data
QUrl cmcURL("https://api.coingecko.com/api/v3/simple/price?ids=hush&vs_currencies=btc%2Cusd%2Ceur&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true");
QUrl cmcURL("ncies=btc%2Cusd%2Ceur&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true");
QNetworkRequest req;
req.setUrl(cmcURL);
@@ -544,7 +546,7 @@ void Controller::refreshhushPrice() {
qDebug() << "Parsed JSON";
const json& item = parsed.get<json::object_t>();
const json& hush = item["hush"].get<json::object_t>();
const json& hush = item["Hush"].get<json::object_t>();
if (hush["usd"] >= 0) {
qDebug() << "Found hush key in price json";

View File

@@ -78,7 +78,7 @@ private:
void refreshTransactions();
bool processUnspent (const json& reply, QMap<QString, qint64>* newBalances, QList<UnspentOutput>* newUtxos);
bool processUnspent (const json& reply, QMap<QString, double>* newBalances, QList<UnspentOutput>* newUtxos);
void updateUI (bool anyUnconfirmed);
void getInfoThenRefresh(bool force);

View File

@@ -7,7 +7,7 @@ DataModel::DataModel() {
QWriteLocker locker(lock);
utxos = new QList<UnspentOutput>();
balances = new QMap<QString, qint64>();
balances = new QMap<QString, double>();
usedAddresses = new QMap<QString, bool>();
zaddresses = new QList<QString>();
taddresses = new QList<QString>();
@@ -44,7 +44,7 @@ void DataModel::replaceTaddresses(QList<QString>* newT) {
taddresses = newT;
}
void DataModel::replaceBalances(QMap<QString, qint64>* newBalances) {
void DataModel::replaceBalances(QMap<QString, double>* newBalances) {
QWriteLocker locker(lock);
Q_ASSERT(newBalances);

View File

@@ -18,7 +18,7 @@ class DataModel {
public:
void replaceZaddresses(QList<QString>* newZ);
void replaceTaddresses(QList<QString>* newZ);
void replaceBalances(QMap<QString, qint64>* newBalances);
void replaceBalances(QMap<QString, double>* newBalances);
void replaceUTXOs(QList<UnspentOutput>* utxos);
void markAddressUsed(QString address);
@@ -29,8 +29,8 @@ public:
const QList<QString> getAllZAddresses() { QReadLocker locker(lock); return *zaddresses; }
const QList<QString> getAllTAddresses() { QReadLocker locker(lock); return *taddresses; }
const QList<UnspentOutput> getUTXOs() { QReadLocker locker(lock); return *utxos; }
const QMap<QString, qint64> getAllBalances() { QReadLocker locker(lock); return *balances; }
const QMap<QString, bool> getUsedAddresses() { QReadLocker locker(lock); return *usedAddresses; }
const QMap<QString, double> getAllBalances() { QReadLocker locker(lock); return *balances; }
const QMap<QString, bool> getUsedAddresses() { QReadLocker locker(lock); return *usedAddresses; }
DataModel();
@@ -39,7 +39,7 @@ private:
int latestBlock;
QList<UnspentOutput>* utxos = nullptr;
QMap<QString, qint64>* balances = nullptr;
QMap<QString, double>* balances = nullptr;
QMap<QString, bool>* usedAddresses = nullptr;
QList<QString>* zaddresses = nullptr;
QList<QString>* taddresses = nullptr;

View File

@@ -11,7 +11,7 @@ using json = nlohmann::json;
// into a struct with address, amount, memo
struct TransactionItemDetail {
QString address;
qint64 amount;
double amount;
QString memo;
};
@@ -45,6 +45,7 @@ public:
const std::function<void(QString)>& err);
void fetchBalance(const std::function<void(json)>& cb);
void createNewZaddr(bool sapling, const std::function<void(json)>& cb);
void createNewTaddr(const std::function<void(json)>& cb);

View File

@@ -17,7 +17,7 @@ using json = nlohmann::json;
// Struct used to hold destination info when sending a Tx.
struct ToFields {
QString addr;
qint64 amount;
double amount;
QString memo;
};
@@ -25,7 +25,7 @@ struct ToFields {
struct Tx {
QString fromAddr;
QList<ToFields> toAddrs;
qint64 fee;
double fee;
};
namespace Ui {

View File

@@ -315,7 +315,7 @@ bool Settings::removeFromhushConf(QString confLocation, QString option) {
}
double Settings::getMinerFee() {
return 10000;
return 0.01;
}
double Settings::getZboardAmount() {