X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fwallet.cpp;h=f94240b03ab5a9bff4aad630a20cf9ea0b10bc68;hb=ef17ac0211ddd486127e1f94756fbb3fd704a9b4;hp=e72c13874e991689acfbeb301d187fb38d489007;hpb=4cdcc9880e8d3398b6009f067dfd96a8aa709724;p=novacoin.git diff --git a/src/wallet.cpp b/src/wallet.cpp index e72c138..f94240b 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -13,7 +13,7 @@ #include "coincontrol.h" #include #include - +#include #include "main.h" using namespace std; @@ -526,19 +526,6 @@ bool CWallet::DecryptWallet(const SecureString& strWalletPassphrase) return true; } -bool CWallet::GetPEM(const CKeyID &keyID, const std::string &fileName, const SecureString &strPassKey) const -{ - BIO *pemOut = BIO_new_file(fileName.c_str(), "w"); - if (pemOut == NULL) - return error("GetPEM() : failed to create file %s\n", fileName.c_str()); - CKey key; - if (!GetKey(keyID, key)) - return error("GetPEM() : failed to get key for address=%s\n", CBitcoinAddress(keyID).ToString().c_str()); - bool result = key.WritePEM(pemOut, strPassKey); - BIO_free(pemOut); - return result; -} - int64_t CWallet::IncOrderPosNext(CWalletDB *pwalletdb) { int64_t nRet = nOrderPosNext++; @@ -1829,7 +1816,9 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, unsigned int nSpendTime, vector > > vValue; int64_t nTotalLower = 0; - random_shuffle(vCoins.begin(), vCoins.end(), GetRandInt); + std::random_device rd; + std::mt19937 g(rd()); + shuffle(vCoins.begin(), vCoins.end(), g); BOOST_FOREACH(const COutput &output, vCoins) { @@ -1888,7 +1877,8 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, unsigned int nSpendTime, } // Solve subset sum by stochastic approximation - sort(vValue.rbegin(), vValue.rend(), CompareValueOnly()); + std::sort(vValue.begin(), vValue.end(), CompareValueOnly()); + std::reverse(vValue.begin(), vValue.end()); vector vfBest; int64_t nBest; @@ -2885,29 +2875,38 @@ set< set > CWallet::GetAddressGroupings() { CWalletTx *pcoin = &walletEntry.second; - if (pcoin->vin.size() > 0 && IsMine(pcoin->vin[0])) + if (pcoin->vin.size() > 0) { + bool any_mine = false; // group all input addresses with each other BOOST_FOREACH(CTxIn txin, pcoin->vin) { CBitcoinAddress address; + if(!IsMine(txin)) // If this input isn't mine, ignore it + continue; if(!ExtractAddress(*this, mapWallet[txin.prevout.hash].vout[txin.prevout.n].scriptPubKey, address)) continue; grouping.insert(address); + any_mine = true; } // group change with input addresses - BOOST_FOREACH(CTxOut txout, pcoin->vout) + if (any_mine) + { + BOOST_FOREACH(CTxOut txout, pcoin->vout) if (IsChange(txout)) { - CWalletTx tx = mapWallet[pcoin->vin[0].prevout.hash]; CBitcoinAddress txoutAddr; if(!ExtractAddress(*this, txout.scriptPubKey, txoutAddr)) continue; grouping.insert(txoutAddr); } - groupings.insert(grouping); - grouping.clear(); + } + if (!grouping.empty()) + { + groupings.insert(grouping); + grouping.clear(); + } } // group lone addrs by themselves