@@ -2455,12 +2455,56 @@ impl Index {
2455
2455
txout,
2456
2456
) ) )
2457
2457
}
2458
+
2459
+ #[ cfg( test) ]
2460
+ pub ( crate ) fn list_all_spks ( & self ) -> Result < Vec < ScriptBuf > > {
2461
+ let rtx = self . database . begin_read ( ) ?;
2462
+ let mut spks = Vec :: new ( ) ;
2463
+
2464
+ for entry in rtx. open_table ( OUTPOINT_TO_UTXO_ENTRY ) ?. iter ( ) ? {
2465
+ let ( _outpoint, utxo_entry) = entry?;
2466
+
2467
+ spks. push ( ScriptBuf :: from_bytes (
2468
+ utxo_entry. value ( ) . parse ( self ) . script_pubkey ( ) . to_vec ( ) ,
2469
+ ) ) ;
2470
+ }
2471
+
2472
+ Ok ( spks)
2473
+ }
2458
2474
}
2459
2475
2460
2476
#[ cfg( test) ]
2461
2477
mod tests {
2462
2478
use { super :: * , crate :: index:: testing:: Context } ;
2463
2479
2480
+ #[ test]
2481
+ fn list_all_spks ( ) {
2482
+ let context = Context :: builder ( ) . build ( ) ;
2483
+
2484
+ context. mine_blocks ( 2 ) ;
2485
+
2486
+ let tx_1 = TransactionTemplate {
2487
+ inputs : & [ ( 1 , 0 , 0 , Default :: default ( ) ) ] ,
2488
+ fee : 0 ,
2489
+ recipient : Some ( address ( 0 ) ) ,
2490
+ ..default ( )
2491
+ } ;
2492
+
2493
+ let tx_2 = TransactionTemplate {
2494
+ inputs : & [ ( 2 , 0 , 0 , Default :: default ( ) ) ] ,
2495
+ fee : 0 ,
2496
+ recipient : Some ( address ( 1 ) ) ,
2497
+ ..default ( )
2498
+ } ;
2499
+
2500
+ context. core . broadcast_tx ( tx_1) ;
2501
+ context. core . broadcast_tx ( tx_2) ;
2502
+
2503
+ context. mine_blocks ( 1 ) ;
2504
+
2505
+ assert_eq ! ( context. index. list_all_spks( ) . unwrap( ) . len( ) , 4 ) ;
2506
+ }
2507
+
2464
2508
#[ test]
2465
2509
fn height_limit ( ) {
2466
2510
{
0 commit comments