Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: streamlining DimIsNone trait and optimizing parse_u256_types #153

Merged
merged 3 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions crates/cli/src/parse/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,7 @@ impl DimIsNone for Args {
}

fn dim_is_none(&self, dim: &Dim) -> bool {
match dim {
Dim::BlockNumber => self.blocks.is_none(),
Dim::TransactionHash => self.txs.is_none(),
Dim::Address => self.address.is_none(),
Dim::FromAddress => self.from_address.is_none(),
Dim::ToAddress => self.to_address.is_none(),
Dim::Contract => self.contract.is_none(),
Dim::CallData => self.call_data.is_none(),
Dim::Slot => self.slot.is_none(),
Dim::Topic0 => self.topic0.is_none(),
Dim::Topic1 => self.topic1.is_none(),
Dim::Topic2 => self.topic2.is_none(),
Dim::Topic3 => self.topic3.is_none(),
}
!self.dim_is_some(dim)
}
}

Expand Down
49 changes: 22 additions & 27 deletions crates/cli/src/parse/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,32 +85,27 @@ pub(crate) fn parse_schemas(
}

fn parse_u256_types(args: &Args) -> Result<Vec<U256Type>, ParseError> {
if let Some(raw_u256_types) = args.u256_types.clone() {
let mut u256_types: Vec<U256Type> = Vec::new();
for raw in raw_u256_types.iter() {
let u256_type = match raw.to_lowercase() {
raw if raw == "binary" => U256Type::Binary,
raw if raw == "string" => U256Type::String,
raw if raw == "str" => U256Type::String,
raw if raw == "f32" => U256Type::F32,
raw if raw == "float32" => U256Type::F32,
raw if raw == "f64" => U256Type::F64,
raw if raw == "float64" => U256Type::F64,
raw if raw == "float" => U256Type::F64,
raw if raw == "u32" => U256Type::U32,
raw if raw == "uint32" => U256Type::U32,
raw if raw == "u64" => U256Type::U64,
raw if raw == "uint64" => U256Type::U64,
raw if raw == "decimal128" => U256Type::Decimal128,
raw if raw == "d128" => U256Type::Decimal128,
_ => return Err(ParseError::ParseError("bad u256 type".to_string())),
};
u256_types.push(u256_type);
}
Ok(u256_types)
} else {
Ok(vec![U256Type::Binary, U256Type::String, U256Type::F64])
}
args.u256_types.as_ref().map_or(
Ok(vec![U256Type::Binary, U256Type::String, U256Type::F64]),
|raw_u256_types| {
raw_u256_types
.iter()
.map(|raw| {
let lower_case = raw.to_lowercase();
match lower_case.as_str() {
"binary" => Ok(U256Type::Binary),
"string" | "str" => Ok(U256Type::String),
"f32" | "float32" => Ok(U256Type::F32),
"f64" | "float64" | "float" => Ok(U256Type::F64),
"u32" | "uint32" => Ok(U256Type::U32),
"u64" | "uint64" => Ok(U256Type::U64),
"decimal128" | "d128" => Ok(U256Type::Decimal128),
_ => Err(ParseError::ParseError(format!("invalid u256 type: {}", raw))),
}
})
.collect()
},
)
}

fn ensure_included_columns(
Expand Down Expand Up @@ -171,7 +166,7 @@ fn ensure_excluded_columns(

fn parse_sort_columns(
raw_sort: &Option<Vec<String>>,
datatypes: &Vec<Datatype>,
datatypes: &[Datatype],
) -> Result<HashMap<Datatype, Option<Vec<String>>>, ParseError> {
match raw_sort {
None => Ok(HashMap::from_iter(
Expand Down
2 changes: 1 addition & 1 deletion crates/freeze/src/types/chunks/subchunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Subchunk for Vec<BlockChunk> {
}
}

fn to_single_chunk(chunks: &Vec<BlockChunk>) -> BlockChunk {
fn to_single_chunk(chunks: &[BlockChunk]) -> BlockChunk {
match (chunks.len(), chunks.first()) {
(1, Some(chunk)) => chunk.clone(),
_ => {
Expand Down
Loading