Skip to content

Commit

Permalink
Adds "network" to handler
Browse files Browse the repository at this point in the history
  • Loading branch information
luis-herasme committed Jul 19, 2024
1 parent 33f014a commit fe7c5b6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
41 changes: 20 additions & 21 deletions ghost-crab-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,32 +117,27 @@ fn create_handler(metadata: TokenStream, input: TokenStream, is_template: bool)
let (name, event_name) = get_source_and_event(metadata);
let config = get_config();

let abi = if is_template {
config.templates.get(&name).expect("Source not found.").abi.clone()
} else {
config.data_sources.get(&name).expect("Source not found.").abi.clone()
};
let abi;
let network;
let execution_mode;

let abi = Literal::string(&abi);
if is_template {
let source = config.templates.get(&name).expect("Source not found.");

let execution_mode = if is_template {
if let Some(execution_mode) =
config.templates.get(&name).expect("Source not found.").execution_mode.clone()
{
execution_mode
} else {
ExecutionMode::Parallel
}
abi = source.abi.clone();
network = source.network.clone();
execution_mode = source.execution_mode.clone().unwrap_or(ExecutionMode::Parallel);
} else {
if let Some(execution_mode) =
config.data_sources.get(&name).expect("Source not found.").execution_mode.clone()
{
execution_mode
} else {
ExecutionMode::Parallel
}
let source = config.data_sources.get(&name).expect("Source not found.");

abi = source.abi.clone();
network = source.network.clone();
execution_mode = source.execution_mode.clone().unwrap_or(ExecutionMode::Parallel);
};

let abi = Literal::string(&abi);
let network = Literal::string(&network);

let execution_mode = match execution_mode {
ExecutionMode::Parallel => quote! {
ExecutionMode::Parallel
Expand Down Expand Up @@ -197,6 +192,10 @@ fn create_handler(metadata: TokenStream, input: TokenStream, is_template: bool)
#is_template
}

fn network(&self) - String {
String::from(#network)
}

fn execution_mode(&self) -> ExecutionMode {
#execution_mode
}
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 network(&self) -> String;
fn execution_mode(&self) -> ExecutionMode;
fn get_event_signature(&self) -> String;
}
Expand Down
8 changes: 2 additions & 6 deletions ghost-crab/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ pub struct Template {

impl TemplateManager {
pub async fn start(&self, template: Template) {
let config = config::load();

let source = config.templates.get(&template.handler.get_source()).unwrap();

let provider = RPC_MANAGER.lock().await.get(source.network.clone()).await;
let provider = RPC_MANAGER.lock().await.get(template.handler.network()).await;

self.tx
.send(HandlerConfig {
Expand Down Expand Up @@ -78,8 +74,8 @@ impl Indexer {
return;
}

let provider = RPC_MANAGER.lock().await.get(handler.network()).await;
let source = self.config.data_sources.get(&handler.get_source()).unwrap();
let provider = RPC_MANAGER.lock().await.get(source.network.clone()).await;

self.handlers.push(HandlerConfig {
start_block: source.start_block,
Expand Down

0 comments on commit fe7c5b6

Please sign in to comment.