mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
Cleanup code using forward declarations.
Use misc methods of avoiding unnecesary header includes. Replace int typedefs with int##_t from stdint.h. Replace PRI64[xdu] with PRI[xdu]64 from inttypes.h. Normalize QT_VERSION ifs where possible. Resolve some indirect dependencies as direct ones. Remove extern declarations from .cpp files.
This commit is contained in:
178
src/wallet.cpp
178
src/wallet.cpp
@@ -4,11 +4,15 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "wallet.h"
|
||||
#include "walletdb.h"
|
||||
#include "crypter.h"
|
||||
#include "ui_interface.h"
|
||||
|
||||
#include "base58.h"
|
||||
#include "net.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <openssl/rand.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -20,8 +24,8 @@ using namespace std;
|
||||
|
||||
struct CompareValueOnly
|
||||
{
|
||||
bool operator()(const pair<int64, pair<const CWalletTx*, unsigned int> >& t1,
|
||||
const pair<int64, pair<const CWalletTx*, unsigned int> >& t2) const
|
||||
bool operator()(const pair<int64_t, pair<const CWalletTx*, unsigned int> >& t1,
|
||||
const pair<int64_t, pair<const CWalletTx*, unsigned int> >& t2) const
|
||||
{
|
||||
return t1.first < t2.first;
|
||||
}
|
||||
@@ -42,7 +46,7 @@ CPubKey CWallet::GenerateNewKey()
|
||||
CPubKey pubkey = secret.GetPubKey();
|
||||
|
||||
// Create new metadata
|
||||
int64 nCreationTime = GetTime();
|
||||
int64_t nCreationTime = GetTime();
|
||||
mapKeyMetadata[pubkey.GetID()] = CKeyMetadata(nCreationTime);
|
||||
if (!nTimeFirstKey || nCreationTime < nTimeFirstKey)
|
||||
nTimeFirstKey = nCreationTime;
|
||||
@@ -148,7 +152,7 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase,
|
||||
return false;
|
||||
if (CCryptoKeyStore::Unlock(vMasterKey))
|
||||
{
|
||||
int64 nStartTime = GetTimeMillis();
|
||||
int64_t nStartTime = GetTimeMillis();
|
||||
crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod);
|
||||
pMasterKey.second.nDeriveIterations = pMasterKey.second.nDeriveIterations * (100 / ((double)(GetTimeMillis() - nStartTime)));
|
||||
|
||||
@@ -256,7 +260,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
||||
RAND_bytes(&kMasterKey.vchSalt[0], WALLET_CRYPTO_SALT_SIZE);
|
||||
|
||||
CCrypter crypter;
|
||||
int64 nStartTime = GetTimeMillis();
|
||||
int64_t nStartTime = GetTimeMillis();
|
||||
crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, 25000, kMasterKey.nDerivationMethod);
|
||||
kMasterKey.nDeriveIterations = 2500000 / ((double)(GetTimeMillis() - nStartTime));
|
||||
|
||||
@@ -319,9 +323,9 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
||||
return true;
|
||||
}
|
||||
|
||||
int64 CWallet::IncOrderPosNext(CWalletDB *pwalletdb)
|
||||
int64_t CWallet::IncOrderPosNext(CWalletDB *pwalletdb)
|
||||
{
|
||||
int64 nRet = nOrderPosNext++;
|
||||
int64_t nRet = nOrderPosNext++;
|
||||
if (pwalletdb) {
|
||||
pwalletdb->WriteOrderPosNext(nOrderPosNext);
|
||||
} else {
|
||||
@@ -414,7 +418,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
|
||||
unsigned int latestEntry = 0;
|
||||
{
|
||||
// Tolerate times up to the last timestamp in the wallet not more than 5 minutes into the future
|
||||
int64 latestTolerated = latestNow + 300;
|
||||
int64_t latestTolerated = latestNow + 300;
|
||||
std::list<CAccountingEntry> acentries;
|
||||
TxItems txOrdered = OrderedTxItems(acentries);
|
||||
for (TxItems::reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
|
||||
@@ -423,7 +427,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
|
||||
if (pwtx == &wtx)
|
||||
continue;
|
||||
CAccountingEntry *const pacentry = (*it).second.second;
|
||||
int64 nSmartTime;
|
||||
int64_t nSmartTime;
|
||||
if (pwtx)
|
||||
{
|
||||
nSmartTime = pwtx->nTimeSmart;
|
||||
@@ -558,7 +562,7 @@ bool CWallet::IsMine(const CTxIn &txin) const
|
||||
return false;
|
||||
}
|
||||
|
||||
int64 CWallet::GetDebit(const CTxIn &txin) const
|
||||
int64_t CWallet::GetDebit(const CTxIn &txin) const
|
||||
{
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
@@ -594,9 +598,9 @@ bool CWallet::IsChange(const CTxOut& txout) const
|
||||
return false;
|
||||
}
|
||||
|
||||
int64 CWalletTx::GetTxTime() const
|
||||
int64_t CWalletTx::GetTxTime() const
|
||||
{
|
||||
int64 n = nTimeSmart;
|
||||
int64_t n = nTimeSmart;
|
||||
return n ? n : nTimeReceived;
|
||||
}
|
||||
|
||||
@@ -639,8 +643,8 @@ int CWalletTx::GetRequestCount() const
|
||||
return nRequests;
|
||||
}
|
||||
|
||||
void CWalletTx::GetAmounts(list<pair<CTxDestination, int64> >& listReceived,
|
||||
list<pair<CTxDestination, int64> >& listSent, int64& nFee, string& strSentAccount) const
|
||||
void CWalletTx::GetAmounts(list<pair<CTxDestination, int64_t> >& listReceived,
|
||||
list<pair<CTxDestination, int64_t> >& listSent, int64_t& nFee, string& strSentAccount) const
|
||||
{
|
||||
nFee = 0;
|
||||
listReceived.clear();
|
||||
@@ -648,10 +652,10 @@ void CWalletTx::GetAmounts(list<pair<CTxDestination, int64> >& listReceived,
|
||||
strSentAccount = strFromAccount;
|
||||
|
||||
// Compute fee:
|
||||
int64 nDebit = GetDebit();
|
||||
int64_t nDebit = GetDebit();
|
||||
if (nDebit > 0) // debit>0 means we signed/sent this transaction
|
||||
{
|
||||
int64 nValueOut = GetValueOut(*this);
|
||||
int64_t nValueOut = GetValueOut(*this);
|
||||
nFee = nDebit - nValueOut;
|
||||
}
|
||||
|
||||
@@ -692,26 +696,26 @@ void CWalletTx::GetAmounts(list<pair<CTxDestination, int64> >& listReceived,
|
||||
|
||||
}
|
||||
|
||||
void CWalletTx::GetAccountAmounts(const string& strAccount, int64& nReceived,
|
||||
int64& nSent, int64& nFee) const
|
||||
void CWalletTx::GetAccountAmounts(const string& strAccount, int64_t& nReceived,
|
||||
int64_t& nSent, int64_t& nFee) const
|
||||
{
|
||||
nReceived = nSent = nFee = 0;
|
||||
|
||||
int64 allFee;
|
||||
int64_t allFee;
|
||||
string strSentAccount;
|
||||
list<pair<CTxDestination, int64> > listReceived;
|
||||
list<pair<CTxDestination, int64> > listSent;
|
||||
list<pair<CTxDestination, int64_t> > listReceived;
|
||||
list<pair<CTxDestination, int64_t> > listSent;
|
||||
GetAmounts(listReceived, listSent, allFee, strSentAccount);
|
||||
|
||||
if (strAccount == strSentAccount)
|
||||
{
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64)& s, listSent)
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& s, listSent)
|
||||
nSent += s.second;
|
||||
nFee = allFee;
|
||||
}
|
||||
{
|
||||
LOCK(pwallet->cs_wallet);
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64)& r, listReceived)
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listReceived)
|
||||
{
|
||||
if (pwallet->mapAddressBook.count(r.first))
|
||||
{
|
||||
@@ -932,7 +936,7 @@ void CWallet::ResendWalletTransactions()
|
||||
CWalletTx& wtx = item.second;
|
||||
// Don't rebroadcast until it's had plenty of time that
|
||||
// it should have gotten in already by now.
|
||||
if (nTimeBestReceived - (int64)wtx.nTimeReceived > 5 * 60)
|
||||
if (nTimeBestReceived - (int64_t)wtx.nTimeReceived > 5 * 60)
|
||||
mapSorted.insert(make_pair(wtx.nTimeReceived, &wtx));
|
||||
}
|
||||
BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted)
|
||||
@@ -954,9 +958,9 @@ void CWallet::ResendWalletTransactions()
|
||||
//
|
||||
|
||||
|
||||
int64 CWallet::GetBalance() const
|
||||
int64_t CWallet::GetBalance() const
|
||||
{
|
||||
int64 nTotal = 0;
|
||||
int64_t nTotal = 0;
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
|
||||
@@ -970,9 +974,9 @@ int64 CWallet::GetBalance() const
|
||||
return nTotal;
|
||||
}
|
||||
|
||||
int64 CWallet::GetUnconfirmedBalance() const
|
||||
int64_t CWallet::GetUnconfirmedBalance() const
|
||||
{
|
||||
int64 nTotal = 0;
|
||||
int64_t nTotal = 0;
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
|
||||
@@ -985,9 +989,9 @@ int64 CWallet::GetUnconfirmedBalance() const
|
||||
return nTotal;
|
||||
}
|
||||
|
||||
int64 CWallet::GetImmatureBalance() const
|
||||
int64_t CWallet::GetImmatureBalance() const
|
||||
{
|
||||
int64 nTotal = 0;
|
||||
int64_t nTotal = 0;
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
|
||||
@@ -1028,8 +1032,8 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed) const
|
||||
}
|
||||
}
|
||||
|
||||
static void ApproximateBestSubset(vector<pair<int64, pair<const CWalletTx*,unsigned int> > >vValue, int64 nTotalLower, int64 nTargetValue,
|
||||
vector<char>& vfBest, int64& nBest, int iterations = 1000)
|
||||
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)
|
||||
{
|
||||
vector<char> vfIncluded;
|
||||
|
||||
@@ -1041,7 +1045,7 @@ static void ApproximateBestSubset(vector<pair<int64, pair<const CWalletTx*,unsig
|
||||
for (int nRep = 0; nRep < iterations && nBest != nTargetValue; nRep++)
|
||||
{
|
||||
vfIncluded.assign(vValue.size(), false);
|
||||
int64 nTotal = 0;
|
||||
int64_t nTotal = 0;
|
||||
bool fReachedTarget = false;
|
||||
for (int nPass = 0; nPass < 2 && !fReachedTarget; nPass++)
|
||||
{
|
||||
@@ -1074,18 +1078,18 @@ static void ApproximateBestSubset(vector<pair<int64, pair<const CWalletTx*,unsig
|
||||
}
|
||||
}
|
||||
|
||||
bool CWallet::SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, vector<COutput> vCoins,
|
||||
set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet) const
|
||||
bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfTheirs, vector<COutput> vCoins,
|
||||
set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const
|
||||
{
|
||||
setCoinsRet.clear();
|
||||
nValueRet = 0;
|
||||
|
||||
// List of values less than target
|
||||
pair<int64, pair<const CWalletTx*,unsigned int> > coinLowestLarger;
|
||||
coinLowestLarger.first = std::numeric_limits<int64>::max();
|
||||
pair<int64_t, pair<const CWalletTx*,unsigned int> > coinLowestLarger;
|
||||
coinLowestLarger.first = std::numeric_limits<int64_t>::max();
|
||||
coinLowestLarger.second.first = NULL;
|
||||
vector<pair<int64, pair<const CWalletTx*,unsigned int> > > vValue;
|
||||
int64 nTotalLower = 0;
|
||||
vector<pair<int64_t, pair<const CWalletTx*,unsigned int> > > vValue;
|
||||
int64_t nTotalLower = 0;
|
||||
|
||||
random_shuffle(vCoins.begin(), vCoins.end(), GetRandInt);
|
||||
|
||||
@@ -1097,9 +1101,9 @@ bool CWallet::SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfThe
|
||||
continue;
|
||||
|
||||
int i = output.i;
|
||||
int64 n = pcoin->vout[i].nValue;
|
||||
int64_t n = pcoin->vout[i].nValue;
|
||||
|
||||
pair<int64,pair<const CWalletTx*,unsigned int> > coin = make_pair(n,make_pair(pcoin, i));
|
||||
pair<int64_t,pair<const CWalletTx*,unsigned int> > coin = make_pair(n,make_pair(pcoin, i));
|
||||
|
||||
if (n == nTargetValue)
|
||||
{
|
||||
@@ -1140,7 +1144,7 @@ bool CWallet::SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfThe
|
||||
// Solve subset sum by stochastic approximation
|
||||
sort(vValue.rbegin(), vValue.rend(), CompareValueOnly());
|
||||
vector<char> vfBest;
|
||||
int64 nBest;
|
||||
int64_t nBest;
|
||||
|
||||
ApproximateBestSubset(vValue, nTotalLower, nTargetValue, vfBest, nBest, 1000);
|
||||
if (nBest != nTargetValue && nTotalLower >= nTargetValue + CENT)
|
||||
@@ -1172,7 +1176,7 @@ bool CWallet::SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfThe
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CWallet::SelectCoins(int64 nTargetValue, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet) const
|
||||
bool CWallet::SelectCoins(int64_t nTargetValue, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const
|
||||
{
|
||||
vector<COutput> vCoins;
|
||||
AvailableCoins(vCoins);
|
||||
@@ -1185,11 +1189,11 @@ bool CWallet::SelectCoins(int64 nTargetValue, set<pair<const CWalletTx*,unsigned
|
||||
|
||||
|
||||
|
||||
bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend,
|
||||
CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason)
|
||||
bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
|
||||
CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason)
|
||||
{
|
||||
int64 nValue = 0;
|
||||
BOOST_FOREACH (const PAIRTYPE(CScript, int64)& s, vecSend)
|
||||
int64_t nValue = 0;
|
||||
BOOST_FOREACH (const PAIRTYPE(CScript, int64_t)& s, vecSend)
|
||||
{
|
||||
if (nValue < 0)
|
||||
{
|
||||
@@ -1216,10 +1220,10 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend,
|
||||
wtxNew.vout.clear();
|
||||
wtxNew.fFromMe = true;
|
||||
|
||||
int64 nTotalValue = nValue + nFeeRet;
|
||||
int64_t nTotalValue = nValue + nFeeRet;
|
||||
double dPriority = 0;
|
||||
// vouts to the payees
|
||||
BOOST_FOREACH (const PAIRTYPE(CScript, int64)& s, vecSend)
|
||||
BOOST_FOREACH (const PAIRTYPE(CScript, int64_t)& s, vecSend)
|
||||
{
|
||||
CTxOut txout(s.second, s.first);
|
||||
if (txout.IsDust(CTransaction::nMinRelayTxFee))
|
||||
@@ -1232,7 +1236,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend,
|
||||
|
||||
// Choose coins to use
|
||||
set<pair<const CWalletTx*,unsigned int> > setCoins;
|
||||
int64 nValueIn = 0;
|
||||
int64_t nValueIn = 0;
|
||||
if (!SelectCoins(nTotalValue, setCoins, nValueIn))
|
||||
{
|
||||
strFailReason = _("Insufficient funds");
|
||||
@@ -1240,21 +1244,21 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend,
|
||||
}
|
||||
BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins)
|
||||
{
|
||||
int64 nCredit = pcoin.first->vout[pcoin.second].nValue;
|
||||
int64_t nCredit = pcoin.first->vout[pcoin.second].nValue;
|
||||
//The priority after the next block (depth+1) is used instead of the current,
|
||||
//reflecting an assumption the user would accept a bit more delay for
|
||||
//a chance at a free transaction.
|
||||
dPriority += (double)nCredit * (pcoin.first->GetDepthInMainChain()+1);
|
||||
}
|
||||
|
||||
int64 nChange = nValueIn - nValue - nFeeRet;
|
||||
int64_t nChange = nValueIn - nValue - nFeeRet;
|
||||
// The following if statement should be removed once enough miners
|
||||
// have upgraded to the 0.9 GetMinFee() rules. Until then, this avoids
|
||||
// creating free transactions that have change outputs less than
|
||||
// CENT bitcoins.
|
||||
if (nFeeRet < CTransaction::nMinTxFee && nChange > 0 && nChange < CENT)
|
||||
{
|
||||
int64 nMoveToFee = min(nChange, CTransaction::nMinTxFee - nFeeRet);
|
||||
int64_t nMoveToFee = min(nChange, CTransaction::nMinTxFee - nFeeRet);
|
||||
nChange -= nMoveToFee;
|
||||
nFeeRet += nMoveToFee;
|
||||
}
|
||||
@@ -1328,9 +1332,9 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend,
|
||||
dPriority /= nTxSizeMod;
|
||||
|
||||
// Check that enough fee is included
|
||||
int64 nPayFee = nTransactionFee * (1 + (int64)nBytes / 1000);
|
||||
int64_t nPayFee = nTransactionFee * (1 + (int64_t)nBytes / 1000);
|
||||
bool fAllowFree = AllowFree(dPriority);
|
||||
int64 nMinFee = GetMinFee(wtxNew, fAllowFree, GMF_SEND);
|
||||
int64_t nMinFee = GetMinFee(wtxNew, fAllowFree, GMF_SEND);
|
||||
if (nFeeRet < max(nPayFee, nMinFee))
|
||||
{
|
||||
nFeeRet = max(nPayFee, nMinFee);
|
||||
@@ -1348,10 +1352,10 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CWallet::CreateTransaction(CScript scriptPubKey, int64 nValue,
|
||||
CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason)
|
||||
bool CWallet::CreateTransaction(CScript scriptPubKey, int64_t nValue,
|
||||
CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason)
|
||||
{
|
||||
vector< pair<CScript, int64> > vecSend;
|
||||
vector< pair<CScript, int64_t> > vecSend;
|
||||
vecSend.push_back(make_pair(scriptPubKey, nValue));
|
||||
return CreateTransaction(vecSend, wtxNew, reservekey, nFeeRet, strFailReason);
|
||||
}
|
||||
@@ -1408,10 +1412,10 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
|
||||
|
||||
|
||||
|
||||
string CWallet::SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee)
|
||||
string CWallet::SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, bool fAskFee)
|
||||
{
|
||||
CReserveKey reservekey(this);
|
||||
int64 nFeeRequired;
|
||||
int64_t nFeeRequired;
|
||||
|
||||
if (IsLocked())
|
||||
{
|
||||
@@ -1439,7 +1443,7 @@ string CWallet::SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew,
|
||||
|
||||
|
||||
|
||||
string CWallet::SendMoneyToDestination(const CTxDestination& address, int64 nValue, CWalletTx& wtxNew, bool fAskFee)
|
||||
string CWallet::SendMoneyToDestination(const CTxDestination& address, int64_t nValue, CWalletTx& wtxNew, bool fAskFee)
|
||||
{
|
||||
// Check amount
|
||||
if (nValue <= 0)
|
||||
@@ -1528,21 +1532,21 @@ bool CWallet::NewKeyPool()
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
CWalletDB walletdb(strWalletFile);
|
||||
BOOST_FOREACH(int64 nIndex, setKeyPool)
|
||||
BOOST_FOREACH(int64_t nIndex, setKeyPool)
|
||||
walletdb.ErasePool(nIndex);
|
||||
setKeyPool.clear();
|
||||
|
||||
if (IsLocked())
|
||||
return false;
|
||||
|
||||
int64 nKeys = max(GetArg("-keypool", 100), (int64)0);
|
||||
int64_t nKeys = max(GetArg("-keypool", 100), (int64_t)0);
|
||||
for (int i = 0; i < nKeys; i++)
|
||||
{
|
||||
int64 nIndex = i+1;
|
||||
int64_t nIndex = i+1;
|
||||
walletdb.WritePool(nIndex, CKeyPool(GenerateNewKey()));
|
||||
setKeyPool.insert(nIndex);
|
||||
}
|
||||
LogPrintf("CWallet::NewKeyPool wrote %"PRI64d" new keys\n", nKeys);
|
||||
LogPrintf("CWallet::NewKeyPool wrote %"PRId64" new keys\n", nKeys);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1562,23 +1566,23 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
|
||||
if (kpSize > 0)
|
||||
nTargetSize = kpSize;
|
||||
else
|
||||
nTargetSize = max(GetArg("-keypool", 100), 0LL);
|
||||
nTargetSize = max(GetArg("-keypool", 100), (int64_t) 0);
|
||||
|
||||
while (setKeyPool.size() < (nTargetSize + 1))
|
||||
{
|
||||
int64 nEnd = 1;
|
||||
int64_t nEnd = 1;
|
||||
if (!setKeyPool.empty())
|
||||
nEnd = *(--setKeyPool.end()) + 1;
|
||||
if (!walletdb.WritePool(nEnd, CKeyPool(GenerateNewKey())))
|
||||
throw runtime_error("TopUpKeyPool() : writing generated key failed");
|
||||
setKeyPool.insert(nEnd);
|
||||
LogPrintf("keypool added key %"PRI64d", size=%"PRIszu"\n", nEnd, setKeyPool.size());
|
||||
LogPrintf("keypool added key %"PRId64", size=%"PRIszu"\n", nEnd, setKeyPool.size());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CWallet::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool)
|
||||
void CWallet::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool)
|
||||
{
|
||||
nIndex = -1;
|
||||
keypool.vchPubKey = CPubKey();
|
||||
@@ -1601,17 +1605,17 @@ void CWallet::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool)
|
||||
if (!HaveKey(keypool.vchPubKey.GetID()))
|
||||
throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool");
|
||||
assert(keypool.vchPubKey.IsValid());
|
||||
LogPrintf("keypool reserve %"PRI64d"\n", nIndex);
|
||||
LogPrintf("keypool reserve %"PRId64"\n", nIndex);
|
||||
}
|
||||
}
|
||||
|
||||
int64 CWallet::AddReserveKey(const CKeyPool& keypool)
|
||||
int64_t CWallet::AddReserveKey(const CKeyPool& keypool)
|
||||
{
|
||||
{
|
||||
LOCK2(cs_main, cs_wallet);
|
||||
CWalletDB walletdb(strWalletFile);
|
||||
|
||||
int64 nIndex = 1 + *(--setKeyPool.end());
|
||||
int64_t nIndex = 1 + *(--setKeyPool.end());
|
||||
if (!walletdb.WritePool(nIndex, keypool))
|
||||
throw runtime_error("AddReserveKey() : writing added key failed");
|
||||
setKeyPool.insert(nIndex);
|
||||
@@ -1620,7 +1624,7 @@ int64 CWallet::AddReserveKey(const CKeyPool& keypool)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void CWallet::KeepKey(int64 nIndex)
|
||||
void CWallet::KeepKey(int64_t nIndex)
|
||||
{
|
||||
// Remove from key pool
|
||||
if (fFileBacked)
|
||||
@@ -1628,22 +1632,22 @@ void CWallet::KeepKey(int64 nIndex)
|
||||
CWalletDB walletdb(strWalletFile);
|
||||
walletdb.ErasePool(nIndex);
|
||||
}
|
||||
LogPrintf("keypool keep %"PRI64d"\n", nIndex);
|
||||
LogPrintf("keypool keep %"PRId64"\n", nIndex);
|
||||
}
|
||||
|
||||
void CWallet::ReturnKey(int64 nIndex)
|
||||
void CWallet::ReturnKey(int64_t nIndex)
|
||||
{
|
||||
// Return to key pool
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
setKeyPool.insert(nIndex);
|
||||
}
|
||||
LogPrintf("keypool return %"PRI64d"\n", nIndex);
|
||||
LogPrintf("keypool return %"PRId64"\n", nIndex);
|
||||
}
|
||||
|
||||
bool CWallet::GetKeyFromPool(CPubKey& result)
|
||||
{
|
||||
int64 nIndex = 0;
|
||||
int64_t nIndex = 0;
|
||||
CKeyPool keypool;
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
@@ -1660,9 +1664,9 @@ bool CWallet::GetKeyFromPool(CPubKey& result)
|
||||
return true;
|
||||
}
|
||||
|
||||
int64 CWallet::GetOldestKeyPoolTime()
|
||||
int64_t CWallet::GetOldestKeyPoolTime()
|
||||
{
|
||||
int64 nIndex = 0;
|
||||
int64_t nIndex = 0;
|
||||
CKeyPool keypool;
|
||||
ReserveKeyFromKeyPool(nIndex, keypool);
|
||||
if (nIndex == -1)
|
||||
@@ -1671,9 +1675,9 @@ int64 CWallet::GetOldestKeyPoolTime()
|
||||
return keypool.nTime;
|
||||
}
|
||||
|
||||
std::map<CTxDestination, int64> CWallet::GetAddressBalances()
|
||||
std::map<CTxDestination, int64_t> CWallet::GetAddressBalances()
|
||||
{
|
||||
map<CTxDestination, int64> balances;
|
||||
map<CTxDestination, int64_t> balances;
|
||||
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
@@ -1699,7 +1703,7 @@ std::map<CTxDestination, int64> CWallet::GetAddressBalances()
|
||||
if(!ExtractDestination(pcoin->vout[i].scriptPubKey, addr))
|
||||
continue;
|
||||
|
||||
int64 n = pcoin->IsSpent(i) ? 0 : pcoin->vout[i].nValue;
|
||||
int64_t n = pcoin->IsSpent(i) ? 0 : pcoin->vout[i].nValue;
|
||||
|
||||
if (!balances.count(addr))
|
||||
balances[addr] = 0;
|
||||
@@ -1860,7 +1864,7 @@ void CWallet::GetAllReserveKeys(set<CKeyID>& setAddress) const
|
||||
CWalletDB walletdb(strWalletFile);
|
||||
|
||||
LOCK2(cs_main, cs_wallet);
|
||||
BOOST_FOREACH(const int64& id, setKeyPool)
|
||||
BOOST_FOREACH(const int64_t& id, setKeyPool)
|
||||
{
|
||||
CKeyPool keypool;
|
||||
if (!walletdb.ReadPool(id, keypool))
|
||||
@@ -1915,7 +1919,7 @@ void CWallet::ListLockedCoins(std::vector<COutPoint>& vOutpts)
|
||||
}
|
||||
}
|
||||
|
||||
void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64> &mapKeyBirth) const {
|
||||
void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const {
|
||||
mapKeyBirth.clear();
|
||||
|
||||
// get birth times for keys with metadata
|
||||
|
||||
Reference in New Issue
Block a user