-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add import_abis binary implementation (#717)
- Loading branch information
1 parent
8468382
commit 6a0700f
Showing
6 changed files
with
73 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use eth_bytecode_db::verification::import_existing_abis; | ||
use sea_orm::Database; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let db_url = std::env::var("DATABASE_URL").expect("DATABASE_URL env was not provided"); | ||
let db_client = Database::connect(db_url) | ||
.await | ||
.expect("Error connecting to database"); | ||
|
||
import_existing_abis::import(&db_client).await; | ||
} |
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
44 changes: 44 additions & 0 deletions
44
eth-bytecode-db/eth-bytecode-db/src/verification/handlers/import_existing_abis.rs
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,44 @@ | ||
use crate::verification::handlers::process_abi_data; | ||
use anyhow::Context; | ||
use entity::sources; | ||
use futures::TryStreamExt; | ||
use sea_orm::{DatabaseConnection, EntityTrait, FromQueryResult, QuerySelect}; | ||
|
||
pub async fn import(db_client: &DatabaseConnection) { | ||
#[derive(FromQueryResult)] | ||
struct Abi { | ||
pub abi: sea_orm::JsonValue, | ||
} | ||
|
||
let mut stream = sources::Entity::find() | ||
.select_only() | ||
.column(sources::Column::Abi) | ||
.distinct() | ||
.into_model::<Abi>() | ||
.stream(db_client) | ||
.await | ||
.expect("creating a stream"); | ||
|
||
let mut processed = 0; | ||
|
||
loop { | ||
match stream.try_next().await.context("getting next abi value") { | ||
Ok(None) => break, | ||
Ok(Some(item)) => { | ||
let abi = item.abi.to_string(); | ||
if let Err(err) = process_abi_data(Some(abi.clone()), db_client).await { | ||
println!("[ERROR] Error while processing abi; abi={abi}, err={err:#}"); | ||
} | ||
} | ||
Err(err) => { | ||
println!("[ERROR] Error while processing next abi: {err}"); | ||
} | ||
} | ||
processed += 1; | ||
|
||
if processed % 100 == 0 { | ||
println!("Processed={processed}") | ||
} | ||
} | ||
println!("\nabis processed successfully; total={processed}"); | ||
} |
1 change: 1 addition & 0 deletions
1
eth-bytecode-db/eth-bytecode-db/src/verification/handlers/mod.rs
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