@@ -176,4 +176,33 @@ defmodule DB.Entry do
176176 end )
177177 end
178178
179+ def build_filter_hashes ( ) do
180+ rebuilt_up_to = RocksDB . get ( "filter_hashes_rebuilt_up_to" , db_handle ( % { } , :sysconf , % { } ) ) || EntryGenesis . get ( ) . hash
181+ entry = by_hash ( rebuilt_up_to )
182+ if rem ( entry . header . height , 10_000 ) == 0 do
183+ IO . inspect { :rebuilt_filter_hashes_up_to , entry . header . height }
184+ end
185+ txs = entry . txs
186+ txs = Enum . map ( txs , fn ( txu ) ->
187+ txu = if ! is_binary ( txu ) do txu else
188+ txu = VanillaSer . decode! ( txu )
189+ tx = VanillaSer . decode! ( txu . tx_encoded )
190+ Map . put ( txu , :tx , tx )
191+ end
192+ action = TX . action ( txu )
193+ args = case action . args do
194+ [ n | t ] when is_integer ( n ) -> [ :erlang . integer_to_binary ( n ) | t ]
195+ args -> args
196+ end
197+
198+ txu = put_in ( txu , [ :tx , :action ] , action )
199+ put_in ( txu , [ :tx , :action , :args ] , args )
200+ end )
201+
202+ tx_filters = RDB . build_tx_hashfilters ( txs )
203+ Enum . each ( tx_filters , fn { key , hash } ->
204+ RocksDB . put ( key , hash , db_handle ( % { } , :tx_filter , % { } ) )
205+ end )
206+ rebuilt_up_to = RocksDB . put ( "filter_hashes_rebuilt_up_to" , next ( rebuilt_up_to ) , db_handle ( % { } , :sysconf , % { } ) ) || EntryGenesis . get ( ) . hash
207+ end
179208end
0 commit comments