Skip to content

Commit 5284721

Browse files
committed
Get rid of nType and nVersion
Remove the nType and nVersion as parameters to all serialization methods and functions. There is only one place where it's read and has an impact (in CAddress), and even there it does not impact any of the recursively invoked serializers. Instead, the few places that need nType or nVersion are changed to read it directly from the stream object, through GetType() and GetVersion() methods which are added to all stream classes.
1 parent 657e05a commit 5284721

36 files changed

+304
-280
lines changed

src/addrdb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CBanEntry
4646
ADD_SERIALIZE_METHODS;
4747

4848
template <typename Stream, typename Operation>
49-
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
49+
inline void SerializationOp(Stream& s, Operation ser_action) {
5050
READWRITE(this->nVersion);
5151
READWRITE(nCreateTime);
5252
READWRITE(nBanUntil);

src/addrman.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class CAddrInfo : public CAddress
5858
ADD_SERIALIZE_METHODS;
5959

6060
template <typename Stream, typename Operation>
61-
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
61+
inline void SerializationOp(Stream& s, Operation ser_action) {
6262
READWRITE(*(CAddress*)this);
6363
READWRITE(source);
6464
READWRITE(nLastSuccess);
@@ -293,7 +293,7 @@ class CAddrMan
293293
* very little in common.
294294
*/
295295
template<typename Stream>
296-
void Serialize(Stream &s, int nType, int nVersionDummy) const
296+
void Serialize(Stream &s) const
297297
{
298298
LOCK(cs);
299299

@@ -343,7 +343,7 @@ class CAddrMan
343343
}
344344

345345
template<typename Stream>
346-
void Unserialize(Stream& s, int nType, int nVersionDummy)
346+
void Unserialize(Stream& s)
347347
{
348348
LOCK(cs);
349349

src/amount.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class CFeeRate
6464
ADD_SERIALIZE_METHODS;
6565

6666
template <typename Stream, typename Operation>
67-
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
67+
inline void SerializationOp(Stream& s, Operation ser_action) {
6868
READWRITE(nSatoshisPerK);
6969
}
7070
};

src/blockencodings.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct TransactionCompressor {
2121
ADD_SERIALIZE_METHODS;
2222

2323
template <typename Stream, typename Operation>
24-
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
24+
inline void SerializationOp(Stream& s, Operation ser_action) {
2525
READWRITE(tx); //TODO: Compress tx encoding
2626
}
2727
};
@@ -35,7 +35,7 @@ class BlockTransactionsRequest {
3535
ADD_SERIALIZE_METHODS;
3636

3737
template <typename Stream, typename Operation>
38-
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
38+
inline void SerializationOp(Stream& s, Operation ser_action) {
3939
READWRITE(blockhash);
4040
uint64_t indexes_size = (uint64_t)indexes.size();
4141
READWRITE(COMPACTSIZE(indexes_size));
@@ -81,7 +81,7 @@ class BlockTransactions {
8181
ADD_SERIALIZE_METHODS;
8282

8383
template <typename Stream, typename Operation>
84-
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
84+
inline void SerializationOp(Stream& s, Operation ser_action) {
8585
READWRITE(blockhash);
8686
uint64_t txn_size = (uint64_t)txn.size();
8787
READWRITE(COMPACTSIZE(txn_size));
@@ -109,7 +109,7 @@ struct PrefilledTransaction {
109109
ADD_SERIALIZE_METHODS;
110110

111111
template <typename Stream, typename Operation>
112-
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
112+
inline void SerializationOp(Stream& s, Operation ser_action) {
113113
uint64_t idx = index;
114114
READWRITE(COMPACTSIZE(idx));
115115
if (idx > std::numeric_limits<uint16_t>::max())
@@ -155,7 +155,7 @@ class CBlockHeaderAndShortTxIDs {
155155
ADD_SERIALIZE_METHODS;
156156

157157
template <typename Stream, typename Operation>
158-
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
158+
inline void SerializationOp(Stream& s, Operation ser_action) {
159159
READWRITE(header);
160160
READWRITE(nonce);
161161

src/bloom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class CBloomFilter
7373
ADD_SERIALIZE_METHODS;
7474

7575
template <typename Stream, typename Operation>
76-
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
76+
inline void SerializationOp(Stream& s, Operation ser_action) {
7777
READWRITE(vData);
7878
READWRITE(nHashFuncs);
7979
READWRITE(nTweak);

src/chain.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class CBlockFileInfo
2828
ADD_SERIALIZE_METHODS;
2929

3030
template <typename Stream, typename Operation>
31-
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
31+
inline void SerializationOp(Stream& s, Operation ser_action) {
3232
READWRITE(VARINT(nBlocks));
3333
READWRITE(VARINT(nSize));
3434
READWRITE(VARINT(nUndoSize));
@@ -76,7 +76,7 @@ struct CDiskBlockPos
7676
ADD_SERIALIZE_METHODS;
7777

7878
template <typename Stream, typename Operation>
79-
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
79+
inline void SerializationOp(Stream& s, Operation ser_action) {
8080
READWRITE(VARINT(nFile));
8181
READWRITE(VARINT(nPos));
8282
}
@@ -357,8 +357,9 @@ class CDiskBlockIndex : public CBlockIndex
357357
ADD_SERIALIZE_METHODS;
358358

359359
template <typename Stream, typename Operation>
360-
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
361-
if (!(nType & SER_GETHASH))
360+
inline void SerializationOp(Stream& s, Operation ser_action) {
361+
int nVersion = s.GetVersion();
362+
if (!(s.GetType() & SER_GETHASH))
362363
READWRITE(VARINT(nVersion));
363364

364365
READWRITE(VARINT(nHeight));

src/coins.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,41 +154,41 @@ class CCoins
154154
}
155155

156156
template<typename Stream>
157-
void Serialize(Stream &s, int nType, int nVersion) const {
157+
void Serialize(Stream &s) const {
158158
unsigned int nMaskSize = 0, nMaskCode = 0;
159159
CalcMaskSize(nMaskSize, nMaskCode);
160160
bool fFirst = vout.size() > 0 && !vout[0].IsNull();
161161
bool fSecond = vout.size() > 1 && !vout[1].IsNull();
162162
assert(fFirst || fSecond || nMaskCode);
163163
unsigned int nCode = 8*(nMaskCode - (fFirst || fSecond ? 0 : 1)) + (fCoinBase ? 1 : 0) + (fFirst ? 2 : 0) + (fSecond ? 4 : 0);
164164
// version
165-
::Serialize(s, VARINT(this->nVersion), nType, nVersion);
165+
::Serialize(s, VARINT(this->nVersion));
166166
// header code
167-
::Serialize(s, VARINT(nCode), nType, nVersion);
167+
::Serialize(s, VARINT(nCode));
168168
// spentness bitmask
169169
for (unsigned int b = 0; b<nMaskSize; b++) {
170170
unsigned char chAvail = 0;
171171
for (unsigned int i = 0; i < 8 && 2+b*8+i < vout.size(); i++)
172172
if (!vout[2+b*8+i].IsNull())
173173
chAvail |= (1 << i);
174-
::Serialize(s, chAvail, nType, nVersion);
174+
::Serialize(s, chAvail);
175175
}
176176
// txouts themself
177177
for (unsigned int i = 0; i < vout.size(); i++) {
178178
if (!vout[i].IsNull())
179-
::Serialize(s, CTxOutCompressor(REF(vout[i])), nType, nVersion);
179+
::Serialize(s, CTxOutCompressor(REF(vout[i])));
180180
}
181181
// coinbase height
182-
::Serialize(s, VARINT(nHeight), nType, nVersion);
182+
::Serialize(s, VARINT(nHeight));
183183
}
184184

185185
template<typename Stream>
186-
void Unserialize(Stream &s, int nType, int nVersion) {
186+
void Unserialize(Stream &s) {
187187
unsigned int nCode = 0;
188188
// version
189-
::Unserialize(s, VARINT(this->nVersion), nType, nVersion);
189+
::Unserialize(s, VARINT(this->nVersion));
190190
// header code
191-
::Unserialize(s, VARINT(nCode), nType, nVersion);
191+
::Unserialize(s, VARINT(nCode));
192192
fCoinBase = nCode & 1;
193193
std::vector<bool> vAvail(2, false);
194194
vAvail[0] = (nCode & 2) != 0;
@@ -197,7 +197,7 @@ class CCoins
197197
// spentness bitmask
198198
while (nMaskCode > 0) {
199199
unsigned char chAvail = 0;
200-
::Unserialize(s, chAvail, nType, nVersion);
200+
::Unserialize(s, chAvail);
201201
for (unsigned int p = 0; p < 8; p++) {
202202
bool f = (chAvail & (1 << p)) != 0;
203203
vAvail.push_back(f);
@@ -209,10 +209,10 @@ class CCoins
209209
vout.assign(vAvail.size(), CTxOut());
210210
for (unsigned int i = 0; i < vAvail.size(); i++) {
211211
if (vAvail[i])
212-
::Unserialize(s, REF(CTxOutCompressor(vout[i])), nType, nVersion);
212+
::Unserialize(s, REF(CTxOutCompressor(vout[i])));
213213
}
214214
// coinbase height
215-
::Unserialize(s, VARINT(nHeight), nType, nVersion);
215+
::Unserialize(s, VARINT(nHeight));
216216
Cleanup();
217217
}
218218

src/compressor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class CScriptCompressor
5656
CScriptCompressor(CScript &scriptIn) : script(scriptIn) { }
5757

5858
template<typename Stream>
59-
void Serialize(Stream &s, int nType, int nVersion) const {
59+
void Serialize(Stream &s) const {
6060
std::vector<unsigned char> compr;
6161
if (Compress(compr)) {
6262
s << CFlatData(compr);
@@ -68,7 +68,7 @@ class CScriptCompressor
6868
}
6969

7070
template<typename Stream>
71-
void Unserialize(Stream &s, int nType, int nVersion) {
71+
void Unserialize(Stream &s) {
7272
unsigned int nSize = 0;
7373
s >> VARINT(nSize);
7474
if (nSize < nSpecialScripts) {
@@ -104,7 +104,7 @@ class CTxOutCompressor
104104
ADD_SERIALIZE_METHODS;
105105

106106
template <typename Stream, typename Operation>
107-
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
107+
inline void SerializationOp(Stream& s, Operation ser_action) {
108108
if (!ser_action.ForRead()) {
109109
uint64_t nVal = CompressAmount(txout.nValue);
110110
READWRITE(VARINT(nVal));

src/hash.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ class CHashWriter
138138

139139
CHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn) {}
140140

141+
int GetType() const { return nType; }
142+
int GetVersion() const { return nVersion; }
143+
141144
void write(const char *pch, size_t size) {
142145
ctx.Write((const unsigned char*)pch, size);
143146
}
@@ -152,7 +155,7 @@ class CHashWriter
152155
template<typename T>
153156
CHashWriter& operator<<(const T& obj) {
154157
// Serialize to this stream
155-
::Serialize(*this, obj, nType, nVersion);
158+
::Serialize(*this, obj);
156159
return (*this);
157160
}
158161
};

src/key.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ struct CExtKey {
162162
CExtPubKey Neuter() const;
163163
void SetMaster(const unsigned char* seed, unsigned int nSeedLen);
164164
template <typename Stream>
165-
void Serialize(Stream& s, int nType, int nVersion) const
165+
void Serialize(Stream& s) const
166166
{
167167
unsigned int len = BIP32_EXTKEY_SIZE;
168168
::WriteCompactSize(s, len);
@@ -171,7 +171,7 @@ struct CExtKey {
171171
s.write((const char *)&code[0], len);
172172
}
173173
template <typename Stream>
174-
void Unserialize(Stream& s, int nType, int nVersion)
174+
void Unserialize(Stream& s)
175175
{
176176
unsigned int len = ::ReadCompactSize(s);
177177
unsigned char code[BIP32_EXTKEY_SIZE];

0 commit comments

Comments
 (0)