Browse Source

Balances

pull/19/head
Aditya Kulkarni 5 years ago
parent
commit
28fdac1b72
  1. 2
      src/connection.cpp
  2. 52
      src/controller.cpp
  3. 3
      src/controller.h
  4. 17
      src/liteinterface.cpp
  5. 9
      src/mainwindow.cpp

2
src/connection.cpp

@ -43,6 +43,7 @@ void ConnectionLoader::doAutoConnect(bool tryEzcashdStart) {
// Initialize the library // Initialize the library
main->logger->write(QObject::tr("Attempting to initialize")); main->logger->write(QObject::tr("Attempting to initialize"));
litelib_initialze(config->dangerous, config->server.toStdString().c_str()); litelib_initialze(config->dangerous, config->server.toStdString().c_str());
auto connection = makeConnection(config); auto connection = makeConnection(config);
// After the lib is initialized, try to do get info // After the lib is initialized, try to do get info
@ -87,7 +88,6 @@ void ConnectionLoader::showInformation(QString info, QString detail) {
* Show error will close the loading dialog and show an error. * Show error will close the loading dialog and show an error.
*/ */
void ConnectionLoader::showError(QString explanation) { void ConnectionLoader::showError(QString explanation) {
rpc->setEZcashd(nullptr);
rpc->noConnection(); rpc->noConnection();
QMessageBox::critical(main, QObject::tr("Connection Error"), explanation, QMessageBox::Ok); QMessageBox::critical(main, QObject::tr("Connection Error"), explanation, QMessageBox::Ok);

52
src/controller.cpp

@ -70,13 +70,6 @@ Controller::~Controller() {
delete zrpc; delete zrpc;
} }
void Controller::setEZcashd(QProcess* p) {
ezcashd = p;
if (ezcashd && ui->tabWidget->widget(4) == nullptr) {
ui->tabWidget->addTab(main->zcashdtab, "zcashd");
}
}
// Called when a connection to zcashd is available. // Called when a connection to zcashd is available.
void Controller::setConnection(Connection* c) { void Controller::setConnection(Connection* c) {
@ -209,10 +202,13 @@ void Controller::getInfoThenRefresh(bool force) {
static bool prevCallSucceeded = false; static bool prevCallSucceeded = false;
zrpc->fetchInfo([=] (const json& reply) { zrpc->fetchInfo([=] (const json& reply) {
qDebug() << "Info updated";
prevCallSucceeded = true; prevCallSucceeded = true;
// Testnet? // Testnet?
if (!reply["testnet"].is_null()) { if (!reply["chain_name"].is_null()) {
Settings::getInstance()->setTestnet(reply["testnet"].get<json::boolean_t>()); Settings::getInstance()->setTestnet(reply["chain_name"].get<json::string_t>() == "test");
}; };
// Recurring pamynets are testnet only // Recurring pamynets are testnet only
@ -224,8 +220,9 @@ void Controller::getInfoThenRefresh(bool force) {
main->statusIcon->setPixmap(i.pixmap(16, 16)); main->statusIcon->setPixmap(i.pixmap(16, 16));
static int lastBlock = 0; static int lastBlock = 0;
int curBlock = reply["blocks"].get<json::number_integer_t>(); int curBlock = reply["latest_block_height"].get<json::number_integer_t>();
int version = reply["version"].get<json::number_integer_t>(); //int version = reply["version"].get<json::string_t>();
int version = 1;
Settings::getInstance()->setZcashdVersion(version); Settings::getInstance()->setZcashdVersion(version);
// See if recurring payments needs anything // See if recurring payments needs anything
@ -241,23 +238,6 @@ void Controller::getInfoThenRefresh(bool force) {
refreshMigration(); // Sapling turnstile migration status. refreshMigration(); // Sapling turnstile migration status.
} }
int connections = reply["connections"].get<json::number_integer_t>();
Settings::getInstance()->setPeers(connections);
if (connections == 0) {
// If there are no peers connected, then the internet is probably off or something else is wrong.
QIcon i = QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning);
main->statusIcon->setPixmap(i.pixmap(16, 16));
}
// Get network sol/s
if (ezcashd) {
zrpc->fetchNetSolOps([=] (qint64 solrate) {
ui->numconnections->setText(QString::number(connections));
ui->solrate->setText(QString::number(solrate) % " Sol/s");
});
}
// Call to see if the blockchain is syncing. // Call to see if the blockchain is syncing.
zrpc->fetchBlockchainInfo([=](const json& reply) { zrpc->fetchBlockchainInfo([=](const json& reply) {
auto progress = reply["verificationprogress"].get<double>(); auto progress = reply["verificationprogress"].get<double>();
@ -304,12 +284,8 @@ void Controller::getInfoThenRefresh(bool force) {
auto zecPrice = Settings::getInstance()->getUSDFromZecAmount(1); auto zecPrice = Settings::getInstance()->getUSDFromZecAmount(1);
QString tooltip; QString tooltip;
if (connections > 0) { tooltip = QObject::tr("Connected to zcashd");
tooltip = QObject::tr("Connected to zcashd");
}
else {
tooltip = QObject::tr("zcashd has no peer connections");
}
tooltip = tooltip % "(v " % QString::number(Settings::getInstance()->getZcashdVersion()) % ")"; tooltip = tooltip % "(v " % QString::number(Settings::getInstance()->getZcashdVersion()) % ")";
if (!zecPrice.isEmpty()) { if (!zecPrice.isEmpty()) {
@ -428,9 +404,9 @@ void Controller::refreshBalances() {
// 1. Get the Balances // 1. Get the Balances
zrpc->fetchBalance([=] (json reply) { zrpc->fetchBalance([=] (json reply) {
auto balT = QString::fromStdString(reply["transparent"]).toDouble(); auto balT = reply["tbalance"].get<json::number_unsigned_t>();
auto balZ = QString::fromStdString(reply["private"]).toDouble(); auto balZ = reply["zbalance"].get<json::number_unsigned_t>();
auto balTotal = QString::fromStdString(reply["total"]).toDouble(); auto balTotal = balT + balZ;
AppDataModel::getInstance()->setBalances(balT, balZ); AppDataModel::getInstance()->setBalances(balT, balZ);
@ -763,7 +739,7 @@ void Controller::refreshZECPrice() {
void Controller::shutdownZcashd() { void Controller::shutdownZcashd() {
// Shutdown embedded zcashd if it was started // Shutdown embedded zcashd if it was started
if (ezcashd == nullptr || ezcashd->processId() == 0 || ~zrpc->haveConnection()) { if (ezcashd == nullptr || ezcashd->processId() == 0 || !zrpc->haveConnection()) {
// No zcashd running internally, just return // No zcashd running internally, just return
return; return;
} }

3
src/controller.h

@ -40,9 +40,6 @@ public:
Connection* getConnection() { return zrpc->getConnection(); } Connection* getConnection() { return zrpc->getConnection(); }
void setConnection(Connection* c); void setConnection(Connection* c);
void setEZcashd(QProcess* p);
const QProcess* getEZcashD() { return ezcashd; }
void refresh(bool force = false); void refresh(bool force = false);
void refreshAddresses(); void refreshAddresses();

17
src/liteinterface.cpp

@ -179,14 +179,7 @@ void LiteInterface::fetchBalance(const std::function<void(json)>& cb) {
if (conn == nullptr) if (conn == nullptr)
return; return;
// json payload = { conn->doRPCWithDefaultErrorHandling("balance", "", cb);
// {"jsonrpc", "1.0"},
// {"id", "someid"},
// {"method", "z_gettotalbalance"},
// {"params", {0}} // Get Unconfirmed balance as well.
// };
// conn->doRPCWithDefaultErrorHandling(payload, cb);
} }
void LiteInterface::fetchTransactions(const std::function<void(json)>& cb) { void LiteInterface::fetchTransactions(const std::function<void(json)>& cb) {
@ -228,13 +221,7 @@ void LiteInterface::fetchInfo(const std::function<void(json)>& cb,
if (conn == nullptr) if (conn == nullptr)
return; return;
// json payload = { conn->doRPC("info", "", cb, err);
// {"jsonrpc", "1.0"},
// {"id", "someid"},
// {"method", "getinfo"}
// };
// conn->doRPC(payload, cb, err);
} }
void LiteInterface::fetchBlockchainInfo(const std::function<void(json)>& cb) { void LiteInterface::fetchBlockchainInfo(const std::function<void(json)>& cb) {

9
src/mainwindow.cpp

@ -335,14 +335,7 @@ void MainWindow::setupSettingsModal() {
isUsingTor = !rpc->getConnection()->config->proxy.isEmpty(); isUsingTor = !rpc->getConnection()->config->proxy.isEmpty();
} }
settings.chkTor->setChecked(isUsingTor); settings.chkTor->setChecked(isUsingTor);
if (rpc->getEZcashD() == nullptr) {
settings.chkTor->setEnabled(false);
settings.lblTor->setEnabled(false);
QString tooltip = tr("Tor configuration is available only when running an embedded zcashd.");
settings.chkTor->setToolTip(tooltip);
settings.lblTor->setToolTip(tooltip);
}
// Connection Settings // Connection Settings
QIntValidator validator(0, 65535); QIntValidator validator(0, 65535);
settings.port->setValidator(&validator); settings.port->setValidator(&validator);

Loading…
Cancel
Save