From c524c4e04f07260fa595a190870c6d4a8c151afd Mon Sep 17 00:00:00 2001 From: Luis Herasme Date: Fri, 19 Jul 2024 19:54:27 -0400 Subject: [PATCH] chore: Adds start_block to handler --- ghost-crab-macros/src/lib.rs | 11 +++++++++-- ghost-crab/src/handler.rs | 1 + ghost-crab/src/indexer.rs | 7 ++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ghost-crab-macros/src/lib.rs b/ghost-crab-macros/src/lib.rs index 5306e79..5db4eb4 100644 --- a/ghost-crab-macros/src/lib.rs +++ b/ghost-crab-macros/src/lib.rs @@ -143,6 +143,7 @@ fn create_handler(metadata: TokenStream, input: TokenStream, is_template: bool) let network; let execution_mode; let address; + let start_block; if is_template { let source = config.templates.get(&name).expect("Source not found."); @@ -152,7 +153,8 @@ fn create_handler(metadata: TokenStream, input: TokenStream, is_template: bool) execution_mode = source.execution_mode.clone().unwrap_or(ExecutionMode::Parallel); address = quote! { Address::ZERO - } + }; + start_block = Literal::u64_suffixed(0); } else { let source = config.data_sources.get(&name).expect("Source not found."); @@ -164,7 +166,8 @@ fn create_handler(metadata: TokenStream, input: TokenStream, is_template: bool) address = quote! { address!(#address_literal) - } + }; + start_block = Literal::u64_suffixed(source.start_block); }; let rpc_url = config.networks.get(&network).expect("RPC url not found for network"); @@ -219,6 +222,10 @@ fn create_handler(metadata: TokenStream, input: TokenStream, is_template: bool) #fn_body } + fn start_block(&self) -> u64 { + #start_block + } + fn get_source(&self) -> String { String::from(#data_source) } diff --git a/ghost-crab/src/handler.rs b/ghost-crab/src/handler.rs index 544b926..1321b48 100644 --- a/ghost-crab/src/handler.rs +++ b/ghost-crab/src/handler.rs @@ -21,6 +21,7 @@ pub trait Handler { async fn handle(&self, params: Context); fn get_source(&self) -> String; fn is_template(&self) -> bool; + fn start_block(&self) -> u64; fn address(&self) -> Address; fn network(&self) -> String; fn rpc_url(&self) -> String; diff --git a/ghost-crab/src/indexer.rs b/ghost-crab/src/indexer.rs index 2f41ddc..023a6c6 100644 --- a/ghost-crab/src/indexer.rs +++ b/ghost-crab/src/indexer.rs @@ -70,12 +70,9 @@ impl Indexer { return; } - let source = self.config.data_sources.get(&handler.get_source()).unwrap(); - let address = handler.address(); - self.handlers.push(HandlerConfig { - start_block: source.start_block, - address, + start_block: handler.start_block(), + address: handler.address(), step: 10_000, handler, templates: self.templates.clone(),