diff options
author | Brandon Dahler <brandon.dahler@gmail.com> | 2013-04-13 00:13:08 -0500 |
---|---|---|
committer | Brandon Dahler <brandon.dahler@gmail.com> | 2013-11-10 09:36:28 -0600 |
commit | 51ed9ec971614aebdbfbd9527aba365dd0afd437 (patch) | |
tree | d2f910390e55aef857023812fbdaefdd66cd99ff /src/wallet.h | |
parent | 7c4c207be8420d394a5abc4368d1bb69ad4f8067 (diff) |
Cleanup code using forward declarations.
Use misc methods of avoiding unnecesary header includes.
Replace int typedefs with int##_t from stdint.h.
Replace PRI64[xdu] with PRI[xdu]64 from inttypes.h.
Normalize QT_VERSION ifs where possible.
Resolve some indirect dependencies as direct ones.
Remove extern declarations from .cpp files.
Diffstat (limited to 'src/wallet.h')
-rw-r--r-- | src/wallet.h | 152 |
1 files changed, 78 insertions, 74 deletions
diff --git a/src/wallet.h b/src/wallet.h index 21510f8c39..5c38d7a1a0 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -5,25 +5,29 @@ #ifndef BITCOIN_WALLET_H #define BITCOIN_WALLET_H -#include "walletdb.h" - -#include <string> -#include <vector> - -#include <stdlib.h> - -#include "main.h" +#include "core.h" +#include "crypter.h" #include "key.h" #include "keystore.h" -#include "script.h" +#include "main.h" #include "ui_interface.h" #include "util.h" +#include "walletdb.h" + +#include <algorithm> +#include <map> +#include <set> +#include <stdexcept> +#include <stdint.h> +#include <string> +#include <utility> +#include <vector> class CAccountingEntry; -class CWalletTx; -class CReserveKey; class COutput; -class CWalletDB; +class CReserveKey; +class CScript; +class CWalletTx; /** (client) version numbers for particular wallet features */ enum WalletFeature @@ -41,7 +45,7 @@ enum WalletFeature class CKeyPool { public: - int64 nTime; + int64_t nTime; CPubKey vchPubKey; CKeyPool() @@ -83,7 +87,7 @@ public: class CWallet : public CCryptoKeyStore, public CWalletInterface { private: - bool SelectCoins(int64 nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet) const; + bool SelectCoins(int64_t nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const; CWalletDB *pwalletdbEncryption; @@ -93,8 +97,8 @@ private: // the maximum wallet format version: memory-only variable that specifies to what version this wallet may be upgraded int nWalletMaxVersion; - int64 nNextResend; - int64 nLastResend; + int64_t nNextResend; + int64_t nLastResend; public: mutable CCriticalSection cs_wallet; @@ -102,7 +106,7 @@ public: bool fFileBacked; std::string strWalletFile; - std::set<int64> setKeyPool; + std::set<int64_t> setKeyPool; std::map<CKeyID, CKeyMetadata> mapKeyMetadata; typedef std::map<unsigned int, CMasterKey> MasterKeyMap; @@ -134,7 +138,7 @@ public: } std::map<uint256, CWalletTx> mapWallet; - int64 nOrderPosNext; + int64_t nOrderPosNext; std::map<uint256, int> mapRequestCount; std::map<CTxDestination, CAddressBookData> mapAddressBook; @@ -143,13 +147,13 @@ public: std::set<COutPoint> setLockedCoins; - int64 nTimeFirstKey; + int64_t nTimeFirstKey; // check whether we are allowed to upgrade (or already support) to the named feature bool CanSupportFeature(enum WalletFeature wf) { return nWalletMaxVersion >= wf; } void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed=true) const; - bool SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet) 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 IsLockedCoin(uint256 hash, unsigned int n) const; void LockCoin(COutPoint& output); void UnlockCoin(COutPoint& output); @@ -179,15 +183,15 @@ public: bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase); bool EncryptWallet(const SecureString& strWalletPassphrase); - void GetKeyBirthTimes(std::map<CKeyID, int64> &mapKeyBirth) const; + void GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const; /** Increment the next transaction order id @return next transaction order id */ - int64 IncOrderPosNext(CWalletDB *pwalletdb = NULL); + int64_t IncOrderPosNext(CWalletDB *pwalletdb = NULL); typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair; - typedef std::multimap<int64, TxPair > TxItems; + typedef std::multimap<int64_t, TxPair > TxItems; /** Get the wallet's activity log @return multimap of ordered transactions and accounting entries @@ -204,46 +208,46 @@ public: int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false); void ReacceptWalletTransactions(); void ResendWalletTransactions(); - int64 GetBalance() const; - int64 GetUnconfirmedBalance() const; - int64 GetImmatureBalance() const; - bool CreateTransaction(const std::vector<std::pair<CScript, int64> >& vecSend, - CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason); - bool CreateTransaction(CScript scriptPubKey, int64 nValue, - CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason); + int64_t GetBalance() const; + int64_t GetUnconfirmedBalance() const; + int64_t GetImmatureBalance() const; + bool CreateTransaction(const std::vector<std::pair<CScript, int64_t> >& vecSend, + CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason); + bool CreateTransaction(CScript scriptPubKey, int64_t nValue, + CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason); bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey); - std::string SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false); - std::string SendMoneyToDestination(const CTxDestination &address, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false); + std::string SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, bool fAskFee=false); + std::string SendMoneyToDestination(const CTxDestination &address, int64_t nValue, CWalletTx& wtxNew, bool fAskFee=false); bool NewKeyPool(); bool TopUpKeyPool(unsigned int kpSize = 0); - int64 AddReserveKey(const CKeyPool& keypool); - void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool); - void KeepKey(int64 nIndex); - void ReturnKey(int64 nIndex); + int64_t AddReserveKey(const CKeyPool& keypool); + void ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool); + void KeepKey(int64_t nIndex); + void ReturnKey(int64_t nIndex); bool GetKeyFromPool(CPubKey &key); - int64 GetOldestKeyPoolTime(); + int64_t GetOldestKeyPoolTime(); void GetAllReserveKeys(std::set<CKeyID>& setAddress) const; std::set< std::set<CTxDestination> > GetAddressGroupings(); - std::map<CTxDestination, int64> GetAddressBalances(); + std::map<CTxDestination, int64_t> GetAddressBalances(); std::set<CTxDestination> GetAccountAddresses(std::string strAccount) const; bool IsMine(const CTxIn& txin) const; - int64 GetDebit(const CTxIn& txin) const; + int64_t GetDebit(const CTxIn& txin) const; bool IsMine(const CTxOut& txout) const { return ::IsMine(*this, txout.scriptPubKey); } - int64 GetCredit(const CTxOut& txout) const + int64_t GetCredit(const CTxOut& txout) const { if (!MoneyRange(txout.nValue)) throw std::runtime_error("CWallet::GetCredit() : value out of range"); return (IsMine(txout) ? txout.nValue : 0); } bool IsChange(const CTxOut& txout) const; - int64 GetChange(const CTxOut& txout) const + int64_t GetChange(const CTxOut& txout) const { if (!MoneyRange(txout.nValue)) throw std::runtime_error("CWallet::GetChange() : value out of range"); @@ -260,9 +264,9 @@ public: { return (GetDebit(tx) > 0); } - int64 GetDebit(const CTransaction& tx) const + int64_t GetDebit(const CTransaction& tx) const { - int64 nDebit = 0; + int64_t nDebit = 0; BOOST_FOREACH(const CTxIn& txin, tx.vin) { nDebit += GetDebit(txin); @@ -271,9 +275,9 @@ public: } return nDebit; } - int64 GetCredit(const CTransaction& tx) const + int64_t GetCredit(const CTransaction& tx) const { - int64 nCredit = 0; + int64_t nCredit = 0; BOOST_FOREACH(const CTxOut& txout, tx.vout) { nCredit += GetCredit(txout); @@ -282,9 +286,9 @@ public: } return nCredit; } - int64 GetChange(const CTransaction& tx) const + int64_t GetChange(const CTransaction& tx) const { - int64 nChange = 0; + int64_t nChange = 0; BOOST_FOREACH(const CTxOut& txout, tx.vout) { nChange += GetChange(txout); @@ -349,7 +353,7 @@ class CReserveKey { protected: CWallet* pwallet; - int64 nIndex; + int64_t nIndex; CPubKey vchPubKey; public: CReserveKey(CWallet* pwalletIn) @@ -372,7 +376,7 @@ public: typedef std::map<std::string, std::string> mapValue_t; -static void ReadOrderPos(int64& nOrderPos, mapValue_t& mapValue) +static void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue) { if (!mapValue.count("n")) { @@ -383,7 +387,7 @@ static void ReadOrderPos(int64& nOrderPos, mapValue_t& mapValue) } -static void WriteOrderPos(const int64& nOrderPos, mapValue_t& mapValue) +static void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue) { if (nOrderPos == -1) return; @@ -409,7 +413,7 @@ public: char fFromMe; std::string strFromAccount; std::vector<char> vfSpent; // which outputs are already spent - int64 nOrderPos; // position in ordered transaction list + int64_t nOrderPos; // position in ordered transaction list // memory only mutable bool fDebitCached; @@ -417,11 +421,11 @@ public: mutable bool fImmatureCreditCached; mutable bool fAvailableCreditCached; mutable bool fChangeCached; - mutable int64 nDebitCached; - mutable int64 nCreditCached; - mutable int64 nImmatureCreditCached; - mutable int64 nAvailableCreditCached; - mutable int64 nChangeCached; + mutable int64_t nDebitCached; + mutable int64_t nCreditCached; + mutable int64_t nImmatureCreditCached; + mutable int64_t nAvailableCreditCached; + mutable int64_t nChangeCached; CWalletTx() { @@ -581,7 +585,7 @@ public: return (!!vfSpent[nOut]); } - int64 GetDebit() const + int64_t GetDebit() const { if (vin.empty()) return 0; @@ -592,7 +596,7 @@ public: return nDebitCached; } - int64 GetCredit(bool fUseCache=true) const + int64_t GetCredit(bool fUseCache=true) const { // Must wait until coinbase is safely deep enough in the chain before valuing it if (IsCoinBase() && GetBlocksToMaturity() > 0) @@ -606,7 +610,7 @@ public: return nCreditCached; } - int64 GetImmatureCredit(bool fUseCache=true) const + int64_t GetImmatureCredit(bool fUseCache=true) const { if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) { @@ -620,7 +624,7 @@ public: return 0; } - int64 GetAvailableCredit(bool fUseCache=true) const + int64_t GetAvailableCredit(bool fUseCache=true) const { // Must wait until coinbase is safely deep enough in the chain before valuing it if (IsCoinBase() && GetBlocksToMaturity() > 0) @@ -629,7 +633,7 @@ public: if (fUseCache && fAvailableCreditCached) return nAvailableCreditCached; - int64 nCredit = 0; + int64_t nCredit = 0; for (unsigned int i = 0; i < vout.size(); i++) { if (!IsSpent(i)) @@ -647,7 +651,7 @@ public: } - int64 GetChange() const + int64_t GetChange() const { if (fChangeCached) return nChangeCached; @@ -656,11 +660,11 @@ public: return nChangeCached; } - void GetAmounts(std::list<std::pair<CTxDestination, int64> >& listReceived, - std::list<std::pair<CTxDestination, int64> >& listSent, int64& nFee, std::string& strSentAccount) const; + void GetAmounts(std::list<std::pair<CTxDestination, int64_t> >& listReceived, + std::list<std::pair<CTxDestination, int64_t> >& listSent, int64_t& nFee, std::string& strSentAccount) const; - void GetAccountAmounts(const std::string& strAccount, int64& nReceived, - int64& nSent, int64& nFee) const; + void GetAccountAmounts(const std::string& strAccount, int64_t& nReceived, + int64_t& nSent, int64_t& nFee) const; bool IsFromMe() const { @@ -712,7 +716,7 @@ public: bool WriteToDisk(); - int64 GetTxTime() const; + int64_t GetTxTime() const; int GetRequestCount() const; void AddSupportingTransactions(); @@ -754,13 +758,13 @@ class CWalletKey { public: CPrivKey vchPrivKey; - int64 nTimeCreated; - int64 nTimeExpires; + int64_t nTimeCreated; + int64_t nTimeExpires; std::string strComment; //// todo: add something to note what created it (user, getnewaddress, change) //// maybe should have a map<string, string> property map - CWalletKey(int64 nExpires=0) + CWalletKey(int64_t nExpires=0) { nTimeCreated = (nExpires ? GetTime() : 0); nTimeExpires = nExpires; @@ -817,13 +821,13 @@ class CAccountingEntry { public: std::string strAccount; - int64 nCreditDebit; - int64 nTime; + int64_t nCreditDebit; + int64_t nTime; std::string strOtherAccount; std::string strComment; mapValue_t mapValue; - int64 nOrderPos; // position in ordered transaction list - uint64 nEntryNo; + int64_t nOrderPos; // position in ordered transaction list + uint64_t nEntryNo; CAccountingEntry() { |