Skip to content

Commit

Permalink
chore: Adds start_block to handler
Browse files Browse the repository at this point in the history
  • Loading branch information
luis-herasme committed Jul 19, 2024
1 parent 3871c0e commit c524c4e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
11 changes: 9 additions & 2 deletions ghost-crab-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -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.");

Expand All @@ -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");
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions ghost-crab/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions ghost-crab/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit c524c4e

Please sign in to comment.