@@ -10,11 +10,16 @@ use graph::cheap_clone::CheapClone;
1010use graph:: components:: network_provider:: ChainIdentifierStore ;
1111use graph:: components:: network_provider:: ChainName ;
1212use graph:: components:: store:: StoreError ;
13+ use graph:: futures03:: compat:: Future01CompatExt as _;
1314use graph:: prelude:: BlockNumber ;
1415use graph:: prelude:: ChainStore as _;
16+ use graph:: prelude:: LightEthereumBlockExt ;
1517use graph:: prelude:: { anyhow, anyhow:: bail} ;
1618use graph:: slog:: Logger ;
1719use graph:: { components:: store:: BlockStore as _, prelude:: anyhow:: Error } ;
20+ use graph_chain_ethereum:: chain:: BlockFinality ;
21+ use graph_chain_ethereum:: EthereumAdapter ;
22+ use graph_chain_ethereum:: EthereumAdapterTrait as _;
1823use graph_store_postgres:: add_chain;
1924use graph_store_postgres:: connection_pool:: PoolCoordinator ;
2025use graph_store_postgres:: find_chain;
@@ -261,3 +266,31 @@ pub fn change_block_cache_shard(
261266
262267 Ok ( ( ) )
263268}
269+
270+ pub async fn ingest (
271+ logger : & Logger ,
272+ chain_store : Arc < ChainStore > ,
273+ ethereum_adapter : Arc < EthereumAdapter > ,
274+ number : BlockNumber ,
275+ ) -> Result < ( ) , Error > {
276+ let Some ( block) = ethereum_adapter
277+ . block_by_number ( logger, number)
278+ . compat ( )
279+ . await
280+ . map_err ( |e| anyhow ! ( "error getting block number {number}: {}" , e) ) ?
281+ else {
282+ bail ! ( "block number {number} not found" ) ;
283+ } ;
284+ let ptr = block. block_ptr ( ) ;
285+ // For inserting the block, it doesn't matter whether the block is final or not.
286+ let block = Arc :: new ( BlockFinality :: Final ( Arc :: new ( block) ) ) ;
287+ chain_store. upsert_block ( block) . await ?;
288+
289+ let rows = chain_store. confirm_block_hash ( ptr. number , & ptr. hash ) ?;
290+
291+ println ! ( "Inserted block {}" , ptr) ;
292+ if rows > 0 {
293+ println ! ( " (also deleted {rows} duplicate row(s) with that number)" ) ;
294+ }
295+ Ok ( ( ) )
296+ }
0 commit comments