Clean up rpc methods
This commit is contained in:
70
src/rpc.cpp
70
src/rpc.cpp
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user