37 #include <boost/algorithm/string/replace.hpp> 38 #include <boost/filesystem.hpp> 39 #include <boost/thread.hpp> 73 const pair<
CAmount, pair<const CWalletTx*, unsigned int> >& t2)
const 75 return t1.first < t2.first;
81 return strprintf(
"COutput(%s, %d, %d) [%s]", tx->GetHash().ToString(), i, nDepth,
FormatMoney(tx->vout[i].nValue));
87 if(tx->vout[i].nValue == d)
return 10000;
88 if(tx->vout[i].nValue < 1*
COIN)
return 20000;
91 return -(tx->vout[i].nValue/
COIN);
97 std::map<uint256, CWalletTx>::const_iterator it = mapWallet.find(hash);
98 if (it == mapWallet.end())
100 return &(it->second);
111 int64_t nCreationTime =
GetTime();
117 DeriveNewChildKey(metadata, secret, nAccountIndex, fInternal);
130 mapKeyMetadata[pubkey.
GetID()] = metadata;
131 if (!nTimeFirstKey || nCreationTime < nTimeFirstKey)
132 nTimeFirstKey = nCreationTime;
134 if (!AddKeyPubKey(secret, pubkey))
135 throw std::runtime_error(std::string(__func__) +
": AddKey failed");
143 if (!GetHDChain(hdChainTmp)) {
144 throw std::runtime_error(std::string(__func__) +
": GetHDChain failed");
147 if (!DecryptHDChain(hdChainTmp))
148 throw std::runtime_error(std::string(__func__) +
": DecryptHDChainSeed failed");
151 throw std::runtime_error(std::string(__func__) +
": Wrong HD chain!");
154 if (!hdChainTmp.
GetAccount(nAccountIndex, acc))
155 throw std::runtime_error(std::string(__func__) +
": Wrong HD account!");
165 secretRet = childKey.
key;
171 mapKeyMetadata[pubkey.
GetID()] = metadata;
172 if (!nTimeFirstKey || metadata.
nCreateTime < nTimeFirstKey)
177 GetHDChain(hdChainCurrent);
186 if (!hdChainCurrent.
SetAccount(nAccountIndex, acc))
187 throw std::runtime_error(std::string(__func__) +
": SetAccount failed");
190 if (!SetCryptedHDChain(hdChainCurrent,
false))
191 throw std::runtime_error(std::string(__func__) +
": SetCryptedHDChain failed");
194 if (!SetHDChain(hdChainCurrent,
false))
195 throw std::runtime_error(std::string(__func__) +
": SetHDChain failed");
198 if (!AddHDPubKey(childKey.
Neuter(), fInternal))
199 throw std::runtime_error(std::string(__func__) +
": AddHDPubKey failed");
205 std::map<CKeyID, CHDPubKey>::const_iterator mi = mapHdPubKeys.find(address);
206 if (mi != mapHdPubKeys.end())
208 const CHDPubKey &hdPubKey = (*mi).second;
219 std::map<CKeyID, CHDPubKey>::const_iterator mi = mapHdPubKeys.find(address);
220 if (mi != mapHdPubKeys.end())
223 const CHDPubKey &hdPubKey = (*mi).second;
225 if (!GetHDChain(hdChainCurrent))
226 throw std::runtime_error(std::string(__func__) +
": GetHDChain failed");
227 if (!DecryptHDChain(hdChainCurrent))
228 throw std::runtime_error(std::string(__func__) +
": DecryptHDChainSeed failed");
231 throw std::runtime_error(std::string(__func__) +
": Wrong HD chain!");
247 if (mapHdPubKeys.count(address) > 0)
265 GetHDChain(hdChainCurrent);
276 if (HaveWatchOnly(script))
277 RemoveWatchOnly(script);
279 if (HaveWatchOnly(script))
280 RemoveWatchOnly(script);
297 if (HaveWatchOnly(script))
298 RemoveWatchOnly(script);
300 if (HaveWatchOnly(script))
301 RemoveWatchOnly(script);
308 mapKeyMetadata[pubkey.
GetID()]);
314 const vector<unsigned char> &vchCryptedSecret)
322 if (pwalletdbEncryption)
323 return pwalletdbEncryption->WriteCryptedKey(vchPubKey,
325 mapKeyMetadata[vchPubKey.
GetID()]);
329 mapKeyMetadata[vchPubKey.
GetID()]);
340 mapKeyMetadata[pubkey.
GetID()] = meta;
366 LogPrintf(
"%s: Warning: This wallet contains a redeemScript of size %i which exceeds maximum size %i thus can never be redeemed. Do not use address %s.\n",
390 if (!HaveWatchOnly())
393 if (!
CWalletDB(strWalletFile).EraseWatchOnly(dest))
412 if (strWalletPassphrase ==
"keepass" &&
GetBoolArg(
"-keepass",
false)) {
415 }
catch (std::exception& e) {
416 LogPrintf(
"CWallet::Unlock could not retrieve passphrase from KeePass: Error: %s\n", e.what());
420 strWalletPassphraseFinal = strWalletPassphrase;
428 BOOST_FOREACH(
const MasterKeyMap::value_type& pMasterKey, mapMasterKeys)
430 if (!crypter.
SetKeyFromPassphrase(strWalletPassphraseFinal, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
432 if (!crypter.
Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey))
437 LogPrintf(
"Keypool replenished, re-initializing automatic backups.\n");
449 bool fWasLocked = IsLocked(
true);
450 bool bUseKeePass =
false;
455 if(strOldWalletPassphrase ==
"keepass" &&
GetBoolArg(
"-keepass",
false)) {
459 }
catch (std::exception& e) {
460 LogPrintf(
"CWallet::ChangeWalletPassphrase -- could not retrieve passphrase from KeePass: Error: %s\n", e.what());
464 strOldWalletPassphraseFinal = strOldWalletPassphrase;
473 BOOST_FOREACH(MasterKeyMap::value_type& pMasterKey, mapMasterKeys)
475 if(!crypter.
SetKeyFromPassphrase(strOldWalletPassphraseFinal, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
477 if (!crypter.
Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey))
482 crypter.
SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod);
483 pMasterKey.second.nDeriveIterations = pMasterKey.second.nDeriveIterations * (100 / ((double)(
GetTimeMillis() - nStartTime)));
486 crypter.
SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod);
487 pMasterKey.second.nDeriveIterations = (pMasterKey.second.nDeriveIterations + pMasterKey.second.nDeriveIterations * 100 / ((double)(
GetTimeMillis() - nStartTime))) / 2;
489 if (pMasterKey.second.nDeriveIterations < 25000)
490 pMasterKey.second.nDeriveIterations = 25000;
492 LogPrintf(
"Wallet passphrase changed to an nDeriveIterations of %i\n", pMasterKey.second.nDeriveIterations);
494 if (!crypter.
SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
496 if (!crypter.
Encrypt(vMasterKey, pMasterKey.second.vchCryptedKey))
504 LogPrintf(
"CWallet::ChangeWalletPassphrase -- Updating KeePass with new passphrase");
507 }
catch (std::exception& e) {
508 LogPrintf(
"CWallet::ChangeWalletPassphrase -- could not update passphrase in KeePass: Error: %s\n", e.what());
530 if (nWalletVersion >= nVersion)
534 if (fExplicit && nVersion > nWalletMaxVersion)
537 nWalletVersion = nVersion;
539 if (nVersion > nWalletMaxVersion)
540 nWalletMaxVersion = nVersion;
545 if (nWalletVersion > 40000)
558 if (nWalletVersion > nVersion)
561 nWalletMaxVersion = nVersion;
571 std::map<uint256, CWalletTx>::const_iterator it = mapWallet.find(txid);
572 if (it == mapWallet.end())
576 std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range;
578 BOOST_FOREACH(
const CTxIn& txin, wtx.
vin)
580 if (mapTxSpends.count(txin.
prevout) <= 1)
582 range = mapTxSpends.equal_range(txin.
prevout);
583 for (TxSpends::const_iterator it = range.first; it != range.second; ++it)
584 result.insert(it->second);
594 bool CWallet::Verify(
const string& walletFile,
string& warningString,
string& errorString)
599 boost::filesystem::path pathDatabase =
GetDataDir() /
"database";
602 boost::filesystem::rename(pathDatabase, pathDatabaseBak);
603 LogPrintf(
"Moved old %s to %s. Retrying.\n", pathDatabase.string(), pathDatabaseBak.string());
604 }
catch (
const boost::filesystem::filesystem_error&) {
624 if (boost::filesystem::exists(
GetDataDir() / walletFile))
629 warningString +=
strprintf(
_(
"Warning: wallet.dat corrupt, data salvaged!" 630 " Original wallet.dat saved as wallet.{timestamp}.bak in %s; if" 631 " your balance or transactions are incorrect you should" 635 errorString +=
_(
"wallet.dat corrupt, salvage failed");
647 int nMinOrderPos = std::numeric_limits<int>::max();
649 for (TxSpends::iterator it = range.first; it != range.second; ++it)
651 const uint256& hash = it->second;
652 int n = mapWallet[hash].nOrderPos;
653 if (
n < nMinOrderPos)
656 copyFrom = &mapWallet[hash];
660 for (TxSpends::iterator it = range.first; it != range.second; ++it)
662 const uint256& hash = it->second;
664 if (copyFrom == copyTo)
continue;
685 pair<TxSpends::const_iterator, TxSpends::const_iterator> range;
686 range = mapTxSpends.equal_range(outpoint);
688 for (TxSpends::const_iterator it = range.first; it != range.second; ++it)
690 const uint256& wtxid = it->second;
691 std::map<uint256, CWalletTx>::const_iterator mit = mapWallet.find(wtxid);
692 if (mit != mapWallet.end()) {
693 int depth = mit->second.GetDepthInMainChain();
694 if (depth > 0 || (depth == 0 && !mit->second.isAbandoned()))
703 mapTxSpends.insert(make_pair(outpoint, wtxid));
704 setWalletUTXO.erase(outpoint);
706 pair<TxSpends::iterator, TxSpends::iterator> range;
707 range = mapTxSpends.equal_range(outpoint);
714 assert(mapWallet.count(wtxid));
716 if (thisTx.IsCoinBase())
719 BOOST_FOREACH(
const CTxIn& txin, thisTx.vin)
720 AddToSpends(txin.
prevout, wtxid);
761 mapMasterKeys[++nMasterKeyMaxID] = kMasterKey;
764 assert(!pwalletdbEncryption);
765 pwalletdbEncryption =
new CWalletDB(strWalletFile);
766 if (!pwalletdbEncryption->TxnBegin()) {
767 delete pwalletdbEncryption;
768 pwalletdbEncryption = NULL;
771 pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey);
776 GetHDChain(hdChainCurrent);
778 if (!EncryptKeys(vMasterKey))
781 pwalletdbEncryption->TxnAbort();
782 delete pwalletdbEncryption;
789 if (!hdChainCurrent.
IsNull()) {
790 assert(EncryptHDChain(vMasterKey));
793 assert(GetHDChain(hdChainCrypted));
796 printf(
"EncryptWallet -- current seed: '%s'\n",
HexStr(hdChainCurrent.
GetSeed()).c_str());
797 printf(
"EncryptWallet -- crypted seed: '%s'\n",
HexStr(hdChainCrypted.
GetSeed()).c_str());
801 assert(hdChainCurrent.
GetID() == hdChainCrypted.
GetID());
804 assert(SetCryptedHDChain(hdChainCrypted,
false));
812 if (!pwalletdbEncryption->TxnCommit()) {
813 delete pwalletdbEncryption;
819 delete pwalletdbEncryption;
820 pwalletdbEncryption = NULL;
824 Unlock(strWalletPassphrase);
842 LogPrintf(
"CWallet::EncryptWallet -- Updating KeePass with new passphrase");
845 }
catch (std::exception& e) {
846 LogPrintf(
"CWallet::EncryptWallet -- could not update passphrase in KeePass: Error: %s\n", e.what());
851 NotifyStatusChanged(
this);
859 int64_t nRet = nOrderPosNext++;
876 fAnonymizableTallyCached =
false;
877 fAnonymizableTallyCachedNonDenom =
false;
886 mapWallet[hash] = wtxIn;
891 BOOST_FOREACH(
const CTxIn& txin, wtx.
vin) {
904 pair<map<uint256, CWalletTx>::iterator,
bool> ret = mapWallet.insert(make_pair(hash, wtxIn));
907 bool fInsertedNew = ret.second;
911 wtx.
nOrderPos = IncOrderPosNext(pwalletdb);
920 int64_t latestEntry = 0;
923 int64_t latestTolerated = latestNow + 300;
924 const TxItems & txOrdered = wtxOrdered;
925 for (TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
927 CWalletTx *
const pwtx = (*it).second.first;
939 nSmartTime = pacentry->
nTime;
940 if (nSmartTime <= latestTolerated)
942 latestEntry = nSmartTime;
943 if (nSmartTime > latestNow)
944 latestNow = nSmartTime;
951 wtx.
nTimeSmart = std::max(latestEntry, std::min(blocktime, latestNow));
954 LogPrintf(
"AddToWallet(): found %s in block %s not in index\n",
959 for(
int i = 0; i < wtx.
vout.size(); ++i) {
960 if (
IsMine(wtx.
vout[i]) && !IsSpent(hash, i)) {
961 setWalletUTXO.insert(
COutPoint(hash, i));
966 bool fUpdated =
false;
994 LogPrintf(
"AddToWallet %s %s%s\n", wtxIn.
GetHash().
ToString(), (fInsertedNew ?
"new" :
""), (fUpdated ?
"update" :
""));
997 if (fInsertedNew || fUpdated)
1008 std::string strCmd =
GetArg(
"-walletnotify",
"");
1010 if ( !strCmd.empty())
1016 fAnonymizableTallyCached =
false;
1017 fAnonymizableTallyCachedNonDenom =
false;
1034 BOOST_FOREACH(
const CTxIn& txin, tx.
vin) {
1035 std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = mapTxSpends.equal_range(txin.
prevout);
1036 while (range.first != range.second) {
1037 if (range.first->second != tx.
GetHash()) {
1038 LogPrintf(
"Transaction %s (in block %s) conflicts with wallet transaction %s (both spend %s:%i)\n", tx.
GetHash().
ToString(), pblock->
GetHash().
ToString(), range.first->second.ToString(), range.first->first.hash.ToString(), range.first->first.n);
1039 MarkConflicted(pblock->
GetHash(), range.first->second);
1046 bool fExisted = mapWallet.count(tx.
GetHash()) != 0;
1047 if (fExisted && !fUpdate)
return false;
1048 if (fExisted ||
IsMine(tx) || IsFromMe(tx))
1058 CWalletDB walletdb(strWalletFile,
"r+",
false);
1060 return AddToWallet(wtx,
false, &walletdb);
1071 CWalletDB walletdb(strWalletFile,
"r+",
false);
1073 std::set<uint256> todo;
1074 std::set<uint256> done;
1077 assert(mapWallet.count(hashTx));
1079 if (origtx.GetDepthInMainChain() > 0 || origtx.InMempool()) {
1083 todo.insert(hashTx);
1085 while (!todo.empty()) {
1089 assert(mapWallet.count(now));
1093 assert(currentconfirm <= 0);
1095 if (currentconfirm == 0 && !wtx.isAbandoned()) {
1097 assert(!wtx.InMempool());
1101 wtx.WriteToDisk(&walletdb);
1104 TxSpends::const_iterator iter = mapTxSpends.lower_bound(
COutPoint(hashTx, 0));
1105 while (iter != mapTxSpends.end() && iter->first.hash == now) {
1106 if (!done.count(iter->second)) {
1107 todo.insert(iter->second);
1113 BOOST_FOREACH(
const CTxIn& txin, wtx.vin)
1121 fAnonymizableTallyCached =
false;
1122 fAnonymizableTallyCachedNonDenom =
false;
1131 int conflictconfirms = 0;
1142 if (conflictconfirms >= 0)
1146 CWalletDB walletdb(strWalletFile,
"r+",
false);
1148 std::set<uint256> todo;
1149 std::set<uint256> done;
1151 todo.insert(hashTx);
1153 while (!todo.empty()) {
1157 assert(mapWallet.count(now));
1160 if (conflictconfirms < currentconfirm) {
1164 wtx.hashBlock = hashBlock;
1166 wtx.WriteToDisk(&walletdb);
1168 TxSpends::const_iterator iter = mapTxSpends.lower_bound(
COutPoint(now, 0));
1169 while (iter != mapTxSpends.end() && iter->first.hash == now) {
1170 if (!done.count(iter->second)) {
1171 todo.insert(iter->second);
1177 BOOST_FOREACH(
const CTxIn& txin, wtx.vin)
1185 fAnonymizableTallyCached =
false;
1186 fAnonymizableTallyCachedNonDenom =
false;
1193 if (!AddToWalletIfInvolvingMe(tx, pblock,
true))
1199 BOOST_FOREACH(
const CTxIn& txin, tx.
vin)
1205 fAnonymizableTallyCached =
false;
1206 fAnonymizableTallyCachedNonDenom =
false;
1214 map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(txin.
prevout.
hash);
1215 if (mi != mapWallet.end())
1229 map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(txin.
prevout.
hash);
1230 if (mi != mapWallet.end())
1244 static std::map<uint256, CMutableTransaction> mDenomWtxes;
1246 if(nRounds >= 16)
return 15;
1249 unsigned int nout = outpoint.
n;
1251 const CWalletTx* wtx = GetWalletTx(hash);
1254 std::map<uint256, CMutableTransaction>::const_iterator mdwi = mDenomWtxes.find(hash);
1255 if (mdwi == mDenomWtxes.end()) {
1257 LogPrint(
"privatesend",
"GetRealOutpointPrivateSendRounds INSERTING %s\n", hash.
ToString());
1259 }
else if(mDenomWtxes[hash].vout[nout].nRounds != -10) {
1261 return mDenomWtxes[hash].vout[nout].nRounds;
1266 if (nout >= wtx->
vout.size()) {
1268 LogPrint(
"privatesend",
"GetRealOutpointPrivateSendRounds UPDATED %s %3d %3d\n", hash.
ToString(), nout, -4);
1272 if (IsCollateralAmount(wtx->
vout[nout].nValue)) {
1273 mDenomWtxes[hash].vout[nout].nRounds = -3;
1274 LogPrint(
"privatesend",
"GetRealOutpointPrivateSendRounds UPDATED %s %3d %3d\n", hash.
ToString(), nout, mDenomWtxes[hash].vout[nout].nRounds);
1275 return mDenomWtxes[hash].vout[nout].nRounds;
1279 if (!IsDenominatedAmount(wtx->
vout[nout].nValue)) {
1280 mDenomWtxes[hash].vout[nout].nRounds = -2;
1281 LogPrint(
"privatesend",
"GetRealOutpointPrivateSendRounds UPDATED %s %3d %3d\n", hash.
ToString(), nout, mDenomWtxes[hash].vout[nout].nRounds);
1282 return mDenomWtxes[hash].vout[nout].nRounds;
1285 bool fAllDenoms =
true;
1287 fAllDenoms = fAllDenoms && IsDenominatedAmount(
out.nValue);
1292 mDenomWtxes[hash].vout[nout].nRounds = 0;
1293 LogPrint(
"privatesend",
"GetRealOutpointPrivateSendRounds UPDATED %s %3d %3d\n", hash.
ToString(), nout, mDenomWtxes[hash].vout[nout].nRounds);
1294 return mDenomWtxes[hash].vout[nout].nRounds;
1297 int nShortest = -10;
1298 bool fDenomFound =
false;
1300 BOOST_FOREACH(
CTxIn txinNext, wtx->
vin) {
1302 int n = GetRealOutpointPrivateSendRounds(txinNext.
prevout, nRounds + 1);
1304 if(
n >= 0 && (
n < nShortest || nShortest == -10)) {
1310 mDenomWtxes[hash].vout[nout].nRounds = fDenomFound
1311 ? (nShortest >= 15 ? 16 : nShortest + 1)
1313 LogPrint(
"privatesend",
"GetRealOutpointPrivateSendRounds UPDATED %s %3d %3d\n", hash.
ToString(), nout, mDenomWtxes[hash].vout[nout].nRounds);
1314 return mDenomWtxes[hash].vout[nout].nRounds;
1324 int realPrivateSendRounds = GetRealOutpointPrivateSendRounds(outpoint, 0);
1332 map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(outpoint.
hash);
1333 if (mi != mapWallet.end()) {
1335 if (outpoint.
n < prev.
vout.size()) {
1336 return IsDenominatedAmount(prev.
vout[outpoint.
n].nValue);
1346 if(nInputAmount == d)
1359 throw std::runtime_error(
"CWallet::GetCredit(): value out of range");
1379 if (!mapAddressBook.count(address))
1388 throw std::runtime_error(
"CWallet::GetChange(): value out of range");
1389 return (IsChange(txout) ? txout.
nValue : 0);
1396 std::string strSeed =
GetArg(
"-hdseed",
"not hex");
1399 std::vector<unsigned char> vchSeed =
ParseHex(strSeed);
1401 throw std::runtime_error(std::string(__func__) +
": SetSeed failed");
1405 LogPrintf(
"CWallet::GenerateNewHDChain -- Incorrect seed, generating random one instead\n");
1408 std::string strMnemonic =
GetArg(
"-mnemonic",
"");
1410 std::string strMnemonicPassphrase =
GetArg(
"-mnemonicpassphrase",
"");
1412 SecureVector vchMnemonic(strMnemonic.begin(), strMnemonic.end());
1413 SecureVector vchMnemonicPassphrase(strMnemonicPassphrase.begin(), strMnemonicPassphrase.end());
1415 if (!newHdChain.
SetMnemonic(vchMnemonic, vchMnemonicPassphrase,
true))
1416 throw std::runtime_error(std::string(__func__) +
": SetMnemonic failed");
1418 newHdChain.
Debug(__func__);
1420 if (!SetHDChain(newHdChain,
false))
1421 throw std::runtime_error(std::string(__func__) +
": SetHDChain failed");
1426 mapArgs.erase(
"-mnemonicpassphrase");
1436 if (!memonly && !
CWalletDB(strWalletFile).WriteHDChain(chain))
1437 throw std::runtime_error(std::string(__func__) +
": WriteHDChain failed");
1452 if (pwalletdbEncryption) {
1453 if (!pwalletdbEncryption->WriteCryptedHDChain(chain))
1454 throw std::runtime_error(std::string(__func__) +
": WriteCryptedHDChain failed");
1457 throw std::runtime_error(std::string(__func__) +
": WriteCryptedHDChain failed");
1469 if (!GetHDChain(hdChainTmp)) {
1473 if (!DecryptHDChain(hdChainTmp))
1480 hdChainRet = hdChainTmp;
1488 return GetHDChain(hdChainCurrent);
1507 BOOST_FOREACH(
const CTxIn& txin, tx.
vin)
1509 nDebit += GetDebit(txin, filter);
1511 throw std::runtime_error(
"CWallet::GetDebit(): value out of range");
1521 nCredit += GetCredit(txout, filter);
1523 throw std::runtime_error(
"CWallet::GetCredit(): value out of range");
1533 nChange += GetChange(txout);
1535 throw std::runtime_error(
"CWallet::GetChange(): value out of range");
1542 int64_t
n = nTimeSmart;
1543 return n ?
n : nTimeReceived;
1551 LOCK(pwallet->cs_wallet);
1557 map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(hashBlock);
1558 if (mi != pwallet->mapRequestCount.end())
1559 nRequests = (*mi).second;
1565 map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(GetHash());
1566 if (mi != pwallet->mapRequestCount.end())
1568 nRequests = (*mi).second;
1571 if (nRequests == 0 && !hashUnset())
1573 map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(hashBlock);
1574 if (mi != pwallet->mapRequestCount.end())
1575 nRequests = (*mi).second;
1586 list<COutputEntry>& listSent,
CAmount& nFee,
string& strSentAccount,
const isminefilter& filter)
const 1589 listReceived.clear();
1591 strSentAccount = strFromAccount;
1594 CAmount nDebit = GetDebit(filter);
1597 CAmount nValueOut = GetValueOut();
1598 nFee = nDebit - nValueOut;
1602 for (
unsigned int i = 0; i < vout.size(); ++i)
1604 const CTxOut& txout = vout[i];
1612 if (pwallet->IsChange(txout))
1615 else if (!(fIsMine & filter))
1623 LogPrintf(
"CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n",
1624 this->GetHash().ToString());
1632 listSent.push_back(output);
1635 if (fIsMine & filter)
1636 listReceived.push_back(output);
1644 nReceived = nSent = nFee = 0;
1647 string strSentAccount;
1648 list<COutputEntry> listReceived;
1649 list<COutputEntry> listSent;
1650 GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
1652 if (strAccount == strSentAccount)
1659 LOCK(pwallet->cs_wallet);
1664 map<CTxDestination, CAddressBookData>::const_iterator mi = pwallet->mapAddressBook.find(r.
destination);
1665 if (mi != pwallet->mapAddressBook.end() && (*mi).second.name == strAccount)
1668 else if (strAccount.empty())
1679 return pwalletdb->
WriteTx(GetHash(), *
this);
1699 while (pindex && nTimeFirstKey && (pindex->
GetBlockTime() < (nTimeFirstKey - 7200)))
1707 if (pindex->
nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0)
1714 if (AddToWalletIfInvolvingMe(tx, &block, fUpdate))
1731 if (!fBroadcastTransactions)
1734 std::map<int64_t, CWalletTx*> mapSorted;
1739 const uint256& wtxid = item.first;
1741 assert(wtx.
GetHash() == wtxid);
1746 mapSorted.insert(std::make_pair(wtx.
nOrderPos, &wtx));
1762 assert(pwallet->GetBroadcastTransactions());
1765 if (GetDepthInMainChain() == 0 && !isAbandoned() && InMempool()) {
1784 if (pwallet != NULL)
1787 result = pwallet->GetConflicts(myHash);
1802 debit += nDebitCached;
1806 fDebitCached =
true;
1807 debit += nDebitCached;
1812 if(fWatchDebitCached)
1813 debit += nWatchDebitCached;
1817 fWatchDebitCached =
true;
1818 debit += nWatchDebitCached;
1827 if (IsCoinBase() && GetBlocksToMaturity() > 0)
1835 credit += nCreditCached;
1839 fCreditCached =
true;
1840 credit += nCreditCached;
1845 if (fWatchCreditCached)
1846 credit += nWatchCreditCached;
1850 fWatchCreditCached =
true;
1851 credit += nWatchCreditCached;
1859 if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
1861 if (fUseCache && fImmatureCreditCached)
1862 return nImmatureCreditCached;
1864 fImmatureCreditCached =
true;
1865 return nImmatureCreditCached;
1877 if (IsCoinBase() && GetBlocksToMaturity() > 0)
1880 if (fUseCache && fAvailableCreditCached)
1881 return nAvailableCreditCached;
1885 for (
unsigned int i = 0; i < vout.size(); i++)
1887 if (!pwallet->IsSpent(hashTx, i))
1889 const CTxOut &txout = vout[i];
1892 throw std::runtime_error(
"CWalletTx::GetAvailableCredit() : value out of range");
1896 nAvailableCreditCached = nCredit;
1897 fAvailableCreditCached =
true;
1903 if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
1905 if (fUseCache && fImmatureWatchCreditCached)
1906 return nImmatureWatchCreditCached;
1908 fImmatureWatchCreditCached =
true;
1909 return nImmatureWatchCreditCached;
1921 if (IsCoinBase() && GetBlocksToMaturity() > 0)
1924 if (fUseCache && fAvailableWatchCreditCached)
1925 return nAvailableWatchCreditCached;
1928 for (
unsigned int i = 0; i < vout.size(); i++)
1930 if (!pwallet->IsSpent(GetHash(), i))
1932 const CTxOut &txout = vout[i];
1935 throw std::runtime_error(
"CWalletTx::GetAvailableCredit() : value out of range");
1939 nAvailableWatchCreditCached = nCredit;
1940 fAvailableWatchCreditCached =
true;
1950 if (IsCoinBase() && GetBlocksToMaturity() > 0)
1953 if (fUseCache && fAnonymizedCreditCached)
1954 return nAnonymizedCreditCached;
1958 for (
unsigned int i = 0; i < vout.size(); i++)
1960 const CTxOut &txout = vout[i];
1963 if(pwallet->IsSpent(hashTx, i) || !pwallet->IsDenominated(outpoint))
continue;
1965 const int nRounds = pwallet->GetOutpointPrivateSendRounds(outpoint);
1969 throw std::runtime_error(
"CWalletTx::GetAnonymizedCredit() : value out of range");
1973 nAnonymizedCreditCached = nCredit;
1974 fAnonymizedCreditCached =
true;
1984 if (IsCoinBase() && GetBlocksToMaturity() > 0)
1987 int nDepth = GetDepthInMainChain(
false);
1988 if(nDepth < 0)
return 0;
1990 bool isUnconfirmed = IsTrusted() && nDepth == 0;
1991 if(unconfirmed != isUnconfirmed)
return 0;
1994 if(unconfirmed && fDenomUnconfCreditCached)
1995 return nDenomUnconfCreditCached;
1996 else if (!unconfirmed && fDenomConfCreditCached)
1997 return nDenomConfCreditCached;
2002 for (
unsigned int i = 0; i < vout.size(); i++)
2004 const CTxOut &txout = vout[i];
2006 if(pwallet->IsSpent(hashTx, i) || !pwallet->IsDenominatedAmount(vout[i].nValue))
continue;
2010 throw std::runtime_error(
"CWalletTx::GetDenominatedCredit() : value out of range");
2014 nDenomUnconfCreditCached = nCredit;
2015 fDenomUnconfCreditCached =
true;
2017 nDenomConfCreditCached = nCredit;
2018 fDenomConfCreditCached =
true;
2026 return nChangeCached;
2027 nChangeCached = pwallet->GetChange(*
this);
2028 fChangeCached =
true;
2029 return nChangeCached;
2046 int nDepth = GetDepthInMainChain();
2059 BOOST_FOREACH(
const CTxIn& txin, vin)
2076 for (
unsigned int i = 0; i < tx1.
vin.size(); i++) tx1.
vin[i].scriptSig =
CScript();
2077 for (
unsigned int i = 0; i < tx2.
vin.size(); i++) tx2.
vin[i].scriptSig =
CScript();
2083 std::vector<uint256>
result;
2087 multimap<unsigned int, CWalletTx*> mapSorted;
2109 if (
GetTime() < nNextResend || !fBroadcastTransactions)
2111 bool fFirst = (nNextResend == 0);
2117 if (nBestBlockTime < nLastResend)
2123 std::vector<uint256> relayed = ResendWalletTransactionsBefore(nBestBlockTime-5*60, connman);
2124 if (!relayed.empty())
2125 LogPrintf(
"%s: rebroadcast %u unconfirmed transactions\n", __func__, relayed.size());
2144 for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
2159 std::vector<CompactTallyItem> vecTally;
2160 if(!SelectCoinsGrouppedByAddresses(vecTally, fSkipDenominated,
true, fSkipUnconfirmed))
return 0;
2167 bool fIsDenominated = IsDenominatedAmount(item.
nAmount);
2168 if(fSkipDenominated && fIsDenominated)
continue;
2170 if(item.
nAmount >= nSmallestDenom + (fIsDenominated ? 0 : nMixingCollateral))
2185 std::set<uint256> setWalletTxesCounted;
2186 for (
auto& outpoint : setWalletUTXO) {
2188 if (setWalletTxesCounted.find(outpoint.hash) != setWalletTxesCounted.end())
continue;
2189 setWalletTxesCounted.insert(outpoint.hash);
2191 for (map<uint256, CWalletTx>::const_iterator it = mapWallet.find(outpoint.hash); it != mapWallet.end() && it->first == outpoint.hash; ++it) {
2192 if (it->second.IsTrusted())
2193 nTotal += it->second.GetAnonymizedCredit();
2210 for (
auto& outpoint : setWalletUTXO) {
2211 if(!IsDenominated(outpoint))
continue;
2213 nTotal += GetOutpointPrivateSendRounds(outpoint);
2217 if(nCount == 0)
return 0;
2219 return (
float)nTotal/nCount;
2231 for (
auto& outpoint : setWalletUTXO) {
2232 map<uint256, CWalletTx>::const_iterator it = mapWallet.find(outpoint.hash);
2233 if (it == mapWallet.end())
continue;
2234 if (!IsDenominated(outpoint))
continue;
2235 if (it->second.GetDepthInMainChain() < 0)
continue;
2237 int nRounds = GetOutpointPrivateSendRounds(outpoint);
2248 CAmount nAnonymizedBalance = GetAnonymizedBalance();
2252 nNeedsToAnonymizeBalance += nMinBalance;
2254 CAmount nAnonymizableBalance = GetAnonymizableBalance();
2257 if(nAnonymizableBalance < nMinBalance)
return 0;
2260 if(nNeedsToAnonymizeBalance > nAnonymizableBalance) nNeedsToAnonymizeBalance = nAnonymizableBalance;
2265 return nNeedsToAnonymizeBalance;
2275 for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
2291 for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
2306 for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
2320 for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
2336 for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
2351 for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
2366 for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
2368 const uint256& wtxid = it->first;
2374 if (fOnlyConfirmed && !pcoin->
IsTrusted())
2390 for (
unsigned int i = 0; i < pcoin->
vout.size(); i++) {
2393 found = IsDenominatedAmount(pcoin->
vout[i].nValue);
2397 if (IsCollateralAmount(pcoin->
vout[i].nValue))
continue;
2398 found = !IsDenominatedAmount(pcoin->
vout[i].nValue);
2401 found = pcoin->
vout[i].nValue == 1000*
COIN;
2403 found = IsCollateralAmount(pcoin->
vout[i].nValue);
2407 if(!found)
continue;
2410 if (!(IsSpent(wtxid, i)) && mine !=
ISMINE_NO &&
2411 (!IsLockedCoin((*it).first, i) || nCoinType ==
ONLY_1000) &&
2412 (pcoin->
vout[i].nValue > 0 || fIncludeZeroValue) &&
2424 vector<char>& vfBest,
CAmount& nBest,
int iterations = 1000,
bool fUseInstantSend =
false)
2426 vector<char> vfIncluded;
2428 vfBest.assign(vValue.size(),
true);
2429 nBest = nTotalLower;
2433 for (
int nRep = 0; nRep < iterations && nBest != nTargetValue; nRep++)
2435 vfIncluded.assign(vValue.size(),
false);
2437 bool fReachedTarget =
false;
2438 for (
int nPass = 0; nPass < 2 && !fReachedTarget; nPass++)
2440 for (
unsigned int i = 0; i < vValue.size(); i++)
2453 nTotal += vValue[i].first;
2454 vfIncluded[i] =
true;
2455 if (nTotal >= nTargetValue)
2457 fReachedTarget =
true;
2461 vfBest = vfIncluded;
2463 nTotal -= vValue[i].first;
2464 vfIncluded[i] =
false;
2472 for (
unsigned int i = 0; i < vValue.size(); i++)
2474 if (vfBest[i] && (nBest - vValue[i].first) >= nTargetValue )
2477 nBest -= vValue[i].first;
2488 bool found1 =
false;
2489 bool found2 =
false;
2492 if(pcoin1->
vout[out1.
i].nValue == d) found1 =
true;
2493 if(pcoin2->
vout[out2.
i].nValue == d) found2 =
true;
2495 return (!found1 && found2);
2499 set<pair<const CWalletTx*,unsigned int> >& setCoinsRet,
CAmount& nValueRet,
bool fUseInstantSend)
const 2501 setCoinsRet.clear();
2505 pair<CAmount, pair<const CWalletTx*,unsigned int> > coinLowestLarger;
2506 coinLowestLarger.first = fUseInstantSend
2508 : std::numeric_limits<CAmount>::max();
2509 coinLowestLarger.second.first = NULL;
2510 vector<pair<CAmount, pair<const CWalletTx*,unsigned int> > > vValue;
2519 for (
unsigned int tryDenom = 0; tryDenom < 2; tryDenom++)
2521 LogPrint(
"selectcoins",
"tryDenom: %d\n", tryDenom);
2537 if (tryDenom == 0 && IsDenominatedAmount(
n))
continue;
2539 pair<CAmount,pair<const CWalletTx*,unsigned int> > coin = make_pair(
n,make_pair(pcoin, i));
2541 if (
n == nTargetValue)
2543 setCoinsRet.insert(coin.second);
2544 nValueRet += coin.first;
2549 vValue.push_back(coin);
2552 else if (
n < coinLowestLarger.first)
2554 coinLowestLarger = coin;
2558 if (nTotalLower == nTargetValue)
2560 for (
unsigned int i = 0; i < vValue.size(); ++i)
2562 setCoinsRet.insert(vValue[i].second);
2563 nValueRet += vValue[i].first;
2568 if (nTotalLower < nTargetValue)
2570 if (coinLowestLarger.second.first == NULL)
2579 setCoinsRet.insert(coinLowestLarger.second);
2580 nValueRet += coinLowestLarger.first;
2591 vector<char> vfBest;
2595 if (nBest != nTargetValue && nTotalLower >= nTargetValue +
MIN_CHANGE)
2600 if (coinLowestLarger.second.first &&
2601 ((nBest != nTargetValue && nBest < nTargetValue +
MIN_CHANGE) || coinLowestLarger.first <= nBest))
2603 setCoinsRet.insert(coinLowestLarger.second);
2604 nValueRet += coinLowestLarger.first;
2607 string s =
"CWallet::SelectCoinsMinConf best subset: ";
2608 for (
unsigned int i = 0; i < vValue.size(); i++)
2612 setCoinsRet.insert(vValue[i].second);
2613 nValueRet += vValue[i].first;
2628 AvailableCoins(
vCoins,
true, coinControl,
false, nCoinType, fUseInstantSend);
2640 int nRounds = GetOutpointPrivateSendRounds(outpoint);
2644 nValueRet +=
out.tx->vout[
out.i].nValue;
2645 setCoinsRet.insert(make_pair(
out.tx,
out.i));
2648 return (nValueRet >= nTargetValue);
2654 CAmount nSmallestDenom = vecPrivateSendDenominations.back();
2656 BOOST_FOREACH(
CAmount nDenom, vecPrivateSendDenominations)
2661 if(
out.tx->vout[
out.i].nValue == nDenom && nValueRet + nDenom < nTargetValue + nSmallestDenom) {
2663 int nRounds = GetOutpointPrivateSendRounds(outpoint);
2666 nValueRet += nDenom;
2667 setCoinsRet.insert(make_pair(
out.tx,
out.i));
2671 return (nValueRet >= nTargetValue);
2674 set<pair<const CWalletTx*, uint32_t> > setPresetCoins;
2675 CAmount nValueFromPresetInputs = 0;
2677 std::vector<COutPoint> vPresetInputs;
2680 BOOST_FOREACH(
const COutPoint& outpoint, vPresetInputs)
2682 map<uint256, CWalletTx>::const_iterator it = mapWallet.find(outpoint.
hash);
2683 if (it != mapWallet.end())
2687 if (pcoin->
vout.size() <= outpoint.
n)
2689 nValueFromPresetInputs += pcoin->
vout[outpoint.
n].nValue;
2690 setPresetCoins.insert(make_pair(pcoin, outpoint.
n));
2696 for (vector<COutput>::iterator it =
vCoins.begin(); it !=
vCoins.end() && coinControl && coinControl->
HasSelected();)
2698 if (setPresetCoins.count(make_pair(it->tx, it->i)))
2704 bool res = nTargetValue <= nValueFromPresetInputs ||
2705 SelectCoinsMinConf(nTargetValue - nValueFromPresetInputs, 1, 6,
vCoins, setCoinsRet, nValueRet, fUseInstantSend) ||
2706 SelectCoinsMinConf(nTargetValue - nValueFromPresetInputs, 1, 1,
vCoins, setCoinsRet, nValueRet, fUseInstantSend) ||
2707 (
bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue - nValueFromPresetInputs, 0, 1,
vCoins, setCoinsRet, nValueRet, fUseInstantSend));
2710 setCoinsRet.insert(setPresetCoins.begin(), setPresetCoins.end());
2713 nValueRet += nValueFromPresetInputs;
2729 vector<CRecipient> vecSend;
2735 vecSend.push_back(recipient);
2741 BOOST_FOREACH(
const CTxIn& txin, tx.
vin)
2746 if (!CreateTransaction(vecSend, wtx, reservekey, nFeeRet, nChangePosRet, strFailReason, &coinControl,
false))
2749 if (nChangePosRet != -1)
2750 tx.
vout.insert(tx.
vout.begin() + nChangePosRet, wtx.
vout[nChangePosRet]);
2753 BOOST_FOREACH(
const CTxIn& txin, wtx.
vin)
2756 tx.
vin.push_back(txin);
2779 std::vector<int> vecBits;
2784 int nDenomResult = 0;
2792 if(nValueRet +
out.tx->vout[
out.i].nValue <= nValueMax){
2796 int nRounds = GetOutpointPrivateSendRounds(txin.
prevout);
2797 if(nRounds >= nPrivateSendRoundsMax)
continue;
2798 if(nRounds < nPrivateSendRoundsMin)
continue;
2800 BOOST_FOREACH(
int nBit, vecBits) {
2801 if(
out.tx->vout[
out.i].nValue == vecPrivateSendDenominations[nBit]) {
2802 if(nValueRet >= nValueMin) {
2804 nValueMax -= insecureRand(nValueMax/5);
2806 int r = insecureRand(
vCoins.size());
2807 if((
int)vecTxInRet.size() > r)
return true;
2810 nValueRet +=
out.tx->vout[
out.i].nValue;
2811 vecTxInRet.push_back(txin);
2812 vCoinsRet.push_back(
out);
2813 nDenomResult |= 1 << nBit;
2819 return nValueRet >= nValueMin && nDenom == nDenomResult;
2838 if(fAnonymizable && fSkipUnconfirmed) {
2839 if(fSkipDenominated && fAnonymizableTallyCachedNonDenom) {
2840 vecTallyRet = vecAnonymizableTallyCachedNonDenom;
2841 LogPrint(
"selectcoins",
"SelectCoinsGrouppedByAddresses - using cache for non-denom inputs %d\n", vecTallyRet.size());
2842 return vecTallyRet.size() > 0;
2844 if(!fSkipDenominated && fAnonymizableTallyCached) {
2845 vecTallyRet = vecAnonymizableTallyCached;
2846 LogPrint(
"selectcoins",
"SelectCoinsGrouppedByAddresses - using cache for all inputs %d\n", vecTallyRet.size());
2847 return vecTallyRet.size() > 0;
2854 map<CTxDestination, CompactTallyItem> mapTally;
2855 std::set<uint256> setWalletTxesCounted;
2856 for (
auto& outpoint : setWalletUTXO) {
2858 if (setWalletTxesCounted.find(outpoint.hash) != setWalletTxesCounted.end())
continue;
2859 setWalletTxesCounted.insert(outpoint.hash);
2861 map<uint256, CWalletTx>::const_iterator it = mapWallet.find(outpoint.hash);
2862 if (it == mapWallet.end())
continue;
2867 if(fSkipUnconfirmed && !wtx.
IsTrusted())
continue;
2869 for (
unsigned int i = 0; i < wtx.
vout.size(); i++) {
2874 if(!(mine & filter))
continue;
2876 if(IsSpent(outpoint.hash, i) || IsLockedCoin(outpoint.hash, i))
continue;
2878 if(fSkipDenominated && IsDenominatedAmount(wtx.
vout[i].nValue))
continue;
2882 if(IsCollateralAmount(wtx.
vout[i].nValue))
continue;
2886 if(wtx.
vout[i].nValue <= nSmallestDenom/10)
continue;
2899 vecTallyRet.clear();
2901 if(fAnonymizable && item.second.
nAmount < nSmallestDenom)
continue;
2902 vecTallyRet.push_back(item.second);
2909 if(fAnonymizable && fSkipUnconfirmed) {
2910 if(fSkipDenominated) {
2911 vecAnonymizableTallyCachedNonDenom = vecTallyRet;
2912 fAnonymizableTallyCachedNonDenom =
true;
2914 vecAnonymizableTallyCached = vecTallyRet;
2915 fAnonymizableTallyCached =
true;
2921 std::string strMessage =
"SelectCoinsGrouppedByAddresses - vecTallyRet:\n";
2924 LogPrint(
"selectcoins",
"%s", strMessage);
2927 return vecTallyRet.size() > 0;
2946 if(
out.tx->vout[
out.i].nValue < nValueMin/10)
continue;
2948 if(IsCollateralAmount(
out.tx->vout[
out.i].nValue))
continue;
2951 if(nValueRet +
out.tx->vout[
out.i].nValue <= nValueMax){
2954 int nRounds = GetOutpointPrivateSendRounds(txin.
prevout);
2955 if(nRounds >= nPrivateSendRoundsMax)
continue;
2956 if(nRounds < nPrivateSendRoundsMin)
continue;
2959 nValueRet +=
out.tx->vout[
out.i].nValue;
2960 vecTxInRet.push_back(txin);
2964 return nValueRet >= nValueMin;
2975 if(IsCollateralAmount(
out.tx->vout[
out.i].nValue))
2979 nValueRet =
out.tx->vout[
out.i].nValue;
2993 std::vector<COutput> vPossibleCoins;
2994 AvailableCoins(vPossibleCoins,
true, NULL,
false,
ONLY_1000);
2995 if(vPossibleCoins.empty()) {
2996 LogPrintf(
"CWallet::GetMasternodeOutpointAndKeys -- Could not locate any valid masternode vin\n");
3000 if(strTxHash.empty())
3001 return GetOutpointAndKeysFromOutput(vPossibleCoins[0], outpointRet, pubKeyRet, keyRet);
3005 int nOutputIndex =
atoi(strOutputIndex.c_str());
3008 if(
out.tx->GetHash() == txHash &&
out.i == nOutputIndex)
3009 return GetOutpointAndKeysFromOutput(
out, outpointRet, pubKeyRet, keyRet);
3011 LogPrintf(
"CWallet::GetMasternodeOutpointAndKeys -- Could not locate specified masternode vin\n");
3023 pubScript =
out.tx->vout[
out.i].scriptPubKey;
3031 LogPrintf(
"CWallet::GetOutpointAndKeysFromOutput -- Address does not refer to a key\n");
3035 if (!GetKey(keyID, keyRet)) {
3036 LogPrintf (
"CWallet::GetOutpointAndKeysFromOutput -- Private key for address is not known\n");
3049 for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
3055 for (
unsigned int i = 0; i < pcoin->
vout.size(); i++) {
3059 if(
out.tx->vout[
out.i].nValue != nInputAmount)
continue;
3060 if(!IsDenominatedAmount(pcoin->
vout[i].nValue))
continue;
3090 txCollateral.
vin.clear();
3091 txCollateral.
vout.clear();
3095 CTxIn txinCollateral;
3097 if (!GetCollateralTxIn(txinCollateral, nValue)) {
3098 strReason =
"PrivateSend requires a collateral transaction and could not locate an acceptable input!";
3109 txCollateral.
vin.push_back(txinCollateral);
3113 txCollateral.
vout.push_back(txout);
3116 strReason =
"Unable to sign collateral transaction!";
3126 if(GetBudgetSystemCollateralTX(wtx, hash, amount, fUseInstantSend)){
3142 int nChangePosRet = -1;
3143 std::string strFail =
"";
3144 vector< CRecipient > vecSend;
3145 vecSend.push_back((
CRecipient){scriptChange, amount,
false});
3148 bool success = CreateTransaction(vecSend, tx, reservekey, nFeeRet, nChangePosRet, strFail, coinControl,
true,
ALL_COINS, fUseInstantSend);
3150 LogPrintf(
"CWallet::GetBudgetSystemCollateralTX -- Error: %s\n", strFail);
3160 BOOST_FOREACH(
CTxIn txin, vecTxIn) {
3167 LogPrintf(
"CWallet::ConvertList -- Couldn't find transaction\n");
3179 unsigned int nSubtractFeeFromAmount = 0;
3180 BOOST_FOREACH (
const CRecipient& recipient, vecSend)
3182 if (nValue < 0 || recipient.
nAmount < 0)
3184 strFailReason =
_(
"Transaction amounts must be positive");
3190 nSubtractFeeFromAmount++;
3192 if (vecSend.empty() || nValue < 0)
3194 strFailReason =
_(
"Transaction amounts must be positive");
3239 if(nFeePay > 0) nFeeRet = nFeePay;
3249 CAmount nValueToSelect = nValue;
3250 if (nSubtractFeeFromAmount == 0)
3251 nValueToSelect += nFeeRet;
3252 double dPriority = 0;
3254 BOOST_FOREACH (
const CRecipient& recipient, vecSend)
3260 txout.
nValue -= nFeeRet / nSubtractFeeFromAmount;
3265 txout.
nValue -= nFeeRet % nSubtractFeeFromAmount;
3274 strFailReason =
_(
"The transaction amount is too small to pay the fee");
3276 strFailReason =
_(
"The transaction amount is too small to send after the fee has been deducted");
3279 strFailReason =
_(
"Transaction amount too small");
3282 txNew.
vout.push_back(txout);
3286 set<pair<const CWalletTx*,unsigned int> > setCoins;
3289 if (!SelectCoins(nValueToSelect, setCoins, nValueIn, coinControl, nCoinType, fUseInstantSend))
3292 strFailReason =
_(
"Unable to locate enough funds for this transaction that are not equal 1000 DASH.");
3294 strFailReason =
_(
"Unable to locate enough PrivateSend non-denominated funds for this transaction that are not equal 1000 DASH.");
3296 strFailReason =
_(
"Unable to locate enough PrivateSend denominated funds for this transaction.");
3297 strFailReason +=
" " +
_(
"PrivateSend uses exact denominated amounts to send funds, you might simply need to anonymize some more coins.");
3298 }
else if (nValueIn < nValueToSelect) {
3299 strFailReason =
_(
"Insufficient funds.");
3300 if (fUseInstantSend) {
3315 CAmount nCredit = pcoin.first->vout[pcoin.second].nValue;
3320 int age = pcoin.first->GetDepthInMainChain();
3324 dPriority += (double)nCredit * age;
3327 const CAmount nChange = nValueIn - nValueToSelect;
3347 if (coinControl && !boost::get<CNoDestination>(&coinControl->
destChange))
3364 strFailReason =
_(
"Keypool ran out, please call keypoolrefill first");
3370 newTxOut =
CTxOut(nChange, scriptChange);
3378 newTxOut.
nValue += nDust;
3379 for (
unsigned int i = 0; i < vecSend.size(); i++)
3381 if (vecSend[i].fSubtractFeeFromAmount)
3383 txNew.
vout[i].nValue -= nDust;
3386 strFailReason =
_(
"The transaction amount is too small to send after the fee has been deducted");
3405 vector<CTxOut>::iterator position = txNew.
vout.begin()+nChangePosRet;
3406 txNew.
vout.insert(position, newTxOut);
3419 std::numeric_limits<unsigned int>::max()-1);
3420 txin.
prevPubKey = coin.first->vout[coin.second].scriptPubKey;
3421 txNew.
vin.push_back(txin);
3428 if (nChangePosRet != -1) {
3430 BOOST_FOREACH(
const CTxOut& txOut, txNew.
vout)
3432 if (txOut == newTxOut)
3444 BOOST_FOREACH(
const CTxIn& txin, txNew.
vin)
3448 CScript& scriptSigRes = txNew.
vin[nIn].scriptSig;
3456 strFailReason =
_(
"Signing transaction failed");
3466 BOOST_FOREACH (
CTxIn& txin, txNew.
vin)
3476 strFailReason =
_(
"Transaction too large");
3488 if (dPriority >= dPriorityNeeded &&
AllowFree(dPriority))
3496 if (coinControl && nFeeNeeded > 0 && coinControl->
nMinimumTotalFee > nFeeNeeded) {
3499 if(fUseInstantSend) {
3500 nFeeNeeded = std::max(nFeeNeeded,
CTxLockRequest(txNew).GetMinFee());
3507 strFailReason =
_(
"Transaction too large for fee policy");
3511 if (nFeeRet >= nFeeNeeded)
3515 nFeeRet = nFeeNeeded;
3543 AddToWallet(wtxNew,
false, pwalletdb);
3546 set<uint256> updated_hahes;
3547 BOOST_FOREACH(
const CTxIn& txin, wtxNew.
vin)
3550 if(updated_hahes.find(txin.
prevout.
hash) != updated_hahes.end())
continue;
3562 mapRequestCount[wtxNew.
GetHash()] = 0;
3564 if (fBroadcastTransactions)
3570 LogPrintf(
"CommitTransaction(): Error: Transaction not valid\n");
3584 laccentries.push_back(acentry);
3601 if (nFeeNeeded == 0) {
3602 int estimateFoundTarget = nConfirmTarget;
3605 if (nFeeNeeded == 0)
3606 nFeeNeeded = fallbackFee.GetFee(nTxBytes);
3609 nFeeNeeded = std::max(nFeeNeeded, GetRequiredFee(nTxBytes));
3620 fFirstRunRet =
false;
3627 setInternalKeyPool.clear();
3628 setExternalKeyPool.clear();
3629 nKeysLeftSinceAutoBackup = 0;
3638 for (
auto& pair : mapWallet) {
3639 for(
int i = 0; i < pair.second.vout.size(); ++i) {
3640 if (
IsMine(pair.second.vout[i]) && !IsSpent(pair.first, i)) {
3641 setWalletUTXO.insert(
COutPoint(pair.first, i));
3648 return nLoadWalletRet;
3649 fFirstRunRet = !vchDefaultKey.IsValid();
3667 setInternalKeyPool.clear();
3668 setExternalKeyPool.clear();
3669 nKeysLeftSinceAutoBackup = 0;
3677 return nZapWalletTxRet;
3685 bool fUpdated =
false;
3688 std::map<CTxDestination, CAddressBookData>::iterator mi = mapAddressBook.find(address);
3689 fUpdated = mi != mapAddressBook.end();
3690 mapAddressBook[address].name = strName;
3691 if (!strPurpose.empty())
3692 mapAddressBook[address].purpose = strPurpose;
3712 BOOST_FOREACH(
const PAIRTYPE(
string,
string) &item, mapAddressBook[address].destdata)
3717 mapAddressBook.erase(address);
3732 if (!
CWalletDB(strWalletFile).WriteDefaultKey(vchPubKey))
3735 vchDefaultKey = vchPubKey;
3748 BOOST_FOREACH(int64_t nIndex, setInternalKeyPool) {
3751 setInternalKeyPool.clear();
3752 BOOST_FOREACH(int64_t nIndex, setExternalKeyPool) {
3755 setExternalKeyPool.clear();
3757 nKeysLeftSinceAutoBackup = 0;
3759 if (!TopUpKeyPool())
3762 LogPrintf(
"CWallet::NewKeyPool rewrote keypool\n");
3770 return setExternalKeyPool.size();
3776 return setInternalKeyPool.size();
3788 unsigned int nTargetSize;
3790 nTargetSize = kpSize;
3796 int64_t amountExternal = setExternalKeyPool.size();
3797 int64_t amountInternal = setInternalKeyPool.size();
3798 int64_t missingExternal = std::max(std::max((int64_t) nTargetSize, (int64_t) 1) - amountExternal, (int64_t) 0);
3799 int64_t missingInternal = std::max(std::max((int64_t) nTargetSize, (int64_t) 1) - amountInternal, (int64_t) 0);
3804 missingInternal = 0;
3808 bool fInternal =
false;
3810 for (int64_t i = missingInternal + missingExternal; i--;)
3813 if (i < missingInternal) {
3816 if (!setInternalKeyPool.empty()) {
3817 nEnd = *(--setInternalKeyPool.end()) + 1;
3819 if (!setExternalKeyPool.empty()) {
3820 nEnd = std::max(nEnd, *(--setExternalKeyPool.end()) + 1);
3823 if (!walletdb.
WritePool(nEnd,
CKeyPool(GenerateNewKey(0, fInternal), fInternal)))
3824 throw runtime_error(
"TopUpKeyPool(): writing generated key failed");
3827 setInternalKeyPool.insert(nEnd);
3829 setExternalKeyPool.insert(nEnd);
3831 LogPrintf(
"keypool added key %d, size=%u, internal=%d\n", nEnd, setInternalKeyPool.size() + setExternalKeyPool.size(), fInternal);
3833 double dProgress = 100.f * nEnd / (nTargetSize + 1);
3834 std::string strMsg =
strprintf(
_(
"Loading wallet... (%3.2f %%)"), dProgress);
3848 if (!IsLocked(
true))
3851 fInternal = fInternal && IsHDEnabled();
3852 std::set<int64_t>& setKeyPool = fInternal ? setInternalKeyPool : setExternalKeyPool;
3855 if(setKeyPool.empty())
3860 nIndex = *setKeyPool.begin();
3861 setKeyPool.erase(nIndex);
3863 throw std::runtime_error(std::string(__func__) +
": read failed");
3865 if (!HaveKey(
keypool.vchPubKey.GetID())) {
3866 throw std::runtime_error(std::string(__func__) +
": unknown key in key pool");
3868 if (
keypool.fInternal != fInternal) {
3869 throw std::runtime_error(std::string(__func__) +
": keypool entry misclassified");
3872 assert(
keypool.vchPubKey.IsValid());
3873 LogPrintf(
"keypool reserve %d\n", nIndex);
3884 nKeysLeftSinceAutoBackup =
nWalletBackups ? nKeysLeftSinceAutoBackup - 1 : 0;
3895 setInternalKeyPool.insert(nIndex);
3897 setExternalKeyPool.insert(nIndex);
3900 LogPrintf(
"keypool return %d\n", nIndex);
3909 ReserveKeyFromKeyPool(nIndex,
keypool, fInternal);
3912 if (IsLocked(
true))
return false;
3914 result = GenerateNewKey(0, fInternal);
3925 int64_t nIndex = *(setKeyPool.begin());
3927 throw std::runtime_error(std::string(__func__) +
": read oldest key in keypool failed");
3929 assert(
keypool.vchPubKey.IsValid());
3938 if (setExternalKeyPool.empty() && setInternalKeyPool.empty())
3942 int64_t oldestKey = -1;
3945 if (!setInternalKeyPool.empty()) {
3948 if (!setExternalKeyPool.empty()) {
3956 map<CTxDestination, CAmount> balances;
3974 for (
unsigned int i = 0; i < pcoin->
vout.size(); i++)
3982 CAmount n = IsSpent(walletEntry.first, i) ? 0 : pcoin->
vout[i].nValue;
3984 if (!balances.count(addr))
3986 balances[addr] +=
n;
3997 set< set<CTxDestination> > groupings;
3998 set<CTxDestination> grouping;
4004 if (pcoin->
vin.size() > 0)
4006 bool any_mine =
false;
4008 BOOST_FOREACH(
CTxIn txin, pcoin->
vin)
4015 grouping.insert(address);
4023 if (IsChange(txout))
4028 grouping.insert(txoutAddr);
4031 if (grouping.size() > 0)
4033 groupings.insert(grouping);
4039 for (
unsigned int i = 0; i < pcoin->
vout.size(); i++)
4045 grouping.insert(address);
4046 groupings.insert(grouping);
4051 set< set<CTxDestination>* > uniqueGroupings;
4052 map< CTxDestination, set<CTxDestination>* > setmap;
4053 BOOST_FOREACH(set<CTxDestination> grouping, groupings)
4056 set< set<CTxDestination>* > hits;
4057 map< CTxDestination, set<CTxDestination>* >::iterator it;
4059 if ((it = setmap.find(address)) != setmap.end())
4060 hits.insert((*it).second);
4063 set<CTxDestination>* merged =
new set<CTxDestination>(grouping);
4064 BOOST_FOREACH(set<CTxDestination>* hit, hits)
4066 merged->insert(hit->begin(), hit->end());
4067 uniqueGroupings.erase(hit);
4070 uniqueGroupings.insert(merged);
4074 setmap[element] = merged;
4077 set< set<CTxDestination> > ret;
4078 BOOST_FOREACH(set<CTxDestination>* uniqueGrouping, uniqueGroupings)
4080 ret.insert(*uniqueGrouping);
4081 delete uniqueGrouping;
4090 set<CTxDestination>
result;
4094 const string& strName = item.second.
name;
4095 if (strName == strAccount)
4106 pwallet->ReserveKeyFromKeyPool(nIndex,
keypool, fInternalIn);
4108 vchPubKey =
keypool.vchPubKey;
4113 fInternal =
keypool.fInternal;
4115 assert(vchPubKey.IsValid());
4123 pwallet->KeepKey(nIndex);
4132 pwallet->ReturnKey(nIndex, fInternal);
4140 BOOST_FOREACH(
const int64_t&
id, setKeyPool)
4144 throw runtime_error(
"GetAllReserveKeyHashes(): read failed");
4145 assert(
keypool.vchPubKey.IsValid());
4147 setAddress.insert(keyID);
4161 BOOST_FOREACH (
const CKeyID& keyID, setAddress) {
4162 if (!HaveKey(keyID)) {
4163 throw std::runtime_error(std::string(__func__) +
": unknown key in key pool");
4173 map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(hashTx);
4174 if (mi != mapWallet.end()){
4184 boost::shared_ptr<CReserveKey> rKey(
new CReserveKey(
this));
4186 if (!rKey->GetReservedKey(pubkey,
false))
4196 setLockedCoins.insert(output);
4197 std::map<uint256, CWalletTx>::iterator it = mapWallet.find(output.
hash);
4198 if (it != mapWallet.end()) it->second.MarkDirty();
4200 fAnonymizableTallyCached =
false;
4201 fAnonymizableTallyCachedNonDenom =
false;
4207 setLockedCoins.erase(output);
4208 std::map<uint256, CWalletTx>::iterator it = mapWallet.find(output.
hash);
4209 if (it != mapWallet.end()) it->second.MarkDirty();
4211 fAnonymizableTallyCached =
false;
4212 fAnonymizableTallyCachedNonDenom =
false;
4218 setLockedCoins.clear();
4226 return (setLockedCoins.count(outpt) > 0);
4232 for (std::set<COutPoint>::iterator it = setLockedCoins.begin();
4233 it != setLockedCoins.end(); it++) {
4235 vOutpts.push_back(outpt);
4251 std::vector<CTxDestination> vDest;
4255 boost::apply_visitor(*
this, dest);
4261 vKeys.push_back(keyId);
4275 mapKeyBirth.clear();
4278 for (std::map<CKeyID, CKeyMetadata>::const_iterator it = mapKeyMetadata.begin(); it != mapKeyMetadata.end(); it++)
4279 if (it->second.nCreateTime)
4280 mapKeyBirth[it->first] = it->second.nCreateTime;
4284 std::map<CKeyID, CBlockIndex*> mapKeyFirstBlock;
4285 std::set<CKeyID> setKeys;
4287 BOOST_FOREACH(
const CKeyID &keyid, setKeys) {
4288 if (mapKeyBirth.count(keyid) == 0)
4289 mapKeyFirstBlock[keyid] = pindexMax;
4294 if (mapKeyFirstBlock.empty())
4298 std::vector<CKeyID> vAffected;
4299 for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); it++) {
4305 int nHeight = blit->second->nHeight;
4306 BOOST_FOREACH(
const CTxOut &txout, wtx.
vout) {
4309 BOOST_FOREACH(
const CKeyID &keyid, vAffected) {
4311 std::map<CKeyID, CBlockIndex*>::iterator rit = mapKeyFirstBlock.find(keyid);
4312 if (rit != mapKeyFirstBlock.end() && nHeight < rit->second->nHeight)
4313 rit->second = blit->second;
4321 for (std::map<CKeyID, CBlockIndex*>::const_iterator it = mapKeyFirstBlock.begin(); it != mapKeyFirstBlock.end(); it++)
4322 mapKeyBirth[it->first] = it->second->GetBlockTime() - 7200;
4327 if (boost::get<CNoDestination>(&dest))
4330 mapAddressBook[dest].destdata.insert(std::make_pair(
key, value));
4338 if (!mapAddressBook[dest].destdata.erase(
key))
4347 mapAddressBook[dest].destdata.insert(std::make_pair(
key, value));
4353 std::map<CTxDestination, CAddressBookData>::const_iterator i = mapAddressBook.find(dest);
4354 if(i != mapAddressBook.end())
4356 CAddressBookData::StringMap::const_iterator j = i->second.destdata.find(
key);
4357 if(j != i->second.destdata.end())
4376 vchPubKey = vchPubKeyIn;
4377 fInternal = fInternalIn;
4382 nTimeCreated = (nExpires ?
GetTime() : 0);
4383 nTimeExpires = nExpires;
4395 for (nIndex = 0; nIndex < (int)block.
vtx.size(); nIndex++)
4398 if (nIndex == (
int)block.
vtx.size())
4401 LogPrintf(
"ERROR: SetMerkleBranch(): couldn't find tx in block\n");
VerifyResult Verify(const std::string &strFile, bool(*recoverFunc)(CDBEnv &dbenv, const std::string &strFile))
const boost::filesystem::path & GetDataDir(bool fNetSpecific)
bool ErasePurpose(const std::string &strAddress)
static CAmount GetMaxCollateralAmount()
CAmount GetCredit(const isminefilter &filter) const
void ClearSkippedDenominations()
std::vector< unsigned char > vchSalt
CTxDestination destChange
static const int INSTANTSEND_CONFIRMATIONS_REQUIRED
int CountInputsWithAmount(CAmount nInputAmount)
void KeepKey(int64_t nIndex)
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE
Default for -spendzeroconfchange.
bool WriteCScript(const uint160 &hash, const CScript &redeemScript)
bool fAllowWatchOnly
Includes watch only addresses which match the ISMINE_WATCH_SOLVABLE criteria.
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
void ReturnKey(int64_t nIndex, bool fInternal)
CAmount GetAnonymizedBalance() const
static const unsigned int DEFAULT_TX_CONFIRM_TARGET
-txconfirmtarget default
bool HaveKey(const CKeyID &address) const
Check whether a key corresponding to a given address is present in the store.
bool IsFromMe(const CTransaction &tx) const
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
void SetBestChain(const CBlockLocator &loc)
std::set< CTxDestination > GetAccountAddresses(const std::string &strAccount) const
boost::signals2::signal< void(const std::string &message)> InitMessage
bool AddAccountingEntry(const CAccountingEntry &, CWalletDB &pwalletdb)
void RelayTransaction(const CTransaction &tx)
const unsigned int WALLET_CRYPTO_KEY_SIZE
void operator()(const CKeyID &keyId)
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
std::set< uint256 > GetConflicts(const uint256 &txid) const
Get wallet transactions that conflict with given transaction (spend same outputs) ...
std::vector< CTxIn > vecTxIn
bool fSubtractFeeFromAmount
void operator()(const CScriptID &scriptId)
CWalletKey(int64_t nExpires=0)
bool IsSelected(const COutPoint &output) const
bool SelectCoinsDark(CAmount nValueMin, CAmount nValueMax, std::vector< CTxIn > &vecTxInRet, CAmount &nValueRet, int nPrivateSendRoundsMin, int nPrivateSendRoundsMax) const
bool GetCollateralTxIn(CTxIn &txinRet, CAmount &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, bool fUseInstantSend=false) const
void ReserveKeyFromKeyPool(int64_t &nIndex, CKeyPool &keypool, bool fInternal)
bool Encrypt(const CKeyingMaterial &vchPlaintext, std::vector< unsigned char > &vchCiphertext)
void GenerateNewHDChain()
bool WriteDestData(const std::string &address, const std::string &key, const std::string &value)
Write destination data key,value tuple to database.
static void NotifyTransactionChanged(TransactionTableModel *ttm, CWallet *wallet, const uint256 &hash, ChangeType status)
static const int SPORK_5_INSTANTSEND_MAX_VALUE
bool operator()(const pair< CAmount, pair< const CWalletTx *, unsigned int > > &t1, const pair< CAmount, pair< const CWalletTx *, unsigned int > > &t2) const
double ComputePriority(double dPriorityInputs, unsigned int nTxSize=0) const
bool IsFromMe(const isminefilter &filter) const
CAmount GetImmatureCredit(bool fUseCache=true) const
bool bSpendZeroConfChange
void RandAddSeedPerfmon()
CFeeRate estimateSmartFee(int nBlocks, int *answerFoundAtBlocks=NULL) const
static const CAmount COIN
bool AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value)
Adds a destination data tuple to the store, and saves it to disk.
bool AddToWallet(const CWalletTx &wtxIn, bool fFromLoadWallet, CWalletDB *pwalletdb)
CAmount GetUnconfirmedBalance() const
int64_t IncOrderPosNext(CWalletDB *pwalletdb=NULL)
bool GetOutpointAndKeysFromOutput(const COutput &out, COutPoint &outpointRet, CPubKey &pubKeyRet, CKey &keyRet)
Extract txin information and keys from output.
std::multimap< int64_t, TxPair > TxItems
bool AbandonTransaction(const uint256 &hashTx)
bool MoneyRange(const CAmount &nValue)
static void ShowProgress(ClientModel *clientmodel, const std::string &title, int nProgress)
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
Add a key to the store.
double estimateSmartPriority(int nBlocks, int *answerFoundAtBlocks=NULL) const
bool SelectCoinsByDenominations(int nDenom, CAmount nValueMin, CAmount nValueMax, std::vector< CTxIn > &vecTxInRet, std::vector< COutput > &vCoinsRet, CAmount &nValueRet, int nPrivateSendRoundsMin, int nPrivateSendRoundsMax)
isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest)
bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
Adds an encrypted key to the store, without saving it to disk (used by LoadWallet) ...
bool WriteHDPubKey(const CHDPubKey &hdPubKey, const CKeyMetadata &keyMeta)
bool IsSpent(const uint256 &hash, unsigned int n) const
bool operator()(const COutput &t1, const COutput &t2) const
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
bool VerifyPubKey(const CPubKey &vchPubKey) const
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
SecureVector GetSeed() const
CAmount GetImmatureWatchOnlyCredit(const bool &fUseCache=true) const
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
static const int COINBASE_MATURITY
bool Unlock(const SecureString &strWalletPassphrase, bool fForMixingOnly=false)
CAmount GetImmatureWatchOnlyBalance() const
std::string ToString() const
DBErrors ZapWalletTx(CWallet *pwallet, std::vector< CWalletTx > &vWtx)
static const uint256 ABANDON_HASH
bool SetKeyFromPassphrase(const SecureString &strKeyData, const std::vector< unsigned char > &chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod)
static CAmount GetCollateralAmount()
void Select(const COutPoint &output)
bool GetDecryptedHDChain(CHDChain &hdChainRet)
int GetRealOutpointPrivateSendRounds(const COutPoint &outpoint, int nRounds) const
bool HasCollateralInputs(bool fOnlyConfirmed=true) const
CAmount GetAvailableCredit(bool fUseCache=true) const
bool AcceptToMemoryPool(bool fLimitFree=true, bool fRejectAbsurdFee=true)
virtual bool AddWatchOnly(const CScript &dest)
Support for Watch-only addresses.
static CAmount GetSmallestDenomination()
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, vector< CTxDestination > &addressRet, int &nRequiredRet)
uint32_t nInternalChainCounter
const CWalletTx * GetWalletTx(const uint256 &hash) const
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransaction &tx, bool fLimitFree, bool *pfMissingInputs, bool fOverrideMempoolLimit, bool fRejectAbsurdFee, bool fDryRun)
bool IsHex(const string &str)
bool IsLockedCoin(uint256 hash, unsigned int n) const
std::set< uint256 > GetConflicts() const
void Flush(bool shutdown=false)
Flush wallet (bitdb flush)
CAmount GetChange(const CTxOut &txout) const
CAmount GetFee(size_t size) const
bool GetKey(const CKeyID &address, CKey &keyOut) const
uint160 Hash160(const T1 pbegin, const T1 pend)
std::pair< CWalletTx *, CAccountingEntry * > TxPair
bool AddToWalletIfInvolvingMe(const CTransaction &tx, const CBlock *pblock, bool fUpdate)
bool CommitTransaction(CWalletTx &wtxNew, CReserveKey &reservekey, CConnman *connman, std::string strCommand="tx")
CAmount GetNeedsToBeAnonymizedBalance(CAmount nMinBalance=0) const
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE
bool WriteCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret, const CKeyMetadata &keyMeta)
bool TopUpKeyPool(unsigned int kpSize=0)
static const unsigned int DEFAULT_KEYPOOL_SIZE
CAmount GetAnonymizableBalance(bool fSkipDenominated=false, bool fSkipUnconfirmed=true) const
static uint32_t insecure_rand(void)
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const =0
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
GetPubKey implementation that also checks the mapHdPubKeys.
bool SetHDChain(const CHDChain &chain)
bool WriteOrderPosNext(int64_t nOrderPosNext)
int SetMerkleBranch(const CBlock &block)
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
bool LoadCScript(const CScript &redeemScript)
static int64_t GetOldestKeyInPool(const std::set< int64_t > &setKeyPool, CWalletDB &walletdb)
bool DelAddressBook(const CTxDestination &address)
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
static void LoadReserveKeysToSet(std::set< CKeyID > &setAddress, const std::set< int64_t > &setKeyPool, CWalletDB &walletdb)
virtual bool RemoveWatchOnly(const CScript &dest)
CPrivKey GetPrivKey() const
static void ApproximateBestSubset(vector< pair< CAmount, pair< const CWalletTx *, unsigned int > > >vValue, const CAmount &nTotalLower, const CAmount &nTargetValue, vector< char > &vfBest, CAmount &nBest, int iterations=1000, bool fUseInstantSend=false)
unsigned int nTimeReceived
CAmount GetChange() const
void DeriveNewChildKey(const CKeyMetadata &metadata, CKey &secretRet, uint32_t nAccountIndex, bool fInternal)
void DeriveChildExtKey(uint32_t nAccountIndex, bool fInternal, uint32_t nChildIndex, CExtKey &extKeyRet)
std::vector< CTransaction > vtx
CAmount GetWatchOnlyBalance() const
std::string ToString() const
void ListSelected(std::vector< COutPoint > &vOutpoints) const
CAmount GetDenominatedCredit(bool unconfirmed, bool fUseCache=true) const
bool AddCScript(const CScript &redeemScript)
Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki.
bool GetKey(const CKeyID &address, CKey &keyOut) const
GetKey implementation that can derive a HD private key on the fly.
bool GetAccount(uint32_t nAccountIndex, CHDAccount &hdAccountRet)
bool Contains(const CBlockIndex *pindex) const
bool SelectCoins(const CAmount &nTargetValue, std::set< std::pair< const CWalletTx *, unsigned int > > &setCoinsRet, CAmount &nValueRet, const CCoinControl *coinControl=NULL, AvailableCoinsType nCoinType=ALL_COINS, bool fUseInstantSend=true) const
static const CAmount MIN_CHANGE
minimum change amount
bool UpdatedTransaction(const uint256 &hashTx)
bool SetMinVersion(enum WalletFeature, CWalletDB *pwalletdbIn=NULL, bool fExplicit=false)
signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVe...
static bool Rewrite(const std::string &strFile, const char *pszSkip=NULL)
bool exists(uint256 hash) const
bool IsChange(const CTxOut &txout) const
CPubKey GenerateNewKey(uint32_t nAccountIndex, bool fInternal)
#define AssertLockHeld(cs)
bool IsUnspendable() const
DBErrors LoadWallet(CWallet *pwallet)
DBErrors ZapWalletTx(std::vector< CWalletTx > &vWtx)
CAmount GetBalance() const
unsigned int nTxConfirmTarget
bool fSendFreeTransactions
size_t KeypoolCountInternalKeys()
bool GetKeyFromPool(CPubKey &key, bool fInternal)
bool GetBoolArg(const std::string &strArg, bool fDefault)
bool CreateTransaction(const std::vector< CRecipient > &vecSend, CWalletTx &wtxNew, CReserveKey &reservekey, CAmount &nFeeRet, int &nChangePosRet, std::string &strFailReason, const CCoinControl *coinControl=NULL, bool sign=true, AvailableCoinsType nCoinType=ALL_COINS, bool fUseInstantSend=false)
bool CheckFinalTx(const CTransaction &tx, int flags)
bool LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &metadata)
Load metadata (used by LoadWallet)
int64_t GetOldestKeyPoolTime()
boost::signals2::signal< void(CWallet *wallet)> LoadWallet
bool WritePool(int64_t nPool, const CKeyPool &keypool)
CExtPubKey Neuter() const
bool WriteCryptedHDChain(const CHDChain &chain)
unsigned int GetSerializeSize(char a, int, int=0)
bool AddWatchOnly(const CScript &dest)
Adds a watch-only address to the store, and saves it to disk.
bool SetHDChain(const CHDChain &chain, bool memonly)
void UnlockCoin(COutPoint &output)
bool RemoveWatchOnly(const CScript &dest)
static int LogPrint(const char *category, const char *format)
CAmount GetUnconfirmedWatchOnlyBalance() const
bool WriteBestBlock(const CBlockLocator &locator)
static bool Recover(CDBEnv &dbenv, const std::string &filename, bool fOnlyKeys)
static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE
Largest (in bytes) free transaction we're willing to create.
bool WriteTx(uint256 hash, const CWalletTx &wtx)
int64_t GetTxTime() const
bool fAllowOtherInputs
If false, allows unselected inputs, but requires all selected inputs be used.
CAmount nMinimumTotalFee
Minimum absolute fee (not per kilobyte)
CAmount GetCredit(const CTxOut &txout, const isminefilter &filter) const
bool SetMaxVersion(int nVersion)
change which version we're allowed to upgrade to (note that this does not immediately imply upgrading...
bool WriteMasterKey(unsigned int nID, const CMasterKey &kMasterKey)
unsigned int nDeriveIterations
bool HaveKey(const CKeyID &address) const
HaveKey implementation that also checks the mapHdPubKeys.
std::vector< unsigned char, secure_allocator< unsigned char > > SecureVector
uint256 uint256S(const char *str)
bool Open(const boost::filesystem::path &path)
uint32_t nExternalChainCounter
CClientUIInterface uiInterface
float GetAverageAnonymizedRounds() const
static CFeeRate fallbackFee
virtual bool AddCScript(const CScript &redeemScript)
Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki.
void Process(const CScript &script)
unsigned int nTimeSmart
time received by this node
bool GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const
Look up a destination data tuple in the store, return true if found false otherwise.
bool WriteName(const std::string &strAddress, const std::string &strName)
std::vector< uint256 > ResendWalletTransactionsBefore(int64_t nTime, CConnman *connman)
bool ConvertList(std::vector< CTxIn > vecTxIn, std::vector< CAmount > &vecAmounts)
static CAmount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool &pool)
static const CAmount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
vector< unsigned char > ParseHex(const char *psz)
void GetAllReserveKeys(std::set< CKeyID > &setAddress) const
bool AllowFree(double dPriority)
bool WriteKey(const CPubKey &vchPubKey, const CPrivKey &vchPrivKey, const CKeyMetadata &keyMeta)
CAmount GetDebit(const isminefilter &filter) const
filter decides which addresses will count towards the debit
std::vector< std::pair< std::string, std::string > > vOrderForm
bool IsLockedInstantSendTransaction(const uint256 &txHash)
static const CAmount DEFAULT_LEGACY_TRANSACTION_MINFEE
-mintxfee default
static const bool DEFAULT_SEND_FREE_TRANSACTIONS
Default for -sendfreetransactions.
std::string ToString() const
bool SetCryptedHDChain(const CHDChain &chain, bool memonly)
static bool GetDenominationsBits(int nDenom, std::vector< int > &vecBitsRet)
CScript GetScriptForDestination(const CTxDestination &dest)
static const CAmount DEFAULT_LEGACY_FALLBACK_FEE
-fallbackfee default
CAffectedKeysVisitor(const CKeyStore &keystoreIn, std::vector< CKeyID > &vKeysIn)
void GetAmounts(std::list< COutputEntry > &listReceived, std::list< COutputEntry > &listSent, CAmount &nFee, std::string &strSentAccount, const isminefilter &filter) const
CAmount GetDebit(const CTxIn &txin, const isminefilter &filter) const
bool LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value)
Adds a destination data tuple to the store, without saving it to disk.
bool IsEquivalentTo(const CWalletTx &tx) const
std::string FormatMoney(const CAmount &n)
bool IsDenominatedAmount(CAmount nInputAmount) const
std::vector< unsigned char > vchCryptedKey
bool ErasePool(int64_t nPool)
void AddToSpends(const COutPoint &outpoint, const uint256 &wtxid)
bool WriteMinVersion(int nVersion)
double GuessVerificationProgress(const CCheckpointData &data, CBlockIndex *pindex, bool fSigchecks)
Guess how far we are in the verification process at the given block index.
void MarkConflicted(const uint256 &hashBlock, const uint256 &hashTx)
DBErrors LoadWallet(bool &fFirstRunRet)
bool CreateCollateralTransaction(CMutableTransaction &txCollateral, std::string &strReason)
const CCheckpointData & Checkpoints() const
bool Decrypt(const std::vector< unsigned char > &vchCiphertext, CKeyingMaterial &vchPlaintext)
std::vector< CTxOut > vout
bool EraseDestData(const CTxDestination &dest, const std::string &key)
Erases a destination data tuple in the store and on disk.
bool SelectCoinsGrouppedByAddresses(std::vector< CompactTallyItem > &vecTallyRet, bool fSkipDenominated=true, bool fAnonymizable=true, bool fSkipUnconfirmed=true) const
static void NotifyAddressBookChanged(WalletModel *walletmodel, CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)
CSporkManager sporkManager
std::string strFromAccount
size_t KeypoolCountExternalKeys()
bool AddHDPubKey(const CExtPubKey &extPubKey, bool fInternal)
Adds a HDPubKey into the wallet(database)
void seed_insecure_rand(bool fDeterministic)
CPrivateSendClient privateSendClient
const unsigned int WALLET_CRYPTO_SALT_SIZE
bool GetReservedKey(CPubKey &pubkey, bool fInternalIn)
unsigned int nDerivationMethod
const std::vector< CTxIn > vin
const char * TXLOCKREQUEST
int ScanForWalletTransactions(CBlockIndex *pindexStart, bool fUpdate=false)
static vector< COutput > vCoins
bool IsCollateralAmount(CAmount nInputAmount) const
bool IsDust(const CFeeRate &minRelayTxFee) const
void Flush(bool fShutdown)
int GetOutpointPrivateSendRounds(const COutPoint &outpoint) const
std::vector< CKeyID > & vKeys
bool GetBudgetSystemCollateralTX(CTransaction &tx, uint256 hash, CAmount amount, bool fUseInstantSend)
bool WriteAccountingEntry_Backend(const CAccountingEntry &acentry)
bool EncryptWallet(const SecureString &strWalletPassphrase)
isminetype IsMine(const CTxIn &txin) const
void MarkDirty()
make sure balances are recalculated
void GetScriptForMining(boost::shared_ptr< CReserveScript > &script)
static bool Verify(const std::string &walletFile, std::string &warningString, std::string &errorString)
Verify the wallet database and perform salvage if required.
static std::vector< CAmount > GetStandardDenominations()
CBlockIndex * Next(const CBlockIndex *pindex) const
const CChainParams & Params()
void updatePassphrase(const SecureString &sWalletPassphrase)
CKeePassIntegrator keePassInt
void ResendWalletTransactions(int64_t nBestBlockTime, CConnman *connman)
static CAmount GetMaxPoolAmount()
bool Unlock(const CKeyingMaterial &vMasterKeyIn, bool fForMixingOnly=false)
bool EraseName(const std::string &strAddress)
CAmount GetDenominatedBalance(bool unconfirmed=false) const
static const int PROTOCOL_VERSION
const uint256 & GetHash() const
CAmount GetMinFee() const
const CKeyStore & keystore
bool ProcessTxLockRequest(const CTxLockRequest &txLockRequest, CConnman &connman)
int64_t GetAdjustedTime()
void runCommand(const std::string &strCommand)
void GetAccountAmounts(const std::string &strAccount, CAmount &nReceived, CAmount &nSent, CAmount &nFee, const isminefilter &filter) const
std::string ToString() const
bool operator()(const CompactTallyItem &t1, const CompactTallyItem &t2) const
void ReacceptWalletTransactions()
virtual bool HaveKey(const CKeyID &address) const =0
Check whether a key corresponding to a given address is present in the store.
std::string GetHex() const
bool ReadPool(int64_t nPool, CKeyPool &keypool)
bool LogAcceptCategory(const char *category)
std::map< CTxDestination, CAmount > GetAddressBalances()
Indicates that we know how to create a scriptSig that would solve this if we were given the appropria...
CPubKey GetPubKey() const
unsigned int fTimeReceivedIsTxTime
void operator()(const CNoDestination &none)
const std::vector< CTxOut > vout
void GetRandBytes(unsigned char *buf, int num)
CFeeRate payTxFee(DEFAULT_TRANSACTION_FEE)
virtual bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
bool GetKeyID(CKeyID &keyID) const
bool FundTransaction(CMutableTransaction &tx, CAmount &nFeeRet, int &nChangePosRet, std::string &strFailReason, bool includeWatching)
bool ProduceSignature(const BaseSignatureCreator &creator, const CScript &fromPubKey, CScript &scriptSig)
CBlockIndex * Tip() const
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
bool IsDenominated(const COutPoint &outpoint) const
bool WriteWatchOnly(const CScript &script)
bool GetMasternodeOutpointAndKeys(COutPoint &outpointRet, CPubKey &pubKeyRet, CKey &keyRet, std::string strTxHash="", std::string strOutputIndex="")
Get 1000DASH output and keys which can be used for the Masternode.
SecureString retrievePassphrase()
CTxDestination destination
static CAmount GetRequiredFee(unsigned int nTxBytes)
bool LoadWatchOnly(const CScript &dest)
Adds a watch-only address to the store, without saving it to disk (used by LoadWallet) ...
static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly)
int64_t GetBlockTime() const
bool WriteToDisk(CWalletDB *pwalletdb)
std::string GetArg(const std::string &strArg, const std::string &strDefault)
static const CAmount DEFAULT_TRANSACTION_FEE
-paytxfee default
bool EraseDestData(const std::string &address, const std::string &key)
Erase destination data tuple from wallet database.
bool LoadHDPubKey(const CHDPubKey &hdPubKey)
loads a HDPubKey into the wallets memory
int64_t GetTime()
For unit testing.
static const unsigned int LOCKTIME_THRESHOLD
bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
Adds an encrypted key to the store, and saves it to disk.
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos, const Consensus::Params &consensusParams)
void LockCoin(COutPoint &output)
void BindWallet(CWallet *pwalletIn)
bool SetMnemonic(const SecureVector &vchMnemonic, const SecureVector &vchMnemonicPassphrase, bool fUpdateID)
int64_t GetSporkValue(int nSporkID)
bool SetAccount(uint32_t nAccountIndex, const CHDAccount &hdAccount)
bool SetSeed(const SecureVector &vchSeedIn, bool fUpdateID)
bool SetCryptedHDChain(const CHDChain &chain)
void ListLockedCoins(std::vector< COutPoint > &vOutpts)
int nHeight
height of the entry in the chain. The genesis block has height 0
CAmount GetImmatureBalance() const
bool SignSignature(const CKeyStore &keystore, const CScript &fromPubKey, CMutableTransaction &txTo, unsigned int nIn, int nHashType)
void SyncMetaData(std::pair< TxSpends::iterator, TxSpends::iterator >)
int GetBlocksToMaturity() const
bool WritePurpose(const std::string &strAddress, const std::string &purpose)
int GetDepthInMainChain(const CBlockIndex *&pindexRet, bool enableIX=true) const
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
bool less_then_denom(const COutput &out1, const COutput &out2)
bool RelayWalletTransaction(CConnman *connman, std::string strCommand="tx")
CAmount GetAnonymizedCredit(bool fUseCache=true) const
void GetKeyBirthTimes(std::map< CKeyID, int64_t > &mapKeyBirth) const
bool SetDefaultKey(const CPubKey &vchPubKey)
std::string _(const char *psz)
CAmount GetNormalizedAnonymizedBalance() const
int atoi(const std::string &str)
CAmount GetDustThreshold(const CFeeRate &minRelayTxFee) const
map< string, string > mapArgs
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
Adds a key to the store, and saves it to disk.
CAmount GetAvailableWatchOnlyCredit(const bool &fUseCache=true) const
uint64_t GetRand(uint64_t nMax)
std::set< std::set< CTxDestination > > GetAddressGroupings()
int GetRequestCount() const
void SyncTransaction(const CTransaction &tx, const CBlock *pblock)
std::vector< unsigned char > ToByteVector(const T &in)
void Debug(std::string strName) const
void AvailableCoins(std::vector< COutput > &vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL, bool fIncludeZeroValue=false, AvailableCoinsType nCoinType=ALL_COINS, bool fUseInstantSend=false) const
static const unsigned int MAX_STANDARD_TX_SIZE