@@ -1020,15 +1020,19 @@ impl Index {
1020
1020
pub fn get_rune_balances_for_output (
1021
1021
& self ,
1022
1022
outpoint : OutPoint ,
1023
- ) -> Result < BTreeMap < SpacedRune , Pile > > {
1023
+ ) -> Result < Option < BTreeMap < SpacedRune , Pile > > > {
1024
+ if !self . index_runes {
1025
+ return Ok ( None ) ;
1026
+ }
1027
+
1024
1028
let rtx = self . database . begin_read ( ) ?;
1025
1029
1026
1030
let outpoint_to_balances = rtx. open_table ( OUTPOINT_TO_RUNE_BALANCES ) ?;
1027
1031
1028
1032
let id_to_rune_entries = rtx. open_table ( RUNE_ID_TO_RUNE_ENTRY ) ?;
1029
1033
1030
1034
let Some ( balances) = outpoint_to_balances. get ( & outpoint. store ( ) ) ? else {
1031
- return Ok ( BTreeMap :: new ( ) ) ;
1035
+ return Ok ( Some ( BTreeMap :: new ( ) ) ) ;
1032
1036
} ;
1033
1037
1034
1038
let balances_buffer = balances. value ( ) ;
@@ -1051,7 +1055,7 @@ impl Index {
1051
1055
) ;
1052
1056
}
1053
1057
1054
- Ok ( balances)
1058
+ Ok ( Some ( balances) )
1055
1059
}
1056
1060
1057
1061
pub fn get_rune_balance_map ( & self ) -> Result < BTreeMap < SpacedRune , BTreeMap < OutPoint , Pile > > > {
@@ -1534,7 +1538,11 @@ impl Index {
1534
1538
pub fn get_inscriptions_on_output_with_satpoints (
1535
1539
& self ,
1536
1540
outpoint : OutPoint ,
1537
- ) -> Result < Vec < ( SatPoint , InscriptionId ) > > {
1541
+ ) -> Result < Option < Vec < ( SatPoint , InscriptionId ) > > > {
1542
+ if !self . index_inscriptions {
1543
+ return Ok ( None ) ;
1544
+ }
1545
+
1538
1546
let rtx = self . database . begin_read ( ) ?;
1539
1547
let outpoint_to_utxo_entry = rtx. open_table ( OUTPOINT_TO_UTXO_ENTRY ) ?;
1540
1548
let sequence_number_to_inscription_entry =
@@ -1547,31 +1555,40 @@ impl Index {
1547
1555
)
1548
1556
}
1549
1557
1550
- pub fn get_inscriptions_for_output ( & self , outpoint : OutPoint ) -> Result < Vec < InscriptionId > > {
1551
- Ok (
1552
- self
1553
- . get_inscriptions_on_output_with_satpoints ( outpoint) ?
1558
+ pub fn get_inscriptions_for_output (
1559
+ & self ,
1560
+ outpoint : OutPoint ,
1561
+ ) -> Result < Option < Vec < InscriptionId > > > {
1562
+ let Some ( inscriptions) = self . get_inscriptions_on_output_with_satpoints ( outpoint) ? else {
1563
+ return Ok ( None ) ;
1564
+ } ;
1565
+
1566
+ Ok ( Some (
1567
+ inscriptions
1554
1568
. iter ( )
1555
1569
. map ( |( _satpoint, inscription_id) | * inscription_id)
1556
1570
. collect ( ) ,
1557
- )
1571
+ ) )
1558
1572
}
1559
1573
1560
1574
pub fn get_inscriptions_for_outputs (
1561
1575
& self ,
1562
1576
outpoints : & Vec < OutPoint > ,
1563
- ) -> Result < Vec < InscriptionId > > {
1564
- let mut inscriptions = Vec :: new ( ) ;
1577
+ ) -> Result < Option < Vec < InscriptionId > > > {
1578
+ let mut result = Vec :: new ( ) ;
1565
1579
for outpoint in outpoints {
1566
- inscriptions. extend (
1567
- self
1568
- . get_inscriptions_on_output_with_satpoints ( * outpoint) ?
1580
+ let Some ( inscriptions) = self . get_inscriptions_on_output_with_satpoints ( * outpoint) ? else {
1581
+ return Ok ( None ) ;
1582
+ } ;
1583
+
1584
+ result. extend (
1585
+ inscriptions
1569
1586
. iter ( )
1570
1587
. map ( |( _satpoint, inscription_id) | * inscription_id) ,
1571
1588
) ;
1572
1589
}
1573
1590
1574
- Ok ( inscriptions )
1591
+ Ok ( Some ( result ) )
1575
1592
}
1576
1593
1577
1594
pub fn get_transaction ( & self , txid : Txid ) -> Result < Option < Transaction > > {
@@ -2247,13 +2264,13 @@ impl Index {
2247
2264
outpoint_to_utxo_entry : & ' a impl ReadableTable < & ' static OutPointValue , & ' static UtxoEntry > ,
2248
2265
sequence_number_to_inscription_entry : & ' a impl ReadableTable < u32 , InscriptionEntryValue > ,
2249
2266
outpoint : OutPoint ,
2250
- ) -> Result < Vec < ( SatPoint , InscriptionId ) > > {
2267
+ ) -> Result < Option < Vec < ( SatPoint , InscriptionId ) > > > {
2251
2268
if !self . index_inscriptions {
2252
- return Ok ( Vec :: new ( ) ) ;
2269
+ return Ok ( None ) ;
2253
2270
}
2254
2271
2255
2272
let Some ( utxo_entry) = outpoint_to_utxo_entry. get ( & outpoint. store ( ) ) ? else {
2256
- return Ok ( Vec :: new ( ) ) ;
2273
+ return Ok ( Some ( Vec :: new ( ) ) ) ;
2257
2274
} ;
2258
2275
2259
2276
let mut inscriptions = utxo_entry. value ( ) . parse ( self ) . parse_inscriptions ( ) ;
@@ -2266,10 +2283,13 @@ impl Index {
2266
2283
let entry = sequence_number_to_inscription_entry
2267
2284
. get ( sequence_number) ?
2268
2285
. unwrap ( ) ;
2286
+
2269
2287
let satpoint = SatPoint { outpoint, offset } ;
2288
+
2270
2289
Ok ( ( satpoint, InscriptionEntry :: load ( entry. value ( ) ) . id ) )
2271
2290
} )
2272
2291
. collect :: < Result < _ > > ( )
2292
+ . map ( Some )
2273
2293
}
2274
2294
2275
2295
pub fn get_address_info ( & self , address : & Address ) -> Result < Vec < OutPoint > > {
@@ -2289,11 +2309,13 @@ impl Index {
2289
2309
pub ( crate ) fn get_aggregated_rune_balances_for_outputs (
2290
2310
& self ,
2291
2311
outputs : & Vec < OutPoint > ,
2292
- ) -> Result < Vec < ( SpacedRune , Decimal , Option < char > ) > > {
2312
+ ) -> Result < Option < Vec < ( SpacedRune , Decimal , Option < char > ) > > > {
2293
2313
let mut runes = BTreeMap :: new ( ) ;
2294
2314
2295
2315
for output in outputs {
2296
- let rune_balances = self . get_rune_balances_for_output ( * output) ?;
2316
+ let Some ( rune_balances) = self . get_rune_balances_for_output ( * output) ? else {
2317
+ return Ok ( None ) ;
2318
+ } ;
2297
2319
2298
2320
for ( spaced_rune, pile) in rune_balances {
2299
2321
runes
@@ -2312,12 +2334,12 @@ impl Index {
2312
2334
}
2313
2335
}
2314
2336
2315
- Ok (
2337
+ Ok ( Some (
2316
2338
runes
2317
2339
. into_iter ( )
2318
2340
. map ( |( spaced_rune, ( decimal, symbol) ) | ( spaced_rune, decimal, symbol) )
2319
2341
. collect ( ) ,
2320
- )
2342
+ ) )
2321
2343
}
2322
2344
2323
2345
pub ( crate ) fn get_sat_balances_for_outputs ( & self , outputs : & Vec < OutPoint > ) -> Result < u64 > {
@@ -3476,7 +3498,8 @@ mod tests {
3476
3498
context
3477
3499
. index
3478
3500
. get_inscriptions_for_output( OutPoint { txid, vout: 0 } )
3479
- . unwrap( ) ,
3501
+ . unwrap( )
3502
+ . unwrap_or_default( ) ,
3480
3503
[ ]
3481
3504
) ;
3482
3505
@@ -3486,7 +3509,8 @@ mod tests {
3486
3509
context
3487
3510
. index
3488
3511
. get_inscriptions_for_output( OutPoint { txid, vout: 0 } )
3489
- . unwrap( ) ,
3512
+ . unwrap( )
3513
+ . unwrap_or_default( ) ,
3490
3514
[ inscription_id]
3491
3515
) ;
3492
3516
@@ -3501,7 +3525,8 @@ mod tests {
3501
3525
context
3502
3526
. index
3503
3527
. get_inscriptions_for_output( OutPoint { txid, vout: 0 } )
3504
- . unwrap( ) ,
3528
+ . unwrap( )
3529
+ . unwrap_or_default( ) ,
3505
3530
[ ]
3506
3531
) ;
3507
3532
@@ -3512,7 +3537,8 @@ mod tests {
3512
3537
txid: send_id,
3513
3538
vout: 0 ,
3514
3539
} )
3515
- . unwrap( ) ,
3540
+ . unwrap( )
3541
+ . unwrap_or_default( ) ,
3516
3542
[ inscription_id]
3517
3543
) ;
3518
3544
}
@@ -3542,7 +3568,8 @@ mod tests {
3542
3568
txid: first,
3543
3569
vout: 0
3544
3570
} )
3545
- . unwrap( ) ,
3571
+ . unwrap( )
3572
+ . unwrap_or_default( ) ,
3546
3573
[ inscription_id]
3547
3574
) ;
3548
3575
@@ -4420,6 +4447,7 @@ mod tests {
4420
4447
. index
4421
4448
. get_inscriptions_on_output_with_satpoints( OutPoint { txid, vout: 0 } )
4422
4449
. unwrap( )
4450
+ . unwrap_or_default( )
4423
4451
. iter( )
4424
4452
. map( |( _satpoint, inscription_id) | * inscription_id)
4425
4453
. collect:: <Vec <InscriptionId >>( )
@@ -4484,6 +4512,7 @@ mod tests {
4484
4512
. index
4485
4513
. get_inscriptions_on_output_with_satpoints( OutPoint { txid, vout: 0 } )
4486
4514
. unwrap( )
4515
+ . unwrap_or_default( )
4487
4516
)
4488
4517
}
4489
4518
}
@@ -4533,6 +4562,7 @@ mod tests {
4533
4562
vout: 0
4534
4563
} )
4535
4564
. unwrap( )
4565
+ . unwrap_or_default( )
4536
4566
)
4537
4567
}
4538
4568
}
0 commit comments