@@ -12,7 +12,6 @@ use crate::{
1212 dense:: { BlockFileId , TxId , TxOutId } ,
1313 indecies:: { ConfirmedTxPtrIndex , DenseIndexSet , INID_NONE , OUTID_NONE , TxPtr } ,
1414 sled:: spk_db:: { SledScriptPubkeyDb , SledScriptPubkeyDbError } ,
15- traits:: ScriptPubkeyDb ,
1615} ;
1716
1817/// Block file layout: 4-byte magic + 4-byte block size (LE) + block payload.
@@ -183,7 +182,6 @@ impl Parser {
183182 tx_out_base,
184183 current_in : 0 ,
185184 current_out : 0 ,
186- spk_db,
187185 error : None ,
188186 } ;
189187 bsl:: Block :: visit ( block_slice, & mut collector)
@@ -218,6 +216,9 @@ impl Parser {
218216 . set ( * out_id, * in_id)
219217 . map_err ( BlockFileError :: Io ) ?;
220218 }
219+ spk_db
220+ . insert_batch_if_absent ( & batch. spk_inserts )
221+ . map_err ( BlockFileError :: SpkDb ) ?;
221222
222223 tx_total += batch. txptrs . len ( ) as u64 ;
223224 if tx_total > u32:: MAX as u64 {
@@ -253,6 +254,8 @@ struct BlockBatch {
253254 out_spents : Vec < u64 > ,
254255 /// `(out_id, in_id)` pairs for outputs spent within or before this block.
255256 out_spent_updates : Vec < ( u64 , u64 ) > ,
257+ /// Script-pubkey index inserts; first-seen per hash wins.
258+ spk_inserts : Vec < ( ScriptPubkeyHash , TxOutId ) > ,
256259}
257260
258261/// Visitor that collects TxIds (file + byte offset) for each transaction in a block.
@@ -277,7 +280,6 @@ struct TxIdCollector<'a> {
277280 tx_out_base : u64 ,
278281 current_in : u64 ,
279282 current_out : u64 ,
280- spk_db : & ' a mut SledScriptPubkeyDb ,
281283 error : Option < BlockFileError > ,
282284}
283285
@@ -338,10 +340,7 @@ impl Visitor for TxIdCollector<'_> {
338340 return ControlFlow :: Break ( ( ) ) ;
339341 }
340342 let spk_hash = script_pubkey_hash ( tx_out. script_pubkey ( ) ) ;
341- if let Err ( err) = self . spk_db . insert_if_absent ( spk_hash, TxOutId :: new ( out_id) ) {
342- self . error = Some ( BlockFileError :: SpkDb ( err) ) ;
343- return ControlFlow :: Break ( ( ) ) ;
344- }
343+ self . batch . spk_inserts . push ( ( spk_hash, TxOutId :: new ( out_id) ) ) ;
345344 self . batch . out_spents . push ( INID_NONE ) ;
346345 self . current_out += 1 ;
347346 ControlFlow :: Continue ( ( ) )
0 commit comments