-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
122 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
mod types; | ||
|
||
use crate::engine::{SearchEngine}; | ||
use ethers::types::{Address}; | ||
use rocket::{get, routes, State}; | ||
use std::str::FromStr; | ||
use std::sync::Arc; | ||
use crate::http::types::ExecJobRequest; | ||
|
||
pub struct HttpApi {} | ||
|
||
impl HttpApi { | ||
pub async fn new(port: u16, address: String, search_engine: Arc<SearchEngine>) { | ||
rocket::build() | ||
.configure(rocket::Config { | ||
address: address.parse().unwrap(), | ||
port, | ||
..rocket::Config::default() | ||
}) | ||
.manage(search_engine) | ||
.mount("/", routes![exec_job]) | ||
.launch() | ||
.await | ||
.expect("Err setup"); | ||
} | ||
} | ||
|
||
// Example: api/v1/exec-job?job_id=test_1&block_number_start=10000&block_number_end=3000000 | ||
#[get("/api/v1/exec-job?<query..>")] | ||
async fn exec_job(search_engine: &State<Arc<SearchEngine>>, query: ExecJobRequest) -> String { | ||
let _search_engine = search_engine.inner().clone(); | ||
let _job_id = query.job_id.clone(); | ||
|
||
tokio::spawn(async move { | ||
_search_engine.execute_job( | ||
query.job_id, | ||
query.block_number_start, | ||
query.block_number_end, | ||
query | ||
.contract | ||
.map(|c| Address::from_str(c.as_str()).unwrap()) | ||
).await.unwrap(); | ||
}); | ||
|
||
|
||
return _job_id; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
use rocket::{FromForm}; | ||
|
||
#[derive(FromForm, Debug)] | ||
pub struct ExecJobRequest { | ||
pub job_id: String, | ||
pub block_number_start: u64, | ||
pub block_number_end: u64, | ||
pub contract: Option<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters