Browse Source

Handle pending outgoing txns properly

pull/9/head
Aditya Kulkarni 5 years ago
parent
commit
3d66568ceb
  1. 6
      lib/Cargo.lock
  2. 2
      lib/Cargo.toml
  3. 64
      src/controller.cpp
  4. 1
      src/controller.h
  5. 1
      src/datamodel.cpp
  6. 24
      src/datamodel.h

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=b928d5f09646cc94023ea25f99951fcf1b43e90d)",
"zecwalletlitelib 0.1.0 (git+https://github.com/adityapk00/zecwallet-light-cli?rev=50d331b0cfe1b3c4b81e33fd6febb4b24264627a)",
]
[[package]]
@ -2266,7 +2266,7 @@ dependencies = [
[[package]]
name = "zecwalletlitelib"
version = "0.1.0"
source = "git+https://github.com/adityapk00/zecwallet-light-cli?rev=b928d5f09646cc94023ea25f99951fcf1b43e90d#b928d5f09646cc94023ea25f99951fcf1b43e90d"
source = "git+https://github.com/adityapk00/zecwallet-light-cli?rev=50d331b0cfe1b3c4b81e33fd6febb4b24264627a#50d331b0cfe1b3c4b81e33fd6febb4b24264627a"
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=b928d5f09646cc94023ea25f99951fcf1b43e90d)" = "<none>"
"checksum zecwalletlitelib 0.1.0 (git+https://github.com/adityapk00/zecwallet-light-cli?rev=50d331b0cfe1b3c4b81e33fd6febb4b24264627a)" = "<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 = "92d3804a5c67ca7621b141518a1f72451ca6ff40" }
zecwalletlitelib = { git = "https://github.com/adityapk00/zecwallet-light-cli", rev = "3e1c61a4b0589be1ff7590cf4ddf025a9160c631" }

64
src/controller.cpp

@ -272,6 +272,34 @@ void Controller::processUnspent(const json& reply, QMap<QString, CAmount>* balan
processFn(reply["pending_utxos"].get<json::array_t>());
};
void Controller::updateUIBalances() {
CAmount balT = getModel()->getBalT();
CAmount balZ = getModel()->getBalZ();
CAmount balVerified = getModel()->getBalVerified();
// Reduce the BalanceZ by the pending outgoing amount. We're adding
// here because totalPending is already negative for outgoing txns.
balZ = balZ + getModel()->getTotalPending();
CAmount balTotal = balT + balZ;
CAmount balAvailable = balT + balVerified;
// Balances table
ui->balSheilded ->setText(balZ.toDecimalZECString());
ui->balVerified ->setText(balVerified.toDecimalZECString());
ui->balTransparent->setText(balT.toDecimalZECString());
ui->balTotal ->setText(balTotal.toDecimalZECString());
ui->balSheilded ->setToolTip(balZ.toDecimalUSDString());
ui->balVerified ->setToolTip(balVerified.toDecimalUSDString());
ui->balTransparent->setToolTip(balT.toDecimalUSDString());
ui->balTotal ->setToolTip(balTotal.toDecimalUSDString());
// Send tab
ui->txtAvailableZEC->setText(balAvailable.toDecimalZECString());
ui->txtAvailableUSD->setText(balAvailable.toDecimalUSDString());
}
void Controller::refreshBalances() {
if (!zrpc->haveConnection())
return noConnection();
@ -282,29 +310,18 @@ void Controller::refreshBalances() {
CAmount balZ = CAmount::fromqint64(reply["zbalance"].get<json::number_unsigned_t>());
CAmount balVerified = CAmount::fromqint64(reply["verified_zbalance"].get<json::number_unsigned_t>());
CAmount balTotal = balT + balZ;
CAmount balAvailable = balT + balVerified;
model->setBalT(balT);
model->setBalZ(balZ);
model->setBalVerified(balVerified);
// This is for the websockets
AppDataModel::getInstance()->setBalances(balT, balZ);
// This is for the datamodel
CAmount balAvailable = balT + balVerified;
model->setAvailableBalance(balAvailable);
// Balances table
ui->balSheilded ->setText(balZ.toDecimalZECString());
ui->balVerified ->setText(balVerified.toDecimalZECString());
ui->balTransparent->setText(balT.toDecimalZECString());
ui->balTotal ->setText(balTotal.toDecimalZECString());
ui->balSheilded ->setToolTip(balZ.toDecimalUSDString());
ui->balVerified ->setToolTip(balVerified.toDecimalUSDString());
ui->balTransparent->setToolTip(balT.toDecimalUSDString());
ui->balTotal ->setToolTip(balTotal.toDecimalUSDString());
// Send tab
ui->txtAvailableZEC->setText(balAvailable.toDecimalZECString());
ui->txtAvailableUSD->setText(balAvailable.toDecimalUSDString());
updateUIBalances();
});
// 2. Get the UTXOs
@ -409,6 +426,21 @@ void Controller::refreshTransactions() {
}
// Calculate the total unspent amount that's pending. This will need to be
// shown in the UI so the user can keep track of pending funds
CAmount totalPending;
for (auto txitem : txdata) {
if (txitem.confirmations == 0) {
for (auto item: txitem.items) {
totalPending = totalPending + item.amount;
}
}
}
getModel()->setTotalPending(totalPending);
// Update UI Balance
updateUIBalances();
// Update model data, which updates the table view
transactionsTableModel->replaceData(txdata);
});

