Skip to content

Commit 0196a0f

Browse files
committed
swiftsync: Add hintsfile writing wrapper type
1 parent 7434062 commit 0196a0f

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

src/swiftsync.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <swiftsync.h>
2+
using namespace swiftsync;
3+
4+
HintsfileWriter::HintsfileWriter(AutoFile& file) : m_file(file.release())
5+
{
6+
m_file << FILE_MAGIC;
7+
m_file << FILE_VERSION;
8+
}
9+
10+
bool HintsfileWriter::WriteStopHeight(uint32_t stop)
11+
{
12+
m_file << stop;
13+
return m_file.Commit();
14+
}
15+
16+
bool HintsfileWriter::WriteHints(const EliasFano& ef)
17+
{
18+
m_file << ef;
19+
return m_file.Commit();
20+
}

src/swiftsync.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <serialize.h>
88
#include <span.h>
9+
#include <streams.h>
910

1011
#include <algorithm>
1112
#include <array>
@@ -204,6 +205,30 @@ class EliasFano
204205
}
205206
};
206207

208+
/**
209+
* Simple wrapper class to assist in writing UTXO set hints to file.
210+
*
211+
* The hints of a block are represented as the Elias-Fano encoding of the indices within a block that will remain unspent.
212+
*/
213+
class HintsfileWriter
214+
{
215+
private:
216+
AutoFile m_file;
217+
218+
public:
219+
/**
220+
* Write the file magic and version number to file.
221+
*/
222+
HintsfileWriter(AutoFile& file);
223+
/**
224+
* Write the termination height this file encodes for.
225+
*/
226+
bool WriteStopHeight(uint32_t stop);
227+
/**
228+
* Write the hints for a block.
229+
*/
230+
bool WriteHints(const EliasFano& ef);
231+
};
207232
} // namespace swiftsync
208233

209234
#endif // BITCOIN_SWIFTSYNC_H

0 commit comments

Comments
 (0)