Clean up rpc methods

This commit is contained in:
adityapk00
2018-10-17 20:46:46 -07:00
parent 5859c3669b
commit a85138f86f
2 changed files with 47 additions and 45 deletions

View File

@@ -337,23 +337,29 @@ void RPC::refreshAddresses() {
}); });
} }
void RPC::refreshBalances() { // Function to create the data model and update the views, used below.
// 1. Get the Balances void RPC::updateUI(bool anyUnconfirmed) {
getBalance([=] (json reply) { ui->unconfirmedWarning->setVisible(anyUnconfirmed);
ui->balSheilded ->setText(QString::fromStdString(reply["private"]) % " " % Utils::getTokenName());
ui->balTransparent ->setText(QString::fromStdString(reply["transparent"]) % " " % Utils::getTokenName());
ui->balTotal ->setText(QString::fromStdString(reply["total"]) % " " % Utils::getTokenName());
});
// 2. Get the UTXOs // Update balances model data, which will update the table too
// First, create a new UTXO list, deleting the old one; balancesTableModel->setNewData(allBalances, utxos);
delete utxos;
utxos = new QList<UnspentOutput>();
delete allBalances;
allBalances = new QMap<QString, double>();
// Function to process reply of the listunspent and z_listunspent API calls, used below. // Add all the addresses into the inputs combo box
auto processUnspent = [=] (const json& reply) -> bool { auto lastFromAddr = ui->inputsCombo->currentText().split("(")[0].trimmed();
ui->inputsCombo->clear();
auto i = allBalances->constBegin();
while (i != allBalances->constEnd()) {
QString item = i.key() % "(" % QString::number(i.value(), 'g', 8) % " " % Utils::getTokenName() % ")";
ui->inputsCombo->addItem(item);
if (item.startsWith(lastFromAddr)) ui->inputsCombo->setCurrentText(item);
++i;
}
};
// Function to process reply of the listunspent and z_listunspent API calls, used below.
bool RPC::processUnspent(const json& reply) {
bool anyUnconfirmed = false; bool anyUnconfirmed = false;
for (auto& it : reply.get<json::array_t>()) { for (auto& it : reply.get<json::array_t>()) {
QString qsAddr = QString::fromStdString(it["address"]); QString qsAddr = QString::fromStdString(it["address"]);
@@ -374,28 +380,22 @@ void RPC::refreshBalances() {
(*allBalances)[qsAddr] = (*allBalances)[qsAddr] + it["amount"].get<json::number_float_t>(); (*allBalances)[qsAddr] = (*allBalances)[qsAddr] + it["amount"].get<json::number_float_t>();
} }
return anyUnconfirmed; return anyUnconfirmed;
}; };
// Function to create the data model and update the views, used below. void RPC::refreshBalances() {
auto updateUI = [=] (bool anyUnconfirmed) { // 1. Get the Balances
ui->unconfirmedWarning->setVisible(anyUnconfirmed); getBalance([=] (json reply) {
ui->balSheilded ->setText(QString::fromStdString(reply["private"]) % " " % Utils::getTokenName());
ui->balTransparent ->setText(QString::fromStdString(reply["transparent"]) % " " % Utils::getTokenName());
ui->balTotal ->setText(QString::fromStdString(reply["total"]) % " " % Utils::getTokenName());
});
// Update balances model data, which will update the table too // 2. Get the UTXOs
balancesTableModel->setNewData(allBalances, utxos); // First, create a new UTXO list, deleting the old one;
delete utxos;
// Add all the addresses into the inputs combo box utxos = new QList<UnspentOutput>();
auto lastFromAddr = ui->inputsCombo->currentText().split("(")[0].trimmed(); delete allBalances;
allBalances = new QMap<QString, double>();
ui->inputsCombo->clear();
auto i = allBalances->constBegin();
while (i != allBalances->constEnd()) {
QString item = i.key() % "(" % QString::number(i.value(), 'g', 8) % " " % Utils::getTokenName() % ")";
ui->inputsCombo->addItem(item);
if (item.startsWith(lastFromAddr)) ui->inputsCombo->setCurrentText(item);
++i;
}
};
// Call the Transparent and Z unspent APIs serially and then, once they're done, update the UI // Call the Transparent and Z unspent APIs serially and then, once they're done, update the UI
getTransparentUnspent([=] (json reply) { getTransparentUnspent([=] (json reply) {

View File

@@ -40,6 +40,8 @@ private:
void refreshBalances(); void refreshBalances();
void refreshTransactions(); void refreshTransactions();
bool processUnspent (const json& reply);
void updateUI (bool anyUnconfirmed);
void getInfoThenRefresh(); void getInfoThenRefresh();