1
src/controller.h

@ -103,6 +103,7 @@ private:
void processUnspent (const json& reply, QMap<QString, CAmount>* newBalances, QList<UnspentOutput>* newUnspentOutputs);
void updateUI (bool anyUnconfirmed);
void updateUIBalances ();
void getInfoThenRefresh (bool force);

1
src/datamodel.cpp

@ -24,6 +24,7 @@ DataModel::~DataModel() {
}
void DataModel::setLatestBlock(int blockHeight) {
QReadLocker locker(lock);
this->latestBlock = blockHeight;
}

24
src/datamodel.h

@ -26,7 +26,7 @@ public:
void markAddressUsed(QString address);
void setLatestBlock(int blockHeight);
int getLatestBlock() { return this->latestBlock; }
int getLatestBlock() { QReadLocker locker(lock); return this->latestBlock; }
void setEncryptionStatus(bool encrypted, bool locked) { this->isEncrypted = encrypted; this->isLocked = locked; }
QPair<bool, bool> getEncryptionStatus() { return qMakePair(this->isEncrypted, this->isLocked); }
@ -37,8 +37,20 @@ public:
const QMap<QString, CAmount> getAllBalances() { QReadLocker locker(lock); return *balances; }
const QMap<QString, bool> getUsedAddresses() { QReadLocker locker(lock); return *usedAddresses; }
CAmount getAvailableBalance() { return availableBalance; }
void setAvailableBalance(CAmount a) { this->availableBalance = a; }
CAmount getAvailableBalance() { QReadLocker locker(lock); return availableBalance; }
void setAvailableBalance(CAmount a) { QReadLocker locker(lock); this->availableBalance = a; }
CAmount getBalT() { QReadLocker locker(lock); return balT; }
void setBalT(CAmount a) { QReadLocker locker(lock); this->balT = a; }
CAmount getBalZ() { QReadLocker locker(lock); return balZ; }
void setBalZ(CAmount a) { QReadLocker locker(lock); this->balZ = a; }
CAmount getBalVerified() { QReadLocker locker(lock); return balVerified; }
void setBalVerified(CAmount a) { QReadLocker locker(lock); this->balVerified = a; }
CAmount getTotalPending() { QReadLocker locker(lock); return totalPending; }
void setTotalPending(CAmount a) { QReadLocker locker(lock); this->totalPending = a; }
DataModel();
~DataModel();
@ -55,9 +67,13 @@ private:
QList<QString>* taddresses = nullptr;
CAmount availableBalance;
CAmount totalPending; // Outgoing pending is -ve
QReadWriteLock* lock;
CAmount balT;
CAmount balZ;
CAmount balVerified;
QReadWriteLock* lock;
};
#endif // DATAMODEL_H
Loading…
Cancel
Save