Skip to content
Open
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
36 changes: 35 additions & 1 deletion crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ pub fn to_table<S: Serialize + core::fmt::Debug>(data: Vec<S>) -> Result<Table,

for record in reader.into_records() {
let record = record?;
let iter = record.iter().map(|s| s.to_owned());
let iter = record.iter().map(|s| {
if s.len() > 20 {
return truncate_string(s, 4, 3);
}
s.to_owned()
});
builder.push_record(iter);
}

Expand Down Expand Up @@ -118,3 +123,32 @@ pub async fn main() -> Result<(), Box<dyn Error>> {

Ok(())
}

fn truncate_string(input: &str, prefix_len: usize, suffix_len: usize) -> String {
// Validate input parameters
if prefix_len == 0 && suffix_len == 0 {
return input.to_string();
}

// Ensure we don't panic on short inputs
let _total_len = prefix_len.saturating_add(suffix_len);
if input.len() <= prefix_len + suffix_len {
return input.to_string(); // No need to truncate
}

format!("{}...{}", &input[..prefix_len], &input[input.len() - suffix_len..])
}


#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_truncate_string() {
assert_eq!(truncate_string("abcdefghijk", 4, 3), "abcd...ijk");
assert_eq!(truncate_string("short", 4, 3), "short");
assert_eq!(truncate_string("a", 4, 3), "a");
assert_eq!(truncate_string("", 4, 3), "");
}
}
3 changes: 2 additions & 1 deletion crates/core/src/common/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ impl TryFrom<Pair<'_, Rule>> for LogFilter {
match pair.as_rule() {
Rule::address_filter_type => extract_value(pair, |s| {
Ok(LogFilter::EmitterAddress(Address::parse_checksummed(
Address::to_checksum(&Address::from_str(s)?, None), None,
Address::to_checksum(&Address::from_str(s)?, None),
None,
)?))
}),
Rule::blockrange_filter => parse_block_range(pair),
Expand Down
134 changes: 62 additions & 72 deletions crates/core/src/interpreter/backend/execution_engine.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use super::{
resolve_account::resolve_account_query,
resolve_block::resolve_block_query,
resolve_logs::resolve_log_query,
resolve_transaction::resolve_transaction_query,
resolve_account::resolve_account_query, resolve_block::resolve_block_query,
resolve_logs::resolve_log_query, resolve_transaction::resolve_transaction_query,
};
use crate::common::{
entity::Entity, query_result::{ExpressionResult, QueryResult}, serializer::dump_results, types::{Expression, GetExpression}
entity::Entity,
query_result::{ExpressionResult, QueryResult},
serializer::dump_results,
types::{Expression, GetExpression},
};
use anyhow::Result;

Expand All @@ -24,10 +25,7 @@ impl ExecutionEngine {
ExecutionEngine
}

pub async fn run(
&self,
expressions: Vec<Expression>,
) -> Result<Vec<QueryResult>> {
pub async fn run(&self, expressions: Vec<Expression>) -> Result<Vec<QueryResult>> {
let mut query_results = vec![];

for expression in expressions {
Expand All @@ -42,15 +40,20 @@ impl ExecutionEngine {
Ok(query_results)
}

async fn run_get_expr(
&self,
expr: &GetExpression,
) -> Result<ExpressionResult> {
async fn run_get_expr(&self, expr: &GetExpression) -> Result<ExpressionResult> {
let result = match &expr.entity {
Entity::Block(block) => ExpressionResult::Block(resolve_block_query(block, &expr.chains).await?),
Entity::Account(account) => ExpressionResult::Account(resolve_account_query(account, &expr.chains).await?),
Entity::Transaction(transaction) => ExpressionResult::Transaction(resolve_transaction_query(transaction, &expr.chains).await?),
Entity::Logs(logs) => ExpressionResult::Log(resolve_log_query(logs, &expr.chains).await?),
Entity::Block(block) => {
ExpressionResult::Block(resolve_block_query(block, &expr.chains).await?)
}
Entity::Account(account) => {
ExpressionResult::Account(resolve_account_query(account, &expr.chains).await?)
}
Entity::Transaction(transaction) => ExpressionResult::Transaction(
resolve_transaction_query(transaction, &expr.chains).await?,
),
Entity::Logs(logs) => {
ExpressionResult::Log(resolve_log_query(logs, &expr.chains).await?)
}
};

if let Some(dump) = &expr.dump {
Expand Down Expand Up @@ -92,9 +95,7 @@ mod test {
BlockNumberOrTag::Number(4638757),
Some(BlockNumberOrTag::Number(4638758)),
)),
LogFilter::EmitterAddress(address!(
"dac17f958d2ee523a2206206994597c13d831ec7"
)),
LogFilter::EmitterAddress(address!("dac17f958d2ee523a2206206994597c13d831ec7")),
LogFilter::Topic0(b256!(
"cb8241adb0c3fdb35b70c24ce35c5eb0c17af7431c99f827d44a445ca624176a"
)),
Expand Down Expand Up @@ -143,18 +144,14 @@ mod test {
async fn test_get_block_fields() {
let execution_engine = ExecutionEngine::new();
let expressions = vec![Expression::Get(GetExpression {
entity: Entity::Block(
Block::new(
Some(vec![
BlockId::Range(BlockRange::new(
BlockNumberOrTag::Number(1),
None,
)),
]),
entity: Entity::Block(Block::new(
Some(vec![BlockId::Range(BlockRange::new(
BlockNumberOrTag::Number(1),
None,
BlockField::all_variants().to_vec(),
)
),
))]),
None,
BlockField::all_variants().to_vec(),
)),
dump: None,
chains: vec![ChainOrRpc::Chain(Chain::Ethereum)],
})];
Expand Down Expand Up @@ -205,13 +202,13 @@ mod test {
async fn test_get_account_fields_using_invalid_ens() {
let execution_engine = ExecutionEngine::new();
let expressions = vec![Expression::Get(GetExpression {
entity: Entity::Account(
Account::new(
Some(vec![NameOrAddress::Name(String::from("thisisinvalid235790123801.eth"))]),
None,
vec![AccountField::Balance],
)
),
entity: Entity::Account(Account::new(
Some(vec![NameOrAddress::Name(String::from(
"thisisinvalid235790123801.eth",
))]),
None,
vec![AccountField::Balance],
)),
chains: vec![ChainOrRpc::Chain(Chain::Ethereum)],
dump: None,
})];
Expand All @@ -223,16 +220,14 @@ mod test {
async fn test_get_transaction_fields() {
let execution_engine = ExecutionEngine::new();
let expressions = vec![Expression::Get(GetExpression {
entity: Entity::Transaction(
Transaction::new(
Some(vec![
b256!("72546b3ca8ef0dfb85fe66d19645e44cb519858c72fbcad0e1c1699256fed890"),
b256!("72546b3ca8ef0dfb85fe66d19645e44cb519858c72fbcad0e1c1699256fed890")
]),
None,
TransactionField::all_variants().to_vec(),
)
),
entity: Entity::Transaction(Transaction::new(
Some(vec![
b256!("72546b3ca8ef0dfb85fe66d19645e44cb519858c72fbcad0e1c1699256fed890"),
b256!("72546b3ca8ef0dfb85fe66d19645e44cb519858c72fbcad0e1c1699256fed890"),
]),
None,
TransactionField::all_variants().to_vec(),
)),
chains: vec![ChainOrRpc::Chain(Chain::Ethereum)],
dump: None,
})];
Expand Down Expand Up @@ -285,7 +280,7 @@ mod test {
chain: Some(Chain::Ethereum),
authorization_list: None,
}])
];
];

let result = execution_engine.run(expressions).await;
match result {
Expand All @@ -300,15 +295,13 @@ mod test {
async fn test_get_inexistent_transaction() {
let execution_engine = ExecutionEngine::new();
let expressions = vec![Expression::Get(GetExpression {
entity: Entity::Transaction(
Transaction::new(
Some(vec![b256!(
"0000000000000000000000000000000000000000000000000000000000000000"
)]),
None,
TransactionField::all_variants().to_vec(),
)
),
entity: Entity::Transaction(Transaction::new(
Some(vec![b256!(
"0000000000000000000000000000000000000000000000000000000000000000"
)]),
None,
TransactionField::all_variants().to_vec(),
)),
chains: vec![ChainOrRpc::Chain(Chain::Ethereum)],
dump: None,
})];
Expand All @@ -321,18 +314,11 @@ mod test {
async fn test_dump_results() {
let execution_engine = ExecutionEngine::new();
let expressions = vec![Expression::Get(GetExpression {
entity: Entity::Block(
Block::new(
Some(vec![
BlockId::Range(BlockRange::new(
1.into(),
None,
))
]),
None,
vec![BlockField::Timestamp],
)
),
entity: Entity::Block(Block::new(
Some(vec![BlockId::Range(BlockRange::new(1.into(), None))]),
None,
vec![BlockField::Timestamp],
)),
chains: vec![ChainOrRpc::Chain(Chain::Ethereum)],
dump: Some(Dump::new(String::from("test"), DumpFormat::Json)),
})];
Expand Down Expand Up @@ -382,7 +368,9 @@ mod test {
(
Expression::Get(GetExpression {
entity: Entity::Account(Account::new(
Some(vec![NameOrAddress::Address(address!("dac17f958d2ee523a2206206994597c13d831ec7"))]),
Some(vec![NameOrAddress::Address(address!(
"dac17f958d2ee523a2206206994597c13d831ec7"
))]),
None,
vec![AccountField::Chain],
)),
Expand All @@ -397,7 +385,9 @@ mod test {
(
Expression::Get(GetExpression {
entity: Entity::Transaction(Transaction::new(
Some(vec![b256!("72546b3ca8ef0dfb85fe66d19645e44cb519858c72fbcad0e1c1699256fed890")]),
Some(vec![b256!(
"72546b3ca8ef0dfb85fe66d19645e44cb519858c72fbcad0e1c1699256fed890"
)]),
None,
vec![TransactionField::Chain],
)),
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/interpreter/backend/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod execution_engine;
mod resolve_account;
mod resolve_block;
mod resolve_logs;
mod resolve_transaction;
pub mod execution_engine;
2 changes: 1 addition & 1 deletion crates/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ pub fn enum_variants_derive(input: TokenStream) -> TokenStream {
};

TokenStream::from(expanded)
}
}