aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet.h')
-rw-r--r--src/wallet.h142
1 files changed, 85 insertions, 57 deletions
diff --git a/src/wallet.h b/src/wallet.h
index 3461446b8b..fa8a94dfc1 100644
--- a/src/wallet.h
+++ b/src/wallet.h
@@ -30,9 +30,9 @@ extern unsigned int nTxConfirmTarget;
extern bool bSpendZeroConfChange;
// -paytxfee default
-static const int64_t DEFAULT_TRANSACTION_FEE = 0;
+static const CAmount DEFAULT_TRANSACTION_FEE = 0;
// -paytxfee will warn if called with a higher fee than this amount (in satoshis) per KB
-static const int nHighTransactionFeeWarning = 0.01 * COIN;
+static const CAmount nHighTransactionFeeWarning = 0.01 * COIN;
// Largest (in bytes) free transaction we're willing to create
static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000;
@@ -98,7 +98,7 @@ public:
class CWallet : public CCryptoKeyStore, public CWalletInterface
{
private:
- bool SelectCoins(int64_t nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet, const CCoinControl *coinControl = NULL) const;
+ bool SelectCoins(const CAmount& nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet, const CCoinControl *coinControl = NULL) const;
CWalletDB *pwalletdbEncryption;
@@ -143,6 +143,7 @@ public:
{
SetNull();
}
+
CWallet(std::string strWalletFileIn)
{
SetNull();
@@ -150,6 +151,13 @@ public:
strWalletFile = strWalletFileIn;
fFileBacked = true;
}
+
+ ~CWallet()
+ {
+ delete pwalletdbEncryption;
+ pwalletdbEncryption = NULL;
+ }
+
void SetNull()
{
nWalletVersion = FEATURE_BASE;
@@ -182,7 +190,7 @@ public:
bool CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; }
void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL) const;
- bool SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfTheirs, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const;
+ bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet) const;
bool IsSpent(const uint256& hash, unsigned int n) const;
@@ -222,6 +230,7 @@ public:
// Adds a watch-only address to the store, and saves it to disk.
bool AddWatchOnly(const CScript &dest);
+ bool RemoveWatchOnly(const CScript &dest);
// Adds a watch-only address to the store, without saving it to disk (used by LoadWallet)
bool LoadWatchOnly(const CScript &dest);
@@ -253,21 +262,21 @@ public:
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
void ReacceptWalletTransactions();
void ResendWalletTransactions();
- int64_t GetBalance() const;
- int64_t GetUnconfirmedBalance() const;
- int64_t GetImmatureBalance() const;
- int64_t GetWatchOnlyBalance() const;
- int64_t GetUnconfirmedWatchOnlyBalance() const;
- int64_t GetImmatureWatchOnlyBalance() const;
- bool CreateTransaction(const std::vector<std::pair<CScript, int64_t> >& vecSend,
- CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL);
- bool CreateTransaction(CScript scriptPubKey, int64_t nValue,
- CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL);
+ CAmount GetBalance() const;
+ CAmount GetUnconfirmedBalance() const;
+ CAmount GetImmatureBalance() const;
+ CAmount GetWatchOnlyBalance() const;
+ CAmount GetUnconfirmedWatchOnlyBalance() const;
+ CAmount GetImmatureWatchOnlyBalance() const;
+ bool CreateTransaction(const std::vector<std::pair<CScript, CAmount> >& vecSend,
+ CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL);
+ bool CreateTransaction(CScript scriptPubKey, const CAmount& nValue,
+ CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL);
bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey);
- std::string SendMoney(const CTxDestination &address, int64_t nValue, CWalletTx& wtxNew);
+ std::string SendMoney(const CTxDestination &address, CAmount nValue, CWalletTx& wtxNew);
static CFeeRate minTxFee;
- static int64_t GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool);
+ static CAmount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool);
bool NewKeyPool();
bool TopUpKeyPool(unsigned int kpSize = 0);
@@ -279,24 +288,24 @@ public:
void GetAllReserveKeys(std::set<CKeyID>& setAddress) const;
std::set< std::set<CTxDestination> > GetAddressGroupings();
- std::map<CTxDestination, int64_t> GetAddressBalances();
+ std::map<CTxDestination, CAmount> GetAddressBalances();
std::set<CTxDestination> GetAccountAddresses(std::string strAccount) const;
isminetype IsMine(const CTxIn& txin) const;
- int64_t GetDebit(const CTxIn& txin, const isminefilter& filter) const;
+ CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const;
isminetype IsMine(const CTxOut& txout) const
{
return ::IsMine(*this, txout.scriptPubKey);
}
- int64_t GetCredit(const CTxOut& txout, const isminefilter& filter) const
+ CAmount GetCredit(const CTxOut& txout, const isminefilter& filter) const
{
if (!MoneyRange(txout.nValue))
throw std::runtime_error("CWallet::GetCredit() : value out of range");
return ((IsMine(txout) & filter) ? txout.nValue : 0);
}
bool IsChange(const CTxOut& txout) const;
- int64_t GetChange(const CTxOut& txout) const
+ CAmount GetChange(const CTxOut& txout) const
{
if (!MoneyRange(txout.nValue))
throw std::runtime_error("CWallet::GetChange() : value out of range");
@@ -313,9 +322,9 @@ public:
{
return (GetDebit(tx, ISMINE_ALL) > 0);
}
- int64_t GetDebit(const CTransaction& tx, const isminefilter& filter) const
+ CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const
{
- int64_t nDebit = 0;
+ CAmount nDebit = 0;
BOOST_FOREACH(const CTxIn& txin, tx.vin)
{
nDebit += GetDebit(txin, filter);
@@ -324,9 +333,9 @@ public:
}
return nDebit;
}
- int64_t GetCredit(const CTransaction& tx, const isminefilter& filter) const
+ CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const
{
- int64_t nCredit = 0;
+ CAmount nCredit = 0;
BOOST_FOREACH(const CTxOut& txout, tx.vout)
{
nCredit += GetCredit(txout, filter);
@@ -335,9 +344,9 @@ public:
}
return nCredit;
}
- int64_t GetChange(const CTransaction& tx) const
+ CAmount GetChange(const CTransaction& tx) const
{
- int64_t nChange = 0;
+ CAmount nChange = 0;
BOOST_FOREACH(const CTxOut& txout, tx.vout)
{
nChange += GetChange(txout);
@@ -457,7 +466,7 @@ static void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue)
struct COutputEntry
{
CTxDestination destination;
- int64_t amount;
+ CAmount amount;
int vout;
};
@@ -504,7 +513,7 @@ public:
READWRITE(nIndex);
}
- int SetMerkleBranch(const CBlock* pblock=NULL);
+ int SetMerkleBranch(const CBlock& block);
// Return depth of transaction in blockchain:
// -1 : not in blockchain, and not in memory pool (conflicted transaction)
@@ -545,15 +554,15 @@ public:
mutable bool fImmatureWatchCreditCached;
mutable bool fAvailableWatchCreditCached;
mutable bool fChangeCached;
- mutable int64_t nDebitCached;
- mutable int64_t nCreditCached;
- mutable int64_t nImmatureCreditCached;
- mutable int64_t nAvailableCreditCached;
- mutable int64_t nWatchDebitCached;
- mutable int64_t nWatchCreditCached;
- mutable int64_t nImmatureWatchCreditCached;
- mutable int64_t nAvailableWatchCreditCached;
- mutable int64_t nChangeCached;
+ mutable CAmount nDebitCached;
+ mutable CAmount nCreditCached;
+ mutable CAmount nImmatureCreditCached;
+ mutable CAmount nAvailableCreditCached;
+ mutable CAmount nWatchDebitCached;
+ mutable CAmount nWatchCreditCached;
+ mutable CAmount nImmatureWatchCreditCached;
+ mutable CAmount nAvailableWatchCreditCached;
+ mutable CAmount nChangeCached;
CWalletTx()
{
@@ -670,12 +679,12 @@ public:
}
// filter decides which addresses will count towards the debit
- int64_t GetDebit(const isminefilter& filter) const
+ CAmount GetDebit(const isminefilter& filter) const
{
if (vin.empty())
return 0;
- int64_t debit = 0;
+ CAmount debit = 0;
if(filter & ISMINE_SPENDABLE)
{
if (fDebitCached)
@@ -701,21 +710,40 @@ public:
return debit;
}
- int64_t GetCredit(bool fUseCache=true) const
+ CAmount GetCredit(const isminefilter& filter) const
{
// Must wait until coinbase is safely deep enough in the chain before valuing it
if (IsCoinBase() && GetBlocksToMaturity() > 0)
return 0;
- // GetBalance can assume transactions in mapWallet won't change
- if (fUseCache && fCreditCached)
- return nCreditCached;
- nCreditCached = pwallet->GetCredit(*this, ISMINE_ALL);
- fCreditCached = true;
- return nCreditCached;
+ int64_t credit = 0;
+ if (filter & ISMINE_SPENDABLE)
+ {
+ // GetBalance can assume transactions in mapWallet won't change
+ if (fCreditCached)
+ credit += nCreditCached;
+ else
+ {
+ nCreditCached = pwallet->GetCredit(*this, ISMINE_SPENDABLE);
+ fCreditCached = true;
+ credit += nCreditCached;
+ }
+ }
+ if (filter & ISMINE_WATCH_ONLY)
+ {
+ if (fWatchCreditCached)
+ credit += nWatchCreditCached;
+ else
+ {
+ nWatchCreditCached = pwallet->GetCredit(*this, ISMINE_WATCH_ONLY);
+ fWatchCreditCached = true;
+ credit += nWatchCreditCached;
+ }
+ }
+ return credit;
}
- int64_t GetImmatureCredit(bool fUseCache=true) const
+ CAmount GetImmatureCredit(bool fUseCache=true) const
{
if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
{
@@ -729,7 +757,7 @@ public:
return 0;
}
- int64_t GetAvailableCredit(bool fUseCache=true) const
+ CAmount GetAvailableCredit(bool fUseCache=true) const
{
if (pwallet == 0)
return 0;
@@ -741,7 +769,7 @@ public:
if (fUseCache && fAvailableCreditCached)
return nAvailableCreditCached;
- int64_t nCredit = 0;
+ CAmount nCredit = 0;
uint256 hashTx = GetHash();
for (unsigned int i = 0; i < vout.size(); i++)
{
@@ -759,7 +787,7 @@ public:
return nCredit;
}
- int64_t GetImmatureWatchOnlyCredit(const bool& fUseCache=true) const
+ CAmount GetImmatureWatchOnlyCredit(const bool& fUseCache=true) const
{
if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
{
@@ -773,7 +801,7 @@ public:
return 0;
}
- int64_t GetAvailableWatchOnlyCredit(const bool& fUseCache=true) const
+ CAmount GetAvailableWatchOnlyCredit(const bool& fUseCache=true) const
{
if (pwallet == 0)
return 0;
@@ -785,7 +813,7 @@ public:
if (fUseCache && fAvailableWatchCreditCached)
return nAvailableWatchCreditCached;
- int64_t nCredit = 0;
+ CAmount nCredit = 0;
for (unsigned int i = 0; i < vout.size(); i++)
{
if (!pwallet->IsSpent(GetHash(), i))
@@ -802,7 +830,7 @@ public:
return nCredit;
}
- int64_t GetChange() const
+ CAmount GetChange() const
{
if (fChangeCached)
return nChangeCached;
@@ -812,10 +840,10 @@ public:
}
void GetAmounts(std::list<COutputEntry>& listReceived,
- std::list<COutputEntry>& listSent, int64_t& nFee, std::string& strSentAccount, const isminefilter& filter) const;
+ std::list<COutputEntry>& listSent, CAmount& nFee, std::string& strSentAccount, const isminefilter& filter) const;
- void GetAccountAmounts(const std::string& strAccount, int64_t& nReceived,
- int64_t& nSent, int64_t& nFee, const isminefilter& filter) const;
+ void GetAccountAmounts(const std::string& strAccount, CAmount& nReceived,
+ CAmount& nSent, CAmount& nFee, const isminefilter& filter) const;
bool IsFromMe(const isminefilter& filter) const
{
@@ -949,7 +977,7 @@ class CAccountingEntry
{
public:
std::string strAccount;
- int64_t nCreditDebit;
+ CAmount nCreditDebit;
int64_t nTime;
std::string strOtherAccount;
std::string strComment;