36 #include <boost/algorithm/string/replace.hpp> 37 #include <boost/filesystem.hpp> 38 #include <boost/thread.hpp> 104 return strprintf(
"COutput(%s, %d, %d) [%s]", tx->GetHash().ToString(), i, nDepth,
FormatMoney(tx->tx->vout[i].nValue));
117 std::vector<CTxDestination> vDest;
121 boost::apply_visitor(*
this, dest);
127 vKeys.push_back(keyId);
142 std::map<uint256, CWalletTx>::const_iterator it = mapWallet.find(hash);
143 if (it == mapWallet.end())
145 return &(it->second);
156 int64_t nCreationTime =
GetTime();
161 DeriveNewChildKey(walletdb, metadata, secret, (CanSupportFeature(
FEATURE_HD_SPLIT) ?
internal :
false));
174 mapKeyMetadata[pubkey.
GetID()] = metadata;
175 UpdateTimeFirstKey(nCreationTime);
177 if (!AddKeyPubKeyWithDB(walletdb, secret, pubkey)) {
178 throw std::runtime_error(std::string(__func__) +
": AddKey failed");
193 if (!GetKey(hdChain.masterKeyID, key))
194 throw std::runtime_error(std::string(__func__) +
": Master key not found");
213 metadata.
hdKeypath =
"m/0'/1'/" + std::to_string(hdChain.nInternalChainCounter) +
"'";
214 hdChain.nInternalChainCounter++;
218 metadata.
hdKeypath =
"m/0'/0'/" + std::to_string(hdChain.nExternalChainCounter) +
"'";
219 hdChain.nExternalChainCounter++;
222 secret = childKey.
key;
226 throw std::runtime_error(std::string(__func__) +
": Writing HD chain model failed");
236 bool needsDB = !pwalletdbEncryption;
238 pwalletdbEncryption = &walletdb;
241 if (needsDB) pwalletdbEncryption =
nullptr;
244 if (needsDB) pwalletdbEncryption =
nullptr;
249 if (HaveWatchOnly(script)) {
250 RemoveWatchOnly(script);
253 if (HaveWatchOnly(script)) {
254 RemoveWatchOnly(script);
260 mapKeyMetadata[pubkey.
GetID()]);
272 const std::vector<unsigned char> &vchCryptedSecret)
278 if (pwalletdbEncryption)
279 return pwalletdbEncryption->WriteCryptedKey(vchPubKey,
281 mapKeyMetadata[vchPubKey.
GetID()]);
285 mapKeyMetadata[vchPubKey.
GetID()]);
293 mapKeyMetadata[keyID] = meta;
309 if (nCreateTime <= 1) {
313 }
else if (!nTimeFirstKey || nCreateTime < nTimeFirstKey) {
314 nTimeFirstKey = nCreateTime;
335 if (redeemScript.
size() > MAX_SCRIPT_ELEMENT_SIZE)
338 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",
339 __func__, redeemScript.
size(), MAX_SCRIPT_ELEMENT_SIZE, strAddr);
352 NotifyWatchonlyChanged(
true);
358 mapKeyMetadata[
CScriptID(dest)].nCreateTime = nCreateTime;
359 return AddWatchOnly(dest);
367 if (!HaveWatchOnly())
368 NotifyWatchonlyChanged(
false);
387 for (
const MasterKeyMap::value_type& pMasterKey : mapMasterKeys)
389 if(!crypter.
SetKeyFromPassphrase(strWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
391 if (!crypter.
Decrypt(pMasterKey.second.vchCryptedKey, _vMasterKey))
402 bool fWasLocked = IsLocked();
410 for (MasterKeyMap::value_type& pMasterKey : mapMasterKeys)
412 if(!crypter.
SetKeyFromPassphrase(strOldWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
414 if (!crypter.
Decrypt(pMasterKey.second.vchCryptedKey, _vMasterKey))
419 crypter.
SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod);
420 pMasterKey.second.nDeriveIterations = pMasterKey.second.nDeriveIterations * (100 / ((double)(
GetTimeMillis() - nStartTime)));
423 crypter.
SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod);
424 pMasterKey.second.nDeriveIterations = (pMasterKey.second.nDeriveIterations + pMasterKey.second.nDeriveIterations * 100 / ((double)(
GetTimeMillis() - nStartTime))) / 2;
426 if (pMasterKey.second.nDeriveIterations < 25000)
427 pMasterKey.second.nDeriveIterations = 25000;
429 LogPrintf(
"Wallet passphrase changed to an nDeriveIterations of %i\n", pMasterKey.second.nDeriveIterations);
431 if (!crypter.
SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
433 if (!crypter.
Encrypt(_vMasterKey, pMasterKey.second.vchCryptedKey))
455 if (nWalletVersion >= nVersion)
459 if (fExplicit && nVersion > nWalletMaxVersion)
462 nWalletVersion = nVersion;
464 if (nVersion > nWalletMaxVersion)
465 nWalletMaxVersion = nVersion;
469 if (nWalletVersion > 40000)
482 if (nWalletVersion > nVersion)
485 nWalletMaxVersion = nVersion;
492 std::set<uint256> result;
495 std::map<uint256, CWalletTx>::const_iterator it = mapWallet.find(txid);
496 if (it == mapWallet.end())
500 std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range;
502 for (
const CTxIn& txin : wtx.
tx->vin)
504 if (mapTxSpends.count(txin.
prevout) <= 1)
506 range = mapTxSpends.equal_range(txin.
prevout);
507 for (TxSpends::const_iterator _it = range.first; _it != range.second; ++_it)
508 result.insert(_it->second);
516 auto iter = mapTxSpends.lower_bound(
COutPoint(txid, 0));
517 return (iter != mapTxSpends.end() && iter->first.hash == txid);
522 dbw->Flush(shutdown);
533 std::set<fs::path> wallet_paths;
535 for (
const std::string& walletFile :
gArgs.
GetArgs(
"-wallet")) {
536 if (boost::filesystem::path(walletFile).filename() != walletFile) {
537 return InitError(
strprintf(
_(
"Error loading wallet %s. -wallet parameter must only specify a filename (not a path)."), walletFile));
541 return InitError(
strprintf(
_(
"Error loading wallet %s. Invalid characters in -wallet filename."), walletFile));
544 fs::path wallet_path = fs::absolute(walletFile,
GetDataDir());
546 if (fs::exists(wallet_path) && (!fs::is_regular_file(wallet_path) || fs::is_symlink(wallet_path))) {
547 return InitError(
strprintf(
_(
"Error loading wallet %s. -wallet filename must be a regular file."), walletFile));
550 if (!wallet_paths.insert(wallet_path).second) {
551 return InitError(
strprintf(
_(
"Error loading wallet %s. Duplicate -wallet filename specified."), walletFile));
554 std::string strError;
562 std::string backup_filename;
568 std::string strWarning;
570 if (!strWarning.empty()) {
590 for (TxSpends::iterator it = range.first; it != range.second; ++it)
593 int n = mapWallet[
hash].nOrderPos;
594 if (n < nMinOrderPos)
597 copyFrom = &mapWallet[
hash];
601 for (TxSpends::iterator it = range.first; it != range.second; ++it)
605 if (copyFrom == copyTo)
continue;
626 std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range;
627 range = mapTxSpends.equal_range(outpoint);
629 for (TxSpends::const_iterator it = range.first; it != range.second; ++it)
631 const uint256& wtxid = it->second;
632 std::map<uint256, CWalletTx>::const_iterator mit = mapWallet.find(wtxid);
633 if (mit != mapWallet.end()) {
634 int depth = mit->second.GetDepthInMainChain();
635 if (depth > 0 || (depth == 0 && !mit->second.isAbandoned()))
644 mapTxSpends.insert(std::make_pair(outpoint, wtxid));
646 std::pair<TxSpends::iterator, TxSpends::iterator> range;
647 range = mapTxSpends.equal_range(outpoint);
654 assert(mapWallet.count(wtxid));
656 if (thisTx.IsCoinBase())
659 for (
const CTxIn& txin : thisTx.tx->vin)
660 AddToSpends(txin.
prevout, wtxid);
699 mapMasterKeys[++nMasterKeyMaxID] = kMasterKey;
700 assert(!pwalletdbEncryption);
701 pwalletdbEncryption =
new CWalletDB(*dbw);
702 if (!pwalletdbEncryption->TxnBegin()) {
703 delete pwalletdbEncryption;
704 pwalletdbEncryption =
nullptr;
707 pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey);
709 if (!EncryptKeys(_vMasterKey))
711 pwalletdbEncryption->TxnAbort();
712 delete pwalletdbEncryption;
721 if (!pwalletdbEncryption->TxnCommit()) {
722 delete pwalletdbEncryption;
728 delete pwalletdbEncryption;
729 pwalletdbEncryption =
nullptr;
732 Unlock(strWalletPassphrase);
736 if (!SetHDMasterKey(GenerateNewHDMasterKey())) {
749 NotifyStatusChanged(
this);
763 typedef std::pair<CWalletTx*, CAccountingEntry*>
TxPair;
764 typedef std::multimap<int64_t, TxPair >
TxItems;
767 for (std::map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
772 std::list<CAccountingEntry> acentries;
776 txByTime.insert(std::make_pair(entry.nTime, TxPair((
CWalletTx*)0, &entry)));
780 std::vector<int64_t> nOrderPosOffsets;
781 for (TxItems::iterator it = txByTime.begin(); it != txByTime.end(); ++it)
783 CWalletTx *
const pwtx = (*it).second.first;
789 nOrderPos = nOrderPosNext++;
790 nOrderPosOffsets.push_back(nOrderPos);
803 int64_t nOrderPosOff = 0;
804 for (
const int64_t& nOffsetStart : nOrderPosOffsets)
806 if (nOrderPos >= nOffsetStart)
809 nOrderPos += nOrderPosOff;
810 nOrderPosNext =
std::max(nOrderPosNext, nOrderPos + 1);
834 int64_t nRet = nOrderPosNext++;
853 debit.
nOrderPos = IncOrderPosNext(&walletdb);
859 AddAccountingEntry(debit, &walletdb);
863 credit.
nOrderPos = IncOrderPosNext(&walletdb);
869 AddAccountingEntry(credit, &walletdb);
890 for (std::map<uint256, CWalletTx>::iterator it = mapWallet.begin();
893 for (
const CTxOut& txout : (*it).second.tx->vout)
903 if (!GetKeyFromPool(account.
vchPubKey,
false))
919 for (std::pair<const uint256, CWalletTx>& item : mapWallet)
920 item.second.MarkDirty();
928 auto mi = mapWallet.find(originalHash);
931 assert(mi != mapWallet.end());
936 assert(wtx.mapValue.count(
"replaced_by_txid") == 0);
938 wtx.mapValue[
"replaced_by_txid"] = newHash.
ToString();
944 LogPrintf(
"%s: Updating walletdb tx %s failed", __func__, wtx.GetHash().ToString());
948 NotifyTransactionChanged(
this, originalHash,
CT_UPDATED);
957 CWalletDB walletdb(*dbw,
"r+", fFlushOnClose);
962 std::pair<std::map<uint256, CWalletTx>::iterator,
bool> ret = mapWallet.insert(std::make_pair(hash, wtxIn));
965 bool fInsertedNew = ret.second;
969 wtx.
nOrderPos = IncOrderPosNext(&walletdb);
975 bool fUpdated =
false;
1005 if (wtxIn.
tx->HasWitness() && !wtx.
tx->HasWitness()) {
1012 LogPrintf(
"AddToWallet %s %s%s\n", wtxIn.
GetHash().
ToString(), (fInsertedNew ?
"new" :
""), (fUpdated ?
"update" :
""));
1015 if (fInsertedNew || fUpdated)
1026 std::string strCmd =
gArgs.
GetArg(
"-walletnotify",
"");
1028 if ( !strCmd.empty())
1041 mapWallet[
hash] = wtxIn;
1046 for (
const CTxIn& txin : wtx.
tx->vin) {
1077 if (pIndex !=
nullptr) {
1079 std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = mapTxSpends.equal_range(txin.
prevout);
1080 while (range.first != range.second) {
1081 if (range.first->second != tx.
GetHash()) {
1082 LogPrintf(
"Transaction %s (in block %s) conflicts with wallet transaction %s (both spend %s:%i)\n", tx.
GetHash().
ToString(), pIndex->
GetBlockHash().
ToString(), range.first->second.ToString(), range.first->first.hash.ToString(), range.first->first.n);
1083 MarkConflicted(pIndex->
GetBlockHash(), range.first->second);
1090 bool fExisted = mapWallet.count(tx.
GetHash()) != 0;
1091 if (fExisted && !fUpdate)
return false;
1092 if (fExisted ||
IsMine(tx) || IsFromMe(tx))
1103 std::vector<CKeyID> vAffected;
1105 for (
const CKeyID &keyid : vAffected) {
1106 std::map<CKeyID, int64_t>::const_iterator mi = m_pool_key_to_index.find(keyid);
1107 if (mi != m_pool_key_to_index.end()) {
1108 LogPrintf(
"%s: Detected a used keypool key, mark all keypool key up to this key as used\n", __func__);
1109 MarkReserveKeysAsUsed(mi->second);
1111 if (!TopUpKeyPool()) {
1112 LogPrintf(
"%s: Topping up keypool failed (locked wallet)\n", __func__);
1121 if (pIndex !=
nullptr)
1124 return AddToWallet(wtx,
false);
1133 const CWalletTx* wtx = GetWalletTx(hashTx);
1143 std::set<uint256> todo;
1144 std::set<uint256> done;
1147 assert(mapWallet.count(hashTx));
1149 if (origtx.GetDepthInMainChain() > 0 || origtx.InMempool()) {
1153 todo.insert(hashTx);
1155 while (!todo.empty()) {
1159 assert(mapWallet.count(now));
1163 assert(currentconfirm <= 0);
1165 if (currentconfirm == 0 && !wtx.isAbandoned()) {
1167 assert(!wtx.InMempool());
1172 NotifyTransactionChanged(
this, wtx.GetHash(),
CT_UPDATED);
1174 TxSpends::const_iterator iter = mapTxSpends.lower_bound(
COutPoint(hashTx, 0));
1175 while (iter != mapTxSpends.end() && iter->first.hash == now) {
1176 if (!done.count(iter->second)) {
1177 todo.insert(iter->second);
1183 for (
const CTxIn& txin : wtx.tx->vin)
1198 int conflictconfirms = 0;
1209 if (conflictconfirms >= 0)
1215 std::set<uint256> todo;
1216 std::set<uint256> done;
1218 todo.insert(hashTx);
1220 while (!todo.empty()) {
1224 assert(mapWallet.count(now));
1227 if (conflictconfirms < currentconfirm) {
1231 wtx.hashBlock = hashBlock;
1235 TxSpends::const_iterator iter = mapTxSpends.lower_bound(
COutPoint(now, 0));
1236 while (iter != mapTxSpends.end() && iter->first.hash == now) {
1237 if (!done.count(iter->second)) {
1238 todo.insert(iter->second);
1244 for (
const CTxIn& txin : wtx.tx->vin)
1256 if (!AddToWalletIfInvolvingMe(ptx, pindex, posInBlock,
true))
1271 SyncTransaction(ptx);
1285 SyncTransaction(ptx);
1287 for (
size_t i = 0; i < pblock->vtx.size(); i++) {
1288 SyncTransaction(pblock->vtx[i], pindex, i);
1296 SyncTransaction(ptx);
1306 std::map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(txin.
prevout.
hash);
1307 if (mi != mapWallet.end())
1323 std::map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(txin.
prevout.
hash);
1324 if (mi != mapWallet.end())
1343 throw std::runtime_error(std::string(__func__) +
": value out of range");
1363 if (!mapAddressBook.count(address))
1372 throw std::runtime_error(std::string(__func__) +
": value out of range");
1373 return (IsChange(txout) ? txout.
nValue : 0);
1394 nDebit += GetDebit(txin, filter);
1396 throw std::runtime_error(std::string(__func__) +
": value out of range");
1408 if (mi == mapWallet.end())
1427 nCredit += GetCredit(txout, filter);
1429 throw std::runtime_error(std::string(__func__) +
": value out of range");
1439 nChange += GetChange(txout);
1441 throw std::runtime_error(std::string(__func__) +
": value out of range");
1451 int64_t nCreationTime =
GetTime();
1466 mapKeyMetadata[pubkey.
GetID()] = metadata;
1469 if (!AddKeyPubKey(key, pubkey))
1470 throw std::runtime_error(std::string(__func__) +
": AddKeyPubKey failed");
1485 SetHDChain(newHdChain,
false);
1494 throw std::runtime_error(std::string(__func__) +
": writing chain failed");
1502 return !hdChain.masterKeyID.IsNull();
1507 int64_t n = nTimeSmart;
1508 return n ? n : nTimeReceived;
1516 LOCK(pwallet->cs_wallet);
1522 std::map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(hashBlock);
1523 if (mi != pwallet->mapRequestCount.end())
1524 nRequests = (*mi).second;
1530 std::map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(GetHash());
1531 if (mi != pwallet->mapRequestCount.end())
1533 nRequests = (*mi).second;
1536 if (nRequests == 0 && !hashUnset())
1538 std::map<uint256, int>::const_iterator _mi = pwallet->mapRequestCount.find(hashBlock);
1539 if (_mi != pwallet->mapRequestCount.end())
1540 nRequests = (*_mi).second;
1551 std::list<COutputEntry>& listSent,
CAmount& nFee, std::string& strSentAccount,
const isminefilter& filter)
const 1554 listReceived.clear();
1556 strSentAccount = strFromAccount;
1559 CAmount nDebit = GetDebit(filter);
1562 CAmount nValueOut = tx->GetValueOut();
1563 nFee = nDebit - nValueOut;
1567 for (
unsigned int i = 0; i < tx->vout.size(); ++i)
1569 const CTxOut& txout = tx->vout[i];
1577 if (pwallet->IsChange(txout))
1580 else if (!(fIsMine & filter))
1588 LogPrintf(
"CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n",
1589 this->GetHash().ToString());
1597 listSent.push_back(output);
1600 if (fIsMine & filter)
1601 listReceived.push_back(output);
1626 const CBlockIndex*
const failedBlock = ScanForWalletTransactions(startBlock, update);
1652 fAbortRescan =
false;
1653 fScanningWallet =
true;
1655 ShowProgress(
_(
"Rescanning..."), 0);
1658 while (pindex && !fAbortRescan)
1660 if (pindex->
nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0)
1669 for (
size_t posInBlock = 0; posInBlock < block.
vtx.size(); ++posInBlock) {
1670 AddToWalletIfInvolvingMe(block.
vtx[posInBlock], pindex, posInBlock, fUpdate);
1677 if (pindex && fAbortRescan) {
1680 ShowProgress(
_(
"Rescanning..."), 100);
1682 fScanningWallet =
false;
1690 if (!fBroadcastTransactions)
1693 std::map<int64_t, CWalletTx*> mapSorted;
1696 for (std::pair<const uint256, CWalletTx>& item : mapWallet)
1698 const uint256& wtxid = item.first;
1705 mapSorted.insert(std::make_pair(wtx.
nOrderPos, &wtx));
1710 for (std::pair<const int64_t, CWalletTx*>& item : mapSorted)
1722 assert(pwallet->GetBroadcastTransactions());
1723 if (!IsCoinBase() && !isAbandoned() && GetDepthInMainChain() == 0)
1728 LogPrintf(
"Relaying wtx %s\n", GetHash().ToString());
1744 std::set<uint256> result;
1745 if (pwallet !=
nullptr)
1748 result = pwallet->GetConflicts(myHash);
1749 result.erase(myHash);
1756 if (tx->vin.empty())
1763 debit += nDebitCached;
1766 nDebitCached = pwallet->GetDebit(*
this, ISMINE_SPENDABLE);
1767 fDebitCached =
true;
1768 debit += nDebitCached;
1773 if(fWatchDebitCached)
1774 debit += nWatchDebitCached;
1777 nWatchDebitCached = pwallet->GetDebit(*
this, ISMINE_WATCH_ONLY);
1778 fWatchDebitCached =
true;
1779 debit += nWatchDebitCached;
1788 if (IsCoinBase() && GetBlocksToMaturity() > 0)
1796 credit += nCreditCached;
1799 nCreditCached = pwallet->GetCredit(*
this, ISMINE_SPENDABLE);
1800 fCreditCached =
true;
1801 credit += nCreditCached;
1806 if (fWatchCreditCached)
1807 credit += nWatchCreditCached;
1810 nWatchCreditCached = pwallet->GetCredit(*
this, ISMINE_WATCH_ONLY);
1811 fWatchCreditCached =
true;
1812 credit += nWatchCreditCached;
1820 if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
1822 if (fUseCache && fImmatureCreditCached)
1823 return nImmatureCreditCached;
1825 fImmatureCreditCached =
true;
1826 return nImmatureCreditCached;
1838 if (IsCoinBase() && GetBlocksToMaturity() > 0)
1841 if (fUseCache && fAvailableCreditCached)
1842 return nAvailableCreditCached;
1846 for (
unsigned int i = 0; i < tx->vout.size(); i++)
1848 if (!pwallet->IsSpent(hashTx, i))
1850 const CTxOut &txout = tx->vout[i];
1853 throw std::runtime_error(std::string(__func__) +
" : value out of range");
1857 nAvailableCreditCached = nCredit;
1858 fAvailableCreditCached =
true;
1864 if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
1866 if (fUseCache && fImmatureWatchCreditCached)
1867 return nImmatureWatchCreditCached;
1869 fImmatureWatchCreditCached =
true;
1870 return nImmatureWatchCreditCached;
1882 if (IsCoinBase() && GetBlocksToMaturity() > 0)
1885 if (fUseCache && fAvailableWatchCreditCached)
1886 return nAvailableWatchCreditCached;
1889 for (
unsigned int i = 0; i < tx->vout.size(); i++)
1891 if (!pwallet->IsSpent(GetHash(), i))
1893 const CTxOut &txout = tx->vout[i];
1896 throw std::runtime_error(std::string(__func__) +
": value out of range");
1900 nAvailableWatchCreditCached = nCredit;
1901 fAvailableWatchCreditCached =
true;
1908 return nChangeCached;
1909 nChangeCached = pwallet->GetChange(*
this);
1910 fChangeCached =
true;
1911 return nChangeCached;
1925 int nDepth = GetDepthInMainChain();
1938 for (
const CTxIn& txin : tx->vin)
1942 if (parent ==
nullptr)
1955 for (
auto& txin : tx1.
vin) txin.scriptSig =
CScript();
1956 for (
auto& txin : tx2.
vin) txin.scriptSig =
CScript();
1962 std::vector<uint256> result;
1967 std::multimap<unsigned int, CWalletTx*> mapSorted;
1968 for (std::pair<const uint256, CWalletTx>& item : mapWallet)
1976 for (std::pair<const unsigned int, CWalletTx*>& item : mapSorted)
1980 result.push_back(wtx.
GetHash());
1989 if (
GetTime() < nNextResend || !fBroadcastTransactions)
1991 bool fFirst = (nNextResend == 0);
1997 if (nBestBlockTime < nLastResend)
2003 std::vector<uint256> relayed = ResendWalletTransactionsBefore(nBestBlockTime-5*60, connman);
2004 if (!relayed.empty())
2005 LogPrintf(
"%s: rebroadcast %u unconfirmed transactions\n", __func__, relayed.size());
2024 for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
2040 for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
2055 for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
2069 for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
2085 for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
2100 for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
2120 for (
const auto& entry : mapWallet) {
2130 const bool outgoing = debit > 0;
2131 for (
const CTxOut& out : wtx.
tx->vout) {
2132 if (outgoing && IsChange(out)) {
2134 }
else if (
IsMine(out) & filter && depth >= minDepth && (!account || *account == GetAccountName(out.
scriptPubKey))) {
2157 std::vector<COutput> vCoins;
2158 AvailableCoins(vCoins,
true, coinControl);
2159 for (
const COutput& out : vCoins) {
2160 if (out.fSpendable) {
2161 balance += out.tx->tx->vout[out.i].nValue;
2176 for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
2178 const uint256& wtxid = it->first;
2213 if (nDepth == 0 && pcoin->
mapValue.count(
"replaces_txid")) {
2225 if (nDepth == 0 && pcoin->
mapValue.count(
"replaced_by_txid")) {
2229 if (fOnlySafe && !safeTx) {
2233 if (nDepth < nMinDepth || nDepth > nMaxDepth)
2236 for (
unsigned int i = 0; i < pcoin->
tx->vout.size(); i++) {
2237 if (pcoin->
tx->vout[i].nValue < nMinimumAmount || pcoin->
tx->vout[i].nValue > nMaximumAmount)
2243 if (IsLockedCoin((*it).first, i))
2246 if (IsSpent(wtxid, i))
2258 vCoins.push_back(
COutput(pcoin, i, nDepth, fSpendableIn, fSolvableIn, safeTx));
2261 if (nMinimumSumAmount != MAX_MONEY) {
2262 nTotal += pcoin->
tx->vout[i].nValue;
2264 if (nTotal >= nMinimumSumAmount) {
2270 if (nMaximumCount > 0 && vCoins.size() >= nMaximumCount) {
2290 std::map<CTxDestination, std::vector<COutput>> result;
2292 std::vector<COutput> availableCoins;
2293 AvailableCoins(availableCoins);
2296 for (
auto& coin : availableCoins) {
2298 if (coin.fSpendable &&
2299 ExtractDestination(FindNonChangeParentOutput(*coin.tx->tx, coin.i).scriptPubKey, address)) {
2300 result[
address].emplace_back(std::move(coin));
2304 std::vector<COutPoint> lockedCoins;
2305 ListLockedCoins(lockedCoins);
2306 for (
const auto& output : lockedCoins) {
2307 auto it = mapWallet.find(output.hash);
2308 if (it != mapWallet.end()) {
2309 int depth = it->second.GetDepthInMainChain();
2310 if (depth >= 0 && output.n < it->second.tx->vout.size() &&
2313 if (
ExtractDestination(FindNonChangeParentOutput(*it->second.tx, output.n).scriptPubKey, address)) {
2315 &it->second, output.n, depth,
true ,
true ,
false );
2328 while (IsChange(ptx->
vout[n]) && ptx->
vin.size() > 0) {
2330 auto it = mapWallet.find(prevout.
hash);
2331 if (it == mapWallet.end() || it->second.tx->vout.size() <= prevout.
n ||
2332 !
IsMine(it->second.tx->vout[prevout.
n])) {
2335 ptx = it->second.tx.get();
2338 return ptx->
vout[n];
2341 static void ApproximateBestSubset(
const std::vector<CInputCoin>& vValue,
const CAmount& nTotalLower,
const CAmount& nTargetValue,
2342 std::vector<char>& vfBest,
CAmount& nBest,
int iterations = 1000)
2344 std::vector<char> vfIncluded;
2346 vfBest.assign(vValue.size(),
true);
2347 nBest = nTotalLower;
2351 for (
int nRep = 0; nRep < iterations && nBest != nTargetValue; nRep++)
2353 vfIncluded.assign(vValue.size(),
false);
2355 bool fReachedTarget =
false;
2356 for (
int nPass = 0; nPass < 2 && !fReachedTarget; nPass++)
2358 for (
unsigned int i = 0; i < vValue.size(); i++)
2366 if (nPass == 0 ? insecure_rand.
randbool() : !vfIncluded[i])
2368 nTotal += vValue[i].txout.nValue;
2369 vfIncluded[i] =
true;
2370 if (nTotal >= nTargetValue)
2372 fReachedTarget =
true;
2376 vfBest = vfIncluded;
2378 nTotal -= vValue[i].txout.nValue;
2379 vfIncluded[i] =
false;
2388 std::set<CInputCoin>& setCoinsRet,
CAmount& nValueRet)
const 2390 setCoinsRet.clear();
2394 boost::optional<CInputCoin> coinLowestLarger;
2395 std::vector<CInputCoin> vValue;
2398 random_shuffle(vCoins.begin(), vCoins.end(),
GetRandInt);
2400 for (
const COutput &output : vCoins)
2402 if (!output.fSpendable)
2419 setCoinsRet.insert(coin);
2423 else if (coin.
txout.
nValue < nTargetValue + MIN_CHANGE)
2425 vValue.push_back(coin);
2428 else if (!coinLowestLarger || coin.
txout.
nValue < coinLowestLarger->txout.nValue)
2430 coinLowestLarger = coin;
2434 if (nTotalLower == nTargetValue)
2436 for (
const auto& input : vValue)
2438 setCoinsRet.insert(input);
2444 if (nTotalLower < nTargetValue)
2446 if (!coinLowestLarger)
2448 setCoinsRet.insert(coinLowestLarger.get());
2449 nValueRet += coinLowestLarger->txout.nValue;
2455 std::reverse(vValue.begin(), vValue.end());
2456 std::vector<char> vfBest;
2459 ApproximateBestSubset(vValue, nTotalLower, nTargetValue, vfBest, nBest);
2460 if (nBest != nTargetValue && nTotalLower >= nTargetValue + MIN_CHANGE)
2461 ApproximateBestSubset(vValue, nTotalLower, nTargetValue + MIN_CHANGE, vfBest, nBest);
2465 if (coinLowestLarger &&
2466 ((nBest != nTargetValue && nBest < nTargetValue + MIN_CHANGE) || coinLowestLarger->txout.nValue <= nBest))
2468 setCoinsRet.insert(coinLowestLarger.get());
2469 nValueRet += coinLowestLarger->txout.nValue;
2472 for (
unsigned int i = 0; i < vValue.size(); i++)
2475 setCoinsRet.insert(vValue[i]);
2476 nValueRet += vValue[i].txout.nValue;
2481 for (
unsigned int i = 0; i < vValue.size(); i++) {
2495 std::vector<COutput> vCoins(vAvailableCoins);
2500 for (
const COutput& out : vCoins)
2502 if (!out.fSpendable)
2504 nValueRet += out.tx->tx->vout[out.i].nValue;
2505 setCoinsRet.insert(
CInputCoin(out.tx, out.i));
2507 return (nValueRet >= nTargetValue);
2511 std::set<CInputCoin> setPresetCoins;
2512 CAmount nValueFromPresetInputs = 0;
2514 std::vector<COutPoint> vPresetInputs;
2517 for (
const COutPoint& outpoint : vPresetInputs)
2519 std::map<uint256, CWalletTx>::const_iterator it = mapWallet.find(outpoint.hash);
2520 if (it != mapWallet.end())
2524 if (pcoin->
tx->vout.size() <= outpoint.n)
2526 nValueFromPresetInputs += pcoin->
tx->vout[outpoint.n].nValue;
2527 setPresetCoins.insert(
CInputCoin(pcoin, outpoint.n));
2533 for (std::vector<COutput>::iterator it = vCoins.begin(); it != vCoins.end() && coinControl && coinControl->
HasSelected();)
2535 if (setPresetCoins.count(
CInputCoin(it->tx, it->i)))
2536 it = vCoins.erase(it);
2541 size_t nMaxChainLength =
std::min(
gArgs.
GetArg(
"-limitancestorcount", DEFAULT_ANCESTOR_LIMIT),
gArgs.
GetArg(
"-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT));
2542 bool fRejectLongChains =
gArgs.
GetBoolArg(
"-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS);
2544 bool res = nTargetValue <= nValueFromPresetInputs ||
2545 SelectCoinsMinConf(nTargetValue - nValueFromPresetInputs, 1, 6, 0, vCoins, setCoinsRet, nValueRet) ||
2546 SelectCoinsMinConf(nTargetValue - nValueFromPresetInputs, 1, 1, 0, vCoins, setCoinsRet, nValueRet) ||
2547 (
bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue - nValueFromPresetInputs, 0, 1, 2, vCoins, setCoinsRet, nValueRet)) ||
2548 (
bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue - nValueFromPresetInputs, 0, 1,
std::min((
size_t)4, nMaxChainLength/3), vCoins, setCoinsRet, nValueRet)) ||
2549 (
bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue - nValueFromPresetInputs, 0, 1, nMaxChainLength/2, vCoins, setCoinsRet, nValueRet)) ||
2550 (
bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue - nValueFromPresetInputs, 0, 1, nMaxChainLength, vCoins, setCoinsRet, nValueRet)) ||
2554 setCoinsRet.insert(setPresetCoins.begin(), setPresetCoins.end());
2557 nValueRet += nValueFromPresetInputs;
2569 for (
const auto& input : tx.
vin) {
2570 std::map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(input.prevout.hash);
2571 if(mi == mapWallet.end() || input.prevout.n >= mi->second.tx->vout.size()) {
2574 const CScript& scriptPubKey = mi->second.tx->vout[input.prevout.n].scriptPubKey;
2575 const CAmount& amount = mi->second.tx->vout[input.prevout.n].nValue;
2588 std::vector<CRecipient> vecSend;
2591 for (
size_t idx = 0; idx < tx.
vout.size(); idx++)
2595 vecSend.push_back(recipient);
2605 if (!CreateTransaction(vecSend, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, coinControl,
false)) {
2609 if (nChangePosInOut != -1) {
2610 tx.
vout.insert(tx.
vout.begin() + nChangePosInOut, wtx.
tx->vout[nChangePosInOut]);
2617 for (
unsigned int idx = 0; idx < tx.
vout.size(); idx++)
2618 tx.
vout[idx].nValue = wtx.
tx->vout[idx].nValue;
2625 tx.
vin.push_back(txin);
2644 discard_rate = (discard_rate ==
CFeeRate(0)) ? CWallet::m_discard_rate :
std::min(discard_rate, CWallet::m_discard_rate);
2647 return discard_rate;
2651 int& nChangePosInOut, std::string& strFailReason,
const CCoinControl& coin_control,
bool sign,
CAmount nGasFee,
bool hasSender)
2654 int nChangePosRequest = nChangePosInOut;
2655 unsigned int nSubtractFeeFromAmount = 0;
2658 std::vector<COutPoint> vSenderInputs;
2660 senderInput=vSenderInputs[0];
2662 for (
const auto& recipient : vecSend)
2664 if (nValue < 0 || recipient.nAmount < 0)
2666 strFailReason =
_(
"Transaction amounts must not be negative");
2669 nValue += recipient.nAmount;
2671 if (recipient.fSubtractFeeFromAmount)
2672 nSubtractFeeFromAmount++;
2674 if (vecSend.empty())
2676 strFailReason =
_(
"Transaction must have at least one recipient");
2717 unsigned int nBytes;
2719 std::set<CInputCoin> setCoins;
2720 std::vector<CInputCoin> vCoins;
2723 std::vector<COutput> vAvailableCoins;
2724 AvailableCoins(vAvailableCoins,
true, &coin_control);
2732 if (!boost::get<CNoDestination>(&coin_control.
destChange)) {
2748 strFailReason =
_(
"Keypool ran out, please call keypoolrefill first");
2754 CTxOut change_prototype_txout(0, scriptChange);
2759 bool pick_new_inputs =
true;
2764 nChangePosInOut = nChangePosRequest;
2770 CAmount nValueToSelect = nValue;
2771 if (nSubtractFeeFromAmount == 0)
2772 nValueToSelect += nFeeRet;
2774 for (
const auto& recipient : vecSend)
2776 CTxOut txout(recipient.nAmount, recipient.scriptPubKey);
2778 if (recipient.fSubtractFeeFromAmount)
2780 txout.
nValue -= nFeeRet / nSubtractFeeFromAmount;
2785 txout.
nValue -= nFeeRet % nSubtractFeeFromAmount;
2791 if (recipient.fSubtractFeeFromAmount && nFeeRet > 0)
2794 strFailReason =
_(
"The transaction amount is too small to pay the fee");
2796 strFailReason =
_(
"The transaction amount is too small to send after the fee has been deducted");
2799 strFailReason =
_(
"Transaction amount too small");
2802 txNew.
vout.push_back(txout);
2806 if (pick_new_inputs) {
2809 if (!SelectCoins(vAvailableCoins, nValueToSelect, setCoins, nValueIn, &coin_control))
2811 strFailReason =
_(
"Insufficient funds");
2816 const CAmount nChange = nValueIn - nValueToSelect;
2822 boost::get<CNoDestination>(&coin_control.
destChange) &&
2823 setCoins.size() > 0)
2827 auto pcoin = setCoins.begin();
2828 scriptChange = pcoin->txout.scriptPubKey;
2830 change_prototype_txout =
CTxOut(0, scriptChange);
2835 CTxOut newTxOut(nChange, scriptChange);
2839 if (
IsDust(newTxOut, discard_rate))
2841 nChangePosInOut = -1;
2846 if (nChangePosInOut == -1)
2851 else if ((
unsigned int)nChangePosInOut > txNew.
vout.size())
2853 strFailReason =
_(
"Change index out of range");
2857 std::vector<CTxOut>::iterator position = txNew.
vout.begin()+nChangePosInOut;
2858 txNew.
vout.insert(position, newTxOut);
2861 nChangePosInOut = -1;
2866 std::copy(setCoins.begin(), setCoins.end(), std::back_inserter(vCoins));
2868 for (std::vector<CInputCoin>::size_type i = 0 ; i != vCoins.size(); i++){
2869 if(vCoins[i].outpoint==senderInput){
2871 iter_swap(vCoins.begin(),vCoins.begin()+i);
2888 for (
const auto& coin : vCoins)
2893 if (!DummySignTx(txNew, vCoins)) {
2894 strFailReason =
_(
"Signing transaction failed");
2901 for (
auto& vin : txNew.
vin) {
2903 vin.scriptWitness.SetNull();
2906 nFeeNeeded = GetMinimumFee(nBytes, coin_control, ::
mempool, ::
feeEstimator, &feeCalc)+nGasFee;
2912 strFailReason =
_(
"Transaction too large for fee policy");
2916 if (nFeeRet >= nFeeNeeded) {
2927 if (nChangePosInOut == -1 && nSubtractFeeFromAmount == 0 && pick_new_inputs) {
2928 unsigned int tx_size_with_change = nBytes + change_prototype_size + 2;
2931 if (nFeeRet >= fee_needed_with_change + minimum_value_for_change) {
2932 pick_new_inputs =
false;
2933 nFeeRet = fee_needed_with_change;
2939 if (nFeeRet > nFeeNeeded && nChangePosInOut != -1 && nSubtractFeeFromAmount == 0) {
2940 CAmount extraFeePaid = nFeeRet - nFeeNeeded;
2941 std::vector<CTxOut>::iterator change_position = txNew.
vout.begin()+nChangePosInOut;
2942 change_position->nValue += extraFeePaid;
2943 nFeeRet -= extraFeePaid;
2947 else if (!pick_new_inputs) {
2952 strFailReason =
_(
"Transaction fee and change calculation failed");
2957 if (nChangePosInOut != -1 && nSubtractFeeFromAmount == 0) {
2958 CAmount additionalFeeNeeded = nFeeNeeded - nFeeRet;
2959 std::vector<CTxOut>::iterator change_position = txNew.
vout.begin()+nChangePosInOut;
2961 if (change_position->nValue >= MIN_FINAL_CHANGE + additionalFeeNeeded) {
2962 change_position->nValue -= additionalFeeNeeded;
2963 nFeeRet += additionalFeeNeeded;
2970 if (nSubtractFeeFromAmount > 0) {
2971 pick_new_inputs =
false;
2975 nFeeRet = nFeeNeeded;
2980 if (nChangePosInOut == -1) reservekey.
ReturnKey();
2986 for (
const auto& coin : vCoins)
2988 const CScript& scriptPubKey = coin.txout.scriptPubKey;
2993 strFailReason =
_(
"Signing transaction failed");
3004 wtxNew.
SetTx(MakeTransactionRef(std::move(txNew)));
3009 strFailReason =
_(
"Transaction too large");
3014 if (
gArgs.
GetBoolArg(
"-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS)) {
3019 size_t nLimitAncestors =
gArgs.
GetArg(
"-limitancestorcount", DEFAULT_ANCESTOR_LIMIT);
3020 size_t nLimitAncestorSize =
gArgs.
GetArg(
"-limitancestorsize", DEFAULT_ANCESTOR_SIZE_LIMIT)*1000;
3021 size_t nLimitDescendants =
gArgs.
GetArg(
"-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT);
3022 size_t nLimitDescendantSize =
gArgs.
GetArg(
"-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT)*1000;
3023 std::string errString;
3025 strFailReason =
_(
"Transaction has too long of a mempool chain");
3049 LogPrintf(
"CommitTransaction:\n%s", wtxNew.
tx->ToString());
3056 AddToWallet(wtxNew);
3059 for (
const CTxIn& txin : wtxNew.
tx->vin)
3068 mapRequestCount[wtxNew.
GetHash()] = 0;
3070 if (fBroadcastTransactions)
3093 return AddAccountingEntry(acentry, &walletdb);
3102 laccentries.push_back(acentry);
3125 fee_needed = coin_control.
m_feerate->GetFee(nTxBytes);
3138 bool conservative_estimate = !coin_control.
signalRbf;
3145 if (fee_needed == 0) {
3147 fee_needed = fallbackFee.GetFee(nTxBytes);
3152 if (fee_needed < min_mempool_fee) {
3153 fee_needed = min_mempool_fee;
3159 CAmount required_fee = GetRequiredFee(nTxBytes);
3160 if (required_fee > fee_needed) {
3161 fee_needed = required_fee;
3179 fFirstRunRet =
false;
3183 if (dbw->Rewrite(
"\x04pool"))
3185 setInternalKeyPool.clear();
3186 setExternalKeyPool.clear();
3187 m_pool_key_to_index.clear();
3195 return nLoadWalletRet;
3196 fFirstRunRet = !vchDefaultKey.IsValid();
3209 mapWallet.erase(
hash);
3213 if (dbw->Rewrite(
"\x04pool"))
3215 setInternalKeyPool.clear();
3216 setExternalKeyPool.clear();
3217 m_pool_key_to_index.clear();
3225 return nZapSelectTxRet;
3239 if (dbw->Rewrite(
"\x04pool"))
3242 setInternalKeyPool.clear();
3243 setExternalKeyPool.clear();
3244 m_pool_key_to_index.clear();
3252 return nZapWalletTxRet;
3260 bool fUpdated =
false;
3263 std::map<CTxDestination, CAddressBookData>::iterator mi = mapAddressBook.find(address);
3264 fUpdated = mi != mapAddressBook.end();
3265 mapAddressBook[
address].name = strName;
3266 if (!strPurpose.empty())
3267 mapAddressBook[address].purpose = strPurpose;
3269 NotifyAddressBookChanged(
this, address, strName, ::
IsMine(*
this, address) !=
ISMINE_NO,
3283 for (
const std::pair<std::string, std::string> &item : mapAddressBook[address].destdata)
3287 mapAddressBook.erase(address);
3300 auto mi = mapAddressBook.find(address);
3301 if (mi != mapAddressBook.end()) {
3302 return mi->second.name;
3307 const static std::string DEFAULT_ACCOUNT_NAME;
3308 return DEFAULT_ACCOUNT_NAME;
3315 vchDefaultKey = vchPubKey;
3329 for (int64_t nIndex : setInternalKeyPool) {
3332 setInternalKeyPool.clear();
3334 for (int64_t nIndex : setExternalKeyPool) {
3337 setExternalKeyPool.clear();
3339 m_pool_key_to_index.clear();
3341 if (!TopUpKeyPool()) {
3344 LogPrintf(
"CWallet::NewKeyPool rewrote keypool\n");
3352 return setExternalKeyPool.size();
3359 setInternalKeyPool.insert(nIndex);
3361 setExternalKeyPool.insert(nIndex);
3363 m_max_keypool_index =
std::max(m_max_keypool_index, nIndex);
3370 if (mapKeyMetadata.count(keyid) == 0)
3383 unsigned int nTargetSize;
3385 nTargetSize = kpSize;
3391 int64_t missingExternal =
std::max(
std::max((int64_t) nTargetSize, (int64_t) 1) - (int64_t)setExternalKeyPool.size(), (int64_t) 0);
3392 int64_t missingInternal =
std::max(
std::max((int64_t) nTargetSize, (int64_t) 1) - (int64_t)setInternalKeyPool.size(), (int64_t) 0);
3397 missingInternal = 0;
3399 bool internal =
false;
3401 for (int64_t i = missingInternal + missingExternal; i--;)
3403 if (i < missingInternal) {
3408 int64_t index = ++m_max_keypool_index;
3410 CPubKey pubkey(GenerateNewKey(walletdb,
internal));
3412 throw std::runtime_error(std::string(__func__) +
": writing generated key failed");
3416 setInternalKeyPool.insert(index);
3418 setExternalKeyPool.insert(index);
3420 m_pool_key_to_index[pubkey.
GetID()] = index;
3422 if (missingInternal + missingExternal > 0) {
3423 LogPrintf(
"keypool added %d keys (%d internal), size=%u (%u internal)\n", missingInternal + missingExternal, missingInternal, setInternalKeyPool.size() + setExternalKeyPool.size(), setInternalKeyPool.size());
3439 bool fReturningInternal = IsHDEnabled() && CanSupportFeature(
FEATURE_HD_SPLIT) && fRequestedInternal;
3440 std::set<int64_t>& setKeyPool = fReturningInternal ? setInternalKeyPool : setExternalKeyPool;
3443 if(setKeyPool.empty())
3448 auto it = setKeyPool.begin();
3450 setKeyPool.erase(it);
3451 if (!walletdb.
ReadPool(nIndex, keypool)) {
3452 throw std::runtime_error(std::string(__func__) +
": read failed");
3455 throw std::runtime_error(std::string(__func__) +
": unknown key in key pool");
3457 if (keypool.
fInternal != fReturningInternal) {
3458 throw std::runtime_error(std::string(__func__) +
": keypool entry misclassified");
3463 LogPrintf(
"keypool reserve %d\n", nIndex);
3481 setInternalKeyPool.insert(nIndex);
3483 setExternalKeyPool.insert(nIndex);
3485 m_pool_key_to_index[pubkey.
GetID()] = nIndex;
3487 LogPrintf(
"keypool return %d\n", nIndex);
3496 ReserveKeyFromKeyPool(nIndex, keypool,
internal);
3499 if (IsLocked())
return false;
3501 result = GenerateNewKey(walletdb,
internal);
3510 static int64_t GetOldestKeyTimeInPool(
const std::set<int64_t>& setKeyPool,
CWalletDB& walletdb) {
3511 if (setKeyPool.empty()) {
3516 int64_t nIndex = *(setKeyPool.begin());
3517 if (!walletdb.
ReadPool(nIndex, keypool)) {
3518 throw std::runtime_error(std::string(__func__) +
": read oldest key in keypool failed");
3521 return keypool.
nTime;
3531 int64_t oldestKey = GetOldestKeyTimeInPool(setExternalKeyPool, walletdb);
3533 oldestKey =
std::max(GetOldestKeyTimeInPool(setInternalKeyPool, walletdb), oldestKey);
3541 std::map<CTxDestination, CAmount> balances;
3545 for (
const auto& walletEntry : mapWallet)
3547 const CWalletTx *pcoin = &walletEntry.second;
3559 for (
unsigned int i = 0; i < pcoin->
tx->vout.size(); i++)
3567 CAmount n = IsSpent(walletEntry.first, i) ? 0 : pcoin->
tx->vout[i].nValue;
3569 if (!balances.count(addr))
3571 balances[addr] += n;
3582 std::set< std::set<CTxDestination> > groupings;
3583 std::set<CTxDestination> grouping;
3585 for (
const auto& walletEntry : mapWallet)
3587 const CWalletTx *pcoin = &walletEntry.second;
3589 if (pcoin->
tx->vin.size() > 0)
3591 bool any_mine =
false;
3593 for (
CTxIn txin : pcoin->
tx->vin)
3600 grouping.insert(address);
3607 for (
CTxOut txout : pcoin->
tx->vout)
3608 if (IsChange(txout))
3613 grouping.insert(txoutAddr);
3616 if (grouping.size() > 0)
3618 groupings.insert(grouping);
3624 for (
const auto& txout : pcoin->
tx->vout)
3630 grouping.insert(address);
3631 groupings.insert(grouping);
3636 std::set< std::set<CTxDestination>* > uniqueGroupings;
3637 std::map< CTxDestination, std::set<CTxDestination>* > setmap;
3638 for (std::set<CTxDestination> _grouping : groupings)
3641 std::set< std::set<CTxDestination>* > hits;
3642 std::map< CTxDestination, std::set<CTxDestination>* >::iterator it;
3644 if ((it = setmap.find(
address)) != setmap.end())
3645 hits.insert((*it).second);
3648 std::set<CTxDestination>* merged =
new std::set<CTxDestination>(_grouping);
3649 for (std::set<CTxDestination>* hit : hits)
3651 merged->insert(hit->begin(), hit->end());
3652 uniqueGroupings.erase(hit);
3655 uniqueGroupings.insert(merged);
3662 std::set< std::set<CTxDestination> > ret;
3663 for (std::set<CTxDestination>* uniqueGrouping : uniqueGroupings)
3665 ret.insert(*uniqueGrouping);
3666 delete uniqueGrouping;
3675 std::set<CTxDestination> result;
3676 for (
const std::pair<CTxDestination, CAddressBookData>& item : mapAddressBook)
3679 const std::string& strName = item.second.name;
3680 if (strName == strAccount)
3681 result.insert(address);
3691 pwallet->ReserveKeyFromKeyPool(nIndex, keypool,
internal);
3699 assert(vchPubKey.IsValid());
3707 pwallet->KeepKey(nIndex);
3715 pwallet->ReturnKey(nIndex, fInternal, vchPubKey);
3724 bool internal = setInternalKeyPool.count(keypool_id);
3725 if (!
internal)
assert(setExternalKeyPool.count(keypool_id));
3726 std::set<int64_t> *setKeyPool =
internal ? &setInternalKeyPool : &setExternalKeyPool;
3727 auto it = setKeyPool->begin();
3730 while (it != std::end(*setKeyPool)) {
3731 const int64_t& index = *(it);
3732 if (index > keypool_id)
break;
3735 if (walletdb.
ReadPool(index, keypool)) {
3739 LogPrintf(
"keypool index %d removed\n", index);
3740 it = setKeyPool->erase(it);
3746 std::shared_ptr<CReserveKey> rKey = std::make_shared<CReserveKey>(
this);
3748 if (!rKey->GetReservedKey(pubkey))
3758 setLockedCoins.insert(output);
3764 setLockedCoins.erase(output);
3770 setLockedCoins.clear();
3778 return (setLockedCoins.count(outpt) > 0);
3784 for (std::set<COutPoint>::iterator it = setLockedCoins.begin();
3785 it != setLockedCoins.end(); it++) {
3787 vOutpts.push_back(outpt);
3795 mapKeyBirth.clear();
3798 for (
const auto& entry : mapKeyMetadata) {
3799 if (entry.second.nCreateTime) {
3800 mapKeyBirth[entry.first] = entry.second.nCreateTime;
3806 std::map<CKeyID, CBlockIndex*> mapKeyFirstBlock;
3807 std::set<CKeyID> setKeys;
3809 for (
const CKeyID &keyid : setKeys) {
3810 if (mapKeyBirth.count(keyid) == 0)
3811 mapKeyFirstBlock[keyid] = pindexMax;
3816 if (mapKeyFirstBlock.empty())
3820 std::vector<CKeyID> vAffected;
3821 for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); it++) {
3827 int nHeight = blit->second->nHeight;
3828 for (
const CTxOut &txout : wtx.
tx->vout) {
3831 for (
const CKeyID &keyid : vAffected) {
3833 std::map<CKeyID, CBlockIndex*>::iterator rit = mapKeyFirstBlock.find(keyid);
3834 if (rit != mapKeyFirstBlock.end() && nHeight < rit->second->nHeight)
3835 rit->second = blit->second;
3843 for (std::map<CKeyID, CBlockIndex*>::const_iterator it = mapKeyFirstBlock.begin(); it != mapKeyFirstBlock.end(); it++)
3844 mapKeyBirth[it->first] = it->second->GetBlockTime() - TIMESTAMP_WINDOW;
3874 int64_t latestEntry = 0;
3877 int64_t latestTolerated = latestNow + 300;
3878 const TxItems& txOrdered = wtxOrdered;
3879 for (
auto it = txOrdered.rbegin(); it != txOrdered.rend(); ++it) {
3880 CWalletTx*
const pwtx = it->second.first;
3892 nSmartTime = pacentry->
nTime;
3894 if (nSmartTime <= latestTolerated) {
3895 latestEntry = nSmartTime;
3896 if (nSmartTime > latestNow) {
3897 latestNow = nSmartTime;
3914 if (boost::get<CNoDestination>(&dest))
3917 mapAddressBook[dest].destdata.insert(std::make_pair(key, value));
3923 if (!mapAddressBook[dest].destdata.erase(key))
3930 mapAddressBook[dest].destdata.insert(std::make_pair(key, value));
3936 std::map<CTxDestination, CAddressBookData>::const_iterator i = mapAddressBook.find(dest);
3937 if(i != mapAddressBook.end())
3939 CAddressBookData::StringMap::const_iterator j = i->second.destdata.find(key);
3940 if(j != i->second.destdata.end())
3953 std::vector<std::string> values;
3954 for (
const auto&
address : mapAddressBook) {
3955 for (
const auto&
data :
address.second.destdata) {
3956 if (!
data.first.compare(0, prefix.size(),
prefix)) {
3957 values.emplace_back(
data.second);
3967 strUsage +=
HelpMessageOpt(
"-disablewallet",
_(
"Do not load the wallet and disable wallet RPC calls"));
3968 strUsage +=
HelpMessageOpt(
"-keypool=<n>",
strprintf(
_(
"Set key pool size to <n> (default: %u)"), DEFAULT_KEYPOOL_SIZE));
3969 strUsage +=
HelpMessageOpt(
"-fallbackfee=<amt>",
strprintf(
_(
"A fee rate (in %s/kB) that will be used when fee estimation has insufficient data (default: %s)"),
3971 strUsage +=
HelpMessageOpt(
"-discardfee=<amt>",
strprintf(
_(
"The fee rate (in %s/kB) that indicates your tolerance for discarding change by adding it to the fee (default: %s). " 3972 "Note: An output is discarded if it is dust at this rate, but we will always discard up to the dust relay fee and a discard fee above that is limited by the fee estimate for the longest target"),
3974 strUsage +=
HelpMessageOpt(
"-mintxfee=<amt>",
strprintf(
_(
"Fees (in %s/kB) smaller than this are considered zero fee for transaction creation (default: %s)"),
3976 strUsage +=
HelpMessageOpt(
"-paytxfee=<amt>",
strprintf(
_(
"Fee (in %s/kB) to add to transactions you send (default: %s)"),
3978 strUsage +=
HelpMessageOpt(
"-rescan",
_(
"Rescan the block chain for missing wallet transactions on startup"));
3979 strUsage +=
HelpMessageOpt(
"-salvagewallet",
_(
"Attempt to recover private keys from a corrupt wallet on startup"));
3980 strUsage +=
HelpMessageOpt(
"-spendzeroconfchange",
strprintf(
_(
"Spend unconfirmed change when sending transactions (default: %u)"), DEFAULT_SPEND_ZEROCONF_CHANGE));
3981 strUsage +=
HelpMessageOpt(
"-txconfirmtarget=<n>",
strprintf(
_(
"If paytxfee is not set, include enough fee so transactions begin confirmation on average within n blocks (default: %u)"), DEFAULT_TX_CONFIRM_TARGET));
3982 strUsage +=
HelpMessageOpt(
"-usehd",
_(
"Use hierarchical deterministic key generation (HD) after BIP32. Only has effect during wallet creation/first start") +
" " +
strprintf(
_(
"(default: %u)"), DEFAULT_USE_HD_WALLET));
3983 strUsage +=
HelpMessageOpt(
"-walletrbf",
strprintf(
_(
"Send transactions with full-RBF opt-in enabled (default: %u)"), DEFAULT_WALLET_RBF));
3984 strUsage +=
HelpMessageOpt(
"-upgradewallet",
_(
"Upgrade wallet to latest format on startup"));
3986 strUsage +=
HelpMessageOpt(
"-walletbroadcast",
_(
"Make the wallet broadcast transactions") +
" " +
strprintf(
_(
"(default: %u)"), DEFAULT_WALLETBROADCAST));
3987 strUsage +=
HelpMessageOpt(
"-walletnotify=<cmd>",
_(
"Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)"));
3988 strUsage +=
HelpMessageOpt(
"-zapwallettxes=<mode>",
_(
"Delete all wallet transactions and only recover those parts of the blockchain through -rescan on startup") +
3989 " " +
_(
"(1 = keep tx meta data e.g. account owner and payment request information, 2 = drop tx meta data)"));
3990 strUsage +=
HelpMessageOpt(
"-rpcmaxgasprice",
strprintf(
_(
"The max value (in satoshis) for gas price allowed through RPC (default: %u)"), MAX_RPC_GAS_PRICE));
3996 strUsage +=
HelpMessageOpt(
"-dblogsize=<n>",
strprintf(
"Flush wallet database activity from memory to disk log every <n> megabytes (default: %u)", DEFAULT_WALLET_DBLOGSIZE));
3997 strUsage +=
HelpMessageOpt(
"-flushwallet",
strprintf(
"Run a thread to flush wallet periodically (default: %u)", DEFAULT_FLUSHWALLET));
3998 strUsage +=
HelpMessageOpt(
"-privdb",
strprintf(
"Sets the DB_PRIVATE flag in the wallet db environment (default: %u)", DEFAULT_WALLET_PRIVDB));
3999 strUsage +=
HelpMessageOpt(
"-walletrejectlongchains",
strprintf(
_(
"Wallet will not create transactions that violate mempool chain limits (default: %u)"), DEFAULT_WALLET_REJECT_LONG_CHAINS));
4008 std::vector<CWalletTx> vWtx;
4022 tempWallet =
nullptr;
4028 bool fFirstRun =
true;
4041 " or address book entries might be missing or incorrect."),
4061 int nMaxVersion =
gArgs.
GetArg(
"-upgradewallet", 0);
4062 if (nMaxVersion == 0)
4065 nMaxVersion = CLIENT_VERSION;
4069 LogPrintf(
"Allowing wallet upgrade up to %i\n", nMaxVersion);
4070 if (nMaxVersion < walletInstance->GetVersion())
4089 throw std::runtime_error(std::string(__func__) +
": Storing master key failed");
4095 InitError(
_(
"Cannot write default address") +=
"\n");
4105 InitError(
strprintf(
_(
"Error loading %s: You can't disable HD on an already existing HD wallet"), walletFile));
4109 InitError(
strprintf(
_(
"Error loading %s: You can't enable HD on an already existing non-HD wallet"), walletFile));
4138 block = block->
pprev;
4140 if (pindexRescan != block) {
4141 InitError(
_(
"Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node)"));
4159 walletInstance->
dbw->IncrementUpdateCounter();
4169 std::map<uint256, CWalletTx>::iterator mi = walletInstance->
mapWallet.find(hash);
4170 if (mi != walletInstance->
mapWallet.end())
4195 return walletInstance;
4205 for (
const std::string& walletFile :
gArgs.
GetArgs(
"-wallet")) {
4206 CWallet *
const pwallet = CreateWalletFromFile(walletFile);
4222 ReacceptWalletTransactions();
4225 if (!CWallet::fFlushScheduled.exchange(
true)) {
4233 const bool is_multiwallet =
gArgs.
GetArgs(
"-wallet").size() > 1;
4239 LogPrintf(
"%s: parameter interaction: -blocksonly=1 -> setting -walletbroadcast=0\n", __func__);
4243 if (is_multiwallet) {
4244 return InitError(
strprintf(
"%s is only allowed with a single wallet file",
"-salvagewallet"));
4248 LogPrintf(
"%s: parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__);
4252 int zapwallettxes =
gArgs.
GetArg(
"-zapwallettxes", 0);
4255 LogPrintf(
"%s: parameter interaction: -zapwallettxes=%s -> setting -persistmempool=0\n", __func__, zapwallettxes);
4259 if (zapwallettxes != 0) {
4260 if (is_multiwallet) {
4261 return InitError(
strprintf(
"%s is only allowed with a single wallet file",
"-zapwallettxes"));
4264 LogPrintf(
"%s: parameter interaction: -zapwallettxes=%s -> setting -rescan=1\n", __func__, zapwallettxes);
4268 if (is_multiwallet) {
4270 return InitError(
strprintf(
"%s is only allowed with a single wallet file",
"-upgradewallet"));
4275 return InitError(
"-sysperms is not allowed in combination with enabled wallet functionality");
4277 return InitError(
_(
"Rescans are not possible in pruned mode. You will need to use -reindex which will download the whole blockchain again."));
4281 _(
"The wallet will avoid paying less than the minimum relay fee."));
4288 if (n > HIGH_TX_FEE_PER_KB)
4290 _(
"This is the minimum transaction fee you pay on every transaction."));
4298 if (nFeePerK > HIGH_TX_FEE_PER_KB)
4300 _(
"This is the transaction fee you may pay when fee estimates are not available."));
4301 CWallet::fallbackFee =
CFeeRate(nFeePerK);
4308 if (nFeePerK > HIGH_TX_FEE_PER_KB)
4310 _(
"This is the transaction fee you may discard if change is smaller than dust at this level"));
4311 CWallet::m_discard_rate =
CFeeRate(nFeePerK);
4318 if (nFeePerK > HIGH_TX_FEE_PER_KB)
4320 _(
"This is the transaction fee you will pay if you send a transaction."));
4325 return InitError(
strprintf(
_(
"Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s)"),
4334 if (nMaxFee > HIGH_MAX_TX_FEE)
4335 InitWarning(
_(
"-maxtxfee is set very high! Fees this large could be paid on a single transaction."));
4339 return InitError(
strprintf(
_(
"Invalid amount for -maxtxfee=<amount>: '%s' (must be at least the minrelay fee of %s to prevent stuck transactions)"),
4353 return dbw->Backup(strDest);
4359 mapToken[
hash] = token;
4367 mapTokenTx[
hash] = tokenTx;
4376 CWalletDB walletdb(*dbw,
"r+", fFlushOnClose);
4380 bool fInsertedNew =
true;
4382 std::map<uint256, CTokenInfo>::iterator it = mapToken.find(hash);
4383 if(it!=mapToken.end())
4385 fInsertedNew =
false;
4402 mapToken[
hash] = wtoken;
4409 for(
auto it = mapTokenTx.begin(); it != mapTokenTx.end(); it++)
4411 uint256 tokenTxHash = it->second.GetHash();
4412 NotifyTokenTransactionChanged(
this, tokenTxHash, CT_UPDATED);
4425 CWalletDB walletdb(*dbw,
"r+", fFlushOnClose);
4429 bool fInsertedNew =
true;
4431 std::map<uint256, CTokenTx>::iterator it = mapTokenTx.find(hash);
4432 if(it!=mapTokenTx.end())
4434 fInsertedNew =
false;
4441 wtokenTx.
strLabel = it->second.strLabel;
4449 mapTokenTx[
hash] = wtokenTx;
4451 NotifyTokenTransactionChanged(
this, hash, fInsertedNew ?
CT_NEW :
CT_UPDATED);
4467 vchPubKey = vchPubKeyIn;
4468 fInternal = internalIn;
4473 nTimeCreated = (nExpires ?
GetTime() : 0);
4474 nTimeExpires = nExpires;
4483 nIndex = posInBlock;
4530 if( this->GetHeight() < consensus.
CoinbaseLock && this->GetHeight() != 2 )
4533 return std::max(0, (COINBASE_MATURITY+1) - GetDepthInMainChain());
4560 for(
auto it = mapToken.begin(); it != mapToken.end(); it++)
4591 for(
auto it = mapToken.begin(); it != mapToken.end(); it++)
4611 CWalletDB walletdb(*dbw,
"r+", fFlushOnClose);
4613 bool fFound =
false;
4615 std::map<uint256, CTokenInfo>::iterator it = mapToken.find(tokenHash);
4616 if(it!=mapToken.end())
4629 NotifyTokenChanged(
this, tokenHash,
CT_DELETED);
4632 for(
auto it = mapTokenTx.begin(); it != mapTokenTx.end(); it++)
4634 uint256 tokenTxHash = it->second.GetHash();
4635 NotifyTokenTransactionChanged(
this, tokenTxHash,
CT_UPDATED);
4646 bool fUpdated =
false;
4649 auto mi = mapContractBook.find(strAddress);
4650 fUpdated = mi != mapContractBook.end();
4651 mapContractBook[strAddress].name = strName;
4652 mapContractBook[strAddress].abi = strAbi;
4655 NotifyContractBookChanged(
this, strAddress, strName, strAbi, (fUpdated ?
CT_UPDATED :
CT_NEW) );
4667 mapContractBook.erase(strAddress);
4670 NotifyContractBookChanged(
this, strAddress,
"",
"",
CT_DELETED);
4683 mapContractBook[
address].name = value;
4685 else if(key ==
"abi")
4687 mapContractBook[
address].abi = value;
CAmount GetImmatureWatchOnlyCredit(const bool &fUseCache=true) const
std::string strTokenSymbol
void postInitProcess(CScheduler &scheduler)
Wallet post-init setup Gives the wallet a chance to register repetitive tasks and complete post-init ...
const std::string CURRENCY_UNIT
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost)
Compute the virtual transaction size (weight reinterpreted as bytes).
CAmount GetFeePerK() const
Return the fee in liu for a size of 1000 bytes.
bool WriteMinVersion(int nVersion)
CBlockIndex * ScanForWalletTransactions(CBlockIndex *pindexStart, bool fUpdate=false)
Scan the block chain (starting in pindexStart) for transactions from or to us.
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
bool SetKeyFromPassphrase(const SecureString &strKeyData, const std::vector< unsigned char > &chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod)
void DeriveNewChildKey(CWalletDB &walletdb, CKeyMetadata &metadata, CKey &secret, bool internal=false)
CFeeRate GetMinFee(size_t sizelimit) const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
std::set< std::set< CTxDestination > > GetAddressGroupings()
const char * DEFAULT_WALLET_DAT
void UpdateTransaction(CMutableTransaction &tx, unsigned int nIn, const SignatureData &data)
void SetTx(CTransactionRef arg)
static const uint256 ABANDON_HASH
Constant used in hashBlock to indicate tx has been abandoned.
CAmount GetAvailableWatchOnlyCredit(const bool &fUseCache=true) const
bool SignTransaction(CMutableTransaction &tx)
CKeyID masterKeyID
master key hash160
static std::string GetWalletHelpString(bool showDebug)
CAmount GetLegacyBalance(const isminefilter &filter, int minDepth, const std::string *account) const
int64_t nOrderPos
position in ordered transaction list
bool AddKeyPubKeyWithDB(CWalletDB &walletdb, const CKey &key, const CPubKey &pubkey)
void SetMerkleBranch(const CBlockIndex *pIndex, int posInBlock)
std::string strReceiverAddress
void BindWallet(CWallet *pwalletIn)
unsigned int nDerivationMethod
0 = EVP_sha512() 1 = scrypt()
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
CAmount GetChange(const CTxOut &txout) const
bool fPruneMode
True if we're running in -prune mode.
std::vector< CWalletRef > vpwallets
bool IsFromMe(const CTransaction &tx) const
should probably be renamed to IsRelevantToMe
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.
int64_t GetOldestKeyPoolTime()
CAmount GetAvailableCredit(bool fUseCache=true) const
int GetDepthInMainChain(const CBlockIndex *&pindexRet) const
Return depth of transaction in blockchain: <0 : conflicts with a transaction this deep in the blockch...
void AvailableCoins(std::vector< COutput > &vCoins, bool fOnlySafe=true, const CCoinControl *coinControl=nullptr, const CAmount &nMinimumAmount=1, const CAmount &nMaximumAmount=MAX_MONEY, const CAmount &nMinimumSumAmount=MAX_MONEY, const uint64_t &nMaximumCount=0, const int &nMinDepth=0, const int &nMaxDepth=9999999) const
populate vCoins with vector of available COutputs.
CAmount GetCredit(const CTxOut &txout, const isminefilter &filter) const
bool fAllowWatchOnly
Includes watch only addresses which match the ISMINE_WATCH_SOLVABLE criteria.
const unsigned char * begin() const
bool IsAllFromMe(const CTransaction &tx, const isminefilter &filter) const
Returns whether all of the inputs match the filter.
bool WriteAccount(const std::string &strAccount, const CAccount &account)
void Process(const CScript &script)
bool AccountMove(std::string strFrom, std::string strTo, CAmount nAmount, std::string strComment="")
int64_t GetTransactionWeight(const CTransaction &tx)
CAmount GetAvailableBalance(const CCoinControl *coinControl=nullptr) const
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
bool DelContractBook(const std::string &strAddress)
const unsigned int WALLET_CRYPTO_KEY_SIZE
CBlockIndex * pprev
pointer to the index of the predecessor of this block
bool IsArgSet(const std::string &strArg)
Return true if the given argument has been manually set.
static bool InitLoadWallet()
Force estimateSmartFee to use non-conservative estimates.
struct evm_uint256be balance(struct evm_env *env, struct evm_uint160be address)
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
char fFromMe
From me flag is set to 1 for transactions that were created by the wallet on this fabcoin node...
bool WriteTx(const CWalletTx &wtx)
bool VerifyPubKey(const CPubKey &vchPubKey) const
Verify thoroughly whether a private key and a public key match.
bool TxnBegin()
Begin a new transaction.
boost::optional< unsigned int > m_confirm_target
Override the default confirmation target if set.
CFeeRate estimateSmartFee(int confTarget, int *answerFoundAtTarget, const CTxMemPool &pool)
Estimate feerate needed to get be included in a block within confTarget blocks.
std::map< CTxDestination, CAddressBookData > mapAddressBook
CCriticalSection cs_wallet
bool SetContractBook(const std::string &strAddress, const std::string &strName, const std::string &strAbi)
const uint256 & GetHash() const
std::unique_ptr< CWalletDBWrapper > dbw
Encryption/decryption context with key information.
bool WriteToken(const CTokenInfo &wtoken)
bool GetTokenTxDetails(const CTokenTx &wtx, uint256 &credit, uint256 &debit, std::string &tokenSymbol, uint8_t &decimals) const
CAmount maxTxFee
Absolute maximum transaction fee (in liu) used by wallet and mempool (rejects high fee in sendrawtran...
CAmount nReserveBalance
Settings.
std::vector< unsigned char > vchCryptedKey
bool bSpendZeroConfChange
std::string strFromAccount
WalletFeature
(client) version numbers for particular wallet features
size_t GetSerializeSize(const T &t, int nType, int nVersion=0)
bool WriteMasterKey(unsigned int nID, const CMasterKey &kMasterKey)
bool IsChange(const CTxOut &txout) const
bool TxnCommit()
Commit current transaction.
bool WriteCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret, const CKeyMetadata &keyMeta)
static const uint32_t SEQUENCE_FINAL
Only serialized through CTransaction.
int64_t IncOrderPosNext(CWalletDB *pwalletdb=nullptr)
Increment the next transaction order id.
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override
Adds a key to the store, and saves it to disk.
std::string GetHex() const
Private key encryption is done based on a CMasterKey, which holds a salt and random encryption key...
void ReacceptWalletTransactions()
bool MoneyRange(const CAmount &nValue)
bool FundTransaction(CMutableTransaction &tx, CAmount &nFeeRet, int &nChangePosInOut, std::string &strFailReason, bool lockUnspents, const std::set< int > &setSubtractFeeFromOutputs, CCoinControl)
Insert additional inputs into the transaction by calling CreateTransaction();.
const Consensus::Params & GetConsensus() const
base58-encoded Fabcoin addresses.
CAmount GetUnconfirmedBalance() const
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
int64_t nOrderPos
position in ordered transaction list
bool Decrypt(const std::vector< unsigned char > &vchCiphertext, CKeyingMaterial &vchPlaintext) const
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
A signature creator for transactions.
virtual bool AddCScript(const CScript &redeemScript) override
Support for BIP 0013 : see https://github.com/fabcoin/bips/blob/master/bip-0013.mediawiki.
void GetStrongRandBytes(unsigned char *out, int num)
Function to gather random data from multiple sources, failing whenever any of those source fail to pr...
bool SelectCoinsMinConf(const CAmount &nTargetValue, int nConfMine, int nConfTheirs, uint64_t nMaxAncestors, std::vector< COutput > vCoins, std::set< CInputCoin > &setCoinsRet, CAmount &nValueRet) const
Shuffle and select coins until nTargetValue is reached while avoiding small change; This method is st...
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
void AddToSpends(const COutPoint &outpoint, const uint256 &wtxid)
std::string strSenderAddress
CPubKey GenerateNewHDMasterKey()
bool SetMaxVersion(int nVersion)
change which version we're allowed to upgrade to (note that this does not immediately imply upgrading...
isminetype IsMine(const CKeyStore &keystore, const CScript &scriptPubKey, SigVersion sigversion)
std::set< txiter, CompareIteratorByHash > setEntries
for(size_t i=trim;i< len;i++) hash[i-trim]
static bool ParameterInteraction()
void GetKeyBirthTimes(std::map< CTxDestination, int64_t > &mapKeyBirth) const
uint8_t isminefilter
used for bitflags of isminetype
std::vector< std::string > GetArgs(const std::string &strArg)
void scheduleEvery(Function f, int64_t deltaMilliSeconds)
boost::signals2::signal< void(CWallet *wallet)> LoadWallet
A wallet has been loaded.
void ListAccountCreditDebit(const std::string &strAccount, std::list< CAccountingEntry > &acentries)
assert(len-trim+(2 *lenIndices)<=WIDTH)
void ListLockedCoins(std::vector< COutPoint > &vOutpts) const
bool AddTokenEntry(const CTokenInfo &token, bool fFlushOnClose=true)
void MarkDirty()
make sure balances are recalculated
CChainParams defines various tweakable parameters of a given instance of the Fabcoin system...
bool SetMinVersion(enum WalletFeature, CWalletDB *pwalletdbIn=nullptr, bool fExplicit=false)
signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVe...
unsigned int GetKeyPoolSize()
int64_t GetTxTime() const
CWalletKey(int64_t nExpires=0)
todo: add something to note what created it (user, getnewaddress, change) maybe should have a map<str...
uint160 Hash160(const T1 pbegin, const T1 pend)
Compute the 160-bit hash an object.
bool ErasePurpose(const std::string &strAddress)
bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry &acentry)
This writes directly to the database, and will not update the CWallet's cached accounting entries! Us...
CAmount GetImmatureCredit(bool fUseCache=true) const
void ListSelected(std::vector< COutPoint > &vOutpoints) const
virtual bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
CAmount GetCredit(const isminefilter &filter) const
bool MarkReplaced(const uint256 &originalHash, const uint256 &newHash)
Mark a transaction as replaced by another transaction (e.g., BIP 125).
DBErrors
Error statuses for the wallet database.
void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool)
bool EncryptWallet(const SecureString &strWalletPassphrase)
if(a.IndicesBefore(b, len, lenIndices))
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
std::shared_ptr< const CTransaction > CTransactionRef
bool ProduceSignature(const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
void ReserveKeyFromKeyPool(int64_t &nIndex, CKeyPool &keypool, bool fRequestedInternal)
double GuessVerificationProgress(const ChainTxData &data, CBlockIndex *pindex)
Guess how far we are in the verification process at the given block index.
bool fOverrideFeeRate
Override automatic min/max checks on fee, m_feerate must be set if true.
void PushInventory(const CInv &inv)
void SyncTransaction(const CTransactionRef &tx, const CBlockIndex *pindex=nullptr, int posInBlock=0)
bool AddWatchOnly(const CScript &dest) override
Private version of AddWatchOnly method which does not accept a timestamp, and which will reset the wa...
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) ...
CAmount GetDebit(const isminefilter &filter) const
filter decides which addresses will count towards the debit
bool LoadContractData(const std::string &address, const std::string &key, const std::string &value)
Adds a contract data tuple to the store, without saving it to disk.
const std::vector< CTxIn > vin
std::map< CTxDestination, CAmount > GetAddressBalances()
bool Derive(CExtKey &out, unsigned int nChild) const
CAmount GetImmatureBalance() const
boost::optional< CFeeRate > m_feerate
Override the default payTxFee if set.
bool IsEquivalentTo(const CWalletTx &tx) const
bool WriteOrderPosNext(int64_t nOrderPosNext)
void BlockDisconnected(const std::shared_ptr< const CBlock > &pblock) override
Notifies listeners of a block being disconnected.
bool TransactionWithinChainLimit(const uint256 &txid, size_t chainLimit) const
Returns false if the transaction is in the mempool and not within the chain limit specified...
bool HasWalletSpend(const uint256 &txid) const
Check if a given transaction has any of its outputs spent by another transaction in the wallet...
static bool RecoverKeysOnlyFilter(void *callbackData, CDataStream ssKey, CDataStream ssValue)
mapValue_t mapValue
Key/value map with information about the transaction.
std::string ToString() const
static CAmount GetRequiredFee(unsigned int nTxBytes)
Return the minimum required fee taking into account the floating relay fee and user set minimum trans...
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< CTxDestination > &addressRet, int &nRequiredRet)
bool CreateTransaction(const std::vector< CRecipient > &vecSend, CWalletTx &wtxNew, CReserveKey &reservekey, CAmount &nFeeRet, int &nChangePosInOut, std::string &strFailReason, const CCoinControl &coin_control, bool sign=true, CAmount nGasFee=0, bool hasSender=false)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
void operator()(const CNoDestination &none)
CAmount GetUnconfirmedWatchOnlyBalance() const
std::string strContractAddress
std::set< CTxDestination > GetAccountAddresses(const std::string &strAccount) const
int GetDepthInMainChain() const
void KeepKey(int64_t nIndex)
int64_t CAmount
Amount in lius (Can be negative)
std::multimap< int64_t, TxPair > TxItems
int64_t GetBlockTimeMax() const
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override
Add a key to the store.
void MarkReserveKeysAsUsed(int64_t keypool_id)
Marks all keys in the keypool up to and including reserve_key as used.
bool fBatchProcessingMode
bool ReadBlockFromDisk(Block &block, const CDiskBlockPos &pos, const Consensus::Params &consensusParams)
Functions for disk access for blocks.
#define AssertLockHeld(cs)
void SetBroadcastTransactions(bool broadcast)
Set whether this wallet broadcasts transactions.
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
CBlockPolicyEstimator feeEstimator
uint256 SerializeHash(const T &obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
Compute the 256-bit hash of an object's serialization.
void MarkConflicted(const uint256 &hashBlock, const uint256 &hashTx)
int GetBlocksToMaturity() const
bool IsTokenTxMine(const CTokenTx &wtx) const
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
DBErrors ReorderTransactions()
size_t KeypoolCountExternalKeys()
bool DelAddressBook(const CTxDestination &address)
int Height() const
Return the maximal height in the chain.
unsigned int nTxConfirmTarget
An instance of this class represents one database.
unsigned int HighestTargetTracked(FeeEstimateHorizon horizon) const
Calculation of highest target that estimates are tracked for.
bool WriteTokenTx(const CTokenTx &wTokenTx)
void GetAmounts(std::list< COutputEntry > &listReceived, std::list< COutputEntry > &listSent, CAmount &nFee, std::string &strSentAccount, const isminefilter &filter) const
static CFeeRate m_discard_rate
bool CheckFinalTx(const CTransaction &tx, int flags)
Check if transaction will be final in the next block to be created.
bool EraseToken(uint256 hash)
unsigned int nStatus
Verification status of this block. See enum BlockStatus.
bool AbandonTransaction(const uint256 &hashTx)
DBErrors LoadWallet(bool &fFirstRunRet)
CBlockIndex * Next(const CBlockIndex *pindex) const
Find the successor of a block in this chain, or nullptr if the given index is not found or is the tip...
void UnlockCoin(const COutPoint &output)
bool signalRbf
Signal BIP-125 replace by fee.
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)
static bool VerifyEnvironment(const std::string &walletFile, const fs::path &dataDir, std::string &errorStr)
const std::string & GetAccountName(const CScript &scriptPubKey) const
CPubKey GenerateNewKey(CWalletDB &walletdb, bool internal=false)
keystore implementation Generate a new key
void TransactionAddedToMempool(const CTransactionRef &tx) override
Notifies listeners of a transaction having been added to mempool.
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) ...
bool NewKeyPool()
Mark old keypool keys as used, and generate all new keys.
std::string strContractAddress
isminetype
IsMine() return codes.
An input of a transaction.
bool AddCScript(const CScript &redeemScript) override
Support for BIP 0013 : see https://github.com/fabcoin/bips/blob/master/bip-0013.mediawiki.
CPubKey GetPubKey() const
Compute the public key from a private key.
We want to be able to estimate feerates that are needed on tx's to be included in a certain number of...
bool WriteName(const std::string &strAddress, const std::string &strName)
CPrivKey GetPrivKey() const
Convert the private key to a CPrivKey (serialized OpenSSL private key data).
DBErrors LoadWallet(CWallet *pwallet)
void SetBestChain(const CBlockLocator &loc) override
Notifies listeners of the new active block chain on-disk.
void operator()(const CScriptID &scriptId)
CTxDestination destChange
const uint32_t BIP32_HARDENED_KEY_LIMIT
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet, txnouttype *typeRet)
int CoinbaseLock
Block height before which the coinbase subsidy will be locked for the same period.
virtual bool HaveKey(const CKeyID &address) const =0
Check whether a key corresponding to a given address is present in the store.
bool TransactionCanBeAbandoned(const uint256 &hashTx) const
Return whether transaction can be abandoned.
bool EraseContractData(const std::string &address, const std::string &key)
Erase contract data tuple from wallet database.
void Select(const COutPoint &output)
uint256 uint256S(const char *str)
An encapsulated public key.
bool fAllowOtherInputs
If false, allows unselected inputs, but requires all selected inputs be used.
bool Unlock(const CKeyingMaterial &vMasterKeyIn)
CAmount GetBalance() const
bool operator()(const CInputCoin &t1, const CInputCoin &t2) const
static bool VerifyDatabaseFile(const std::string &walletFile, const fs::path &dataDir, std::string &warningStr, std::string &errorStr)
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
const std::vector< CTxOut > vout
Chars allowed in filenames.
const ChainTxData & TxData() const
bool SelectCoins(const std::vector< COutput > &vAvailableCoins, const CAmount &nTargetValue, std::set< CInputCoin > &setCoinsRet, CAmount &nValueRet, const CCoinControl *coinControl=nullptr) const
Select a set of coins such that nValueRet >= nTargetValue and at least all coins from coinControl are...
bool IsUnspendable() const
Returns whether the script is guaranteed to fail at execution, regardless of the initial stack...
bool WriteDestData(const std::string &address, const std::string &key, const std::string &value)
Write destination data key,value tuple to database.
void Flush(bool shutdown=false)
Flush wallet (bitdb flush)
bool EraseDestData(const CTxDestination &dest, const std::string &key)
Erases a destination data tuple in the store and on disk.
void UpdateTimeFirstKey(int64_t nCreateTime)
Update wallet first key creation time.
void MaybeCompactWalletDB()
Compacts BDB state so that wallet.dat is self-contained (if there are changes)
void ResendWalletTransactions(int64_t nBestBlockTime, CConnman *connman) override
Tells listeners to broadcast their data.
bool GetReservedKey(CPubKey &pubkey, bool internal=false)
std::string ToString() const
unsigned int ComputeTimeSmart(const CWalletTx &wtx) const
Compute smart timestamp for a transaction being added to the wallet.
bool ParseMoney(const std::string &str, CAmount &nRet)
CAmount GetDebit(const CTxIn &txin, const isminefilter &filter) const
Returns amount of debit if the input matches the filter, otherwise returns 0.
DBErrors ZapSelectTx(std::vector< uint256 > &vHashIn, std::vector< uint256 > &vHashOut)
An output of a transaction.
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
static bool Recover(const std::string &filename, void *callbackDataIn, bool(*recoverKVcallback)(void *callbackData, CDataStream ssKey, CDataStream ssValue), std::string &out_backup_filename)
bool AddToWalletIfInvolvingMe(const CTransactionRef &tx, const CBlockIndex *pIndex, int posInBlock, bool fUpdate)
Add a transaction to the wallet, or update it.
CScript GetScriptForDestination(const CTxDestination &dest)
bool LoadToWallet(const CWalletTx &wtxIn)
bool IsFromMe(const isminefilter &filter) const
Parameters that influence chain consensus.
std::string AmountHighWarn(const std::string &optname)
An outpoint - a combination of a transaction hash and an index n into its vout.
std::vector< CTxOut > vout
bool ErasePool(int64_t nPool)
bool EraseWatchOnly(const CScript &script)
unsigned int fTimeReceivedIsTxTime
static CWallet * CreateWalletFromFile(const std::string walletFile)
std::string FormatMoney(const CAmount &n)
Money parsing/formatting utilities.
CAmount GetDustThreshold(const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
void ForEachNode(Callable &&func)
virtual bool RemoveWatchOnly(const CScript &dest) override
void LockCoin(const COutPoint &output)
bool AddToWallet(const CWalletTx &wtxIn, bool fFlushOnClose=true)
Access to the wallet database.
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree, bool *pfMissingInputs, std::list< CTransactionRef > *plTxnReplaced, bool fOverrideMempoolLimit, const CAmount nAbsurdFee, bool rawTx)
(try to) add transaction to memory pool plTxnReplaced will be appended to with all transactions repla...
A transaction with a bunch of additional info that only the owner cares about.
DBErrors ZapWalletTx(std::vector< CWalletTx > &vWtx)
void RegisterValidationInterface(CValidationInterface *pwalletIn)
Register a wallet to receive updates from core.
std::map< CTxDestination, std::vector< COutput > > ListCoins() const
Return list of available coins and locked coins grouped by non-change output address.
bool SetHDMasterKey(const CPubKey &key)
bool exists(uint256 hash) const
bool ReadBestBlock(CBlockLocator &locator)
CBlockIndex * FindEarliestAtLeast(int64_t nTime) const
Find the earliest block with timestamp equal or greater than the given.
std::string GetRejectReason() const
bool WriteDefaultKey(const CPubKey &vchPubKey)
int64_t RescanFromTime(int64_t startTime, bool update)
Scan active chain for relevant transactions after importing keys.
const CTxOut & FindNonChangeParentOutput(const CTransaction &tx, int output) const
Find non-change parent output.
std::string ToString() const
#define LogPrint(category,...)
CAmount GetWatchOnlyBalance() const
bool WriteHDChain(const CHDChain &chain)
write the hdchain model (external chain child index counter)
CBlockIndex * Genesis() const
Returns the index entry for the genesis block of this chain, or nullptr if none.
Signature sign(Secret const &_k, h256 const &_hash)
Returns siganture of message hash.
CAmount GetFee(size_t nBytes) const
Return the fee in liu for the given size in bytes.
Capture information about block/transaction validation.
std::vector< uint256 > ResendWalletTransactionsBefore(int64_t nTime, CConnman *connman)
bool WriteBestBlock(const CBlockLocator &locator)
static bool Verify()
Responsible for reading and validating the -wallet arguments and verifying the wallet database...
const unsigned int WALLET_CRYPTO_SALT_SIZE
std::set< uint256 > GetConflicts(const uint256 &txid) const
Get wallet transactions that conflict with given transaction (spend same outputs) ...
void GetScriptForMining(std::shared_ptr< CReserveScript > &script)
static std::atomic< bool > fFlushScheduled
static CAmount GetMinimumFee(unsigned int nTxBytes, const CCoinControl &coin_control, const CTxMemPool &pool, const CBlockPolicyEstimator &estimator, FeeCalculation *feeCalc)
Estimate the minimum fee considering user set parameters and the required fee.
std::vector< CTransactionRef > vtx
CAmount GetImmatureWatchOnlyBalance() const
const CWalletTx * GetWalletTx(const uint256 &hash) const
bool InitError(const std::string &str)
Show error message.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
bool randbool()
Generate a random boolean.
int GetRequestCount() const
DBErrors ZapWalletTx(std::vector< CWalletTx > &vWtx)
static CFeeRate fallbackFee
If fee estimation does not have enough data to provide estimates, use this fee instead.
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
PlatformStyle::TableColorType type
A key allocated from the key pool.
bool LoadKeyMetadata(const CTxDestination &pubKey, const CKeyMetadata &metadata)
Load metadata (used by LoadWallet)
void SyncMetaData(std::pair< TxSpends::iterator, TxSpends::iterator >)
The block chain is a tree shaped structure starting with the genesis block at the root...
const CChainParams & Params()
Return the currently selected parameters.
bool ReadPool(int64_t nPool, CKeyPool &keypool)
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
Serialized script, used inside transaction inputs and outputs.
bool LoadTokenTx(const CTokenTx &tokenTx)
bool Encrypt(const CKeyingMaterial &vchPlaintext, std::vector< unsigned char > &vchCiphertext) const
bool RemoveTokenEntry(const uint256 &tokenHash, bool fFlushOnClose=true)
CAmount GetAccountCreditDebit(const std::string &strAccount)
bool TopUpKeyPool(unsigned int kpSize=0)
bool fWalletUnlockStakingOnly
bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret) override
Adds an encrypted key to the store, and saves it to disk.
unsigned int nTimeSmart
Stable timestamp that never changes, and reflects the order a transaction was added to the wallet...
void BlockConnected(const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindex, const std::vector< CTransactionRef > &vtxConflicted) override
Notifies listeners of a block being connected.
void ListAccountCreditDebit(const std::string &strAccount, std::list< CAccountingEntry > &entries)
A virtual base class for key stores.
bool SetDefaultKey(const CPubKey &vchPubKey)
bool RelayWalletTransaction(CConnman *connman)
CBlockIndex * FindForkInGlobalIndex(const CChain &chain, const CBlockLocator &locator)
Find the last common block between the parameter chain and a locator.
int64_t GetAdjustedTime()
void runCommand(const std::string &strCommand)
A reference to a CKey: the Hash160 of its serialized public key.
bool WriteContractData(const std::string &address, const std::string &key, const std::string &value)
Write contract data key,value tuple to database.
std::string ToString() const
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
bool GetAccountPubkey(CPubKey &pubKey, std::string strAccount, bool bForceNew=false)
static CFeeRate minTxFee
Fees smaller than this (in liu) are considered zero fee (for transaction creation) Override with -min...
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
void operator()(const CKeyID &keyId)
Fee rate in liu per kilobyte: CAmount / kB.
bool SetHDChain(const CHDChain &chain, bool memonly)
bool LoadCScript(const CScript &redeemScript)
CFeeRate payTxFee(DEFAULT_TRANSACTION_FEE)
Transaction fee set by the user.
void SetMaster(const unsigned char *seed, unsigned int nSeedLen)
std::vector< unsigned char > vchSalt
std::map< uint256, CWalletTx > mapWallet
static const int VERSION_HD_CHAIN_SPLIT
bool LoadToken(const CTokenInfo &token)
A reference to a CScript: the Hash160 of its serialization (see script.h)
bool GetKeyFromPool(CPubKey &key, bool internal=false)
std::vector< CKeyID > & vKeys
bool IsDust(const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
A mutable version of CTransaction.
const uint256 & GetHash() const
std::set< uint256 > GetConflicts() const
Indicates that we know how to create a scriptSig that would solve this if we were given the appropria...
std::vector< std::string > GetDestValues(const std::string &prefix) const
Get all destination values matching a prefix.
FeeEstimateMode m_fee_mode
Fee estimation mode to control arguments to estimateSmartFee.
const fs::path & GetDataDir(bool fNetSpecific)
isminetype IsMine(const CTxIn &txin) const
std::string strSenderAddress
std::map< int, ScriptsElement > scriptsMap
Cache of the recent mpos scripts for the block reward recipients The max size of the map is 2 * nCach...
dev::WithExisting max(dev::WithExisting _a, dev::WithExisting _b)
bool IsLockedCoin(uint256 hash, unsigned int n) const
int64_t GetTime()
GetTimeMicros() and GetTimeMillis() both return the system time, but in different units...
struct evm_uint160be address(struct evm_env *env)
unsigned int nTimeReceived
time received by this node
void InitWarning(const std::string &str)
Show warning message.
An encapsulated private key.
bool EraseName(const std::string &strAddress)
CBlockLocator GetLocator(const CBlockIndex *pindex=nullptr) const
Return a CBlockLocator that refers to a block in this chain (by default the tip). ...
CClientUIInterface uiInterface
The basic transaction that is broadcasted on the network and contained in blocks. ...
int nHeight
height of the entry in the chain. The genesis block has height 0
Use default settings based on other criteria.
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.
Information about a peer.
unsigned int nDeriveIterations
full block available in blk*.dat
bool WriteCScript(const uint160 &hash, const CScript &redeemScript)
bool WritePurpose(const std::string &strAddress, const std::string &purpose)
bool IsSpent(const uint256 &hash, unsigned int n) const
Outpoint is spent if any non-conflicted transaction spends it:
int64_t GetBlockTime() const
std::pair< CWalletTx *, CAccountingEntry * > TxPair
unsigned int size() const
Simple read-only vector-like interface.
bool IsSelected(const COutPoint &output) const
bool BackupWallet(const std::string &strDest)
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
std::string AmountErrMsg(const char *const optname, const std::string &strValue)
bool AddAccountingEntry(const CAccountingEntry &)
bool fNotUseChangeAddress
std::string SanitizeString(const std::string &str, int rule)
Remove unsafe chars.
DBErrors ZapSelectTx(std::vector< uint256 > &vHashIn, std::vector< uint256 > &vHashOut)
void mine(Client &c, int numBlocks)
std::string strOtherAccount
bool bZeroBalanceAddressToken
void ReturnKey(int64_t nIndex, bool fInternal, const CPubKey &pubkey)
bool AcceptToMemoryPool(const CAmount &nAbsurdFee, CValidationState &state)
Pass this transaction to the mempool.
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
bool WriteWatchOnly(const CScript &script, const CKeyMetadata &keymeta)
bool ReadAccount(const std::string &strAccount, CAccount &account)
unsigned int nTx
Number of transactions in this block.
bool LoadWatchOnly(const CScript &dest)
Adds a watch-only address to the store, without saving it to disk (used by LoadWallet) ...
static const int VERSION_HD_BASE
bool CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntries &setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString, bool fSearchForParents=true) const
Try to calculate all in-mempool ancestors of entry.
bool AddTokenTxEntry(const CTokenTx &tokenTx, bool fFlushOnClose=true)
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result...
boost::signals2::signal< void(const std::string &message)> InitMessage
Progress message during initialization.
bool RemoveWatchOnly(const CScript &dest) override
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const =0
uint256 GetBlockHash() const
uint64_t GetRand(uint64_t nMax)
CAffectedKeysVisitor(const CKeyStore &keystoreIn, std::vector< CKeyID > &vKeysIn)
bool WriteKey(const CPubKey &vchPubKey, const CPrivKey &vchPrivKey, const CKeyMetadata &keyMeta)
bool Unlock(const SecureString &strWalletPassphrase)
virtual bool AddWatchOnly(const CScript &dest) override
Support for Watch-only addresses.
CAmount GetChange() const
std::vector< unsigned char > ToByteVector(const T &in)
const CKeyStore & keystore
std::vector< std::pair< std::string, std::string > > vOrderForm
bool CommitTransaction(CWalletTx &wtxNew, CReserveKey &reservekey, CConnman *connman, CValidationState &state)
Call after CreateTransaction unless you want to abort.
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.