@@ -47,16 +47,16 @@ bool SerializeDB(Stream& stream, const Data& data)
4747}
4848
4949template <typename Data>
50- bool SerializeFileDB (const std::string& prefix, const fs::path& path, const Data& data, int version )
50+ bool SerializeFileDB (const std::string& prefix, const fs::path& path, const Data& data)
5151{
5252 // Generate random temporary filename
5353 const uint16_t randv{GetRand<uint16_t >()};
5454 std::string tmpfn = strprintf (" %s.%04x" , prefix, randv);
5555
56- // open temp output file, and associate with CAutoFile
56+ // open temp output file
5757 fs::path pathTmp = gArgs .GetDataDirNet () / fs::u8path (tmpfn);
5858 FILE *file = fsbridge::fopen (pathTmp, " wb" );
59- CAutoFile fileout ( file, SER_DISK, version) ;
59+ AutoFile fileout{ file} ;
6060 if (fileout.IsNull ()) {
6161 fileout.fclose ();
6262 remove (pathTmp);
@@ -86,9 +86,9 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data
8686}
8787
8888template <typename Stream, typename Data>
89- void DeserializeDB (Stream& stream, Data& data, bool fCheckSum = true )
89+ void DeserializeDB (Stream& stream, Data&& data, bool fCheckSum = true )
9090{
91- CHashVerifier<Stream> verifier (& stream) ;
91+ HashVerifier verifier{ stream} ;
9292 // de-serialize file header (network specific magic number) and ..
9393 unsigned char pchMsgTmp[4 ];
9494 verifier >> pchMsgTmp;
@@ -111,11 +111,10 @@ void DeserializeDB(Stream& stream, Data& data, bool fCheckSum = true)
111111}
112112
113113template <typename Data>
114- void DeserializeFileDB (const fs::path& path, Data& data, int version )
114+ void DeserializeFileDB (const fs::path& path, Data&& data)
115115{
116- // open input file, and associate with CAutoFile
117116 FILE* file = fsbridge::fopen (path, " rb" );
118- CAutoFile filein ( file, SER_DISK, version) ;
117+ AutoFile filein{ file} ;
119118 if (filein.IsNull ()) {
120119 throw DbNotFoundError{};
121120 }
@@ -175,10 +174,10 @@ bool CBanDB::Read(banmap_t& banSet)
175174bool DumpPeerAddresses (const ArgsManager& args, const AddrMan& addr)
176175{
177176 const auto pathAddr = args.GetDataDirNet () / " peers.dat" ;
178- return SerializeFileDB (" peers" , pathAddr, addr, CLIENT_VERSION );
177+ return SerializeFileDB (" peers" , pathAddr, addr);
179178}
180179
181- void ReadFromStream (AddrMan& addr, CDataStream & ssPeers)
180+ void ReadFromStream (AddrMan& addr, DataStream & ssPeers)
182181{
183182 DeserializeDB (ssPeers, addr, false );
184183}
@@ -191,7 +190,7 @@ util::Result<std::unique_ptr<AddrMan>> LoadAddrman(const NetGroupManager& netgro
191190 const auto start{SteadyClock::now ()};
192191 const auto path_addr{args.GetDataDirNet () / " peers.dat" };
193192 try {
194- DeserializeFileDB (path_addr, *addrman, CLIENT_VERSION );
193+ DeserializeFileDB (path_addr, *addrman);
195194 LogPrintf (" Loaded %i addresses from peers.dat %dms\n " , addrman->Size (), Ticks<std::chrono::milliseconds>(SteadyClock::now () - start));
196195 } catch (const DbNotFoundError&) {
197196 // Addrman can be in an inconsistent state after failure, reset it
@@ -217,14 +216,14 @@ util::Result<std::unique_ptr<AddrMan>> LoadAddrman(const NetGroupManager& netgro
217216void DumpAnchors (const fs::path& anchors_db_path, const std::vector<CAddress>& anchors)
218217{
219218 LOG_TIME_SECONDS (strprintf (" Flush %d outbound block-relay-only peer addresses to anchors.dat" , anchors.size ()));
220- SerializeFileDB (" anchors" , anchors_db_path, anchors, CLIENT_VERSION | ADDRV2_FORMAT );
219+ SerializeFileDB (" anchors" , anchors_db_path, WithParams (CAddress::V2_DISK, anchors) );
221220}
222221
223222std::vector<CAddress> ReadAnchors (const fs::path& anchors_db_path)
224223{
225224 std::vector<CAddress> anchors;
226225 try {
227- DeserializeFileDB (anchors_db_path, anchors, CLIENT_VERSION | ADDRV2_FORMAT );
226+ DeserializeFileDB (anchors_db_path, WithParams (CAddress::V2_DISK, anchors) );
228227 LogPrintf (" Loaded %i addresses from %s\n " , anchors.size (), fs::quoted (fs::PathToString (anchors_db_path.filename ())));
229228 } catch (const std::exception&) {
230229 anchors.clear ();
0 commit comments