-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Decode logs based on event signature * Remove examples * event-signature flag, add to schema even in event of no logs in batch * fmt * fix tests, doc comments * apply clippy lints + formatter * initial commit * clean merged code --------- Co-authored-by: Erik Reppel <erik@zora.co>
- Loading branch information
Showing
39 changed files
with
3,499 additions
and
249 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,12 +1,11 @@ | ||
mod args; | ||
mod blocks; | ||
mod file_output; | ||
mod parse_utils; | ||
mod query; | ||
mod schemas; | ||
mod source; | ||
mod transactions; | ||
|
||
pub use args::*; | ||
// use blocks::*; | ||
// use file_output::*; | ||
// use query::*; | ||
// use source::*; | ||
use schemas::*; |
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,83 @@ | ||
use cryo_freeze::ParseError; | ||
use std::collections::HashMap; | ||
|
||
pub(crate) fn hex_string_to_binary(hex_string: &String) -> Result<Vec<u8>, ParseError> { | ||
let hex_string = hex_string.strip_prefix("0x").unwrap_or(hex_string); | ||
hex::decode(hex_string) | ||
.map_err(|_| ParseError::ParseError("could not parse data as hex".to_string())) | ||
} | ||
|
||
pub(crate) fn hex_strings_to_binary(hex_strings: &[String]) -> Result<Vec<Vec<u8>>, ParseError> { | ||
hex_strings | ||
.iter() | ||
.map(|x| { | ||
hex::decode(x.strip_prefix("0x").unwrap_or(x)) | ||
.map_err(|_| ParseError::ParseError("could not parse data as hex".to_string())) | ||
}) | ||
.collect::<Result<Vec<_>, _>>() | ||
} | ||
|
||
#[derive(Eq, PartialEq, Hash)] | ||
pub(crate) enum BinaryInputList { | ||
Explicit, | ||
ParquetColumn(String, String), | ||
} | ||
|
||
type ParsedBinaryArg = HashMap<BinaryInputList, Vec<Vec<u8>>>; | ||
|
||
/// parse binary argument list | ||
/// each argument can be a hex string or a parquet column reference | ||
/// each parquet column is loaded into its own list, hex strings loaded into another | ||
pub(crate) fn parse_binary_arg( | ||
inputs: &[String], | ||
default_column: &str, | ||
) -> Result<ParsedBinaryArg, ParseError> { | ||
let mut parsed = HashMap::new(); | ||
|
||
// separate into files vs explicit | ||
let (files, hex_strings): (Vec<&String>, Vec<&String>) = | ||
inputs.iter().partition(|tx| std::path::Path::new(tx).exists()); | ||
|
||
// files columns | ||
for path in files { | ||
let reference = parse_file_column_reference(path, default_column)?; | ||
let values = cryo_freeze::read_binary_column(&reference.path, &reference.column) | ||
.map_err(|_e| ParseError::ParseError("could not read input".to_string()))?; | ||
let key = BinaryInputList::ParquetColumn(reference.path, reference.column); | ||
parsed.insert(key, values); | ||
} | ||
|
||
// explicit binary strings | ||
if !hex_strings.is_empty() { | ||
let hex_strings: Vec<String> = hex_strings.into_iter().cloned().collect(); | ||
let binary_vec = hex_strings_to_binary(&hex_strings)?; | ||
parsed.insert(BinaryInputList::Explicit, binary_vec); | ||
}; | ||
|
||
Ok(parsed) | ||
} | ||
|
||
struct FileColumnReference { | ||
path: String, | ||
column: String, | ||
} | ||
|
||
fn parse_file_column_reference( | ||
path: &str, | ||
default_column: &str, | ||
) -> Result<FileColumnReference, ParseError> { | ||
let (path, column) = if path.contains(':') { | ||
let pieces: Vec<&str> = path.split(':').collect(); | ||
if pieces.len() == 2 { | ||
(pieces[0], pieces[1]) | ||
} else { | ||
return Err(ParseError::ParseError("could not parse path column".to_string())) | ||
} | ||
} else { | ||
(path, default_column) | ||
}; | ||
|
||
let parsed = FileColumnReference { path: path.to_string(), column: column.to_string() }; | ||
|
||
Ok(parsed) | ||
} |
Oops, something went wrong.