@@ -385,8 +385,8 @@ impl Index {
385385 etching,
386386 terms : Some ( Terms {
387387 amount : Some ( 100 ) ,
388- cap : Some ( 1_000_000_000 as u128 ) ,
389- height : ( Some ( 350_000 ) , Some ( Epoch ( 5 ) . starting_height ( ) . 0 as u64 ) ) ,
388+ cap : Some ( 1_000_000_000 ) ,
389+ height : ( Some ( 350_000 ) , Some ( u64 :: from ( Epoch ( 5 ) . starting_height ( ) . 0 ) ) ) ,
390390 offset : ( None , None ) ,
391391 } ) ,
392392 mints : 0 ,
@@ -1491,7 +1491,7 @@ impl Index {
14911491 . open_table ( INSCRIPTION_ID_TO_OUTPOINTS ) ?
14921492 . get ( & inscription_id. store ( ) ) ?
14931493 . map ( |x| x. value ( ) )
1494- . map ( |x| Vec :: < OutPoint > :: load ( x ) )
1494+ . map ( Vec :: < OutPoint > :: load)
14951495 else {
14961496 return Ok ( None ) ;
14971497 } ;
@@ -1500,8 +1500,7 @@ impl Index {
15001500 . get_transactions ( partial_txs. iter ( ) . map ( |x| x. txid ) ) ?
15011501 . into_iter ( )
15021502 . zip ( partial_txs. iter ( ) . map ( |x| x. txid ) )
1503- . map ( |( tx, txid) | tx. map ( |tx| ( txid, tx) ) )
1504- . flatten ( )
1503+ . filter_map ( |( tx, txid) | tx. map ( |tx| ( txid, tx) ) )
15051504 . collect :: < HashMap < _ , _ > > ( ) ;
15061505
15071506 let scripts = partial_txs
@@ -2340,6 +2339,55 @@ impl Index {
23402339 . collect ( )
23412340 }
23422341
2342+ pub fn get_address_runes (
2343+ & self ,
2344+ address : & Address ,
2345+ ) -> Result < Vec < ( SpacedRune , Decimal , Option < char > ) > > {
2346+ let v = self
2347+ . database
2348+ . begin_read ( ) ?
2349+ . open_multimap_table ( SCRIPT_PUBKEY_TO_OUTPOINT ) ?
2350+ . get ( address. script_pubkey ( ) . as_bytes ( ) ) ?
2351+ . map ( |result| {
2352+ result
2353+ . map_err ( |err| anyhow ! ( err) )
2354+ . map ( |value| OutPoint :: load ( value. value ( ) ) )
2355+ . and_then ( |outpoint| {
2356+ self
2357+ . get_rune_balances_for_output ( outpoint)
2358+ . map_err ( |err| anyhow ! ( err) )
2359+ } )
2360+ } )
2361+ . collect :: < Result < Vec < BTreeMap < SpacedRune , Pile > > > > ( ) ?;
2362+
2363+ let mut runes = BTreeMap :: new ( ) ;
2364+
2365+ for rune_balances in v {
2366+ for ( spaced_rune, pile) in rune_balances {
2367+ runes
2368+ . entry ( spaced_rune)
2369+ . and_modify ( |( decimal, _symbol) : & mut ( Decimal , Option < char > ) | {
2370+ assert_eq ! ( decimal. scale, pile. divisibility) ;
2371+ decimal. value += pile. amount ;
2372+ } )
2373+ . or_insert ( (
2374+ Decimal {
2375+ value : pile. amount ,
2376+ scale : pile. divisibility ,
2377+ } ,
2378+ pile. symbol ,
2379+ ) ) ;
2380+ }
2381+ }
2382+
2383+ Ok (
2384+ runes
2385+ . into_iter ( )
2386+ . map ( |( spaced_rune, ( decimal, symbol) ) | ( spaced_rune, decimal, symbol) )
2387+ . collect ( ) ,
2388+ )
2389+ }
2390+
23432391 pub ( crate ) fn get_aggregated_rune_balances_for_outputs (
23442392 & self ,
23452393 outputs : & Vec < OutPoint > ,
@@ -6053,13 +6101,9 @@ mod tests {
60536101 . unwrap ( )
60546102 . unwrap ( ) ;
60556103
6056- assert ! ( Charm :: charms( entry. charms)
6057- . iter( )
6058- . any( |charm| * charm == Charm :: Cursed ) ) ;
6104+ assert ! ( Charm :: charms( entry. charms) . contains( & Charm :: Cursed ) ) ;
60596105
6060- assert ! ( !Charm :: charms( entry. charms)
6061- . iter( )
6062- . any( |charm| * charm == Charm :: Vindicated ) ) ;
6106+ assert ! ( !Charm :: charms( entry. charms) . contains( & Charm :: Vindicated ) ) ;
60636107
60646108 let sat = entry. sat ;
60656109
@@ -6087,13 +6131,9 @@ mod tests {
60876131
60886132 assert_eq ! ( entry. inscription_number, 0 ) ;
60896133
6090- assert ! ( !Charm :: charms( entry. charms)
6091- . iter( )
6092- . any( |charm| * charm == Charm :: Cursed ) ) ;
6134+ assert ! ( !Charm :: charms( entry. charms) . contains( & Charm :: Cursed ) ) ;
60936135
6094- assert ! ( !Charm :: charms( entry. charms)
6095- . iter( )
6096- . any( |charm| * charm == Charm :: Vindicated ) ) ;
6136+ assert ! ( !Charm :: charms( entry. charms) . contains( & Charm :: Vindicated ) ) ;
60976137
60986138 assert_eq ! ( sat, entry. sat) ;
60996139
@@ -6117,13 +6157,9 @@ mod tests {
61176157 . unwrap ( )
61186158 . unwrap ( ) ;
61196159
6120- assert ! ( Charm :: charms( entry. charms)
6121- . iter( )
6122- . any( |charm| * charm == Charm :: Cursed ) ) ;
6160+ assert ! ( Charm :: charms( entry. charms) . contains( & Charm :: Cursed ) ) ;
61236161
6124- assert ! ( !Charm :: charms( entry. charms)
6125- . iter( )
6126- . any( |charm| * charm == Charm :: Vindicated ) ) ;
6162+ assert ! ( !Charm :: charms( entry. charms) . contains( & Charm :: Vindicated ) ) ;
61276163
61286164 assert_eq ! ( entry. inscription_number, -2 ) ;
61296165
@@ -6164,13 +6200,9 @@ mod tests {
61646200 . unwrap ( )
61656201 . unwrap ( ) ;
61666202
6167- assert ! ( !Charm :: charms( entry. charms)
6168- . iter( )
6169- . any( |charm| * charm == Charm :: Cursed ) ) ;
6203+ assert ! ( !Charm :: charms( entry. charms) . contains( & Charm :: Cursed ) ) ;
61706204
6171- assert ! ( Charm :: charms( entry. charms)
6172- . iter( )
6173- . any( |charm| * charm == Charm :: Vindicated ) ) ;
6205+ assert ! ( Charm :: charms( entry. charms) . contains( & Charm :: Vindicated ) ) ;
61746206
61756207 let sat = entry. sat ;
61766208
@@ -6196,13 +6228,9 @@ mod tests {
61966228 . unwrap ( )
61976229 . unwrap ( ) ;
61986230
6199- assert ! ( !Charm :: charms( entry. charms)
6200- . iter( )
6201- . any( |charm| * charm == Charm :: Cursed ) ) ;
6231+ assert ! ( !Charm :: charms( entry. charms) . contains( & Charm :: Cursed ) ) ;
62026232
6203- assert ! ( !Charm :: charms( entry. charms)
6204- . iter( )
6205- . any( |charm| * charm == Charm :: Vindicated ) ) ;
6233+ assert ! ( !Charm :: charms( entry. charms) . contains( & Charm :: Vindicated ) ) ;
62066234
62076235 assert_eq ! ( entry. inscription_number, 1 ) ;
62086236
@@ -6228,13 +6256,9 @@ mod tests {
62286256 . unwrap ( )
62296257 . unwrap ( ) ;
62306258
6231- assert ! ( !Charm :: charms( entry. charms)
6232- . iter( )
6233- . any( |charm| * charm == Charm :: Cursed ) ) ;
6259+ assert ! ( !Charm :: charms( entry. charms) . contains( & Charm :: Cursed ) ) ;
62346260
6235- assert ! ( Charm :: charms( entry. charms)
6236- . iter( )
6237- . any( |charm| * charm == Charm :: Vindicated ) ) ;
6261+ assert ! ( Charm :: charms( entry. charms) . contains( & Charm :: Vindicated ) ) ;
62386262
62396263 assert_eq ! ( entry. inscription_number, 2 ) ;
62406264
0 commit comments