Add batchRPC, and add shielded receive txs to the transactions table.
This commit is contained in:
53
src/rpc.cpp
53
src/rpc.cpp
@@ -368,6 +368,8 @@ void RPC::getReceivedZTrans(QList<QString> zaddrs) {
|
|||||||
return payload;
|
return payload;
|
||||||
},
|
},
|
||||||
[=] (QMap<QString, json>* txidDetails) {
|
[=] (QMap<QString, json>* txidDetails) {
|
||||||
|
QList<TransactionItem> txdata;
|
||||||
|
|
||||||
// Combine them both together. For every zAddr's txid, get the amount, fee, confirmations and time
|
// Combine them both together. For every zAddr's txid, get the amount, fee, confirmations and time
|
||||||
for (auto it = zaddrTxids->constBegin(); it != zaddrTxids->constEnd(); it++) {
|
for (auto it = zaddrTxids->constBegin(); it != zaddrTxids->constEnd(); it++) {
|
||||||
for (auto& i : it.value().get<json::array_t>()) {
|
for (auto& i : it.value().get<json::array_t>()) {
|
||||||
@@ -380,11 +382,15 @@ void RPC::getReceivedZTrans(QList<QString> zaddrs) {
|
|||||||
// And then find the values
|
// And then find the values
|
||||||
auto timestamp = txidInfo["time"].get<json::number_unsigned_t>();
|
auto timestamp = txidInfo["time"].get<json::number_unsigned_t>();
|
||||||
auto amount = i["amount"].get<json::number_float_t>();
|
auto amount = i["amount"].get<json::number_float_t>();
|
||||||
|
auto confirmations = txidInfo["confirmations"].get<json::number_unsigned_t>();
|
||||||
|
|
||||||
std::cout << zaddr.toStdString() << ":" << txid.toStdString() << ":" << timestamp << ":" << amount << std::endl;
|
TransactionItem tx{ QString("receive"), timestamp, zaddr, txid, amount, confirmations };
|
||||||
|
txdata.push_front(tx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transactionsTableModel->addNewData(txdata);
|
||||||
|
|
||||||
// Cleanup both responses;
|
// Cleanup both responses;
|
||||||
delete zaddrTxids;
|
delete zaddrTxids;
|
||||||
delete txidDetails;
|
delete txidDetails;
|
||||||
@@ -419,10 +425,13 @@ void RPC::getInfoThenRefresh() {
|
|||||||
QIcon i(":/icons/res/connected.png");
|
QIcon i(":/icons/res/connected.png");
|
||||||
main->statusIcon->setPixmap(i.pixmap(16, 16));
|
main->statusIcon->setPixmap(i.pixmap(16, 16));
|
||||||
|
|
||||||
// Refresh everything.
|
// Expect 2 data additions, then automatically refresh the table
|
||||||
|
transactionsTableModel->prepNewData(2);
|
||||||
|
|
||||||
|
// Refresh everything.
|
||||||
refreshBalances();
|
refreshBalances();
|
||||||
refreshTransactions();
|
|
||||||
refreshAddresses();
|
refreshAddresses();
|
||||||
|
refreshTransactions();
|
||||||
|
|
||||||
// Call to see if the blockchain is syncing.
|
// Call to see if the blockchain is syncing.
|
||||||
json payload = {
|
json payload = {
|
||||||
@@ -545,45 +554,29 @@ void RPC::refreshBalances() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RPC::refreshTransactions() {
|
void RPC::refreshTransactions() {
|
||||||
auto txdata = new QList<TransactionItem>();
|
|
||||||
/*
|
|
||||||
auto getZReceivedTransactions = ([=] (const json& reply) {
|
|
||||||
for (auto& it : reply.get<json::array_t>()) {
|
|
||||||
TransactionItem tx(
|
|
||||||
QString("receive"),
|
|
||||||
QDateTime::fromSecsSinceEpoch(it["time"].get<json::number_unsigned_t>()).toLocalTime().toString(),
|
|
||||||
(it["address"].is_null() ? "" : QString::fromStdString(it["address"])),
|
|
||||||
QString::fromStdString(it["txid"]),
|
|
||||||
it["amount"].get<json::number_float_t>(),
|
|
||||||
it["confirmations"].get<json::number_float_t>()
|
|
||||||
);
|
|
||||||
|
|
||||||
txdata->push_front(tx);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
getTransactions([=] (json reply) {
|
getTransactions([=] (json reply) {
|
||||||
|
QList<TransactionItem> txdata;
|
||||||
|
|
||||||
for (auto& it : reply.get<json::array_t>()) {
|
for (auto& it : reply.get<json::array_t>()) {
|
||||||
double fee = 0;
|
double fee = 0;
|
||||||
if (it.find("fee") != it.end()) {
|
if (it.find("fee") != it.end()) {
|
||||||
fee = it["fee"].get<json::number_float_t>();
|
fee = it["fee"].get<json::number_float_t>();
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionItem tx(
|
TransactionItem tx{
|
||||||
QString::fromStdString(it["category"]),
|
QString::fromStdString(it["category"]),
|
||||||
QDateTime::fromSecsSinceEpoch(it["time"].get<json::number_unsigned_t>()).toLocalTime().toString(),
|
it["time"].get<json::number_unsigned_t>(),
|
||||||
(it["address"].is_null() ? "" : QString::fromStdString(it["address"])),
|
(it["address"].is_null() ? "(shielded)" : QString::fromStdString(it["address"])),
|
||||||
QString::fromStdString(it["txid"]),
|
QString::fromStdString(it["txid"]),
|
||||||
it["amount"].get<json::number_float_t>() + fee,
|
it["amount"].get<json::number_float_t>() + fee,
|
||||||
it["confirmations"].get<json::number_float_t>()
|
it["confirmations"].get<json::number_unsigned_t>()
|
||||||
);
|
};
|
||||||
|
|
||||||
txdata->push_front(tx);
|
txdata.push_back(tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update model data, which updates the table view
|
// Update model data, which updates the table view
|
||||||
transactionsTableModel->setNewData(txdata);
|
transactionsTableModel->addNewData(txdata);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -630,7 +623,7 @@ void RPC::refreshTxStatus(const QString& newOpid) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
watchingOps.remove(id);
|
watchingOps.remove(id);
|
||||||
txTimer->start(10 * 1000);
|
txTimer->start(Utils::updateSpeed);
|
||||||
|
|
||||||
main->ui->statusBar->showMessage(" Tx " % id % " failed", 15 * 1000);
|
main->ui->statusBar->showMessage(" Tx " % id % " failed", 15 * 1000);
|
||||||
main->loadingLabel->setVisible(false);
|
main->loadingLabel->setVisible(false);
|
||||||
@@ -638,7 +631,7 @@ void RPC::refreshTxStatus(const QString& newOpid) {
|
|||||||
msg.exec();
|
msg.exec();
|
||||||
} else if (status == "executing") {
|
} else if (status == "executing") {
|
||||||
// If the operation is executing, then watch every second.
|
// If the operation is executing, then watch every second.
|
||||||
txTimer->start(1 * 1000);
|
txTimer->start(Utils::quickUpdateSpeed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
#include "transactionitem.h"
|
|
||||||
|
|
||||||
TransactionItem::TransactionItem(const QString& type, const QString& datetime, const QString& address, const QString& txid,
|
|
||||||
double amount, int confirmations)
|
|
||||||
{
|
|
||||||
this->type = type;
|
|
||||||
this->datetime = datetime;
|
|
||||||
this->address = address;
|
|
||||||
this->txid = txid;
|
|
||||||
this->amount = amount;
|
|
||||||
this->confirmations = confirmations;
|
|
||||||
}
|
|
||||||
@@ -3,18 +3,13 @@
|
|||||||
|
|
||||||
#include "precompiled.h"
|
#include "precompiled.h"
|
||||||
|
|
||||||
class TransactionItem
|
struct TransactionItem {
|
||||||
{
|
QString type;
|
||||||
public:
|
unsigned long datetime;
|
||||||
TransactionItem(const QString& type, const QString& datetime, const QString& address, const QString& txid,
|
QString address;
|
||||||
double amount, int confirmations);
|
QString txid;
|
||||||
|
double amount;
|
||||||
QString type;
|
unsigned long confirmations;
|
||||||
QString datetime;
|
|
||||||
QString address;
|
|
||||||
QString txid;
|
|
||||||
double amount;
|
|
||||||
int confirmations;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TRANSACTIONITEM_H
|
#endif // TRANSACTIONITEM_H
|
||||||
|
|||||||
@@ -11,13 +11,34 @@ TxTableModel::~TxTableModel() {
|
|||||||
delete modeldata;
|
delete modeldata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TxTableModel::setNewData(QList<TransactionItem>* data) {
|
void TxTableModel::prepNewData(int expect) {
|
||||||
delete modeldata;
|
newmodeldata = new QList<TransactionItem>();
|
||||||
modeldata = data;
|
expectedData = expect;
|
||||||
|
}
|
||||||
|
|
||||||
dataChanged(index(0, 0), index(modeldata->size()-1, columnCount(index(0,0))-1));
|
void TxTableModel::addNewData(const QList<TransactionItem>& data) {
|
||||||
layoutChanged();
|
// Make sure we're expecting some data.
|
||||||
}
|
Q_ASSERT(expectedData > 0);
|
||||||
|
|
||||||
|
// Add all
|
||||||
|
std::copy(data.begin(), data.end(), std::back_inserter(*newmodeldata));
|
||||||
|
expectedData--;
|
||||||
|
|
||||||
|
if (expectedData == 0) {
|
||||||
|
delete modeldata;
|
||||||
|
|
||||||
|
modeldata = newmodeldata;
|
||||||
|
newmodeldata = nullptr;
|
||||||
|
|
||||||
|
// Sort by reverse time
|
||||||
|
std::sort(modeldata->begin(), modeldata->end(), [=] (auto a, auto b) {
|
||||||
|
return a.datetime > b.datetime; // reverse sort
|
||||||
|
});
|
||||||
|
|
||||||
|
dataChanged(index(0, 0), index(modeldata->size()-1, columnCount(index(0,0))-1));
|
||||||
|
layoutChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int TxTableModel::rowCount(const QModelIndex&) const
|
int TxTableModel::rowCount(const QModelIndex&) const
|
||||||
{
|
{
|
||||||
@@ -53,7 +74,7 @@ void TxTableModel::setNewData(QList<TransactionItem>* data) {
|
|||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0: return modeldata->at(index.row()).type;
|
case 0: return modeldata->at(index.row()).type;
|
||||||
case 1: return modeldata->at(index.row()).address;
|
case 1: return modeldata->at(index.row()).address;
|
||||||
case 2: return modeldata->at(index.row()).datetime;
|
case 2: return QDateTime::fromSecsSinceEpoch(modeldata->at(index.row()).datetime).toLocalTime().toString();
|
||||||
case 3: {
|
case 3: {
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole)
|
||||||
return Settings::getInstance()->getZECDisplayFormat(modeldata->at(index.row()).amount);
|
return Settings::getInstance()->getZECDisplayFormat(modeldata->at(index.row()).amount);
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ public:
|
|||||||
TxTableModel(QObject* parent);
|
TxTableModel(QObject* parent);
|
||||||
~TxTableModel();
|
~TxTableModel();
|
||||||
|
|
||||||
void setNewData(QList<TransactionItem>* addresses);
|
void prepNewData (int expectedData);
|
||||||
|
void addNewData (const QList<TransactionItem>& data);
|
||||||
|
|
||||||
QString getTxId(int row);
|
QString getTxId(int row);
|
||||||
|
|
||||||
@@ -20,7 +21,10 @@ public:
|
|||||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<TransactionItem>* modeldata = nullptr;
|
QList<TransactionItem>* modeldata = nullptr;
|
||||||
|
QList<TransactionItem>* newmodeldata = nullptr;
|
||||||
|
int expectedData;
|
||||||
|
|
||||||
QList<QString> headers;
|
QList<QString> headers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ public:
|
|||||||
static double getDevFee();
|
static double getDevFee();
|
||||||
static double getTotalFee();
|
static double getTotalFee();
|
||||||
|
|
||||||
static const int updateSpeed = 20 * 1000; // 20 sec
|
static const int updateSpeed = 20 * 1000; // 20 sec
|
||||||
|
static const int quickUpdateSpeed = 5 * 1000; // 5 sec
|
||||||
private:
|
private:
|
||||||
Utils() = delete;
|
Utils() = delete;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ SOURCES += \
|
|||||||
src/settings.cpp \
|
src/settings.cpp \
|
||||||
src/sendtab.cpp \
|
src/sendtab.cpp \
|
||||||
src/txtablemodel.cpp \
|
src/txtablemodel.cpp \
|
||||||
src/transactionitem.cpp \
|
|
||||||
src/utils.cpp
|
src/utils.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
|||||||
Reference in New Issue
Block a user