11#include < array>
2+ #include < cstddef>
3+ #include < cstdint>
24#include < primitives/transaction.h>
35#include < random.h>
6+ #include < serialize.h>
7+ #include < streams.h>
48#include < swiftsync.h>
59#include < uint256.h>
10+ #include < vector>
611
712Aggregate::Aggregate () : m_limb0(0 ), m_limb1(0 ), m_limb2(0 ), m_limb3(0 )
813{
@@ -23,3 +28,59 @@ void Aggregate::Spend(const COutPoint& outpoint)
2328 auto a0 = (HashWriter (m_salted_hasher) << outpoint).GetSHA256 ().GetUint64 (0 );
2429 m_limb0 -= a0;
2530}
31+
32+ Hintfile::Hintfile (AutoFile file) : m_file(file.release())
33+ {
34+ uint256 m_stop_hash;
35+ uint32_t m_stop_height;
36+ m_file >> m_stop_height;
37+ m_file >> m_stop_hash;
38+ m_curr_height = 0 ;
39+ }
40+
41+ Hintfile::Hintfile (AutoFile file, const uint256& stop_hash, const uint32_t & stop_height) : m_file(file.release())
42+ {
43+ m_file << stop_height;
44+ m_file << stop_hash;
45+ m_curr_height = 0 ;
46+ }
47+
48+ BlockUnspentHints::BlockUnspentHints (const std::vector<uint64_t > offsets)
49+ {
50+ // Assuming a vector of ordered offsets is given, unpack into the literal indexes.
51+ std::vector<uint64_t > m_unspent_indexes;
52+ uint64_t prev = 0 ;
53+ for (const auto & offset : offsets) {
54+ auto next = prev + offset;
55+ m_unspent_indexes.push_back (next);
56+ prev = next;
57+ }
58+ }
59+
60+ bool BlockUnspentHints::IsUnspent (const uint64_t index)
61+ {
62+ auto found = std::find (m_unspent_indexes.begin (), m_unspent_indexes.end (), index);
63+ return found != m_unspent_indexes.end ();
64+ }
65+
66+ BlockUnspentHints Hintfile::ReadNextBlock ()
67+ {
68+ m_curr_height++;
69+ uint64_t num_unspent = ReadCompactSize (m_file);
70+ std::vector<uint64_t > offsets;
71+ offsets.reserve (num_unspent);
72+ for (uint64_t i = 0 ; i < num_unspent; i++) {
73+ offsets.push_back (ReadCompactSize (m_file));
74+ }
75+ return BlockUnspentHints (offsets);
76+ }
77+
78+ bool Hintfile::WriteNextBlock (const std::vector<uint64_t >& unspent_offsets)
79+ {
80+ m_curr_height++;
81+ WriteCompactSize (m_file, unspent_offsets.size ());
82+ for (const auto & offset : unspent_offsets) {
83+ WriteCompactSize (m_file, offset);
84+ }
85+ return m_file.Commit ();
86+ }
0 commit comments