1- use std:: { fs:: File , sync:: Arc } ;
1+ use std:: { fs:: File , io :: Write , sync:: Arc } ;
22
3- use bitcoin:: consensus;
3+ use bitcoin:: { consensus, OutPoint } ;
4+ use hintfile:: write_compact_size;
45use kernel:: { ChainType , ChainstateManager , ChainstateManagerOptions , ContextBuilder , KernelError } ;
56
67fn main ( ) {
@@ -21,6 +22,8 @@ fn main() {
2122 let chainman = ChainstateManager :: new ( options, context) . unwrap ( ) ;
2223 println ! ( "Chain state initialized" ) ;
2324 let genesis = chainman. get_block_index_genesis ( ) ;
25+ let tip = chainman. get_block_index_tip ( ) . block_hash ( ) . hash ;
26+ file. write_all ( & tip) . unwrap ( ) ;
2427 let mut current = chainman. get_next_block_index ( genesis) . unwrap ( ) ;
2528 loop {
2629 let block = chainman. read_block_data ( & current) . unwrap ( ) ;
@@ -30,7 +33,25 @@ fn main() {
3033 println ! ( "On block {}" , current. height( ) ) ;
3134 let mut delta: u64 = 0 ;
3235 let mut block_offsets: Vec < u64 > = Vec :: new ( ) ;
33- for tx in transactions { }
36+ for tx in transactions {
37+ let txid = tx. compute_txid ( ) ;
38+ for ( index, _txout) in tx. outputs . iter ( ) . enumerate ( ) {
39+ let _outpoint = OutPoint {
40+ txid,
41+ vout : index as u32 ,
42+ } ;
43+ // if true
44+ block_offsets. push ( delta) ;
45+ delta = 0 ;
46+ }
47+ }
48+ // Overflows 32 bit machines
49+ let len_encode = block_offsets. len ( ) as u64 ;
50+ println ! ( "Writing block offsets" ) ;
51+ write_compact_size ( len_encode, & mut file) . expect ( "unexpected EOF" ) ;
52+ for offset in block_offsets {
53+ write_compact_size ( offset, & mut file) . expect ( "unexpected EOF" ) ;
54+ }
3455 match chainman. get_next_block_index ( current) {
3556 Ok ( next) => current = next,
3657 Err ( KernelError :: OutOfBounds ) => break ,
0 commit comments