FEATURE_WALLETCRYPT = 40000, // wallet encryption
FEATURE_COMPRPUBKEY = 60000, // compressed public keys
-
FEATURE_LATEST = 60000
};
bool LoadCScript(const CScript& redeemScript) { return CCryptoKeyStore::AddCScript(redeemScript); }
// Adds a watch-only address to the store, and saves it to disk.
- bool AddWatchOnly(const CTxDestination &dest);
+ bool AddWatchOnly(const CScript &dest);
// Adds a watch-only address to the store, without saving it to disk (used by LoadWallet)
- bool LoadWatchOnly(const CTxDestination &dest);
+ bool LoadWatchOnly(const CScript &dest);
bool Unlock(const SecureString& strWalletPassphrase);
bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
void ReacceptWalletTransactions();
void ResendWalletTransactions();
int64 GetBalance() const;
+ int64 GetBalanceWatchOnly() const;
int64 GetUnconfirmedBalance() const;
int64 GetImmatureBalance() const;
int64 GetStake() 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);
+ return (ismine != MINE_NO ? txout.nValue : 0);
+ }
+ int64 GetCreditWatchOnly(const CTxOut& txout) const
+ {
+ if (!MoneyRange(txout.nValue))
+ throw std::runtime_error("CWallet::GetCreditWatchOnly() : value out of range");
+ isminetype ismine = IsMine(txout);
+ if (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 nCredit;
}
+ int64 GetCreditWatchOnly(const CTransaction& tx) const
+ {
+ int64 nCredit = 0;
+ BOOST_FOREACH(const CTxOut& txout, tx.vout)
+ {
+ nCredit += GetCreditWatchOnly(txout);
+ if (!MoneyRange(nCredit))
+ throw std::runtime_error("CWallet::GetCredit() : value out of range");
+ }
+ return nCredit;
+ }
int64 GetChange(const CTransaction& tx) const
{
int64 nChange = 0;
// 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 0;
// GetBalance can assume transactions in mapWallet won't change
- if (fUseCache && fCreditCached)
- return nCreditCached;
+ if (fUseCache) {
+ if (fCreditCached)
+ return nCreditCached;
+ }
+
nCreditCached = pwallet->GetCredit(*this);
fCreditCached = true;
+
return nCreditCached;
}
if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0)
return 0;
- if (fUseCache && fAvailableCreditCached)
- return nAvailableCreditCached;
+ if (fUseCache) {
+ if (fAvailableCreditCached)
+ return nAvailableCreditCached;
+ }
int64 nCredit = 0;
for (unsigned int i = 0; i < vout.size(); i++)
nAvailableCreditCached = nCredit;
fAvailableCreditCached = true;
+
+ return nCredit;
+ }
+
+ int64 GetCreditWatchOnly(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) {
+ if (fWatchOnlyCreditCached)
+ return nWatchOnlyCreditCached;
+ }
+
+ nWatchOnlyCreditCached = pwallet->GetCreditWatchOnly(*this);
+ fWatchOnlyCreditCached = true;
+
+ return nWatchOnlyCreditCached;
+ }
+
+ int64 GetAvailableCreditWatchOnly(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) {
+ if (fAvailableWatchOnlyCreditCached)
+ return nAvailableWatchOnlyCreditCached;
+ }
+
+ int64 nCredit = 0;
+ for (unsigned int i = 0; i < vout.size(); i++)
+ {
+ if (!IsSpent(i))
+ {
+ const CTxOut &txout = vout[i];
+ nCredit += pwallet->GetCreditWatchOnly(txout);
+ if (!MoneyRange(nCredit))
+ throw std::runtime_error("CWalletTx::GetAvailableCreditWatchOnly() : value out of range");
+ }
+ }
+
+ nAvailableWatchOnlyCreditCached = nCredit;
+ fAvailableWatchOnlyCreditCached = true;
+
return nCredit;
}