@@ -474,11 +474,43 @@ where L::Target: Logger {
474474 decay_params : ProbabilisticScoringDecayParameters ,
475475 network_graph : G ,
476476 logger : L ,
477- channel_liquidities : HashMap < u64 , ChannelLiquidity > ,
477+ channel_liquidities : ChannelLiquidities ,
478478}
479-
479+ /// ChannelLiquidities contains live and historical liquidity bounds for each channel.
480480pub struct ChannelLiquidities ( HashMap < u64 , ChannelLiquidity > ) ;
481481
482+ impl ChannelLiquidities {
483+ fn new ( ) -> Self {
484+ Self ( new_hash_map ( ) )
485+ }
486+
487+ fn merge ( & mut self , other : Self ) {
488+ for ( id, item) in other. 0 {
489+ match self . 0 . get_mut ( & id) {
490+ None => { self . 0 . insert ( id, item) ; } ,
491+ Some ( current) => {
492+ current. merge ( & item) ;
493+ }
494+ }
495+ }
496+ }
497+ }
498+
499+ impl Deref for ChannelLiquidities {
500+ type Target = HashMap < u64 , ChannelLiquidity > ;
501+
502+ fn deref ( & self ) -> & Self :: Target {
503+ & self . 0
504+ }
505+ }
506+
507+
508+ impl DerefMut for ChannelLiquidities {
509+ fn deref_mut ( & mut self ) -> & mut Self :: Target {
510+ & mut self . 0
511+ }
512+ }
513+
482514impl Readable for ChannelLiquidities {
483515 #[ inline]
484516 fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
@@ -862,23 +894,13 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref> ProbabilisticScorer<G, L> whe
862894 decay_params,
863895 network_graph,
864896 logger,
865- channel_liquidities : new_hash_map ( ) ,
897+ channel_liquidities : ChannelLiquidities :: new ( ) ,
866898 }
867899 }
868900
869901 /// Merge external channel liquidity data into the internal state.
870902 pub fn merge ( & mut self , other : ChannelLiquidities ) {
871-
872- let channel_liquidities = & mut self . channel_liquidities ;
873-
874- for ( id, item) in other. 0 {
875- match channel_liquidities. get_mut ( & id) {
876- None => { channel_liquidities. insert ( id, item) ; } ,
877- Some ( current) => {
878- current. merge ( & item) ;
879- }
880- }
881- }
903+ self . channel_liquidities . merge ( other) ;
882904 }
883905
884906 #[ cfg( test) ]
@@ -2126,10 +2148,7 @@ ReadableArgs<(ProbabilisticScoringDecayParameters, G, L)> for ProbabilisticScore
21262148 r : & mut R , args : ( ProbabilisticScoringDecayParameters , G , L )
21272149 ) -> Result < Self , DecodeError > {
21282150 let ( decay_params, network_graph, logger) = args;
2129- let mut channel_liquidities = new_hash_map ( ) ;
2130- read_tlv_fields ! ( r, {
2131- ( 0 , channel_liquidities, required) ,
2132- } ) ;
2151+ let channel_liquidities = ChannelLiquidities :: read ( r) ?;
21332152 Ok ( Self {
21342153 decay_params,
21352154 network_graph,
0 commit comments