#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:
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;
- nNextResend = 0;
- nLastResend = 0;
- 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);
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);
- auto 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
(
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");
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;
+ int64_t nOrderPos = -1; // position in ordered transaction list
+ uint64_t nEntryNo = 0;
- CAccountingEntry()
- {
- SetNull();
- }
-
- void SetNull()
- {
- nCreditDebit = 0;
- nTime = 0;
- strAccount.clear();
- strOtherAccount.clear();
- strComment.clear();
- nOrderPos = -1;
- }
+ CAccountingEntry() { }
IMPLEMENT_SERIALIZE
(