@@ -69,12 +69,12 @@ impl ChainStore {
6969 BlocksStateQueryResponse :: Error ( "Invalid message for blocks-state" . into ( ) ) ,
7070 ) ) ) ;
7171 } ;
72- let Some ( state) = query_history. lock ( ) . await . current ( ) . map ( |s| s . clone ( ) ) else {
72+ let Some ( state) = query_history. lock ( ) . await . current ( ) . cloned ( ) else {
7373 return Arc :: new ( Message :: StateQueryResponse ( StateQueryResponse :: Blocks (
7474 BlocksStateQueryResponse :: Error ( "unitialised state" . to_string ( ) ) ,
7575 ) ) ) ;
7676 } ;
77- let res = Self :: handle_blocks_query ( & query_store, & state, & query)
77+ let res = Self :: handle_blocks_query ( & query_store, & state, query)
7878 . unwrap_or_else ( |err| BlocksStateQueryResponse :: Error ( err. to_string ( ) ) ) ;
7979 Arc :: new ( Message :: StateQueryResponse ( StateQueryResponse :: Blocks ( res) ) )
8080 }
@@ -95,23 +95,20 @@ impl ChainStore {
9595 error ! ( "Could not insert block: {err}" ) ;
9696 }
9797
98- match message. as_ref ( ) {
99- Message :: Cardano ( ( block_info, _) ) => {
100- if block_info. new_epoch {
101- let Ok ( ( _, message) ) = params_message. await else {
102- return ;
103- } ;
104- let mut history = history. lock ( ) . await ;
105- let mut state = history. get_current_state ( ) ;
106- if !Self :: handle_new_params ( & mut state, message) . is_ok ( ) {
107- return ;
108- } ;
109- history. commit ( block_info. number , state) ;
110- // Have the next params message ready for the next epoch
111- params_message = params_subscription. read ( ) ;
112- }
98+ if let Message :: Cardano ( ( block_info, _) ) = message. as_ref ( ) {
99+ if block_info. new_epoch {
100+ let Ok ( ( _, message) ) = params_message. await else {
101+ return ;
102+ } ;
103+ let mut history = history. lock ( ) . await ;
104+ let mut state = history. get_current_state ( ) ;
105+ if Self :: handle_new_params ( & mut state, message) . is_err ( ) {
106+ return ;
107+ } ;
108+ history. commit ( block_info. number , state) ;
109+ // Have the next params message ready for the next epoch
110+ params_message = params_subscription. read ( ) ;
113111 }
114- _ => ( ) ,
115112 }
116113 }
117114 } ) ;
@@ -137,7 +134,7 @@ impl ChainStore {
137134 let Some ( block) = store. get_latest_block ( ) ? else {
138135 return Ok ( BlocksStateQueryResponse :: NotFound ) ;
139136 } ;
140- let info = Self :: to_block_info ( block, store, & state, true ) ?;
137+ let info = Self :: to_block_info ( block, store, state, true ) ?;
141138 Ok ( BlocksStateQueryResponse :: LatestBlock ( info) )
142139 }
143140 BlocksStateQuery :: GetLatestBlockTransactions { limit, skip, order } => {
@@ -158,21 +155,21 @@ impl ChainStore {
158155 let Some ( block) = Self :: get_block_by_key ( store, block_key) ? else {
159156 return Ok ( BlocksStateQueryResponse :: NotFound ) ;
160157 } ;
161- let info = Self :: to_block_info ( block, store, & state, false ) ?;
158+ let info = Self :: to_block_info ( block, store, state, false ) ?;
162159 Ok ( BlocksStateQueryResponse :: BlockInfo ( info) )
163160 }
164161 BlocksStateQuery :: GetBlockBySlot { slot } => {
165162 let Some ( block) = store. get_block_by_slot ( * slot) ? else {
166163 return Ok ( BlocksStateQueryResponse :: NotFound ) ;
167164 } ;
168- let info = Self :: to_block_info ( block, store, & state, false ) ?;
165+ let info = Self :: to_block_info ( block, store, state, false ) ?;
169166 Ok ( BlocksStateQueryResponse :: BlockBySlot ( info) )
170167 }
171168 BlocksStateQuery :: GetBlockByEpochSlot { epoch, slot } => {
172169 let Some ( block) = store. get_block_by_epoch_slot ( * epoch, * slot) ? else {
173170 return Ok ( BlocksStateQueryResponse :: NotFound ) ;
174171 } ;
175- let info = Self :: to_block_info ( block, store, & state, false ) ?;
172+ let info = Self :: to_block_info ( block, store, state, false ) ?;
176173 Ok ( BlocksStateQueryResponse :: BlockByEpochSlot ( info) )
177174 }
178175 BlocksStateQuery :: GetNextBlocks {
@@ -185,7 +182,7 @@ impl ChainStore {
185182 blocks : vec ! [ ] ,
186183 } ) ) ;
187184 }
188- let Some ( block) = Self :: get_block_by_key ( store, & block_key) ? else {
185+ let Some ( block) = Self :: get_block_by_key ( store, block_key) ? else {
189186 return Ok ( BlocksStateQueryResponse :: NotFound ) ;
190187 } ;
191188 let number = match block_key {
@@ -195,7 +192,7 @@ impl ChainStore {
195192 let min_number = number + 1 + skip;
196193 let max_number = min_number + limit - 1 ;
197194 let blocks = store. get_blocks_by_number_range ( min_number, max_number) ?;
198- let info = Self :: to_block_info_bulk ( blocks, store, & state, false ) ?;
195+ let info = Self :: to_block_info_bulk ( blocks, store, state, false ) ?;
199196 Ok ( BlocksStateQueryResponse :: NextBlocks ( NextBlocks {
200197 blocks : info,
201198 } ) )
@@ -210,7 +207,7 @@ impl ChainStore {
210207 blocks : vec ! [ ] ,
211208 } ) ) ;
212209 }
213- let Some ( block) = Self :: get_block_by_key ( store, & block_key) ? else {
210+ let Some ( block) = Self :: get_block_by_key ( store, block_key) ? else {
214211 return Ok ( BlocksStateQueryResponse :: NotFound ) ;
215212 } ;
216213 let number = match block_key {
@@ -224,7 +221,7 @@ impl ChainStore {
224221 } ;
225222 let min_number = max_number. saturating_sub ( limit - 1 ) ;
226223 let blocks = store. get_blocks_by_number_range ( min_number, max_number) ?;
227- let info = Self :: to_block_info_bulk ( blocks, store, & state, false ) ?;
224+ let info = Self :: to_block_info_bulk ( blocks, store, state, false ) ?;
228225 Ok ( BlocksStateQueryResponse :: PreviousBlocks ( PreviousBlocks {
229226 blocks : info,
230227 } ) )
@@ -325,7 +322,7 @@ impl ChainStore {
325322 is_latest : bool ,
326323 ) -> Result < BlockInfo > {
327324 let blocks = vec ! [ block] ;
328- let mut info = Self :: to_block_info_bulk ( blocks, store, & state, is_latest) ?;
325+ let mut info = Self :: to_block_info_bulk ( blocks, store, state, is_latest) ?;
329326 Ok ( info. remove ( 0 ) )
330327 }
331328
@@ -491,17 +488,13 @@ impl ChainStore {
491488 for tx in decoded. txs ( ) {
492489 let hash = TxHash ( * tx. hash ( ) ) ;
493490 for output in tx. outputs ( ) {
494- match output. address ( ) {
495- Ok ( pallas_address) => match map_parameters:: map_address ( & pallas_address) {
496- Ok ( address) => {
497- addresses
498- . entry ( BechOrdAddress ( address) )
499- . or_insert_with ( Vec :: new)
500- . push ( hash. clone ( ) ) ;
501- }
502- _ => ( ) ,
503- } ,
504- _ => ( ) ,
491+ if let Ok ( pallas_address) = output. address ( ) {
492+ if let Ok ( address) = map_parameters:: map_address ( & pallas_address) {
493+ addresses
494+ . entry ( BechOrdAddress ( address) )
495+ . or_insert_with ( Vec :: new)
496+ . push ( hash) ;
497+ }
505498 }
506499 }
507500 }
@@ -518,16 +511,13 @@ impl ChainStore {
518511 }
519512
520513 fn handle_new_params ( state : & mut State , message : Arc < Message > ) -> Result < ( ) > {
521- match message. as_ref ( ) {
522- Message :: Cardano ( ( _, CardanoMessage :: ProtocolParams ( params) ) ) => {
523- if let Some ( byron) = & params. params . byron {
524- state. byron_heavy_delegates = byron. heavy_delegation . clone ( ) ;
525- }
526- if let Some ( shelley) = & params. params . shelley {
527- state. shelley_genesis_delegates = shelley. gen_delegs . clone ( ) ;
528- }
514+ if let Message :: Cardano ( ( _, CardanoMessage :: ProtocolParams ( params) ) ) = message. as_ref ( ) {
515+ if let Some ( byron) = & params. params . byron {
516+ state. byron_heavy_delegates = byron. heavy_delegation . clone ( ) ;
517+ }
518+ if let Some ( shelley) = & params. params . shelley {
519+ state. shelley_genesis_delegates = shelley. gen_delegs . clone ( ) ;
529520 }
530- _ => ( ) ,
531521 }
532522 Ok ( ( ) )
533523 }
0 commit comments