Handle pending outgoing txns properly
This commit is contained in:
6
lib/Cargo.lock
generated
6
lib/Cargo.lock
generated
@@ -1051,7 +1051,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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]]
|
[[package]]
|
||||||
@@ -2266,7 +2266,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "zecwalletlitelib"
|
name = "zecwalletlitelib"
|
||||||
version = "0.1.0"
|
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 = [
|
dependencies = [
|
||||||
"base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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_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_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 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>"
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ crate-type = ["staticlib"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
libc = "0.2.58"
|
libc = "0.2.58"
|
||||||
lazy_static = "1.4.0"
|
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" }
|
||||||
|
|||||||
@@ -272,6 +272,34 @@ void Controller::processUnspent(const json& reply, QMap<QString, CAmount>* balan
|
|||||||
processFn(reply["pending_utxos"].get<json::array_t>());
|
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() {
|
void Controller::refreshBalances() {
|
||||||
if (!zrpc->haveConnection())
|
if (!zrpc->haveConnection())
|
||||||
return noConnection();
|
return noConnection();
|
||||||
@@ -282,29 +310,18 @@ void Controller::refreshBalances() {
|
|||||||
CAmount balZ = CAmount::fromqint64(reply["zbalance"].get<json::number_unsigned_t>());
|
CAmount balZ = CAmount::fromqint64(reply["zbalance"].get<json::number_unsigned_t>());
|
||||||
CAmount balVerified = CAmount::fromqint64(reply["verified_zbalance"].get<json::number_unsigned_t>());
|
CAmount balVerified = CAmount::fromqint64(reply["verified_zbalance"].get<json::number_unsigned_t>());
|
||||||
|
|
||||||
CAmount balTotal = balT + balZ;
|
model->setBalT(balT);
|
||||||
CAmount balAvailable = balT + balVerified;
|
model->setBalZ(balZ);
|
||||||
|
model->setBalVerified(balVerified);
|
||||||
|
|
||||||
// This is for the websockets
|
// This is for the websockets
|
||||||
AppDataModel::getInstance()->setBalances(balT, balZ);
|
AppDataModel::getInstance()->setBalances(balT, balZ);
|
||||||
|
|
||||||
// This is for the datamodel
|
// This is for the datamodel
|
||||||
|
CAmount balAvailable = balT + balVerified;
|
||||||
model->setAvailableBalance(balAvailable);
|
model->setAvailableBalance(balAvailable);
|
||||||
|
|
||||||
// Balances table
|
updateUIBalances();
|
||||||
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());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 2. Get the UTXOs
|
// 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
|
// Update model data, which updates the table view
|
||||||
transactionsTableModel->replaceData(txdata);
|
transactionsTableModel->replaceData(txdata);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ private:
|
|||||||
|
|
||||||
void processUnspent (const json& reply, QMap<QString, CAmount>* newBalances, QList<UnspentOutput>* newUnspentOutputs);
|
void processUnspent (const json& reply, QMap<QString, CAmount>* newBalances, QList<UnspentOutput>* newUnspentOutputs);
|
||||||
void updateUI (bool anyUnconfirmed);
|
void updateUI (bool anyUnconfirmed);
|
||||||
|
void updateUIBalances ();
|
||||||
|
|
||||||
void getInfoThenRefresh (bool force);
|
void getInfoThenRefresh (bool force);
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ DataModel::~DataModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DataModel::setLatestBlock(int blockHeight) {
|
void DataModel::setLatestBlock(int blockHeight) {
|
||||||
|
QReadLocker locker(lock);
|
||||||
this->latestBlock = blockHeight;
|
this->latestBlock = blockHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public:
|
|||||||
void markAddressUsed(QString address);
|
void markAddressUsed(QString address);
|
||||||
|
|
||||||
void setLatestBlock(int blockHeight);
|
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; }
|
void setEncryptionStatus(bool encrypted, bool locked) { this->isEncrypted = encrypted; this->isLocked = locked; }
|
||||||
QPair<bool, bool> getEncryptionStatus() { return qMakePair(this->isEncrypted, this->isLocked); }
|
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, CAmount> getAllBalances() { QReadLocker locker(lock); return *balances; }
|
||||||
const QMap<QString, bool> getUsedAddresses() { QReadLocker locker(lock); return *usedAddresses; }
|
const QMap<QString, bool> getUsedAddresses() { QReadLocker locker(lock); return *usedAddresses; }
|
||||||
|
|
||||||
CAmount getAvailableBalance() { return availableBalance; }
|
CAmount getAvailableBalance() { QReadLocker locker(lock); return availableBalance; }
|
||||||
void setAvailableBalance(CAmount a) { this->availableBalance = a; }
|
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();
|
||||||
~DataModel();
|
~DataModel();
|
||||||
@@ -55,9 +67,13 @@ private:
|
|||||||
QList<QString>* taddresses = nullptr;
|
QList<QString>* taddresses = nullptr;
|
||||||
|
|
||||||
CAmount availableBalance;
|
CAmount availableBalance;
|
||||||
|
CAmount totalPending; // Outgoing pending is -ve
|
||||||
|
|
||||||
|
CAmount balT;
|
||||||
|
CAmount balZ;
|
||||||
|
CAmount balVerified;
|
||||||
|
|
||||||
QReadWriteLock* lock;
|
QReadWriteLock* lock;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DATAMODEL_H
|
#endif // DATAMODEL_H
|
||||||
Reference in New Issue
Block a user