@@ -4,8 +4,9 @@ use acropolis_common::{
44    crypto:: keyhash, 
55    messages:: { CardanoMessage ,  Message ,  StateQuery ,  StateQueryResponse } , 
66    queries:: blocks:: { 
7-         BlockInfo ,  BlockTransaction ,  BlockTransactions ,  BlockTransactionsCBOR ,  BlocksStateQuery , 
8-         BlocksStateQueryResponse ,  NextBlocks ,  PreviousBlocks ,  DEFAULT_BLOCKS_QUERY_TOPIC , 
7+         BlockInfo ,  BlockKey ,  BlockTransaction ,  BlockTransactions ,  BlockTransactionsCBOR , 
8+         BlocksStateQuery ,  BlocksStateQueryResponse ,  NextBlocks ,  PreviousBlocks , 
9+         DEFAULT_BLOCKS_QUERY_TOPIC , 
910    } , 
1011    TxHash , 
1112} ; 
@@ -107,7 +108,7 @@ impl ChainStore {
107108                Ok ( BlocksStateQueryResponse :: LatestBlockTransactionsCBOR ( txs) ) 
108109            } 
109110            BlocksStateQuery :: GetBlockInfo  {  block_key }  => { 
110-                 let  Some ( block)  = store . get_block_by_hash ( block_key) ? else  { 
111+                 let  Some ( block)  = Self :: get_block_by_key ( store ,   block_key) ? else  { 
111112                    return  Ok ( BlocksStateQueryResponse :: NotFound ) ; 
112113                } ; 
113114                let  info = Self :: to_block_info ( block,  store,  false ) ?; 
@@ -137,7 +138,7 @@ impl ChainStore {
137138                        blocks :  vec ! [ ] , 
138139                    } ) ) ; 
139140                } 
140-                 let  Some ( block)  = store . get_block_by_hash ( & block_key) ? else  { 
141+                 let  Some ( block)  = Self :: get_block_by_key ( store ,   & block_key) ? else  { 
141142                    return  Ok ( BlocksStateQueryResponse :: NotFound ) ; 
142143                } ; 
143144                let  number = Self :: get_block_number ( & block) ?; 
@@ -159,7 +160,7 @@ impl ChainStore {
159160                        blocks :  vec ! [ ] , 
160161                    } ) ) ; 
161162                } 
162-                 let  Some ( block)  = store . get_block_by_hash ( & block_key) ? else  { 
163+                 let  Some ( block)  = Self :: get_block_by_key ( store ,   & block_key) ? else  { 
163164                    return  Ok ( BlocksStateQueryResponse :: NotFound ) ; 
164165                } ; 
165166                let  number = Self :: get_block_number ( & block) ?; 
@@ -176,14 +177,14 @@ impl ChainStore {
176177                } ) ) 
177178            } 
178179            BlocksStateQuery :: GetBlockTransactions  {  block_key }  => { 
179-                 let  Some ( block)  = store . get_block_by_hash ( block_key) ? else  { 
180+                 let  Some ( block)  = Self :: get_block_by_key ( store ,   block_key) ? else  { 
180181                    return  Ok ( BlocksStateQueryResponse :: NotFound ) ; 
181182                } ; 
182183                let  txs = Self :: to_block_transactions ( block) ?; 
183184                Ok ( BlocksStateQueryResponse :: BlockTransactions ( txs) ) 
184185            } 
185186            BlocksStateQuery :: GetBlockTransactionsCBOR  {  block_key }  => { 
186-                 let  Some ( block)  = store . get_block_by_hash ( block_key) ? else  { 
187+                 let  Some ( block)  = Self :: get_block_by_key ( store ,   block_key) ? else  { 
187188                    return  Ok ( BlocksStateQueryResponse :: NotFound ) ; 
188189                } ; 
189190                let  txs = Self :: to_block_transactions_cbor ( block) ?; 
@@ -194,6 +195,13 @@ impl ChainStore {
194195        } 
195196    } 
196197
198+     fn  get_block_by_key ( store :  & Arc < dyn  Store > ,  block_key :  & BlockKey )  -> Result < Option < Block > >  { 
199+         match  block_key { 
200+             BlockKey :: Hash ( hash)  => store. get_block_by_hash ( hash) , 
201+             BlockKey :: Number ( number)  => store. get_block_by_number ( * number) , 
202+         } 
203+     } 
204+ 
197205    fn  get_block_number ( block :  & Block )  -> Result < u64 >  { 
198206        Ok ( pallas_traverse:: MultiEraBlock :: decode ( & block. bytes ) ?. number ( ) ) 
199207    } 
0 commit comments