File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed
Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -104,16 +104,23 @@ impl Hints {
104104 self . file
105105 . seek ( SeekFrom :: Start ( file_pos) )
106106 . expect ( "missing file position." ) ;
107- let num_unspents = read_compact_size ( & mut self . file ) . expect ( "unexpected missing hints." ) ;
108- let mut indexes = Vec :: new ( ) ;
109- let mut prev = 0 ;
110- for _ in 0 ..num_unspents {
111- let offset = read_compact_size ( & mut self . file ) . expect ( "unexpected missing hints." ) ;
112- let next = prev + offset;
113- indexes. push ( next) ;
114- prev = next;
107+ let mut bits_arr = [ 0 ; 4 ] ;
108+ self . file . read_exact ( & mut bits_arr) . unwrap ( ) ;
109+ let mut unspents = Vec :: new ( ) ;
110+ let num_bits = u32:: from_le_bytes ( bits_arr) ;
111+ let mut curr_byte: u8 = 0 ;
112+ for bit_pos in 0 ..num_bits {
113+ let leftovers = bit_pos % 8 ;
114+ if leftovers == 0 {
115+ let mut single_byte_arr = [ 0 ; 1 ] ;
116+ self . file . read_exact ( & mut single_byte_arr) . unwrap ( ) ;
117+ curr_byte = u8:: from_le_bytes ( single_byte_arr) ;
118+ }
119+ if ( ( curr_byte >> leftovers) & 0x01 ) == 0x01 {
120+ unspents. push ( bit_pos as u64 ) ;
121+ }
115122 }
116- indexes
123+ unspents
117124 }
118125}
119126
You can’t perform that action at this time.
0 commit comments