Skip to content

Commit 7730260

Browse files
author
MarcoFalke
committed
Merge #17212: refactor: Remove unused CExt{Pub,}Key (de)serialization methods
5b44a75 refactor: Remove unused CExt{Pub,}Key (de)serialization methods (Sebastian Falbesoner) Pull request description: As pointed out in issue #17130, the serialization/deserialization methods for the classes `CExtKey` and `CExtPubKey` are only used in the BIP32 unit tests and hence can be removed (see comments bitcoin/bitcoin#17130 (comment), bitcoin/bitcoin#17130 (comment) and bitcoin/bitcoin#17130 (comment)). ACKs for top commit: practicalswift: ACK 5b44a75 -- -60 LOC diff looks correct :) promag: ACK 5b44a75. MarcoFalke: unsigned ACK 5b44a75 fjahr: ACK 5b44a75 jonatack: Light ACK 5b44a75. Built, ran tests and bitcoind. `git blame` shows most of the last changes are from commit 90604f1 in 2015 to add bip32 pubkey serialization. Tree-SHA512: 6887573b76b9e54e117a076557407b6f7908719b2202fb9eea498522baf9f30198b3f78b87a62efcd17ad1ab0886196f099239992ce7cbbaee79979ffe9e5f2c
2 parents 4af0447 + 5b44a75 commit 7730260

File tree

3 files changed

+0
-60
lines changed

3 files changed

+0
-60
lines changed

src/key.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -162,25 +162,6 @@ struct CExtKey {
162162
bool Derive(CExtKey& out, unsigned int nChild) const;
163163
CExtPubKey Neuter() const;
164164
void SetSeed(const unsigned char* seed, unsigned int nSeedLen);
165-
template <typename Stream>
166-
void Serialize(Stream& s) const
167-
{
168-
unsigned int len = BIP32_EXTKEY_SIZE;
169-
::WriteCompactSize(s, len);
170-
unsigned char code[BIP32_EXTKEY_SIZE];
171-
Encode(code);
172-
s.write((const char *)&code[0], len);
173-
}
174-
template <typename Stream>
175-
void Unserialize(Stream& s)
176-
{
177-
unsigned int len = ::ReadCompactSize(s);
178-
unsigned char code[BIP32_EXTKEY_SIZE];
179-
if (len != BIP32_EXTKEY_SIZE)
180-
throw std::runtime_error("Invalid extended key size\n");
181-
s.read((char *)&code[0], len);
182-
Decode(code);
183-
}
184165
};
185166

186167
/** Initialize the elliptic curve support. May not be called twice without calling ECC_Stop first. */

src/pubkey.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -222,31 +222,6 @@ struct CExtPubKey {
222222
void Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const;
223223
void Decode(const unsigned char code[BIP32_EXTKEY_SIZE]);
224224
bool Derive(CExtPubKey& out, unsigned int nChild) const;
225-
226-
void Serialize(CSizeComputer& s) const
227-
{
228-
// Optimized implementation for ::GetSerializeSize that avoids copying.
229-
s.seek(BIP32_EXTKEY_SIZE + 1); // add one byte for the size (compact int)
230-
}
231-
template <typename Stream>
232-
void Serialize(Stream& s) const
233-
{
234-
unsigned int len = BIP32_EXTKEY_SIZE;
235-
::WriteCompactSize(s, len);
236-
unsigned char code[BIP32_EXTKEY_SIZE];
237-
Encode(code);
238-
s.write((const char *)&code[0], len);
239-
}
240-
template <typename Stream>
241-
void Unserialize(Stream& s)
242-
{
243-
unsigned int len = ::ReadCompactSize(s);
244-
unsigned char code[BIP32_EXTKEY_SIZE];
245-
if (len != BIP32_EXTKEY_SIZE)
246-
throw std::runtime_error("Invalid extended key size\n");
247-
s.read((char *)&code[0], len);
248-
Decode(code);
249-
}
250225
};
251226

252227
/** Users of this module must hold an ECCVerifyHandle. The constructor and

src/test/bip32_tests.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,6 @@ static void RunTest(const TestVector &test) {
118118
}
119119
key = keyNew;
120120
pubkey = pubkeyNew;
121-
122-
CDataStream ssPub(SER_DISK, CLIENT_VERSION);
123-
ssPub << pubkeyNew;
124-
BOOST_CHECK(ssPub.size() == 75);
125-
126-
CDataStream ssPriv(SER_DISK, CLIENT_VERSION);
127-
ssPriv << keyNew;
128-
BOOST_CHECK(ssPriv.size() == 75);
129-
130-
CExtPubKey pubCheck;
131-
CExtKey privCheck;
132-
ssPub >> pubCheck;
133-
ssPriv >> privCheck;
134-
135-
BOOST_CHECK(pubCheck == pubkeyNew);
136-
BOOST_CHECK(privCheck == keyNew);
137121
}
138122
}
139123

0 commit comments

Comments
 (0)