Use latest block instead of info

This commit is contained in:
Aditya Kulkarni
2019-11-13 15:11:11 -08:00
parent c98da96b97
commit bcf2d4e9d6
11 changed files with 67 additions and 41 deletions

View File

@@ -49,7 +49,7 @@ void ConnectionLoader::doAutoConnect() {
main->logger->write(QObject::tr("Attempting to initialize library with ") + config->server);
// Check to see if there's an existing wallet
if (litelib_wallet_exists(Settings::getChainName().toStdString().c_str())) {
if (litelib_wallet_exists(Settings::getDefaultChainName().toStdString().c_str())) {
main->logger->write(QObject::tr("Using existing wallet."));
char* resp = litelib_initialize_existing(config->dangerous, config->server.toStdString().c_str());
QString response = litelib_process_response(resp);
@@ -68,9 +68,10 @@ void ConnectionLoader::doAutoConnect() {
auto me = this;
// After the lib is initialized, try to do get info
connection->doRPC("info", "", [=](auto) {
connection->doRPC("info", "", [=](auto reply) {
// If success, set the connection
main->logger->write("Connection is online.");
connection->setInfo(reply);
isSyncing = new QAtomicInteger<bool>();
isSyncing->store(true);

View File

@@ -123,8 +123,12 @@ public:
void showTxError(const QString& error);
json getInfo() { return serverInfo; }
void setInfo(const json& info) { serverInfo = info; }
private:
bool shutdownInProgress = false;
bool shutdownInProgress = false;
json serverInfo;
};
#endif

View File

@@ -67,6 +67,8 @@ void Controller::setConnection(Connection* c) {
ui->statusBar->showMessage("Ready!");
processInfo(c->getInfo());
// If we're allowed to get the Zec Price, get the prices
if (Settings::getInstance()->getAllowFetchPrices())
refreshZECPrice();
@@ -137,42 +139,46 @@ void Controller::refresh(bool force) {
getInfoThenRefresh(force);
}
void Controller::processInfo(const json& info) {
// Testnet?
QString chainName;
if (!info["chain_name"].is_null()) {
chainName = QString::fromStdString(info["chain_name"].get<json::string_t>());
Settings::getInstance()->setTestnet(chainName == "test");
};
QString version = QString::fromStdString(info["version"].get<json::string_t>());
Settings::getInstance()->setZcashdVersion(version);
// Recurring pamynets are testnet only
if (!Settings::getInstance()->isTestnet())
main->disableRecurring();
}
void Controller::getInfoThenRefresh(bool force) {
if (!zrpc->haveConnection())
return noConnection();
static bool prevCallSucceeded = false;
zrpc->fetchInfo([=] (const json& reply) {
prevCallSucceeded = true;
zrpc->fetchLatestBlock([=] (const json& reply) {
prevCallSucceeded = true;
// Testnet?
QString chainName;
if (!reply["chain_name"].is_null()) {
chainName = QString::fromStdString(reply["chain_name"].get<json::string_t>());
Settings::getInstance()->setTestnet(chainName == "test");
};
// Recurring pamynets are testnet only
if (!Settings::getInstance()->isTestnet())
main->disableRecurring();
int curBlock = reply["latest_block_height"].get<json::number_integer_t>();
int curBlock = reply["height"].get<json::number_integer_t>();
bool doUpdate = force || (model->getLatestBlock() != curBlock);
model->setLatestBlock(curBlock);
// Connected, so display checkmark.
auto tooltip = Settings::getInstance()->getSettings().server + "\n" + QString::fromStdString(reply.dump());
auto tooltip = Settings::getInstance()->getSettings().server + "\n" +
QString::fromStdString(zrpc->getConnection()->getInfo().dump());
QIcon i(":/icons/res/connected.gif");
QString chainName = Settings::getInstance()->isTestnet() ? "test" : "main";
main->statusLabel->setText(chainName + "(" + QString::number(curBlock) + ")");
main->statusLabel->setToolTip(tooltip);
main->statusIcon->setPixmap(i.pixmap(16, 16));
main->statusIcon->setToolTip(tooltip);
//int version = reply["version"].get<json::string_t>();
int version = 1;
Settings::getInstance()->setZcashdVersion(version);
// See if recurring payments needs anything
Recurring::getInstance()->processPending(main);

View File

@@ -107,6 +107,7 @@ public:
QString getDefaultTAddress();
private:
void processInfo(const json&);
void refreshBalances();
void refreshTransactions();

View File

@@ -130,6 +130,15 @@ void LiteInterface::fetchInfo(const std::function<void(json)>& cb,
conn->doRPC("info", "", cb, err);
}
void LiteInterface::fetchLatestBlock(const std::function<void(json)>& cb,
const std::function<void(QString)>& err) {
if (conn == nullptr)
return;
conn->doRPC("height", "", cb, err);
}
/**
* Method to get all the private keys for both z and t addresses. It will make 2 batch calls,
* combine the result, and call the callback with a single list containing both the t-addr and z-addr

View File

@@ -44,6 +44,9 @@ public:
void fetchInfo(const std::function<void(json)>& cb,
const std::function<void(QString)>& err);
void fetchLatestBlock(const std::function<void(json)>& cb,
const std::function<void(QString)>& err);
void fetchBalance(const std::function<void(json)>& cb);

View File

@@ -74,11 +74,11 @@ bool Settings::isTAddress(QString addr) {
return addr.startsWith("t");
}
int Settings::getZcashdVersion() {
QString Settings::getZcashdVersion() {
return _zcashdVersion;
}
void Settings::setZcashdVersion(int version) {
void Settings::setZcashdVersion(QString version) {
_zcashdVersion = version;
}

View File

@@ -42,8 +42,8 @@ public:
bool isSyncing();
void setSyncing(bool syncing);
int getZcashdVersion();
void setZcashdVersion(int version);
QString getZcashdVersion();
void setZcashdVersion(QString version);
void setUseEmbedded(bool r) { _useEmbedded = r; }
bool useEmbedded() { return _useEmbedded; }
@@ -95,12 +95,11 @@ public:
static bool isValidAddress(QString addr);
static QString getChainName() { return QString("main"); }
static QString getDefaultChainName() { return QString("main"); }
static const QString labelRegExp;
static const int updateSpeed = 20 * 1000; // 20 sec
static const int quickUpdateSpeed = 5 * 1000; // 5 sec
static const int updateSpeed = 60 * 1000; // 60 sec
static const int priceRefreshSpeed = 60 * 60 * 1000; // 1 hr
private:
@@ -114,7 +113,7 @@ private:
bool _isTestnet = false;
bool _isSyncing = false;
int _blockNumber = 0;
int _zcashdVersion = 0;
QString _zcashdVersion = 0;
bool _useEmbedded = false;
bool _headless = false;

View File

@@ -70,15 +70,18 @@ bool TxTableModel::exportToCsv(QString fileName) const {
}
QString TxTableModel::concatMultipleMemos(const TransactionItem& dat) const {
// Concat all the memos
QString memo;
for (auto item : dat.items) {
if (!item.memo.trimmed().isEmpty()) {
memo += item.address + ": \"" + item.memo + "\"\n";
if (dat.items.length() == 1) {
return dat.items[0].memo;
} else {
// Concat all the memos
QString memo;
for (auto item : dat.items) {
if (!item.memo.trimmed().isEmpty()) {
memo += item.address + ": \"" + item.memo + "\"\n";
}
}
return memo;
}
return memo;
};
QVariant TxTableModel::data(const QModelIndex &index, int role) const {