From 9b0369c773c1d350a05435d8d3ec4e954828fb82 Mon Sep 17 00:00:00 2001 From: Chris Moore Date: Mon, 27 Feb 2012 04:19:32 -0800 Subject: 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. --- src/wallet.h | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src/wallet.h') 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 >& setCoinsRet, int64& nValueRet) const; + void AvailableCoins(std::vector& vCoins) const; bool SelectCoins(int64 nTargetValue, std::set >& 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 vCoins, std::set >& 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 { -- cgit v1.2.3