@@ -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:: find_chain;
2025use graph_store_postgres:: update_chain_name;
@@ -259,3 +264,31 @@ pub fn change_block_cache_shard(
259264
260265 Ok ( ( ) )
261266}
267+
268+ pub async fn ingest (
269+ logger : & Logger ,
270+ chain_store : Arc < ChainStore > ,
271+ ethereum_adapter : Arc < EthereumAdapter > ,
272+ number : BlockNumber ,
273+ ) -> Result < ( ) , Error > {
274+ let Some ( block) = ethereum_adapter
275+ . block_by_number ( logger, number)
276+ . compat ( )
277+ . await
278+ . map_err ( |e| anyhow ! ( "error getting block number {number}: {}" , e) ) ?
279+ else {
280+ bail ! ( "block number {number} not found" ) ;
281+ } ;
282+ let ptr = block. block_ptr ( ) ;
283+ // For inserting the block, it doesn't matter whether the block is final or not.
284+ let block = Arc :: new ( BlockFinality :: Final ( Arc :: new ( block) ) ) ;
285+ chain_store. upsert_block ( block) . await ?;
286+
287+ let rows = chain_store. confirm_block_hash ( ptr. number , & ptr. hash ) ?;
288+
289+ println ! ( "Inserted block {}" , ptr) ;
290+ if rows > 0 {
291+ println ! ( " (also deleted {rows} duplicate row(s) with that number)" ) ;
292+ }
293+ Ok ( ( ) )
294+ }
0 commit comments