13 #include <boost/algorithm/string/replace.hpp>
14 #include <openssl/rand.h>
29 bool operator()(
const pair<int64_t, pair<const CWalletTx*, unsigned int> >& t1,
30 const pair<int64_t, pair<const CWalletTx*, unsigned int> >& t2)
const
32 return t1.first < t2.first;
39 std::map<uint256, CWalletTx>::const_iterator it = mapWallet.find(hash);
40 if (it == mapWallet.end())
61 int64_t nCreationTime =
GetTime();
63 if (!nTimeFirstKey || nCreationTime < nTimeFirstKey)
64 nTimeFirstKey = nCreationTime;
66 if (!AddKeyPubKey(secret, pubkey))
67 throw std::runtime_error(
"CWallet::GenerateNewKey() : AddKey failed");
81 mapKeyMetadata[pubkey.
GetID()]);
87 const vector<unsigned char> &vchCryptedSecret)
95 if (pwalletdbEncryption)
96 return pwalletdbEncryption->WriteCryptedKey(vchPubKey,
98 mapKeyMetadata[vchPubKey.
GetID()]);
102 mapKeyMetadata[vchPubKey.
GetID()]);
113 mapKeyMetadata[pubkey.
GetID()] = meta;
139 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",
154 BOOST_FOREACH(
const MasterKeyMap::value_type& pMasterKey, mapMasterKeys)
156 if(!crypter.
SetKeyFromPassphrase(strWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
158 if (!crypter.
Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey))
169 bool fWasLocked = IsLocked();
177 BOOST_FOREACH(MasterKeyMap::value_type& pMasterKey, mapMasterKeys)
179 if(!crypter.
SetKeyFromPassphrase(strOldWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
181 if (!crypter.
Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey))
186 crypter.
SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod);
187 pMasterKey.second.nDeriveIterations = pMasterKey.second.nDeriveIterations * (100 / ((double)(
GetTimeMillis() - nStartTime)));
190 crypter.
SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod);
191 pMasterKey.second.nDeriveIterations = (pMasterKey.second.nDeriveIterations + pMasterKey.second.nDeriveIterations * 100 / ((double)(
GetTimeMillis() - nStartTime))) / 2;
193 if (pMasterKey.second.nDeriveIterations < 25000)
194 pMasterKey.second.nDeriveIterations = 25000;
196 LogPrintf(
"Wallet passphrase changed to an nDeriveIterations of %i\n", pMasterKey.second.nDeriveIterations);
198 if (!crypter.
SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
200 if (!crypter.
Encrypt(vMasterKey, pMasterKey.second.vchCryptedKey))
222 if (nWalletVersion >= nVersion)
226 if (fExplicit && nVersion > nWalletMaxVersion)
229 nWalletVersion = nVersion;
231 if (nVersion > nWalletMaxVersion)
232 nWalletMaxVersion = nVersion;
237 if (nWalletVersion > 40000)
250 if (nWalletVersion > nVersion)
253 nWalletMaxVersion = nVersion;
263 std::map<uint256, CWalletTx>::const_iterator it = mapWallet.find(txid);
264 if (it == mapWallet.end())
268 std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range;
270 BOOST_FOREACH(
const CTxIn& txin, wtx.
vin)
272 if (mapTxSpends.count(txin.
prevout) <= 1)
274 range = mapTxSpends.equal_range(txin.
prevout);
275 for (TxSpends::const_iterator it = range.first; it != range.second; ++it)
276 result.insert(it->second);
287 int nMinOrderPos = std::numeric_limits<int>::max();
289 for (TxSpends::iterator it = range.first; it != range.second; ++it)
291 const uint256& hash = it->second;
292 int n = mapWallet[hash].nOrderPos;
293 if (n < nMinOrderPos)
296 copyFrom = &mapWallet[hash];
300 for (TxSpends::iterator it = range.first; it != range.second; ++it)
302 const uint256& hash = it->second;
304 if (copyFrom == copyTo)
continue;
322 pair<TxSpends::const_iterator, TxSpends::const_iterator> range;
323 range = mapTxSpends.equal_range(outpoint);
325 for (TxSpends::const_iterator it = range.first; it != range.second; ++it)
327 const uint256& wtxid = it->second;
328 std::map<uint256, CWalletTx>::const_iterator mit = mapWallet.find(wtxid);
329 if (mit != mapWallet.end() && mit->second.GetDepthInMainChain() >= 0)
337 mapTxSpends.insert(make_pair(outpoint, wtxid));
339 pair<TxSpends::iterator, TxSpends::iterator> range;
340 range = mapTxSpends.equal_range(outpoint);
347 assert(mapWallet.count(wtxid));
349 if (thisTx.IsCoinBase())
352 BOOST_FOREACH(
const CTxIn& txin, thisTx.vin)
353 AddToSpends(txin.
prevout, wtxid);
394 mapMasterKeys[++nMasterKeyMaxID] = kMasterKey;
398 if (!pwalletdbEncryption->TxnBegin())
400 pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey);
403 if (!EncryptKeys(vMasterKey))
406 pwalletdbEncryption->TxnAbort();
415 if (!pwalletdbEncryption->TxnCommit())
418 delete pwalletdbEncryption;
419 pwalletdbEncryption = NULL;
423 Unlock(strWalletPassphrase);
432 NotifyStatusChanged(
this);
440 int64_t nRet = nOrderPosNext++;
459 for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
479 item.second.MarkDirty();
489 mapWallet[hash] = wtxIn;
497 pair<map<uint256, CWalletTx>::iterator,
bool> ret = mapWallet.insert(make_pair(hash, wtxIn));
500 bool fInsertedNew = ret.second;
512 unsigned int latestEntry = 0;
515 int64_t latestTolerated = latestNow + 300;
516 std::list<CAccountingEntry> acentries;
517 TxItems txOrdered = OrderedTxItems(acentries);
518 for (TxItems::reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
520 CWalletTx *
const pwtx = (*it).second.first;
532 nSmartTime = pacentry->
nTime;
533 if (nSmartTime <= latestTolerated)
535 latestEntry = nSmartTime;
536 if (nSmartTime > latestNow)
537 latestNow = nSmartTime;
544 wtx.
nTimeSmart = std::max(latestEntry, std::min(blocktime, latestNow));
547 LogPrintf(
"AddToWallet() : found %s in block %s not in index\n",
554 bool fUpdated =
false;
577 LogPrintf(
"AddToWallet %s %s%s\n", wtxIn.
GetHash().
ToString(), (fInsertedNew ?
"new" :
""), (fUpdated ?
"update" :
""));
580 if (fInsertedNew || fUpdated)
591 std::string strCmd =
GetArg(
"-walletnotify",
"");
593 if ( !strCmd.empty())
610 bool fExisted = mapWallet.count(hash);
611 if (fExisted && !fUpdate)
return false;
612 if (fExisted ||
IsMine(tx) || IsFromMe(tx))
617 wtx.SetMerkleBranch(pblock);
618 return AddToWallet(wtx);
627 if (!AddToWalletIfInvolvingMe(hash, tx, pblock,
true))
633 BOOST_FOREACH(
const CTxIn& txin, tx.
vin)
646 if (mapWallet.erase(hash))
657 map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(txin.
prevout.
hash);
658 if (mi != mapWallet.end())
673 map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(txin.
prevout.
hash);
674 if (mi != mapWallet.end())
699 if (!mapAddressBook.count(address))
707 int64_t n = nTimeSmart;
708 return n ? n : nTimeReceived;
716 LOCK(pwallet->cs_wallet);
722 map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(hashBlock);
723 if (mi != pwallet->mapRequestCount.end())
724 nRequests = (*mi).second;
730 map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(GetHash());
731 if (mi != pwallet->mapRequestCount.end())
733 nRequests = (*mi).second;
736 if (nRequests == 0 && hashBlock != 0)
738 map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(hashBlock);
739 if (mi != pwallet->mapRequestCount.end())
740 nRequests = (*mi).second;
751 list<pair<CTxDestination, int64_t> >& listSent, int64_t& nFee,
string& strSentAccount)
const
754 listReceived.clear();
756 strSentAccount = strFromAccount;
759 int64_t nDebit = GetDebit();
762 int64_t nValueOut = GetValueOut();
763 nFee = nDebit - nValueOut;
767 BOOST_FOREACH(
const CTxOut& txout, vout)
776 if (pwallet->IsChange(txout))
778 fIsMine = pwallet->IsMine(txout);
780 else if (!(fIsMine = pwallet->IsMine(txout)))
787 LogPrintf(
"CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n",
788 this->GetHash().ToString());
794 listSent.push_back(make_pair(address, txout.
nValue));
798 listReceived.push_back(make_pair(address, txout.
nValue));
804 int64_t& nSent, int64_t& nFee)
const
806 nReceived = nSent = nFee = 0;
809 string strSentAccount;
810 list<pair<CTxDestination, int64_t> > listReceived;
811 list<pair<CTxDestination, int64_t> > listSent;
812 GetAmounts(listReceived, listSent, allFee, strSentAccount);
814 if (strAccount == strSentAccount)
821 LOCK(pwallet->cs_wallet);
824 if (pwallet->mapAddressBook.count(r.first))
826 map<CTxDestination, CAddressBookData>::const_iterator mi = pwallet->mapAddressBook.find(r.first);
827 if (mi != pwallet->mapAddressBook.end() && (*mi).second.name == strAccount)
828 nReceived += r.second;
830 else if (strAccount.empty())
832 nReceived += r.second;
858 while (pindex && nTimeFirstKey && (pindex->
nTime < (nTimeFirstKey - 7200)))
866 if (pindex->
nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0)
873 if (AddToWalletIfInvolvingMe(tx.
GetHash(), tx, &block, fUpdate))
892 const uint256& wtxid = item.first;
894 assert(wtx.
GetHash() == wtxid);
911 if (GetDepthInMainChain() == 0) {
925 result = pwallet->GetConflicts(myHash);
926 result.erase(myHash);
937 bool fFirst = (nNextResend == 0);
948 LogPrintf(
"ResendWalletTransactions()\n");
952 multimap<unsigned int, CWalletTx*> mapSorted;
985 for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
1001 for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
1016 for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
1032 for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
1034 const uint256& wtxid = it->first;
1040 if (fOnlyConfirmed && !pcoin->
IsTrusted())
1050 for (
unsigned int i = 0; i < pcoin->
vout.size(); i++) {
1051 if (!(IsSpent(wtxid, i)) &&
IsMine(pcoin->
vout[i]) &&
1052 !IsLockedCoin((*it).first, i) && pcoin->
vout[i].nValue > 0 &&
1054 vCoins.push_back(
COutput(pcoin, i, nDepth));
1060 static void ApproximateBestSubset(vector<pair<int64_t, pair<const CWalletTx*,unsigned int> > >vValue, int64_t nTotalLower, int64_t nTargetValue,
1061 vector<char>& vfBest, int64_t& nBest,
int iterations = 1000)
1063 vector<char> vfIncluded;
1065 vfBest.assign(vValue.size(),
true);
1066 nBest = nTotalLower;
1070 for (
int nRep = 0; nRep < iterations && nBest != nTargetValue; nRep++)
1072 vfIncluded.assign(vValue.size(),
false);
1074 bool fReachedTarget =
false;
1075 for (
int nPass = 0; nPass < 2 && !fReachedTarget; nPass++)
1077 for (
unsigned int i = 0; i < vValue.size(); i++)
1087 nTotal += vValue[i].first;
1088 vfIncluded[i] =
true;
1089 if (nTotal >= nTargetValue)
1091 fReachedTarget =
true;
1095 vfBest = vfIncluded;
1097 nTotal -= vValue[i].first;
1098 vfIncluded[i] =
false;
1107 set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet)
const
1109 setCoinsRet.clear();
1113 pair<int64_t, pair<const CWalletTx*,unsigned int> > coinLowestLarger;
1114 coinLowestLarger.first = std::numeric_limits<int64_t>::max();
1115 coinLowestLarger.second.first = NULL;
1116 vector<pair<int64_t, pair<const CWalletTx*,unsigned int> > > vValue;
1117 int64_t nTotalLower = 0;
1119 random_shuffle(vCoins.begin(), vCoins.end(),
GetRandInt);
1121 BOOST_FOREACH(
COutput output, vCoins)
1125 if (output.
nDepth < (pcoin->
IsFromMe() ? nConfMine : nConfTheirs))
1129 int64_t n = pcoin->
vout[i].nValue;
1131 pair<int64_t,pair<const CWalletTx*,unsigned int> > coin = make_pair(n,make_pair(pcoin, i));
1133 if (n == nTargetValue)
1135 setCoinsRet.insert(coin.second);
1136 nValueRet += coin.first;
1139 else if (n < nTargetValue +
CENT)
1141 vValue.push_back(coin);
1144 else if (n < coinLowestLarger.first)
1146 coinLowestLarger = coin;
1150 if (nTotalLower == nTargetValue)
1152 for (
unsigned int i = 0; i < vValue.size(); ++i)
1154 setCoinsRet.insert(vValue[i].second);
1155 nValueRet += vValue[i].first;
1160 if (nTotalLower < nTargetValue)
1162 if (coinLowestLarger.second.first == NULL)
1164 setCoinsRet.insert(coinLowestLarger.second);
1165 nValueRet += coinLowestLarger.first;
1171 vector<char> vfBest;
1175 if (nBest != nTargetValue && nTotalLower >= nTargetValue +
CENT)
1180 if (coinLowestLarger.second.first &&
1181 ((nBest != nTargetValue && nBest < nTargetValue +
CENT) || coinLowestLarger.first <= nBest))
1183 setCoinsRet.insert(coinLowestLarger.second);
1184 nValueRet += coinLowestLarger.first;
1187 for (
unsigned int i = 0; i < vValue.size(); i++)
1190 setCoinsRet.insert(vValue[i].second);
1191 nValueRet += vValue[i].first;
1194 LogPrint(
"selectcoins",
"SelectCoins() best subset: ");
1195 for (
unsigned int i = 0; i < vValue.size(); i++)
1206 vector<COutput> vCoins;
1207 AvailableCoins(vCoins,
true, coinControl);
1212 BOOST_FOREACH(
const COutput& out, vCoins)
1214 nValueRet += out.
tx->
vout[out.
i].nValue;
1215 setCoinsRet.insert(make_pair(out.
tx, out.
i));
1217 return (nValueRet >= nTargetValue);
1220 return (SelectCoinsMinConf(nTargetValue, 1, 6, vCoins, setCoinsRet, nValueRet) ||
1221 SelectCoinsMinConf(nTargetValue, 1, 1, vCoins, setCoinsRet, nValueRet) ||
1222 (
bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue, 0, 1, vCoins, setCoinsRet, nValueRet)));
1236 strFailReason =
_(
"Transaction amounts must be positive");
1241 if (vecSend.empty() || nValue < 0)
1243 strFailReason =
_(
"Transaction amounts must be positive");
1256 wtxNew.
vout.clear();
1259 int64_t nTotalValue = nValue + nFeeRet;
1260 double dPriority = 0;
1264 CTxOut txout(s.second, s.first);
1267 strFailReason =
_(
"Transaction amount too small");
1270 wtxNew.
vout.push_back(txout);
1274 set<pair<const CWalletTx*,unsigned int> > setCoins;
1275 int64_t nValueIn = 0;
1276 if (!SelectCoins(nTotalValue, setCoins, nValueIn, coinControl))
1278 strFailReason =
_(
"Insufficient funds");
1283 int64_t nCredit = pcoin.first->vout[pcoin.second].nValue;
1287 dPriority += (double)nCredit * (pcoin.first->GetDepthInMainChain()+1);
1290 int64_t nChange = nValueIn - nValue - nFeeRet;
1295 if (nFeeRet < CTransaction::nMinTxFee && nChange > 0 && nChange <
CENT)
1298 nChange -= nMoveToFee;
1299 nFeeRet += nMoveToFee;
1310 if (coinControl && !boost::get<CNoDestination>(&coinControl->
destChange))
1332 CTxOut newTxOut(nChange, scriptChange);
1344 vector<CTxOut>::iterator position = wtxNew.
vout.begin()+
GetRandInt(wtxNew.
vout.size()+1);
1345 wtxNew.
vout.insert(position, newTxOut);
1353 wtxNew.vin.push_back(
CTxIn(coin.first->GetHash(),coin.second));
1360 strFailReason =
_(
"Signing transaction failed");
1368 strFailReason =
_(
"Transaction too large");
1377 if (nFeeRet < max(nPayFee, nMinFee))
1379 nFeeRet = max(nPayFee, nMinFee);
1395 vector< pair<CScript, int64_t> > vecSend;
1396 vecSend.push_back(make_pair(scriptPubKey, nValue));
1397 return CreateTransaction(vecSend, wtxNew, reservekey, nFeeRet, strFailReason, coinControl);
1417 AddToWallet(wtxNew);
1420 set<CWalletTx*> setCoins;
1421 BOOST_FOREACH(
const CTxIn& txin, wtxNew.
vin)
1433 mapRequestCount[wtxNew.
GetHash()] = 0;
1439 LogPrintf(
"CommitTransaction() : Error: Transaction not valid");
1453 int64_t nFeeRequired;
1457 string strError =
_(
"Error: Wallet locked, unable to create transaction!");
1458 LogPrintf(
"SendMoney() : %s", strError);
1462 if (!CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired, strError))
1464 if (nValue + nFeeRequired > GetBalance())
1465 strError =
strprintf(
_(
"Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds!"),
FormatMoney(nFeeRequired));
1466 LogPrintf(
"SendMoney() : %s\n", strError);
1470 if (!CommitTransaction(wtxNew, reservekey))
1471 return _(
"Error: The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here.");
1482 return _(
"Invalid amount");
1484 return _(
"Insufficient funds");
1490 return SendMoney(scriptPubKey, nValue, wtxNew);
1500 fFirstRunRet =
false;
1515 return nLoadWalletRet;
1516 fFirstRunRet = !vchDefaultKey.IsValid();
1542 return nZapWalletTxRet;
1550 bool fUpdated =
false;
1553 std::map<CTxDestination, CAddressBookData>::iterator mi = mapAddressBook.find(address);
1554 fUpdated = mi != mapAddressBook.end();
1555 mapAddressBook[address].name = strName;
1556 if (!strPurpose.empty())
1557 mapAddressBook[address].purpose = strPurpose;
1577 BOOST_FOREACH(
const PAIRTYPE(
string,
string) &item, mapAddressBook[address].destdata)
1582 mapAddressBook.erase(address);
1600 vchDefaultKey = vchPubKey;
1613 BOOST_FOREACH(int64_t nIndex, setKeyPool)
1620 int64_t nKeys = max(
GetArg(
"-keypool", 100), (int64_t)0);
1621 for (
int i = 0; i < nKeys; i++)
1623 int64_t nIndex = i+1;
1625 setKeyPool.insert(nIndex);
1627 LogPrintf(
"CWallet::NewKeyPool wrote %d new keys\n", nKeys);
1643 unsigned int nTargetSize;
1645 nTargetSize = kpSize;
1647 nTargetSize = max(
GetArg(
"-keypool", 100), (int64_t) 0);
1649 while (setKeyPool.size() < (nTargetSize + 1))
1652 if (!setKeyPool.empty())
1653 nEnd = *(--setKeyPool.end()) + 1;
1655 throw runtime_error(
"TopUpKeyPool() : writing generated key failed");
1656 setKeyPool.insert(nEnd);
1657 LogPrintf(
"keypool added key %d, size=%u\n", nEnd, setKeyPool.size());
1674 if(setKeyPool.empty())
1679 nIndex = *(setKeyPool.begin());
1680 setKeyPool.erase(setKeyPool.begin());
1681 if (!walletdb.
ReadPool(nIndex, keypool))
1682 throw runtime_error(
"ReserveKeyFromKeyPool() : read failed");
1684 throw runtime_error(
"ReserveKeyFromKeyPool() : unknown key in key pool");
1686 LogPrintf(
"keypool reserve %d\n", nIndex);
1696 int64_t nIndex = 1 + *(--setKeyPool.end());
1697 if (!walletdb.
WritePool(nIndex, keypool))
1698 throw runtime_error(
"AddReserveKey() : writing added key failed");
1699 setKeyPool.insert(nIndex);
1721 setKeyPool.insert(nIndex);
1723 LogPrintf(
"keypool return %d\n", nIndex);
1732 ReserveKeyFromKeyPool(nIndex, keypool);
1735 if (IsLocked())
return false;
1736 result = GenerateNewKey();
1749 ReserveKeyFromKeyPool(nIndex, keypool);
1753 return keypool.
nTime;
1758 map<CTxDestination, int64_t> balances;
1773 if (nDepth < (pcoin->
IsFromMe() ? 0 : 1))
1776 for (
unsigned int i = 0; i < pcoin->
vout.size(); i++)
1784 int64_t n = IsSpent(walletEntry.first, i) ? 0 : pcoin->
vout[i].nValue;
1786 if (!balances.count(addr))
1788 balances[addr] += n;
1799 set< set<CTxDestination> > groupings;
1800 set<CTxDestination> grouping;
1806 if (pcoin->
vin.size() > 0)
1808 bool any_mine =
false;
1810 BOOST_FOREACH(
CTxIn txin, pcoin->
vin)
1817 grouping.insert(address);
1825 if (IsChange(txout))
1830 grouping.insert(txoutAddr);
1833 if (grouping.size() > 0)
1835 groupings.insert(grouping);
1841 for (
unsigned int i = 0; i < pcoin->
vout.size(); i++)
1847 grouping.insert(address);
1848 groupings.insert(grouping);
1853 set< set<CTxDestination>* > uniqueGroupings;
1854 map< CTxDestination, set<CTxDestination>* > setmap;
1855 BOOST_FOREACH(set<CTxDestination> grouping, groupings)
1858 set< set<CTxDestination>* > hits;
1859 map< CTxDestination, set<CTxDestination>* >::iterator it;
1861 if ((it = setmap.find(address)) != setmap.end())
1862 hits.insert((*it).second);
1865 set<CTxDestination>* merged =
new set<CTxDestination>(grouping);
1866 BOOST_FOREACH(set<CTxDestination>* hit, hits)
1868 merged->insert(hit->begin(), hit->end());
1869 uniqueGroupings.erase(hit);
1872 uniqueGroupings.insert(merged);
1876 setmap[element] = merged;
1879 set< set<CTxDestination> > ret;
1880 BOOST_FOREACH(set<CTxDestination>* uniqueGrouping, uniqueGroupings)
1882 ret.insert(*uniqueGrouping);
1883 delete uniqueGrouping;
1892 set<CTxDestination> result;
1896 const string& strName = item.second.
name;
1897 if (strName == strAccount)
1898 result.insert(address);
1908 pwallet->ReserveKeyFromKeyPool(nIndex, keypool);
1912 if (pwallet->vchDefaultKey.IsValid()) {
1913 LogPrintf(
"CReserveKey::GetReservedKey(): Warning: Using default key instead of a new key, top up your keypool!");
1914 vchPubKey = pwallet->vchDefaultKey;
1927 pwallet->KeepKey(nIndex);
1935 pwallet->ReturnKey(nIndex);
1947 BOOST_FOREACH(
const int64_t&
id, setKeyPool)
1950 if (!walletdb.
ReadPool(
id, keypool))
1951 throw runtime_error(
"GetAllReserveKeyHashes() : read failed");
1954 if (!HaveKey(keyID))
1955 throw runtime_error(
"GetAllReserveKeyHashes() : unknown key in key pool");
1956 setAddress.insert(keyID);
1965 map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(hashTx);
1966 if (mi != mapWallet.end())
1974 setLockedCoins.insert(output);
1980 setLockedCoins.erase(output);
1986 setLockedCoins.clear();
1994 return (setLockedCoins.count(outpt) > 0);
2000 for (std::set<COutPoint>::iterator it = setLockedCoins.begin();
2001 it != setLockedCoins.end(); it++) {
2003 vOutpts.push_back(outpt);
2009 mapKeyBirth.clear();
2012 for (std::map<CKeyID, CKeyMetadata>::const_iterator it = mapKeyMetadata.begin(); it != mapKeyMetadata.end(); it++)
2013 if (it->second.nCreateTime)
2014 mapKeyBirth[it->first] = it->second.nCreateTime;
2018 std::map<CKeyID, CBlockIndex*> mapKeyFirstBlock;
2019 std::set<CKeyID> setKeys;
2021 BOOST_FOREACH(
const CKeyID &keyid, setKeys) {
2022 if (mapKeyBirth.count(keyid) == 0)
2023 mapKeyFirstBlock[keyid] = pindexMax;
2028 if (mapKeyFirstBlock.empty())
2032 std::vector<CKeyID> vAffected;
2033 for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); it++) {
2039 int nHeight = blit->second->nHeight;
2040 BOOST_FOREACH(
const CTxOut &txout, wtx.
vout) {
2043 BOOST_FOREACH(
const CKeyID &keyid, vAffected) {
2045 std::map<CKeyID, CBlockIndex*>::iterator rit = mapKeyFirstBlock.find(keyid);
2046 if (rit != mapKeyFirstBlock.end() && nHeight < rit->second->nHeight)
2047 rit->second = blit->second;
2055 for (std::map<CKeyID, CBlockIndex*>::const_iterator it = mapKeyFirstBlock.begin(); it != mapKeyFirstBlock.end(); it++)
2056 mapKeyBirth[it->first] = it->second->nTime - 7200;
2061 if (boost::get<CNoDestination>(&dest))
2064 mapAddressBook[dest].destdata.insert(std::make_pair(key, value));
2072 if (!mapAddressBook[dest].destdata.erase(key))
2081 mapAddressBook[dest].destdata.insert(std::make_pair(key, value));
2087 std::map<CTxDestination, CAddressBookData>::const_iterator i = mapAddressBook.find(dest);
2088 if(i != mapAddressBook.end())
2090 CAddressBookData::StringMap::const_iterator j = i->second.destdata.find(key);
2091 if(j != i->second.destdata.end())
bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
CClientUIInterface uiInterface
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
bool WriteMinVersion(int nVersion)
bool SetKeyFromPassphrase(const SecureString &strKeyData, const std::vector< unsigned char > &chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod)
uint64_t GetRand(uint64_t nMax)
int64_t AddReserveKey(const CKeyPool &keypool)
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
void BindWallet(CWallet *pwalletIn)
unsigned int nDerivationMethod
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
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.
static uint32_t insecure_rand(void)
int64_t GetImmatureBalance() const
void KeepKey(int64_t nIndex)
bool IsMine(const CTxIn &txin) const
bool Encrypt(const CKeyingMaterial &vchPlaintext, std::vector< unsigned char > &vchCiphertext)
bool AddToWalletIfInvolvingMe(const uint256 &hash, const CTransaction &tx, const CBlock *pblock, bool fUpdate)
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
const unsigned int WALLET_CRYPTO_KEY_SIZE
bool LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &metadata)
double ComputePriority(double dPriorityInputs, unsigned int nTxSize=0) 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
void ListLockedCoins(std::vector< COutPoint > &vOutpts)
static bool Rewrite(const std::string &strFile, const char *pszSkip=NULL)
Encryption/decryption context with key information.
std::vector< unsigned char > vchCryptedKey
bool bSpendZeroConfChange
std::string strFromAccount
WalletFeature
(client) version numbers for particular wallet features
bool WriteMasterKey(unsigned int nID, const CMasterKey &kMasterKey)
bool WriteCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret, const CKeyMetadata &keyMeta)
std::map< CTxDestination, int64_t > GetAddressBalances()
Master key for wallet encryption.
bool SignSignature(const CKeyStore &keystore, const CScript &fromPubKey, CTransaction &txTo, unsigned int nIn, int nHashType)
void seed_insecure_rand(bool fDeterministic)
Seed insecure_rand using the random pool.
std::string strWalletFile
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
static void ShowProgress(SplashScreen *splash, const std::string &title, int nProgress)
bool IsSelected(const uint256 &hash, unsigned int n) const
int64_t GetMinFee(const CTransaction &tx, unsigned int nBytes, bool fAllowFree, enum GetMinFee_mode mode)
void GetAllReserveKeys(std::set< CKeyID > &setAddress) const
boost::signals2::signal< void(CWallet *wallet)> LoadWallet
A wallet has been loaded.
void ListAccountCreditDebit(const std::string &strAccount, std::list< CAccountingEntry > &acentries)
base58-encoded Bitcoin addresses.
uint160 Hash160(const T1 pbegin, const T1 pend)
bool ErasePurpose(const std::string &strAddress)
bool SetMaxVersion(int nVersion)
virtual bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
bool AllowFree(double dPriority)
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE
DBErrors
Error statuses for the wallet database.
void GetKeyBirthTimes(std::map< CKeyID, int64_t > &mapKeyBirth) const
void RandAddSeedPerfmon()
static int64_t nMinTxFee
Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) ...
string FormatMoney(int64_t n, bool fPlus)
void ReacceptWalletTransactions()
CChain chainActive
The currently-connected chain of blocks.
std::set< uint256 > GetConflicts(const uint256 &txid) const
bool SetDefaultKey(const CPubKey &vchPubKey)
std::string SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx &wtxNew)
bool WriteOrderPosNext(int64_t nOrderPosNext)
int64_t IncOrderPosNext(CWalletDB *pwalletdb=NULL)
Increment the next transaction order id.
void SetBestChain(const CBlockLocator &loc)
void EraseFromWallet(const uint256 &hash)
bool EraseTx(uint256 hash)
void SetDestination(const CTxDestination &address)
virtual bool AddCScript(const CScript &redeemScript)
std::multimap< int64_t, TxPair > TxItems
bool SetMinVersion(enum WalletFeature, CWalletDB *pwalletdbIn=NULL, bool fExplicit=false)
int64_t GetBalance() const
#define AssertLockHeld(cs)
bool CreateTransaction(const std::vector< std::pair< CScript, int64_t > > &vecSend, CWalletTx &wtxNew, CReserveKey &reservekey, int64_t &nFeeRet, std::string &strFailReason, const CCoinControl *coinControl=NULL)
int GetBlocksToMaturity() const
void GetAccountAmounts(const std::string &strAccount, int64_t &nReceived, int64_t &nSent, int64_t &nFee) const
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or NULL if none.
int GetRequestCount() const
int Height() const
Return the maximal height in the chain.
DBErrors ZapWalletTx(CWallet *pwallet)
bool IsSpent(const uint256 &hash, unsigned int n) const
void SyncMetaData(std::pair< TxSpends::iterator, TxSpends::iterator >)
int64_t GetAdjustedTime()
void AddToSpends(const COutPoint &outpoint, const uint256 &wtxid)
CBlockIndex * Next(const CBlockIndex *pindex) const
Find the successor of a block in this chain, or NULL if the given index is not found or is the tip...
void LockCoin(COutPoint &output)
bool EraseDestData(const std::string &address, const std::string &key)
Erase destination data tuple from wallet database.
bool WritePool(int64_t nPool, const CKeyPool &keypool)
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
bool SelectCoins(int64_t nTargetValue, std::set< std::pair< const CWalletTx *, unsigned int > > &setCoinsRet, int64_t &nValueRet, const CCoinControl *coinControl=NULL) const
unsigned int GetSerializeSize(char a, int, int=0)
static int LogPrint(const char *category, const char *format)
An input of a transaction.
int64_t GetOldestKeyPoolTime()
const CWalletTx * GetWalletTx(const uint256 &hash) const
CPubKey GetPubKey() const
bool WriteName(const std::string &strAddress, const std::string &strName)
CPrivKey GetPrivKey() const
std::vector< CTxOut > vout
DBErrors LoadWallet(CWallet *pwallet)
CTxDestination destChange
void UnlockCoin(COutPoint &output)
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
An encapsulated public key.
bool Unlock(const CKeyingMaterial &vMasterKeyIn)
bool Decrypt(const std::vector< unsigned char > &vchCiphertext, CKeyingMaterial &vchPlaintext)
std::string SendMoneyToDestination(const CTxDestination &address, int64_t nValue, CWalletTx &wtxNew)
void MakeNewKey(bool fCompressed)
std::vector< uint256 > vMerkleBranch
bool TopUpKeyPool(unsigned int kpSize=0)
bool AcceptToMemoryPool(bool fLimitFree=true)
bool WriteDestData(const std::string &address, const std::string &key, const std::string &value)
Write destination data key,value tuple to database.
void RelayTransaction(const CTransaction &tx, const uint256 &hash)
bool EraseDestData(const CTxDestination &dest, const std::string &key)
Erases a destination data tuple in the store and on disk.
bool CommitTransaction(CWalletTx &wtxNew, CReserveKey &reservekey)
std::string ToString() const
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
void RelayWalletTransaction()
An output of a transaction.
bool GetReservedKey(CPubKey &pubkey)
std::set< std::set< CTxDestination > > GetAddressGroupings()
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 AvailableCoins(std::vector< COutput > &vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL) const
An outpoint - a combination of a transaction hash and an index n into its vout.
bool LoadCScript(const CScript &redeemScript)
std::set< CTxDestination > GetAccountAddresses(std::string strAccount) const
bool ErasePool(int64_t nPool)
std::string GetHex() const
int64_t GetDebit(const CTxIn &txin) const
unsigned int fTimeReceivedIsTxTime
double GuessVerificationProgress(CBlockIndex *pindex, bool fSigchecks)
bool WriteTx(uint256 hash, const CWalletTx &wtx)
std::string ToString() const
Access to the wallet database (wallet.dat)
A transaction with a bunch of additional info that only the owner cares about.
int64_t GetTxTime() const
static void ApproximateBestSubset(vector< pair< int64_t, pair< const CWalletTx *, unsigned int > > >vValue, int64_t nTotalLower, int64_t nTargetValue, vector< char > &vfBest, int64_t &nBest, int iterations=1000)
static void NotifyAddressBookChanged(WalletModel *walletmodel, CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)
void UpdatedTransaction(const uint256 &hashTx)
bool WriteBestBlock(const CBlockLocator &locator)
const unsigned int WALLET_CRYPTO_SALT_SIZE
static void NotifyTransactionChanged(WalletModel *walletmodel, CWallet *wallet, const uint256 &hash, ChangeType status)
int64_t nTimeBestReceived
int64_t GetUnconfirmedBalance() const
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos)
int ScanForWalletTransactions(CBlockIndex *pindexStart, bool fUpdate=false)
bool EncryptWallet(const SecureString &strWalletPassphrase)
A key allocated from the key pool.
The block chain is a tree shaped structure starting with the genesis block at the root...
bool ReadPool(int64_t nPool, CKeyPool &keypool)
Serialized script, used inside transaction inputs and outputs.
std::string ToString() const
static const int PROTOCOL_VERSION
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result...
bool IsMine(const CKeyStore &keystore, const CTxDestination &dest)
void ReturnKey(int64_t nIndex)
A reference to a CKey: the Hash160 of its serialized public key.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
bool Unlock(const SecureString &strWalletPassphrase)
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
bool IsChange(const CTxOut &txout) const
void ResendWalletTransactions()
void ReserveKeyFromKeyPool(int64_t &nIndex, CKeyPool &keypool)
std::set< uint256 > GetConflicts() const
int GetDepthInMainChain(CBlockIndex *&pindexRet) const
std::vector< unsigned char > vchSalt
void SyncTransaction(const uint256 &hash, const CTransaction &tx, const CBlock *pblock)
static int64_t nMinRelayTxFee
Fees smaller than this (in satoshi) are considered zero fee (for relaying and mining) ...
static const int64_t CENT
static const unsigned int MAX_STANDARD_TX_SIZE
The maximum size for transactions we're willing to relay/mine.
bool AddCScript(const CScript &redeemScript)
bool operator()(const pair< int64_t, pair< const CWalletTx *, unsigned int > > &t1, const pair< int64_t, pair< const CWalletTx *, unsigned int > > &t2) const
bool AddToWallet(const CWalletTx &wtxIn, bool fFromLoadWallet=false)
DBErrors LoadWallet(bool &fFirstRunRet)
std::vector< CTransaction > vtx
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
bool GetKeyFromPool(CPubKey &key)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
unsigned int nTimeReceived
An encapsulated private key.
bool EraseName(const std::string &strAddress)
int64_t GetAvailableCredit(bool fUseCache=true) const
The basic transaction that is broadcasted on the network and contained in blocks. ...
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.
unsigned int nDeriveIterations
bool WriteCScript(const uint160 &hash, const CScript &redeemScript)
bool WritePurpose(const std::string &strAddress, const std::string &purpose)
bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
std::pair< CWalletTx *, CAccountingEntry * > TxPair
bool IsLockedCoin(uint256 hash, unsigned int n) const
bool DelAddressBook(const CTxDestination &address)
void ExtractAffectedKeys(const CKeyStore &keystore, const CScript &scriptPubKey, std::vector< CKeyID > &vKeys)
map< uint256, CBlockIndex * > mapBlockIndex
static const int64_t DEFAULT_TRANSACTION_FEE
int64_t GetImmatureCredit(bool fUseCache=true) const
bool WriteKey(const CPubKey &vchPubKey, const CPrivKey &vchPrivKey, const CKeyMetadata &keyMeta)
void runCommand(std::string strCommand)
std::vector< std::pair< std::string, std::string > > vOrderForm
TxItems OrderedTxItems(std::list< CAccountingEntry > &acentries, std::string strAccount="")
Get the wallet's activity log.
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.