package Ġcom . rar ible . blockchain . scanner . re conc iliation Ċ Ċ import Ġcom . rar ible . blockchain . scanner . Log EventHandler Ċ import Ġcom . rar ible . blockchain . scanner . Log Event Publisher Ċ import Ġcom . rar ible . blockchain . scanner . framework . client . Blockchain Block Ċ import Ġcom . rar ible . blockchain . scanner . framework . client . Blockchain Client Ċ import Ġcom . rar ible . blockchain . scanner . framework . client . Blockchain Log Ċ import Ġcom . rar ible . blockchain . scanner . framework . data . Block Event Ċ import Ġcom . rar ible . blockchain . scanner . framework . data . Full Block Ċ import Ġcom . rar ible . blockchain . scanner . framework . data . Source Ċ import Ġcom . rar ible . blockchain . scanner . framework . mapper . Block Mapper Ċ import Ġcom . rar ible . blockchain . scanner . framework . model . Block Ċ import Ġcom . rar ible . blockchain . scanner . framework . model . Descriptor Ċ import Ġcom . rar ible . blockchain . scanner . framework . model . Log Ċ import Ġcom . rar ible . blockchain . scanner . framework . model . Log Record Ċ import Ġcom . rar ible . blockchain . scanner . framework . service . Block Service Ċ import Ġcom . rar ible . blockchain . scanner . util . Block Ranges Ċ import Ġcom . rar ible . core . apm . with Span Ċ import Ġcom . rar ible . core . apm . with Transaction Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . Flow Preview Ċ import Ġkotlinx . coroutines . flow . Flow Ċ import Ġkotlinx . coroutines . flow . on Completion Ċ import Ġkotlinx . coroutines . flow . on Each Ċ import Ġkotlinx . coroutines . flow . toList Ċ import Ġorg . slf 4 j . LoggerFactory Ċ Ċ /** Ċ Ġ* ĠRe conc iliation Ġindexer Ġfor Ġsingle ĠLog EventHandler Ġ( which Ġmeans , Ġfor Ġsingle Ġsubscriber ). Ċ Ġ* ĠThe Ġgoal Ġof Ġsuch Ġindexer Ġto Ġre - read ĠLog Events Ġfrom Ġblocks , Ġupdate Ġthem Ġand Ġpublish Ġchanges . Ċ Ġ* ĠIndex er Ġdo ĠNOT Ġcheck Ġpending Ġblocks / logs Ġand Ġalso Ġdo ĠNOT Ġupdate Ġstate Ġof Ġblocks . Ċ Ġ*/ Ċ @ Flow Preview Ċ @ Experimental Cor outines Api Ċ class ĠRe conc iliation Indexer < BB Ġ: ĠBlock chain Block , ĠB : ĠBlock , ĠBL Ġ: ĠBlock chain Log , ĠL Ġ: ĠLog , ĠR Ġ: ĠLog Record < L , Ġ* >, ĠD Ġ: ĠDescriptor >( ĊĠĠĠ Ġprivate Ġval Ġblockchain Client : ĠBlock chain Client < BB , ĠBL , ĠD >, ĊĠĠĠ Ġprivate Ġval Ġlog EventHandler : ĠLog EventHandler < BB , ĠBL , ĠL , ĠR , ĠD >, ĊĠĠĠ Ġprivate Ġval Ġlog Event Publisher : ĠLog Event Publisher < L , ĠR >, ĊĠĠĠ Ġprivate Ġval Ġblock Service : ĠBlock Service < B >, ĊĠĠĠ Ġprivate Ġval Ġblock Mapper : ĠBlock Mapper < BB , ĠB > Ċ ) Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġlogger Ġ= ĠLoggerFactory . getLogger ( log EventHandler . subscriber . java Class ) ĊĊĊĠĠĠ Ġfun Ġre index ( from : ĠLong , Ġto : ĠLong , Ġbatch Size : ĠLong ): ĠFlow < Long Range > Ġ{ ĊĠĠĠĠĠĠĠ Ġlogger . info (" Sc anning Ġfor ĠLogs Ġin Ġbatches Ġfrom ={} Ġto ={} Ġwith Ġbatch Size ={ }", Ġfrom , Ġto , Ġbatch Size ) ĊĠĠĠĠĠĠĠ Ġreturn ĠBlock Ranges . get Ranges ( from , Ġto , Ġbatch Size . toInt ()). on Each Ġ{ Ġrange Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwith Transaction (" re index ", ĠlistOf (" range " Ġto Ġrange . toString ())) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġdescriptor Ġ= Ġlog EventHandler . subscriber . get Descriptor () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġevents Ġ= Ġwith Span (" getBlock Events ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġblockchain Client . getBlock Events ( descriptor , Ġrange ). toList () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġevents . on Each Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwith Span (" process Block ", Ġlabels Ġ= ĠlistOf (" block Number " Ġto Ġit . block . number )) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġprocessed Logs Ġ= Ġre index Block ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġblock Event Ġ= ĠBlock Event ( Source . RE INDEX , Ġit . block ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlog Event Publisher . on Block Processed ( block Event , Ġprocessed Logs ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġsuspend Ġfun Ġre index Block ( full Block : ĠFull Block < BB , ĠBL >): ĠList < R > Ġ{ ĊĠĠĠĠĠĠĠ Ġlogger . info (" Re indexing ĠBlock Ġ{} Ġwith Ġ{} ĠLogs ", Ġfull Block . block . hash , Ġfull Block . logs . size ) ĊĠĠĠĠĠĠĠ Ġreturn Ġlog EventHandler . handle Logs ( full Block ). on Completion Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġblock Service . save ( block Mapper . map ( full Block . block , ĠBlock . Status . SUCCESS )) ĊĠĠĠĠĠĠĠ Ġ}. toList () ĊĠĠĠ Ġ} Ċ Ċ } Ċ