eql_core 0.1.12

EVM Query Language core components
Documentation
program = _{SOI ~ (get){1, } ~ silent_eoi}

get       = {
    "GET" ~
    WHITESPACE* ~
    fields* ~
    WHITESPACE* ~
    "FROM" ~
    WHITESPACE* ~
    entity ~
    WHITESPACE* ~
    (entity_id | filter) ~
    WHITESPACE* ~
    "ON" ~
    WHITESPACE* ~
    chain ~
    (WHITESPACE* ~ dump)* ~
    exp_separator* ~
    WHITESPACE*
}

fields    = { (star_operator | account_field_list | block_field_list | tx_field_list | log_field_list) }
entity    = { "account" | "block" | "tx" | "log" }
entity_id = { tx_id_list | account_id_list | block_id_list }

dump = { ">" ~ WHITESPACE* ~ file_name ~ "." ~ file_format }
file_name = { (ASCII_ALPHANUMERIC | "-" | "_")+ }
file_format = { "json" | "csv" | "yaml" | "toml" | "parquet" }

filter = _{ "WHERE" ~ WHITESPACE* ~ entity_filter}
entity_filter = { log_filter_list | block_filter_list}

// Account
account_field_list = _{ account_field ~ ("," ~ WHITESPACE* ~ account_field)* }
account_field = {
    "nonce" |
    "balance" |
    "code"
}
account_id_list = _{ account_id ~ ("," ~ WHITESPACE* ~ account_id)* }
account_id = { address | ens }

// Block
block_field_list = _{ block_field ~ ("," ~ WHITESPACE* ~ block_field_list)* }
// TODO: Check if we need uncles
block_field      =  { 
    "number" |
    "hash" |
    "parent_hash" |
    "timestamp" | 
    "state_root" |
    "transactions_root" |
    "receipts_root" |
    "logs_bloom" |
    "extra_data" |
    "mix_hash" |
    "total_difficulty" |
    "base_fee_per_gas" |
    "withdrawals_root" |
    "blob_gas_used" |
    "excess_blob_gas" |
    "parent_beacon_block_root" |
    "parent_beacon_block_root" |
    "size"
}
block_id_list = _{ block_id ~ ("," ~ WHITESPACE* ~ block_id)* }
block_id    = { block_tag ~ ":" ~ block_tag | block_tag }
block_tag = _{ "latest" | "earliest" | "pending" | "finalized" | "safe" | integer }
block_filter_list = _{ block_filter ~ ("," ~ WHITESPACE* ~ block_filter)* }
block_filter = _{
    blockrange_filter
}

// Transaction
tx_field_list = _{ tx_field ~ ("," ~ WHITESPACE* ~ tx_field)* }
tx_field = {
    "transaction_type" |
    "hash" |
    "from" | 
    "to" | 
    "data" | 
    "value" | 
    "fee" |
    "gas_price" |
    "gas" |
    "status" |
    "chain_id" |
    "v" |
    "r" |
    "s" |

    // EIP-4844
    "max_fee_per_blob_gas" |
    "blob_versioned_hashes" |

    // EIP-1559
    "max_fee_per_gas" |
    "max_priority_fee_per_gas" |

    // EIP-2930
    "access_list" |
    "y_parity"
}
tx_id_list = _{ tx_id ~ ("," ~ WHITESPACE* ~ tx_id)* }
tx_id = { hash } 

// Log
log_field_list = _{ log_field ~ ("," ~ WHITESPACE* ~ log_field)* }
log_field      =  {
    "address" |
    "topic0" |
    "topic1" |
    "topic2" |
    "topic3" |
    "data" |
    "block_hash" |
    "block_number" |
    "block_timestamp" |
    "transaction_hash" |
    "transaction_index" |
    "log_index" |
    "removed"
}
log_filter_list = _{ log_filter ~ ("," ~ WHITESPACE* ~ log_filter)* }
log_filter = _{
    address_filter |
    topic0_filter |
    topic1_filter |
    topic2_filter |
    topic3_filter |
    blockhash_filter |
    blockrange_filter |
    event_signature_filter
}

//Filters
address_filter = {"address" ~ address}
topic0_filter = {"topic0" ~ hash}
topic1_filter = {"topic1" ~ hash}
topic2_filter = {"topic2" ~ hash}
topic3_filter = {"topic3" ~ hash}
blockhash_filter = {"block_hash" ~ hash}
blockrange_filter = {"block" ~ block_id}
event_signature_filter ={"event_signature" ~ function_signature}
   
// Terminals
unit = { "ether" | "gwei" | "wei" }
number = _{ float | integer }
integer = _{ (ASCII_DIGIT)+ }
float = _{ integer ~ "." ~ integer }
chain = {
    "eth" |
    "arb" |
    "op" |
    "base" |
    "blast" |
    "polygon" |
    "sepolia" |
    "anvil" |
    "local" |
    "mantle" |
    "zksync" |
    "taiko" |
    "celo" |
    "avalanche" |
    "scroll" |
    "bnb" |
    "linea" |
    "tron" |
    "zora" |
    "moonbeam" |
    "moonriver" |
    "ronin" |
    "fantom" |
    "kava" |
    "gnosis"
}
address = { "0x" ~ (ASCII_HEX_DIGIT){40} }
hash = { "0x" ~ (ASCII_HEX_DIGIT){64} }
ens = { (ASCII_ALPHANUMERIC)+ ~ ".eth" }
function_signature = { ASCII_ALPHANUMERIC+ ~ "(" ~ solidity_type* ~ ("," ~ solidity_type)* ~ ")" }
solidity_type = _{ 
    ("uint" ~ size | "uint[]" | "uint" ) |
    ("bytes" ~ size | "bytes[]" | "bytes" ) |
    ("int" ~ size | "int[]" | "int" ) |
    ("address" ~ "[]"*) | 
    ("string" ~ "[]"*) |
    "bool" 
}
size = _{integer ~ "[]"*}

// Helpers
WHITESPACE = _{ " " | "\t" | NEWLINE }
exp_separator = _{"," | ";"}
silent_eoi = _{ !ANY }
star_operator = { "*" }