</widget>
</item>
<item row="0" column="1">
- <widget class="QLabel" name="labelBalance">
+ <widget class="QLabel" name="labelBalanceTotal">
<property name="font">
<font>
<weight>75</weight>
</widget>
</item>
<item row="1" column="0">
+ <widget class="QLabel" name="labelBalanceWatchOnlyText">
+ <property name="text">
+ <string>Unspendable:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLabel" name="labelBalanceWatchOnly">
+ <property name="font">
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
+ <property name="cursor">
+ <cursorShape>IBeamCursor</cursorShape>
+ </property>
+ <property name="toolTip">
+ <string>Your unspendable balance</string>
+ </property>
+ <property name="text">
+ <string notr="true">0 NVC</string>
+ </property>
+ <property name="textInteractionFlags">
+ <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Stake:</string>
</property>
</widget>
</item>
- <item row="1" column="1">
+ <item row="2" column="1">
<widget class="QLabel" name="labelStake">
<property name="font">
<font>
</property>
</widget>
</item>
- <item row="2" column="0">
+ <item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Unconfirmed:</string>
</property>
</widget>
</item>
- <item row="2" column="1">
+ <item row="3" column="1">
<widget class="QLabel" name="labelUnconfirmed">
<property name="font">
<font>
</property>
</widget>
</item>
- <item row="3" column="0">
+ <item row="4" column="0">
<widget class="QLabel" name="labelImmatureText">
<property name="text">
<string>Immature:</string>
</property>
</widget>
</item>
- <item row="3" column="1">
+ <item row="4" column="1">
<widget class="QLabel" name="labelImmature">
<property name="font">
<font>
</property>
</widget>
</item>
- <item row="4" column="0">
+ <item row="5" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Number of transactions:</string>
</property>
</widget>
</item>
- <item row="4" column="1">
+ <item row="5" column="1">
<widget class="QLabel" name="labelNumTransactions">
<property name="toolTip">
<string>Total number of transactions in wallet</string>
<translation>Unconfirmed:</translation>
</message>
<message>
+ <location line="-55"/>
+ <source>Unspendable:</source>
+ <translation>Unspendable:</translation>
+ </message>
+ <message>
<location line="-107"/>
<source>Wallet</source>
<translation>Wallet</translation>
<translation>Your current balance</translation>
</message>
<message>
+ <location line="-147"/>
+ <source>Your unspendable balance</source>
+ <translation>Your unspendable balance</translation>
+ </message>
+ <message>
<location line="+58"/>
<source>Total of transactions that have yet to be confirmed, and do not yet count toward the current balance</source>
<translation>Total of transactions that have yet to be confirmed, and do not yet count toward the current balance</translation>
<translation>Незрелые:</translation>
</message>
<message>
+ <location line="+136"/>
+ <source>Unspendable:</source>
+ <translation>Недоступно:</translation>
+ </message>
+ <message>
<location line="+13"/>
<source>Mined balance that has not yet matured</source>
<translation>Баланс добытых монет, который ещё не созрел</translation>
<translation>Ваш текущий баланс</translation>
</message>
<message>
+ <location line="-147"/>
+ <source>Your unspendable balance</source>
+ <translation>Недоступный баланс</translation>
+ </message>
+ <message>
<location line="+58"/>
<source>Total of transactions that have yet to be confirmed, and do not yet count toward the current balance</source>
<translation>Общая сумма всех транзакций, которые до сих пор не подтверждены, и до сих пор не учитываются в текущем балансе</translation>
OverviewPage::OverviewPage(QWidget *parent) :
QWidget(parent),
ui(new Ui::OverviewPage),
- currentBalance(-1),
+ currentBalanceTotal(-1),
+ currentBalanceWatchOnly(0),
currentStake(0),
currentUnconfirmedBalance(-1),
currentImmatureBalance(-1),
delete ui;
}
-void OverviewPage::setBalance(qint64 balance, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance)
+void OverviewPage::setBalance(qint64 total, qint64 watchOnly, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance)
{
int unit = model->getOptionsModel()->getDisplayUnit();
- currentBalance = balance;
+ currentBalanceTotal = total;
+ currentBalanceWatchOnly = watchOnly;
currentStake = stake;
currentUnconfirmedBalance = unconfirmedBalance;
currentImmatureBalance = immatureBalance;
- ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balance));
+ ui->labelBalanceTotal->setText(BitcoinUnits::formatWithUnit(unit, total));
+ ui->labelBalanceWatchOnly->setText(BitcoinUnits::formatWithUnit(unit, watchOnly));
ui->labelStake->setText(BitcoinUnits::formatWithUnit(unit, stake));
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, unconfirmedBalance));
ui->labelImmature->setText(BitcoinUnits::formatWithUnit(unit, immatureBalance));
bool showImmature = immatureBalance != 0;
ui->labelImmature->setVisible(showImmature);
ui->labelImmatureText->setVisible(showImmature);
+
+ // only show watch-only balance if it's non-zero, so as not to complicate things
+ // for users
+ bool showWatchOnly = watchOnly != 0;
+ ui->labelBalanceWatchOnly->setVisible(showWatchOnly);
+ ui->labelBalanceWatchOnlyText->setVisible(showWatchOnly);
}
void OverviewPage::setNumTransactions(int count)
ui->listTransactions->setModelColumn(TransactionTableModel::ToAddress);
// Keep up to date with wallet
- setBalance(model->getBalance(), model->getStake(), model->getUnconfirmedBalance(), model->getImmatureBalance());
- connect(model, SIGNAL(balanceChanged(qint64, qint64, qint64, qint64)), this, SLOT(setBalance(qint64, qint64, qint64, qint64)));
+ qint64 nTotal=0, nWatchOnly=0;
+ model->getBalance(nTotal, nWatchOnly);
+ setBalance(nTotal, nWatchOnly, model->getStake(), model->getUnconfirmedBalance(), model->getImmatureBalance());
+ connect(model, SIGNAL(balanceChanged(qint64, qint64, qint64, qint64, qint64)), this, SLOT(setBalance(qint64, qint64, qint64, qint64, qint64)));
setNumTransactions(model->getNumTransactions());
connect(model, SIGNAL(numTransactionsChanged(int)), this, SLOT(setNumTransactions(int)));
{
if(model && model->getOptionsModel())
{
- if(currentBalance != -1)
- setBalance(currentBalance, model->getStake(), currentUnconfirmedBalance, currentImmatureBalance);
+ if(currentBalanceTotal != -1)
+ setBalance(currentBalanceTotal, currentBalanceWatchOnly, model->getStake(), currentUnconfirmedBalance, currentImmatureBalance);
// Update txdelegate->unit with the current unit
txdelegate->unit = model->getOptionsModel()->getDisplayUnit();
void showOutOfSyncWarning(bool fShow);
public slots:
- void setBalance(qint64 balance, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance);
+ void setBalance(qint64 total, qint64 watchOnly, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance);
void setNumTransactions(int count);
signals:
private:
Ui::OverviewPage *ui;
WalletModel *model;
- qint64 currentBalance;
+ qint64 currentBalanceTotal;
+ qint64 currentBalanceWatchOnly;
qint64 currentStake;
qint64 currentUnconfirmedBalance;
qint64 currentImmatureBalance;
}
if(model && model->getOptionsModel())
{
- setBalance(model->getBalance(), model->getStake(), model->getUnconfirmedBalance(), model->getImmatureBalance());
- connect(model, SIGNAL(balanceChanged(qint64, qint64, qint64, qint64)), this, SLOT(setBalance(qint64, qint64, qint64, qint64)));
+ qint64 nTotal=0, nWatchOnly=0;
+ model->getBalance(nTotal, nWatchOnly);
+ setBalance(nTotal, nWatchOnly, model->getStake(), model->getUnconfirmedBalance(), model->getImmatureBalance());
+ connect(model, SIGNAL(balanceChanged(qint64, qint64, qint64, qint64, qint64)), this, SLOT(setBalance(qint64, qint64, qint64, qint64, qint64)));
connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
// Coin Control
return false;
}
-void SendCoinsDialog::setBalance(qint64 balance, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance)
+void SendCoinsDialog::setBalance(qint64 total, qint64 watchOnly, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance)
{
Q_UNUSED(stake);
Q_UNUSED(unconfirmedBalance);
return;
int unit = model->getOptionsModel()->getDisplayUnit();
- ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balance));
+ ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, total - watchOnly));
}
void SendCoinsDialog::updateDisplayUnit()
if(model && model->getOptionsModel())
{
// Update labelBalance with the current balance and the current unit
- ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), model->getBalance()));
+ qint64 total=0, watchOnly=0;
+ model->getBalance(total, watchOnly);
+ ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), total - watchOnly));
}
}
void accept();
SendCoinsEntry *addEntry();
void updateRemoveEnabled();
- void setBalance(qint64 balance, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance);
+ void setBalance(qint64 total, qint64 watchOnly, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance);
void on_addressBookButton_clicked();
void on_pasteButton_clicked();
strHTML += "<html><font face='verdana, arial, helvetica, sans-serif'>";
int64 nTime = wtx.GetTxTime();
- int64 nCredit = wtx.GetCredit();
+ int64 nCredit = wtx.GetCredit(false);
int64 nDebit = wtx.GetDebit();
int64 nNet = nCredit - nDebit;
//
int64 nUnmatured = 0;
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
- nUnmatured += wallet->GetCredit(txout);
+ nUnmatured += wallet->GetCredit(txout, false);
strHTML += "<b>" + tr("Credit") + ":</b> ";
if (wtx.IsInMainChain())
strHTML += BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nUnmatured)+ " (" + tr("matures in %n more block(s)", "", wtx.GetBlocksToMaturity()) + ")";
strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, -wallet->GetDebit(txin)) + "<br>";
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
if (wallet->IsMine(txout))
- strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, wallet->GetCredit(txout)) + "<br>";
+ strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, wallet->GetCredit(txout, false)) + "<br>";
}
}
strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, -wallet->GetDebit(txin)) + "<br>";
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
if(wallet->IsMine(txout))
- strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, wallet->GetCredit(txout)) + "<br>";
+ strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, wallet->GetCredit(txout, false)) + "<br>";
strHTML += "<br><b>" + tr("Transaction") + ":</b><br>";
strHTML += GUIUtil::HtmlEscape(wtx.ToString(), true);
{
QList<TransactionRecord> parts;
int64 nTime = wtx.GetTxTime();
- int64 nCredit = wtx.GetCredit(true);
+ int64 nCredit = wtx.GetCredit(false,true);
int64 nDebit = wtx.GetDebit();
int64 nNet = nCredit - nDebit;
uint256 hash = wtx.GetHash(), hashPrev = 0;
// For generated transactions, determine maturity
if(type == TransactionRecord::Generated)
{
- int64 nCredit = wtx.GetCredit(true);
+ int64 nCredit = wtx.GetCredit(false,true);
if (nCredit == 0)
{
status.maturity = TransactionStatus::Immature;
return wallet->GetBalance();
}
+void WalletModel::getBalance(qint64 &nTotal, qint64 &nWatchOnly) const
+{
+ wallet->GetBalance(nTotal, nWatchOnly);
+}
+
qint64 WalletModel::getUnconfirmedBalance() const
{
return wallet->GetUnconfirmedBalance();
void WalletModel::checkBalanceChanged()
{
- qint64 newBalance = getBalance();
+ qint64 newBalanceTotal=0, newBalanceWatchOnly=0;
+ getBalance(newBalanceTotal, newBalanceWatchOnly);
+
qint64 newStake = getStake();
qint64 newUnconfirmedBalance = getUnconfirmedBalance();
qint64 newImmatureBalance = getImmatureBalance();
- if(cachedBalance != newBalance || cachedStake != newStake || cachedUnconfirmedBalance != newUnconfirmedBalance || cachedImmatureBalance != newImmatureBalance)
+ if(cachedBalance != newBalanceTotal || cachedStake != newStake || cachedUnconfirmedBalance != newUnconfirmedBalance || cachedImmatureBalance != newImmatureBalance)
{
- cachedBalance = newBalance;
+ cachedBalance = newBalanceTotal;
cachedStake = newStake;
cachedUnconfirmedBalance = newUnconfirmedBalance;
cachedImmatureBalance = newImmatureBalance;
- emit balanceChanged(newBalance, newStake, newUnconfirmedBalance, newImmatureBalance);
+ emit balanceChanged(newBalanceTotal, newBalanceWatchOnly, newStake, newUnconfirmedBalance, newImmatureBalance);
}
}
TransactionTableModel *getTransactionTableModel();
qint64 getBalance() const;
+ void getBalance(qint64 &nTotal, qint64 &nWatchOnly) const;
qint64 getStake() const;
qint64 getUnconfirmedBalance() const;
qint64 getImmatureBalance() const;
signals:
// Signal that balance in wallet changed
- void balanceChanged(qint64 balance, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance);
+ void balanceChanged(qint64 total, qint64 watchOnly, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance);
// Number of transactions in wallet changed
void numTransactionsChanged(int count);
proxyType proxy;
GetProxy(NET_IPV4, proxy);
+ int64 nTotal = 0, nWatchOnly = 0;
+ pwalletMain->GetBalance(nTotal, nWatchOnly);
+
Object obj, diff;
obj.push_back(Pair("version", FormatFullVersion()));
obj.push_back(Pair("protocolversion",(int)PROTOCOL_VERSION));
obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
- obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
+ obj.push_back(Pair("balance", ValueFromAmount(nTotal)));
+ obj.push_back(Pair("unspendable", ValueFromAmount(nWatchOnly)));
obj.push_back(Pair("newmint", ValueFromAmount(pwalletMain->GetNewMint())));
obj.push_back(Pair("stake", ValueFromAmount(pwalletMain->GetStake())));
obj.push_back(Pair("blocks", (int)nBestHeight));
bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired);
if (!fCreated)
{
- if (totalAmount + nFeeRequired > pwalletMain->GetBalance())
+ int64 nTotal = 0, nWatchOnly = 0;
+ pwalletMain->GetBalance(nTotal, nWatchOnly);
+
+ if (totalAmount + nFeeRequired > nTotal - nWatchOnly)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds");
throw JSONRPCError(RPC_WALLET_ERROR, "Transaction creation failed");
}
TxToJSON(wtx, 0, entry);
- int64 nCredit = wtx.GetCredit();
+ int64 nCredit = wtx.GetCredit(false);
int64 nDebit = wtx.GetDebit();
int64 nNet = nCredit - nDebit;
int64 nFee = (wtx.IsFromMe() ? wtx.GetValueOut() - nDebit : 0);
printf("WalletUpdateSpent: bad wtx %s\n", wtx.GetHash().ToString().c_str());
else if (!wtx.IsSpent(txin.prevout.n) && IsMine(wtx.vout[txin.prevout.n]))
{
- printf("WalletUpdateSpent found spent coin %snvc %s\n", FormatMoney(wtx.GetCredit()).c_str(), wtx.GetHash().ToString().c_str());
+ printf("WalletUpdateSpent found spent coin %snvc %s\n", FormatMoney(wtx.GetCredit(false)).c_str(), wtx.GetHash().ToString().c_str());
wtx.MarkSpent(txin.prevout.n);
wtx.WriteToDisk();
NotifyTransactionChanged(this, txin.prevout.hash, CT_UPDATED);
if (GetBlocksToMaturity() > 0)
nGeneratedImmature = pwallet->GetCredit(*this);
else
- nGeneratedMature = GetCredit();
+ nGeneratedMature = GetCredit(false);
return;
}
}
if (fUpdated)
{
- printf("ReacceptWalletTransactions found spent coin %snvc %s\n", FormatMoney(wtx.GetCredit()).c_str(), wtx.GetHash().ToString().c_str());
+ printf("ReacceptWalletTransactions found spent coin %snvc %s\n", FormatMoney(wtx.GetCredit(false)).c_str(), wtx.GetHash().ToString().c_str());
wtx.MarkDirty();
wtx.WriteToDisk();
}
{
const CWalletTx* pcoin = &(*it).second;
if (pcoin->IsTrusted())
- nTotal += pcoin->GetAvailableCredit();
+ nTotal += pcoin->GetAvailableCredit(false);
}
}
return nTotal;
}
+void CWallet::GetBalance(int64 &nTotal, int64 &nWatchOnly) const
+{
+ {
+ LOCK(cs_wallet);
+ for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
+ {
+ const CWalletTx* pcoin = &(*it).second;
+ if (pcoin->IsTrusted()) {
+ nWatchOnly += pcoin->GetAvailableCredit(true);
+ nTotal += pcoin->GetAvailableCredit(false);
+ }
+ }
+ }
+}
+
int64 CWallet::GetUnconfirmedBalance() const
{
int64 nTotal = 0;
{
const CWalletTx* pcoin = &(*it).second;
if (!pcoin->IsFinal() || !pcoin->IsTrusted())
- nTotal += pcoin->GetAvailableCredit();
+ nTotal += pcoin->GetAvailableCredit(false);
}
}
return nTotal;
if (block.IsProofOfWork() && mapWallet.count(block.vtx[0].GetHash()))
{
CWalletTx& wtx = mapWallet[block.vtx[0].GetHash()];
- printf(" mine: %d %d %"PRI64d"", wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit());
+ printf(" mine: %d %d %"PRI64d"", wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit(false));
}
if (block.IsProofOfStake() && mapWallet.count(block.vtx[1].GetHash()))
{
CWalletTx& wtx = mapWallet[block.vtx[1].GetHash()];
- printf(" stake: %d %d %"PRI64d"", wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit());
+ printf(" stake: %d %d %"PRI64d"", wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit(false));
}
}
void ReacceptWalletTransactions();
void ResendWalletTransactions();
int64 GetBalance() const;
+ void GetBalance(int64 &nTotal, int64 &nWatchOnly) const;
int64 GetUnconfirmedBalance() const;
int64 GetImmatureBalance() const;
int64 GetStake() const;
{
return ::IsMine(*this, txout.scriptPubKey);
}
- int64 GetCredit(const CTxOut& txout) const
+ int64 GetCredit(const CTxOut& txout, bool fWatchOnly=false) const
{
if (!MoneyRange(txout.nValue))
throw std::runtime_error("CWallet::GetCredit() : value out of range");
- return (IsMine(txout) ? txout.nValue : 0);
+ isminetype ismine = IsMine(txout);
+ if (fWatchOnly && ismine != MINE_WATCH_ONLY)
+ return 0;
+ return (ismine != MINE_NO ? txout.nValue : 0);
}
bool IsChange(const CTxOut& txout) const;
int64 GetChange(const CTxOut& txout) const
}
return nDebit;
}
- int64 GetCredit(const CTransaction& tx) const
+ int64 GetCredit(const CTransaction& tx, bool fWatchOnly=true) const
{
int64 nCredit = 0;
BOOST_FOREACH(const CTxOut& txout, tx.vout)
{
- nCredit += GetCredit(txout);
+ if (!fWatchOnly || (fWatchOnly && IsMine(txout) == MINE_WATCH_ONLY))
+ nCredit += GetCredit(txout);
+
if (!MoneyRange(nCredit))
throw std::runtime_error("CWallet::GetCredit() : value out of range");
}
// memory only
mutable bool fDebitCached;
mutable bool fCreditCached;
+ mutable bool fWatchOnlyCreditCached;
mutable bool fAvailableCreditCached;
+ mutable bool fAvailableWatchOnlyCreditCached;
mutable bool fChangeCached;
mutable int64 nDebitCached;
mutable int64 nCreditCached;
+ mutable int64 nWatchOnlyCreditCached;
mutable int64 nAvailableCreditCached;
+ mutable int64 nAvailableWatchOnlyCreditCached;
mutable int64 nChangeCached;
CWalletTx()
vfSpent.clear();
fDebitCached = false;
fCreditCached = false;
+ fWatchOnlyCreditCached = false;
fAvailableCreditCached = false;
+ fAvailableWatchOnlyCreditCached = false;
fChangeCached = false;
nDebitCached = 0;
nCreditCached = 0;
+ nWatchOnlyCreditCached = 0;
nAvailableCreditCached = 0;
+ nAvailableWatchOnlyCreditCached = 0;
nChangeCached = 0;
nOrderPos = -1;
}
{
vfSpent[i] = true;
fReturn = true;
- fAvailableCreditCached = false;
+ fAvailableCreditCached = fAvailableWatchOnlyCreditCached = false;
}
}
return fReturn;
void MarkDirty()
{
fCreditCached = false;
- fAvailableCreditCached = false;
+ fAvailableCreditCached = fAvailableWatchOnlyCreditCached = false;
fDebitCached = false;
fChangeCached = false;
}
if (!vfSpent[nOut])
{
vfSpent[nOut] = true;
- fAvailableCreditCached = false;
+ fAvailableCreditCached = fAvailableWatchOnlyCreditCached = false;
}
}
if (vfSpent[nOut])
{
vfSpent[nOut] = false;
- fAvailableCreditCached = false;
+ fAvailableCreditCached = fAvailableWatchOnlyCreditCached = false;
}
}
return nDebitCached;
}
- int64 GetCredit(bool fUseCache=true) const
+ int64 GetCredit(bool fWatchOnly, bool fUseCache=true) const
{
// Must wait until coinbase is safely deep enough in the chain before valuing it
if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0)
return 0;
// GetBalance can assume transactions in mapWallet won't change
- if (fUseCache && fCreditCached)
- return nCreditCached;
+ if (fUseCache) {
+ if (fWatchOnly && fCreditCached)
+ return nWatchOnlyCreditCached;
+ if (fCreditCached)
+ return nCreditCached;
+ }
+
+ if (fWatchOnly) {
+ nWatchOnlyCreditCached = pwallet->GetCredit(*this, true);
+ fWatchOnlyCreditCached = true;
+
+ return nWatchOnlyCreditCached;
+ }
+
nCreditCached = pwallet->GetCredit(*this);
fCreditCached = true;
+
return nCreditCached;
}
- int64 GetAvailableCredit(bool fUseCache=true) const
+ int64 GetAvailableCredit(bool fWatchOnly, bool fUseCache=true) const
{
// Must wait until coinbase is safely deep enough in the chain before valuing it
if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0)
return 0;
- if (fUseCache && fAvailableCreditCached)
- return nAvailableCreditCached;
+ if (fUseCache) {
+ if (fWatchOnly && fAvailableWatchOnlyCreditCached)
+ return nAvailableWatchOnlyCreditCached;
+
+ if (fAvailableCreditCached)
+ return nAvailableCreditCached;
+ }
int64 nCredit = 0;
for (unsigned int i = 0; i < vout.size(); i++)
if (!IsSpent(i))
{
const CTxOut &txout = vout[i];
- nCredit += pwallet->GetCredit(txout);
+ nCredit += pwallet->GetCredit(txout, fWatchOnly);
if (!MoneyRange(nCredit))
throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range");
}
}
- nAvailableCreditCached = nCredit;
- fAvailableCreditCached = true;
+ if (fWatchOnly) {
+ nAvailableWatchOnlyCreditCached = nCredit;
+ fAvailableWatchOnlyCreditCached = true;
+ } else {
+ nAvailableCreditCached = nCredit;
+ fAvailableCreditCached = true;
+ }
return nCredit;
}