diff options
author | Chris Moore <dooglus@gmail.com> | 2012-02-27 04:19:32 -0800 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2012-06-04 16:36:34 +0000 |
commit | 9b0369c773c1d350a05435d8d3ec4e954828fb82 (patch) | |
tree | 43b695e7dd82200c0bcd407b40613ee4501ac2eb /src/wallet.h | |
parent | 882ba0e7524b54be861b379366b5845a3978b256 (diff) | |
download | bitcoin-9b0369c773c1d350a05435d8d3ec4e954828fb82.tar.xz |
Refactor SelectCoinsMinConf() and add unit tests.
AvailableCoins() makes a vector of available outputs which is then passed to SelectCoinsMinConf(). This allows unit tests to test the coin selection algorithm without having the whole blockchain available.
Diffstat (limited to 'src/wallet.h')
-rw-r--r-- | src/wallet.h | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/wallet.h b/src/wallet.h index dfdb7b8257..b2e0e5260e 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -14,6 +14,7 @@ class CWalletTx; class CReserveKey; class CWalletDB; +class COutput; /** (client) version numbers for particular wallet features */ enum WalletFeature @@ -60,7 +61,7 @@ public: class CWallet : public CCryptoKeyStore { private: - bool SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet) const; + void AvailableCoins(std::vector<COutput>& vCoins) const; bool SelectCoins(int64 nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet) const; CWalletDB *pwalletdbEncryption; @@ -112,6 +113,8 @@ public: // check whether we are allowed to upgrade (or already support) to the named feature bool CanSupportFeature(enum WalletFeature wf) { return nWalletMaxVersion >= wf; } + bool SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet) const; + // keystore implementation // Generate a new key CPubKey GenerateNewKey(); @@ -602,6 +605,34 @@ public: }; + + +class COutput +{ +public: + const CWalletTx *tx; + int i; + int nDepth; + + COutput(const CWalletTx *txIn, int iIn, int nDepthIn) + { + tx = txIn; i = iIn; nDepth = nDepthIn; + } + + std::string ToString() const + { + return strprintf("COutput(%s, %d, %d) [%s]", tx->GetHash().ToString().substr(0,10).c_str(), i, nDepth, FormatMoney(tx->vout[i].nValue).c_str()); + } + + void print() const + { + printf("%s\n", ToString().c_str()); + } +}; + + + + /** Private key that includes an expiration date in case it never gets used. */ class CWalletKey { |