#include "walletdb.h"
#include "base58.h"
-extern unsigned int nStakeMaxAge;
extern bool fWalletUnlockMintOnly;
extern bool fConfChange;
class CAccountingEntry;
// Set of selected transactions
typedef std::set<std::pair<const CWalletTx*,unsigned int> > CoinsSet;
-/** (client) version numbers for particular wallet features */
+// (client) version numbers for particular wallet features
enum WalletFeature
{
FEATURE_BASE = 10500, // the earliest version new wallets supports (only useful for getinfo's clientversion output)
FEATURE_LATEST = 60017
};
-/** A key pool entry */
+// A key pool entry
class CKeyPool
{
public:
int64_t nTime;
CPubKey vchPubKey;
- CKeyPool()
- {
- nTime = GetTime();
- }
-
- CKeyPool(const CPubKey& vchPubKeyIn)
- {
- nTime = GetTime();
- vchPubKey = vchPubKeyIn;
- }
+ CKeyPool() : nTime(GetTime()) {}
+ CKeyPool(const CPubKey& vchPubKeyIn) : nTime(GetTime()), vchPubKey(vchPubKeyIn) {}
IMPLEMENT_SERIALIZE
(
)
};
-/** A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,
- * and provides the ability to create new transactions.
- */
+// A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,
+// and provides the ability to create new transactions.
+//
class CWallet : public CCryptoKeyStore
{
private:
// the maximum wallet format version: memory-only variable that specifies to what version this wallet may be upgraded
int nWalletMaxVersion;
+ int64_t nNextResend;
+ int64_t nLastResend;
+
// stake mining statistics
uint64_t nKernelsTried;
uint64_t nCoinDaysTried;
MasterKeyMap mapMasterKeys;
unsigned int nMasterKeyMaxID;
- CWallet()
- {
- SetNull();
- }
- CWallet(std::string strWalletFileIn)
- {
- SetNull();
-
- strWalletFile = strWalletFileIn;
- fFileBacked = true;
- }
- void SetNull()
- {
- nWalletVersion = FEATURE_BASE;
- nWalletMaxVersion = FEATURE_BASE;
- fFileBacked = false;
- nMasterKeyMaxID = 0;
- pwalletdbEncryption = NULL;
- pwalletdbDecryption = NULL;
- nOrderPosNext = 0;
- nKernelsTried = 0;
- nCoinDaysTried = 0;
- nTimeFirstKey = 0;
- }
+ CWallet();
+ CWallet(std::string strWalletFileIn);
+ void SetNull();
std::map<uint256, CWalletTx> mapWallet;
std::vector<uint256> vMintingWalletUpdated;
bool LoadKey(const CMalleableKeyView &keyView, const CSecret &vchSecretH) { return CCryptoKeyStore::AddMalleableKey(keyView, vchSecretH); }
bool LoadCryptedKey(const CMalleableKeyView &keyView, const std::vector<unsigned char> &vchCryptedSecretH) { return CCryptoKeyStore::AddCryptedMalleableKey(keyView, vchCryptedSecretH); }
- bool LoadMinVersion(int nVersion) { nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; }
+ bool LoadMinVersion(int nVersion);
// Adds an encrypted key to the store, and saves it to disk.
bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
int ScanForWalletTransaction(const uint256& hashTx);
void ReacceptWalletTransactions();
- void ResendWalletTransactions(bool fForceResend=false);
+ void ResendWalletTransactions(int64_t nBestBlockTime);
+ std::vector<uint256> ResendWalletTransactionsBefore(int64_t nTime);
int64_t GetBalance() const;
int64_t GetWatchOnlyBalance() const;
int64_t GetUnconfirmedBalance() const;
bool NewKeyPool(unsigned int nSize = 0);
bool TopUpKeyPool(unsigned int nSize = 0);
- int64_t AddReserveKey(const CKeyPool& keypool);
void ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool);
void KeepKey(int64_t nIndex);
void ReturnKey(int64_t nIndex);
bool DelAddressBookName(const CBitcoinAddress& address);
void UpdatedTransaction(const uint256 &hashTx);
void PrintWallet(const CBlock& block);
-
- void Inventory(const uint256 &hash)
- {
- {
- LOCK(cs_wallet);
- std::map<uint256, int>::iterator mi = mapRequestCount.find(hash);
- if (mi != mapRequestCount.end())
- (*mi).second++;
- }
- }
+ void Inventory(const uint256 &hash);
unsigned int GetKeyPoolSize()
{
int64_t nIndex;
CPubKey vchPubKey;
public:
- CReserveKey(CWallet* pwalletIn)
- {
- nIndex = -1;
- pwallet = pwalletIn;
- }
+ CReserveKey(CWallet* pwalletIn) : pwallet(pwalletIn), nIndex(-1) {}
~CReserveKey()
{
typedef std::map<std::string, std::string> mapValue_t;
-
static void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue)
{
if (!mapValue.count("n"))
nOrderPos = -1; // TODO: calculate elsewhere
return;
}
- nOrderPos = atoi64(mapValue["n"].c_str());
+ nOrderPos = strtoll(mapValue["n"]);
}
-
static void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue)
{
if (nOrderPos == -1)
}
-/** A transaction with a bunch of additional info that only the owner cares about.
- * It includes any unrecorded transactions needed to link it back to the block chain.
- */
+// A transaction with a bunch of additional info that only the owner cares about.
+// It includes any unrecorded transactions needed to link it back to the block chain.
+//
class CWalletTx : public CMerkleTx
{
private:
mutable int64_t nAvailableWatchCreditCached;
mutable int64_t nChangeCached;
- CWalletTx()
- {
- Init(NULL);
- }
-
- CWalletTx(const CWallet* pwalletIn)
- {
- Init(pwalletIn);
- }
-
- CWalletTx(const CWallet* pwalletIn, const CMerkleTx& txIn) : CMerkleTx(txIn)
- {
- Init(pwalletIn);
- }
-
- CWalletTx(const CWallet* pwalletIn, const CTransaction& txIn) : CMerkleTx(txIn)
- {
- Init(pwalletIn);
- }
-
- void Init(const CWallet* pwalletIn)
- {
- pwallet = pwalletIn;
- vtxPrev.clear();
- mapValue.clear();
- vOrderForm.clear();
- fTimeReceivedIsTxTime = false;
- nTimeReceived = 0;
- nTimeSmart = 0;
- fFromMe = false;
- strFromAccount.clear();
- vfSpent.clear();
- fDebitCached = false;
- fWatchDebitCached = false;
- fCreditCached = false;
- fWatchCreditCached = false;
- fAvailableCreditCached = false;
- fAvailableWatchCreditCached = false;
- fImmatureCreditCached = false;
- fImmatureWatchCreditCached = false;
- fChangeCached = false;
- nDebitCached = 0;
- nWatchDebitCached = 0;
- nCreditCached = 0;
- nWatchCreditCached = 0;
- nAvailableCreditCached = 0;
- nAvailableWatchCreditCached = 0;
- nImmatureCreditCached = 0;
- nImmatureWatchCreditCached = 0;
- nChangeCached = 0;
- nOrderPos = -1;
- }
+ CWalletTx();
+ CWalletTx(const CWallet* pwalletIn);
+ CWalletTx(const CWallet* pwalletIn, const CMerkleTx& txIn);
+ CWalletTx(const CWallet* pwalletIn, const CTransaction& txIn);
+ void Init(const CWallet* pwalletIn);
IMPLEMENT_SERIALIZE
(
pthis->mapValue["fromaccount"] = pthis->strFromAccount;
std::string str;
- BOOST_FOREACH(char f, vfSpent)
+ for(char f : vfSpent)
{
str += (f ? '1' : '0');
if (f)
pthis->strFromAccount = pthis->mapValue["fromaccount"];
if (mapValue.count("spent"))
- BOOST_FOREACH(char c, pthis->mapValue["spent"])
+ for(char c : pthis->mapValue["spent"])
pthis->vfSpent.push_back(c != '0');
else
pthis->vfSpent.assign(vout.size(), fSpent);
ReadOrderPos(pthis->nOrderPos, pthis->mapValue);
- pthis->nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(pthis->mapValue["timesmart"]) : 0;
+ pthis->nTimeSmart = mapValue.count("timesmart") ? (unsigned int)strtoll(pthis->mapValue["timesmart"]) : 0;
}
pthis->mapValue.erase("fromaccount");
// marks certain txout's as spent
// returns true if any update took place
- bool UpdateSpent(const std::vector<char>& vfNewSpent)
- {
- bool fReturn = false;
- for (unsigned int i = 0; i < vfNewSpent.size(); i++)
- {
- if (i == vfSpent.size())
- break;
-
- if (vfNewSpent[i] && !vfSpent[i])
- {
- vfSpent[i] = true;
- fReturn = true;
- fAvailableCreditCached = fAvailableWatchCreditCached = false;
- }
- }
- return fReturn;
- }
+ bool UpdateSpent(const std::vector<char>& vfNewSpent);
// make sure balances are recalculated
- void MarkDirty()
- {
- fCreditCached = false;
- fAvailableCreditCached = fAvailableWatchCreditCached = false;
- fDebitCached = fWatchDebitCached = false;
- fChangeCached = false;
- }
-
- void BindWallet(CWallet *pwalletIn)
- {
- pwallet = pwalletIn;
- MarkDirty();
- }
-
- void MarkSpent(unsigned int nOut)
- {
- if (nOut >= vout.size())
- throw std::runtime_error("CWalletTx::MarkSpent() : nOut out of range");
- vfSpent.resize(vout.size());
- if (!vfSpent[nOut])
- {
- vfSpent[nOut] = true;
- fAvailableCreditCached = fAvailableWatchCreditCached = false;
- }
- }
-
- void MarkUnspent(unsigned int nOut)
- {
- if (nOut >= vout.size())
- throw std::runtime_error("CWalletTx::MarkUnspent() : nOut out of range");
- vfSpent.resize(vout.size());
- if (vfSpent[nOut])
- {
- vfSpent[nOut] = false;
- fAvailableCreditCached = fAvailableWatchCreditCached = false;
- }
- }
-
- bool IsSpent(unsigned int nOut) const
- {
- if (nOut >= vout.size())
- throw std::runtime_error("CWalletTx::IsSpent() : nOut out of range");
- if (nOut >= vfSpent.size())
- return false;
- return (!!vfSpent[nOut]);
- }
+ void MarkDirty();
+ void BindWallet(CWallet *pwalletIn);
+ void MarkSpent(unsigned int nOut);
+ void MarkUnspent(unsigned int nOut);
+ bool IsSpent(unsigned int nOut) const;
int64_t GetDebit(const isminefilter& filter) const;
int64_t GetCredit(const isminefilter& filter) const;
bool AcceptWalletTransaction(CTxDB& txdb, bool fCheckInputs=true);
bool AcceptWalletTransaction();
- void RelayWalletTransaction(CTxDB& txdb);
- void RelayWalletTransaction();
+ bool RelayWalletTransaction(CTxDB& txdb);
+ bool RelayWalletTransaction();
};
int nDepth;
bool fSpendable;
- COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn)
- {
- tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn;
- }
+ COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn) :
+ tx(txIn), i(iIn), nDepth(nDepthIn), fSpendable(fSpendableIn) {}
std::string ToString() const
{
-/** Private key that includes an expiration date in case it never gets used. */
+// Private key that includes an expiration date in case it never gets used.
class CWalletKey
{
public:
//// todo: add something to note what created it (user, getnewaddress, change)
//// maybe should have a map<string, string> property map
- CWalletKey(int64_t nExpires=0)
- {
- nTimeCreated = (nExpires ? GetTime() : 0);
- nTimeExpires = nExpires;
- }
+ CWalletKey(int64_t nExpires=0) : nTimeCreated(nExpires ? GetTime() : 0), nTimeExpires(nExpires) {}
IMPLEMENT_SERIALIZE
(
-
-
/** Account information.
* Stored in wallet with key "acc"+string account name.
*/
class CAccountingEntry
{
public:
- std::string strAccount;
- int64_t nCreditDebit;
- int64_t nTime;
- std::string strOtherAccount;
- std::string strComment;
+ std::string strAccount = "";
+ int64_t nCreditDebit = 0;
+ int64_t nTime = 0;
+ std::string strOtherAccount = "";
+ std::string strComment = "";
mapValue_t mapValue;
- int64_t nOrderPos; // position in ordered transaction list
- uint64_t nEntryNo;
-
- CAccountingEntry()
- {
- SetNull();
- }
+ int64_t nOrderPos = -1; // position in ordered transaction list
+ uint64_t nEntryNo = 0;
- void SetNull()
- {
- nCreditDebit = 0;
- nTime = 0;
- strAccount.clear();
- strOtherAccount.clear();
- strComment.clear();
- nOrderPos = -1;
- }
+ CAccountingEntry() { }
IMPLEMENT_SERIALIZE
(