C++20 Round 5: typedef -> using, IMPLEMENT_SERIALIZE macro cleanup

- Convert 15 typedef declarations to C++11 using aliases across 12 files:
  script.h (valtype, CTxDestination), serialize.h (CSerializeData),
  keystore.h (KeyMap, ScriptMap, CryptedKeyMap), sync.h (CCriticalSection,
  CWaitableCriticalSection), sync.cpp (LockStack), key.h (CPrivKey, CSecret),
  crypter.h (CKeyingMaterial), allocators.h (SecureString), main.h (MapPrevTx),
  wallet.h (mapValue_t, removed duplicate), miner.cpp (TxPriority),
  kernel.cpp (MapModifierCheckpoints)
- Remove redundant duplicate mapValue_t typedef in wallet.h
- IMPLEMENT_SERIALIZE macro: replace assert() warning suppression with
  [[maybe_unused]] attributes on fGetSize/fWrite/fRead/nSerSize
This commit is contained in:
2026-05-08 23:08:40 -07:00
parent 9d80ddb6ac
commit 4b8d5ab8b1
12 changed files with 28 additions and 34 deletions
+1 -1
View File
@@ -254,7 +254,7 @@ struct zero_after_free_allocator : public std::allocator<T>
};
// This is exactly like std::string, but with a custom allocator.
typedef std::basic_string<char, std::char_traits<char>, secure_allocator<char> > SecureString;
using SecureString = std::basic_string<char, std::char_traits<char>, secure_allocator<char>>;
static inline SecureString MakeSecureString(const std::string& value)
{
+1 -1
View File
@@ -80,7 +80,7 @@ public:
};
typedef std::vector<unsigned char, secure_allocator<unsigned char> > CKeyingMaterial;
using CKeyingMaterial = std::vector<unsigned char, secure_allocator<unsigned char>>;
/** Encryption/decryption context with key information */
class CCrypter
+1 -1
View File
@@ -14,7 +14,7 @@ extern unsigned int nTargetSpacing;
// Set to 20-minute for production network
//unsigned int nModifierInterval = MODIFIER_INTERVAL;
typedef std::map<int, unsigned int> MapModifierCheckpoints;
using MapModifierCheckpoints = std::map<int, unsigned int>;
// Hard checkpoints of stake modifiers to ensure they are deterministic
static std::map<int, unsigned int> mapStakeModifierCheckpoints = {
+2 -3
View File
@@ -99,9 +99,8 @@ public:
// secure_allocator is defined in allocators.h
// CPrivKey is a serialized private key, with all parameters included (279 bytes)
typedef std::vector<unsigned char, secure_allocator<unsigned char> > CPrivKey;
// CSecret is a serialization of just the secret parameter (32 bytes)
typedef std::vector<unsigned char, secure_allocator<unsigned char> > CSecret;
using CPrivKey = std::vector<unsigned char, secure_allocator<unsigned char>>;
using CSecret = std::vector<unsigned char, secure_allocator<unsigned char>>;
/** An encapsulated secp256k1 elliptic-curve key (public and/or private). */
class CKey
+3 -3
View File
@@ -44,8 +44,8 @@ public:
}
};
typedef std::map<CKeyID, std::pair<CSecret, bool> > KeyMap;
typedef std::map<CScriptID, CScript > ScriptMap;
using KeyMap = std::map<CKeyID, std::pair<CSecret, bool>>;
using ScriptMap = std::map<CScriptID, CScript>;
/** Basic key store, that keeps keys in an address->secret map */
class CBasicKeyStore : public CKeyStore
@@ -94,7 +94,7 @@ public:
virtual bool GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const;
};
typedef std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char> > > CryptedKeyMap;
using CryptedKeyMap = std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char>>>;
/** Keystore which keeps the private keys encrypted.
* It derives from the basic key store, which is used if no encryption is active.
+1 -1
View File
@@ -475,7 +475,7 @@ public:
}
};
typedef std::map<COutPoint, CUtxoEntry> MapPrevTx;
using MapPrevTx = std::map<COutPoint, CUtxoEntry>;
/** The basic transaction that is broadcasted on the network and contained in
* blocks. A transaction can contain multiple inputs and outputs.
+1 -1
View File
@@ -50,7 +50,7 @@ uint64_t nLastBlockSize = 0;
int64_t nLastCoinStakeSearchInterval = 0;
// We want to sort transactions by priority and fee, so:
typedef std::tuple<double, double, CTransaction*> TxPriority;
using TxPriority = std::tuple<double, double, CTransaction*>;
class TxPriorityCompare
{
bool byFee;
+2 -2
View File
@@ -16,7 +16,7 @@
#include "keystore.h"
#include "bignum.h"
typedef std::vector<unsigned char> valtype;
using valtype = std::vector<unsigned char>;
class CTransaction;
@@ -51,7 +51,7 @@ public:
* * CScriptID: TX_SCRIPTHASH destination
* A CTxDestination is the internal data type encoded in a CTrianglesAddress
*/
typedef std::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;
using CTxDestination = std::variant<CNoDestination, CKeyID, CScriptID>;
const char* GetTxnOutputType(TxnOutType t);
+12 -15
View File
@@ -59,12 +59,11 @@ enum
unsigned int GetSerializeSize(int nType, int nVersion) const \
{ \
CSerActionGetSerializeSize ser_action; \
const bool fGetSize = true; \
const bool fWrite = false; \
const bool fRead = false; \
[[maybe_unused]] const bool fGetSize = true; \
[[maybe_unused]] const bool fWrite = false; \
[[maybe_unused]] const bool fRead = false; \
unsigned int nSerSize = 0; \
ser_streamplaceholder s; \
assert(fGetSize||fWrite||fRead); /* suppress warning */ \
s.nType = nType; \
s.nVersion = nVersion; \
{statements} \
@@ -74,22 +73,20 @@ enum
void Serialize(Stream& s, int nType, int nVersion) const \
{ \
CSerActionSerialize ser_action; \
const bool fGetSize = false; \
const bool fWrite = true; \
const bool fRead = false; \
unsigned int nSerSize = 0; \
assert(fGetSize||fWrite||fRead); /* suppress warning */ \
[[maybe_unused]] const bool fGetSize = false; \
[[maybe_unused]] const bool fWrite = true; \
[[maybe_unused]] const bool fRead = false; \
[[maybe_unused]] unsigned int nSerSize = 0; \
{statements} \
} \
template<typename Stream> \
void Unserialize(Stream& s, int nType, int nVersion) \
{ \
CSerActionUnserialize ser_action; \
const bool fGetSize = false; \
const bool fWrite = false; \
const bool fRead = true; \
unsigned int nSerSize = 0; \
assert(fGetSize||fWrite||fRead); /* suppress warning */ \
[[maybe_unused]] const bool fGetSize = false; \
[[maybe_unused]] const bool fWrite = false; \
[[maybe_unused]] const bool fRead = true; \
[[maybe_unused]] unsigned int nSerSize = 0; \
{statements} \
}
@@ -705,7 +702,7 @@ struct ser_streamplaceholder
typedef std::vector<char, zero_after_free_allocator<char> > CSerializeData;
using CSerializeData = std::vector<char, zero_after_free_allocator<char>>;
/** Double ended buffer combining vector and stream-like interfaces.
*
+1 -1
View File
@@ -46,7 +46,7 @@ private:
int sourceLine;
};
typedef std::vector< std::pair<void*, CLockLocation> > LockStack;
using LockStack = std::vector<std::pair<void*, CLockLocation>>;
static std::mutex dd_mutex;
static std::map<std::pair<void*, void*>, LockStack> lockorders;
+2 -2
View File
@@ -9,10 +9,10 @@
#include <condition_variable>
/** Recursive mutex: supports recursive locking, but no waiting */
typedef std::recursive_mutex CCriticalSection;
using CCriticalSection = std::recursive_mutex;
/** Plain mutex: supports waiting but not recursive locking */
typedef std::mutex CWaitableCriticalSection;
using CWaitableCriticalSection = std::mutex;
#ifdef DEBUG_LOCKORDER
void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false);
+1 -3
View File
@@ -29,7 +29,7 @@ class COutput;
class CCoinControl;
//typedef std::map<CKeyID, CStealthKeyMetadata> StealthKeyMetaMap;
typedef std::map<std::string, std::string> mapValue_t;
using mapValue_t = std::map<std::string, std::string>;
/** (client) version numbers for particular wallet features */
enum class WalletFeature : int
@@ -359,8 +359,6 @@ public:
};
typedef std::map<std::string, std::string> mapValue_t;
static void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue)
{