Browse Source

Use latest block instead of info

pull/25/head^2
Aditya Kulkarni 5 years ago
parent
commit
bcf2d4e9d6
  1. 6
      lib/Cargo.lock
  2. 2
      lib/Cargo.toml
  3. 5
      src/connection.cpp
  4. 6
      src/connection.h
  5. 44
      src/controller.cpp
  6. 1
      src/controller.h
  7. 9
      src/liteinterface.cpp
  8. 3
      src/liteinterface.h
  9. 4
      src/settings.cpp
  10. 11
      src/settings.h
  11. 17
      src/txtablemodel.cpp

6
lib/Cargo.lock

@ -1051,7 +1051,7 @@ version = "0.1.0"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"zecwalletlitelib 0.1.0 (git+https://github.com/adityapk00/zecwallet-light-cli?rev=af0e0b9b2bcc131804d5e940f94d45c6fef74481)",
"zecwalletlitelib 0.1.0 (git+https://github.com/adityapk00/zecwallet-light-cli?rev=61dc063fe155d1510e9a074e5a3577a0621f8c3a)",
]
[[package]]
@ -2266,7 +2266,7 @@ dependencies = [
[[package]]
name = "zecwalletlitelib"
version = "0.1.0"
source = "git+https://github.com/adityapk00/zecwallet-light-cli?rev=af0e0b9b2bcc131804d5e940f94d45c6fef74481#af0e0b9b2bcc131804d5e940f94d45c6fef74481"
source = "git+https://github.com/adityapk00/zecwallet-light-cli?rev=61dc063fe155d1510e9a074e5a3577a0621f8c3a#61dc063fe155d1510e9a074e5a3577a0621f8c3a"
dependencies = [
"base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bellman 0.1.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)",
@ -2562,4 +2562,4 @@ dependencies = [
"checksum zcash_client_backend 0.0.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)" = "<none>"
"checksum zcash_primitives 0.0.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)" = "<none>"
"checksum zcash_proofs 0.0.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)" = "<none>"
"checksum zecwalletlitelib 0.1.0 (git+https://github.com/adityapk00/zecwallet-light-cli?rev=af0e0b9b2bcc131804d5e940f94d45c6fef74481)" = "<none>"
"checksum zecwalletlitelib 0.1.0 (git+https://github.com/adityapk00/zecwallet-light-cli?rev=61dc063fe155d1510e9a074e5a3577a0621f8c3a)" = "<none>"

2
lib/Cargo.toml

@ -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
src/connection.cpp

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

6
src/connection.h

@ -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

44
src/controller.cpp

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

1
src/controller.h

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

9
src/liteinterface.cpp

@ -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

3
src/liteinterface.h

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

4
src/settings.cpp

@ -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;
}

11
src/settings.h

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

17
src/txtablemodel.cpp

@ -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 {

Loading…
Cancel
Save