From 90fcea8a8ee743d9da20ebacbdcffa6155a4330c Mon Sep 17 00:00:00 2001 From: svost Date: Wed, 5 Oct 2016 10:20:33 +0300 Subject: [PATCH] Rework some header files --- src/kernel_worker.h | 7 ++-- src/main.h | 99 +++++++++++++++++++++++++-------------------------- src/wallet.cpp | 18 +++++++++ src/wallet.h | 65 +++++++++------------------------ 4 files changed, 87 insertions(+), 102 deletions(-) diff --git a/src/kernel_worker.h b/src/kernel_worker.h index e83cd9a..38e8b05 100644 --- a/src/kernel_worker.h +++ b/src/kernel_worker.h @@ -3,7 +3,6 @@ #include -using namespace std; class KernelWorker { @@ -12,14 +11,14 @@ public: { } KernelWorker(uint8_t *kernel, uint32_t nBits, uint32_t nInputTxTime, int64_t nValueIn, uint32_t nIntervalBegin, uint32_t nIntervalEnd); void Do(); - vector >& GetSolutions(); + std::vector >& GetSolutions(); private: // One way hashing. void Do_generic(); // Kernel solutions. - vector > solutions; + std::vector > solutions; // Kernel metadata. uint8_t *kernel = nullptr; @@ -33,6 +32,6 @@ private: }; // Scan given kernel for solutions -bool ScanKernelBackward(uint8_t *kernel, uint32_t nBits, uint32_t nInputTxTime, int64_t nValueIn, pair &SearchInterval, pair &solution); +bool ScanKernelBackward(uint8_t *kernel, uint32_t nBits, uint32_t nInputTxTime, int64_t nValueIn, std::pair &SearchInterval, std::pair &solution); #endif // NOVACOIN_KERNELWORKER_H diff --git a/src/main.h b/src/main.h index 594bdbd..0a5f02b 100644 --- a/src/main.h +++ b/src/main.h @@ -19,7 +19,6 @@ #include #include -using namespace std; class CWallet; class CBlock; @@ -46,7 +45,7 @@ static const unsigned int MAX_INV_SZ = 50000; static const int64_t MIN_TX_FEE = CENT/10; static const int64_t MIN_RELAY_TX_FEE = CENT/50; -static const int64_t MAX_MONEY = numeric_limits::max(); +static const int64_t MAX_MONEY = std::numeric_limits::max(); static const int64_t MAX_MINT_PROOF_OF_WORK = 100 * COIN; static const int64_t MAX_MINT_PROOF_OF_STAKE = 1 * COIN; static const int64_t MIN_TXOUT_AMOUNT = CENT/100; @@ -67,8 +66,8 @@ inline int64_t FutureDrift(int64_t nTime) { return nTime + 2 * nOneHour; } // up extern CScript COINBASE_FLAGS; extern CCriticalSection cs_main; -extern map mapBlockIndex; -extern set > setStakeSeen; +extern std::map mapBlockIndex; +extern std::set > setStakeSeen; extern CBlockIndex* pindexGenesisBlock; extern unsigned int nNodeLifespan; extern unsigned int nStakeMinAge; @@ -82,12 +81,12 @@ extern unsigned int nTransactionsUpdated; extern uint64_t nLastBlockTx; extern uint64_t nLastBlockSize; extern uint32_t nLastCoinStakeSearchInterval; -extern const string strMessageMagic; +extern const std::string strMessageMagic; extern int64_t nTimeBestReceived; extern CCriticalSection cs_setpwalletRegistered; -extern set setpwalletRegistered; +extern std::set setpwalletRegistered; extern uint32_t nNetworkID; -extern map mapOrphanBlocks; +extern std::map mapOrphanBlocks; // Settings extern int64_t nTransactionFee; @@ -133,7 +132,7 @@ unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime); unsigned int ComputeMinStake(unsigned int nBase, int64_t nTime, unsigned int nBlockTime); int GetNumBlocksOfPeers(); bool IsInitialBlockDownload(); -string GetWarnings(string strFor); +std::string GetWarnings(std::string strFor); bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock); uint256 WantedByOrphan(const CBlock* pblockOrphan); const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfStake); @@ -144,7 +143,7 @@ bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, uint3 -bool GetWalletFile(CWallet* pwallet, string &strWalletFileOut); +bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut); // Position on disk for a particular transaction. class CDiskTxPos @@ -158,8 +157,8 @@ public: CDiskTxPos(unsigned int nFileIn, unsigned int nBlockPosIn, unsigned int nTxPosIn) : nFile(nFileIn), nBlockPos(nBlockPosIn), nTxPos(nTxPosIn) {} IMPLEMENT_SERIALIZE( READWRITE(FLATDATA(*this)); ) - void SetNull() { nFile = numeric_limits::max(); nBlockPos = 0; nTxPos = 0; } - bool IsNull() const { return (nFile == numeric_limits::max()); } + void SetNull() { nFile = std::numeric_limits::max(); nBlockPos = 0; nTxPos = 0; } + bool IsNull() const { return (nFile == std::numeric_limits::max()); } friend bool operator==(const CDiskTxPos& a, const CDiskTxPos& b) { @@ -174,7 +173,7 @@ public: } - string ToString() const + std::string ToString() const { if (IsNull()) return "null"; @@ -199,8 +198,8 @@ public: CInPoint() { SetNull(); } CInPoint(CTransaction* ptxIn, uint32_t nIn) : ptx(ptxIn), n(nIn) {} - void SetNull() { ptx = NULL; n = numeric_limits::max(); } - bool IsNull() const { return (ptx == NULL && n == numeric_limits::max()); } + void SetNull() { ptx = NULL; n = std::numeric_limits::max(); } + bool IsNull() const { return (ptx == NULL && n == std::numeric_limits::max()); } }; @@ -215,8 +214,8 @@ public: COutPoint() { SetNull(); } COutPoint(uint256 hashIn, uint32_t nIn) : hash(hashIn), n(nIn) {} IMPLEMENT_SERIALIZE( READWRITE(FLATDATA(*this)); ) - void SetNull() { hash = 0; n = numeric_limits::max(); } - bool IsNull() const { return (hash == 0 && n == numeric_limits::max()); } + void SetNull() { hash = 0; n = std::numeric_limits::max(); } + bool IsNull() const { return (hash == 0 && n == std::numeric_limits::max()); } friend bool operator<(const COutPoint& a, const COutPoint& b) { @@ -233,7 +232,7 @@ public: return !(a == b); } - string ToString() const + std::string ToString() const { return strprintf("COutPoint(%s, %" PRIu32 ")", hash.ToString().substr(0,10).c_str(), n); } @@ -257,10 +256,10 @@ public: CScript scriptSig; uint32_t nSequence; - CTxIn() : nSequence(numeric_limits::max()) {} - explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=numeric_limits::max()) + CTxIn() : nSequence(std::numeric_limits::max()) {} + explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=std::numeric_limits::max()) : prevout(prevoutIn), scriptSig(scriptSigIn), nSequence(nSequenceIn) {} - CTxIn(uint256 hashPrevTx, unsigned int nOut, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=numeric_limits::max()) + CTxIn(uint256 hashPrevTx, unsigned int nOut, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=std::numeric_limits::max()) : prevout(COutPoint(hashPrevTx, nOut)), scriptSig(scriptSigIn), nSequence(nSequenceIn) {} IMPLEMENT_SERIALIZE @@ -272,7 +271,7 @@ public: bool IsFinal() const { - return (nSequence == numeric_limits::max()); + return (nSequence == std::numeric_limits::max()); } friend bool operator==(const CTxIn& a, const CTxIn& b) @@ -287,12 +286,12 @@ public: return !(a == b); } - string ToStringShort() const + std::string ToStringShort() const { return strprintf(" %s %d", prevout.hash.ToString().c_str(), prevout.n); } - string ToString() const; + std::string ToString() const; void print() const { @@ -358,12 +357,12 @@ public: return !(a == b); } - string ToStringShort() const + std::string ToStringShort() const { return strprintf(" out %s %s", FormatMoney(nValue).c_str(), scriptPubKey.ToString(true).c_str()); } - string ToString() const + std::string ToString() const { if (IsEmpty()) return "CTxOut(empty)"; if (scriptPubKey.size() < 6) @@ -387,7 +386,7 @@ enum GetMinFee_mode GMF_SEND }; -typedef map > MapPrevTx; +typedef std::map > MapPrevTx; /** The basic transaction that is broadcasted on the network and contained in * blocks. A transaction can contain multiple inputs and outputs. @@ -398,8 +397,8 @@ public: static const int CURRENT_VERSION=1; int nVersion; uint32_t nTime; - vector vin; - vector vout; + std::vector vin; + std::vector vout; uint32_t nLockTime; // Denial-of-service detection: @@ -458,10 +457,10 @@ public: /** Check for standard transaction types @return True if all outputs (scriptPubKeys) use only standard transaction forms */ - bool IsStandard(string& strReason) const; + bool IsStandard(std::string& strReason) const; bool IsStandard() const { - string strReason; + std::string strReason; return IsStandard(strReason); } @@ -524,8 +523,8 @@ public: return !(a == b); } - string ToStringShort() const; - string ToString() const; + std::string ToStringShort() const; + std::string ToString() const; void print() const { @@ -548,7 +547,7 @@ public: @param[out] fInvalid returns true if transaction is invalid @return Returns true if all inputs are in txdb or mapTestPool */ - bool FetchInputs(CTxDB& txdb, const map& mapTestPool, + bool FetchInputs(CTxDB& txdb, const std::map& mapTestPool, bool fBlock, bool fMiner, MapPrevTx& inputsRet, bool& fInvalid); /** Sanity check previous transactions, then, if all checks succeed, @@ -565,9 +564,9 @@ public: @param[in] pvChecks NULL If pvChecks is not NULL, script checks are pushed onto it instead of being performed inline. @return Returns true if all checks succeed */ - bool ConnectInputs(CTxDB& txdb, MapPrevTx inputs, map& mapTestPool, const CDiskTxPos& posThisTx, const CBlockIndex* pindexBlock, + bool ConnectInputs(CTxDB& txdb, MapPrevTx inputs, std::map& mapTestPool, const CDiskTxPos& posThisTx, const CBlockIndex* pindexBlock, bool fBlock, bool fMiner, bool fScriptChecks=true, - unsigned int flags=STRICT_FLAGS, vector *pvChecks = NULL); + unsigned int flags=STRICT_FLAGS, std::vector *pvChecks = NULL); bool ClientConnectInputs(); bool CheckTransaction() const; bool AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs=true, bool* pfMissingInputs=NULL); @@ -585,7 +584,7 @@ class CMerkleTx : public CTransaction { public: uint256 hashBlock; - vector vMerkleBranch; + std::vector vMerkleBranch; int32_t nIndex; // memory only @@ -640,7 +639,7 @@ class CTxIndex { public: CDiskTxPos pos; - vector vSpent; + std::vector vSpent; CTxIndex() { @@ -710,13 +709,13 @@ public: uint32_t nNonce; // network and disk - vector vtx; + std::vector vtx; // ppcoin: block signature - signed by one of the coin base txout[N]'s owner - vector vchBlockSig; + std::vector vchBlockSig; // memory only - mutable vector vMerkleTree; + mutable std::vector vMerkleTree; // Denial-of-service detection: mutable int nDoS; @@ -795,7 +794,7 @@ public: return !IsProofOfStake(); } - pair GetProofOfStake() const + std::pair GetProofOfStake() const { if (IsProofOfStake()) return { vtx[1].vin[0].prevout, vtx[1].nTime }; @@ -805,8 +804,8 @@ public: // ppcoin: get max transaction timestamp int64_t GetMaxTransactionTime() const; uint256 BuildMerkleTree() const; - vector GetMerkleBranch(int nIndex) const; - static uint256 CheckMerkleBranch(uint256 hash, const vector& vMerkleBranch, int nIndex); + std::vector GetMerkleBranch(int nIndex) const; + static uint256 CheckMerkleBranch(uint256 hash, const std::vector& vMerkleBranch, int nIndex); bool WriteToDisk(unsigned int& nFileRet, unsigned int& nBlockPosRet); bool ReadFromDisk(unsigned int nFile, unsigned int nBlockPos, bool fReadTransactions=true); void print() const; @@ -995,7 +994,7 @@ public: } void SetStakeModifier(uint64_t nModifier, bool fGeneratedStakeModifier); - string ToString() const; + std::string ToString() const; void print() const { @@ -1059,7 +1058,7 @@ public: ) uint256 GetBlockHash() const; - string ToString() const; + std::string ToString() const; void print() const { @@ -1076,11 +1075,11 @@ public: class CBlockLocator { protected: - vector vHave; + std::vector vHave; public: CBlockLocator() { } - CBlockLocator(const vector& vHaveIn) : vHave(vHaveIn) { } + CBlockLocator(const std::vector& vHaveIn) : vHave(vHaveIn) { } explicit CBlockLocator(const CBlockIndex* pindex) { @@ -1124,15 +1123,15 @@ class CTxMemPool { public: mutable CCriticalSection cs; - map mapTx; - map mapNextTx; + std::map mapTx; + std::map mapNextTx; bool accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs, bool* pfMissingInputs); bool addUnchecked(const uint256& hash, CTransaction &tx); bool remove(CTransaction &tx); void clear(); - void queryHashes(vector& vtxid); + void queryHashes(std::vector& vtxid); size_t size() { diff --git a/src/wallet.cpp b/src/wallet.cpp index 5c93959..5813953 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -205,6 +205,13 @@ bool CWallet::LoadKeyMetadata(const CMalleableKeyView &keyView, const CKeyMetada return true; } +bool CWallet::LoadMinVersion(int nVersion) +{ + nWalletVersion = nVersion; + nWalletMaxVersion = max(nWalletMaxVersion, nVersion); + return true; +} + bool CWallet::AddCScript(const CScript& redeemScript) { if (!CCryptoKeyStore::AddCScript(redeemScript)) @@ -839,6 +846,7 @@ isminetype CWallet::IsMine(const CTxIn &txin) const return MINE_NO; } + CWalletTx::CWalletTx() { Init(NULL); @@ -2723,6 +2731,16 @@ void CWallet::PrintWallet(const CBlock& block) printf("\n"); } +void CWallet::Inventory(const uint256 &hash) +{ + { + LOCK(cs_wallet); + auto mi = mapRequestCount.find(hash); + if (mi != mapRequestCount.end()) + (*mi).second++; + } +} + bool CWallet::GetTransaction(const uint256 &hashTx, CWalletTx& wtx) { { diff --git a/src/wallet.h b/src/wallet.h index 87adeb2..2e5e6d2 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -31,7 +31,7 @@ class CCoinControl; // Set of selected transactions typedef std::set > 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) @@ -42,23 +42,15 @@ enum WalletFeature 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 ( @@ -69,9 +61,9 @@ public: ) }; -/** 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: @@ -153,7 +145,7 @@ public: bool LoadKey(const CMalleableKeyView &keyView, const CSecret &vchSecretH) { return CCryptoKeyStore::AddMalleableKey(keyView, vchSecretH); } bool LoadCryptedKey(const CMalleableKeyView &keyView, const std::vector &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 &vchCryptedSecret); @@ -257,16 +249,7 @@ public: 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() { @@ -310,11 +293,7 @@ protected: int64_t nIndex; CPubKey vchPubKey; public: - CReserveKey(CWallet* pwalletIn) - { - nIndex = -1; - pwallet = pwalletIn; - } + CReserveKey(CWallet* pwalletIn) : pwallet(pwalletIn), nIndex(-1) {} ~CReserveKey() { @@ -330,7 +309,6 @@ public: typedef std::map mapValue_t; - static void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue) { if (!mapValue.count("n")) @@ -341,7 +319,6 @@ static void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue) nOrderPos = strtoll(mapValue["n"]); } - static void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue) { if (nOrderPos == -1) @@ -350,9 +327,9 @@ static void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue) } -/** 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: @@ -511,10 +488,8 @@ public: 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 { @@ -525,7 +500,7 @@ public: -/** 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: @@ -536,11 +511,7 @@ public: //// todo: add something to note what created it (user, getnewaddress, change) //// maybe should have a map 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 ( @@ -556,8 +527,6 @@ public: - - /** Account information. * Stored in wallet with key "acc"+string account name. */ -- 1.7.1