Skip to content

Commit

Permalink
Use latest block instead of info
Browse files Browse the repository at this point in the history
  • Loading branch information
adityapk00 committed Nov 13, 2019
1 parent c98da96 commit bcf2d4e
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 41 deletions.
6 changes: 3 additions & 3 deletions lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ crate-type = ["staticlib"]
[dependencies]
libc = "0.2.58"
lazy_static = "1.4.0"
zecwalletlitelib = { git = "https://github.com/adityapk00/zecwallet-light-cli", rev = "af0e0b9b2bcc131804d5e940f94d45c6fef74481" }
zecwalletlitelib = { git = "https://github.com/adityapk00/zecwallet-light-cli", rev = "61dc063fe155d1510e9a074e5a3577a0621f8c3a" }
5 changes: 3 additions & 2 deletions src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,12 @@ Q_OBJECT

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
44 changes: 25 additions & 19 deletions src/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;

// Testnet?
QString chainName;
if (!reply["chain_name"].is_null()) {
chainName = QString::fromStdString(reply["chain_name"].get<json::string_t>());
Settings::getInstance()->setTestnet(chainName == "test");
};
zrpc->fetchLatestBlock([=] (const json& reply) {
prevCallSucceeded = true;

// 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);

Expand Down
1 change: 1 addition & 0 deletions src/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class Controller
QString getDefaultTAddress();

private:
void processInfo(const json&);
void refreshBalances();

void refreshTransactions();
Expand Down
9 changes: 9 additions & 0 deletions src/liteinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/liteinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class LiteInterface {

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);

Expand Down
4 changes: 2 additions & 2 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
11 changes: 5 additions & 6 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class Settings
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; }
Expand Down Expand Up @@ -95,12 +95,11 @@ class Settings

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:
Expand All @@ -114,7 +113,7 @@ class Settings
bool _isTestnet = false;
bool _isSyncing = false;
int _blockNumber = 0;
int _zcashdVersion = 0;
QString _zcashdVersion = 0;
bool _useEmbedded = false;
bool _headless = false;

Expand Down
17 changes: 10 additions & 7 deletions src/txtablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit bcf2d4e

Please sign in to comment.