diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9cfbf29..f84e91c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,68 +19,69 @@ jobs: test_dev: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - uses: Swatinem/rust-cache@v2 - - name: Install Dependencies - run: | + - uses: actions/checkout@v3 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - uses: Swatinem/rust-cache@v2 + - name: Install Dependencies + run: | export DEBIAN_FRONTEND=noninteractive sudo apt-get install -y capnproto libcapnp-dev - - name: Check Rust version - run: | + - name: Check Rust version + run: | rustc --version cargo --version rustup show - - name: Build - run: cargo build - - name: Test - run: cargo test + - name: Build + run: cargo build + - name: Test + run: cargo test test_release: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - uses: Swatinem/rust-cache@v2 - - name: Install Dependencies - run: | + - uses: actions/checkout@v3 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - uses: Swatinem/rust-cache@v2 + - name: Install Dependencies + run: | export DEBIAN_FRONTEND=noninteractive sudo apt-get install -y capnproto libcapnp-dev - - name: Check Rust version - run: | + - name: Check Rust version + run: | rustc --version cargo --version rustup show - - name: Build - run: cargo build --release - - name: Test - run: cargo test --release + - name: Build + run: cargo build --release + - name: Test + run: cargo test --release lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - uses: Swatinem/rust-cache@v2 - - name: Install Dependencies - run: | + - uses: actions/checkout@v3 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: rustfmt, clippy + override: true + - uses: Swatinem/rust-cache@v2 + - name: Install Dependencies + run: | export DEBIAN_FRONTEND=noninteractive sudo apt-get install -y capnproto libcapnp-dev - - name: Check Rust version - run: | + - name: Check Rust version + run: | rustc --version cargo --version rustup show - - name: Rustfmt - run: cargo fmt --check - - name: Clippy - run: cargo clippy -- -Dwarnings \ No newline at end of file + - name: Rustfmt + run: cargo fmt --check + - name: Clippy + run: cargo clippy -- -Dwarnings diff --git a/hypersync-client/Cargo.toml b/hypersync-client/Cargo.toml index b5eae35..77f8073 100644 --- a/hypersync-client/Cargo.toml +++ b/hypersync-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hypersync-client" -version = "0.19.0" +version = "0.20.0" edition = "2021" description = "client library for hypersync" license = "MPL-2.0" @@ -47,7 +47,7 @@ nohash-hasher = "0.2.0" ethers = { version = "2.0.14", optional = true } alloy-primitives = "1.1" -hypersync-net-types = { path = "../hypersync-net-types", version = "0.10" } +hypersync-net-types = { path = "../hypersync-net-types", version = "0.11" } hypersync-format = { path = "../hypersync-format", version = "0.5" } hypersync-schema = { path = "../hypersync-schema", version = "0.3" } diff --git a/hypersync-client/src/preset_query.rs b/hypersync-client/src/preset_query.rs index 7a08a1c..02ece3e 100644 --- a/hypersync-client/src/preset_query.rs +++ b/hypersync-client/src/preset_query.rs @@ -3,7 +3,9 @@ use std::collections::BTreeSet; use arrayvec::ArrayVec; use hypersync_format::{Address, LogArgument}; -use hypersync_net_types::{FieldSelection, LogSelection, Query, TransactionSelection}; +use hypersync_net_types::{ + FieldSelection, LogFilter, LogSelection, Query, TransactionFilter, TransactionSelection, +}; /// Returns a query for all Blocks and Transactions within the block range (from_block, to_block] /// If to_block is None then query runs to the head of the chain. @@ -81,10 +83,10 @@ pub fn logs(from_block: u64, to_block: Option, contract_address: Address) - Query { from_block, to_block, - logs: vec![LogSelection { + logs: vec![LogSelection::from(LogFilter { address: vec![contract_address], ..Default::default() - }], + })], field_selection: FieldSelection { log: all_log_fields, ..Default::default() @@ -116,11 +118,11 @@ pub fn logs_of_event( Query { from_block, to_block, - logs: vec![LogSelection { + logs: vec![LogSelection::from(LogFilter { address: vec![contract_address], topics, ..Default::default() - }], + })], field_selection: FieldSelection { log: all_log_fields, ..Default::default() @@ -170,10 +172,10 @@ pub fn transactions_from_address( Query { from_block, to_block, - transactions: vec![TransactionSelection { + transactions: vec![TransactionSelection::from(TransactionFilter { from: vec![address], ..Default::default() - }], + })], field_selection: FieldSelection { transaction: all_txn_fields, ..Default::default() diff --git a/hypersync-client/tests/api_test.rs b/hypersync-client/tests/api_test.rs index 1d5eeda..9bf5b35 100644 --- a/hypersync-client/tests/api_test.rs +++ b/hypersync-client/tests/api_test.rs @@ -5,7 +5,7 @@ use hypersync_client::{ preset_query, simple_types::Transaction, Client, ClientConfig, ColumnMapping, StreamConfig, }; use hypersync_format::{Address, FilterWrapper, Hex, LogArgument}; -use hypersync_net_types::{FieldSelection, Query, TransactionSelection}; +use hypersync_net_types::{FieldSelection, Query, TransactionFilter, TransactionSelection}; use polars_arrow::array::UInt64Array; #[tokio::test(flavor = "multi_thread")] @@ -458,10 +458,10 @@ async fn test_small_bloom_filter_query() { from_block: 19_000_000, to_block: Some(19_300_000), logs: Vec::new(), - transactions: vec![TransactionSelection { + transactions: vec![TransactionSelection::from(TransactionFilter { from_filter: Some(from_address_filter), ..Default::default() - }], + })], field_selection: FieldSelection { block: Default::default(), log: Default::default(), diff --git a/hypersync-net-types/Cargo.toml b/hypersync-net-types/Cargo.toml index 47f751d..b08ae47 100644 --- a/hypersync-net-types/Cargo.toml +++ b/hypersync-net-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hypersync-net-types" -version = "0.10.0" +version = "0.11.0" edition = "2021" description = "hypersync types for transport over network" license = "MPL-2.0" diff --git a/hypersync-net-types/src/lib.rs b/hypersync-net-types/src/lib.rs index 5bd8906..cfeda95 100644 --- a/hypersync-net-types/src/lib.rs +++ b/hypersync-net-types/src/lib.rs @@ -12,7 +12,30 @@ pub mod hypersync_net_types_capnp { } #[derive(Default, Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct BlockSelection { +pub struct Selection { + /// Filters where matching values should be included in the response + /// Default::default() means include everything + #[serde(default, flatten)] + pub include: T, + /// Filters where matching values should be excluded from the response + /// None means exclude nothing, Some(Default::default()) means exclude everything + #[serde(default)] + pub exclude: Option, +} + +impl From for Selection { + fn from(include: T) -> Self { + Self { + include, + exclude: None, + } + } +} + +pub type BlockSelection = Selection; + +#[derive(Default, Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct BlockFilter { /// Hash of a block, any blocks that have one of these hashes will be returned. /// Empty means match all. #[serde(default)] @@ -23,8 +46,10 @@ pub struct BlockSelection { pub miner: Vec
, } +pub type LogSelection = Selection; + #[derive(Default, Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct LogSelection { +pub struct LogFilter { /// Address of the contract, any logs that has any of these addresses will be returned. /// Empty means match all. #[serde(default)] @@ -37,8 +62,10 @@ pub struct LogSelection { pub topics: ArrayVec, 4>, } +pub type TransactionSelection = Selection; + #[derive(Default, Serialize, Deserialize, Clone, Debug)] -pub struct TransactionSelection { +pub struct TransactionFilter { /// Address the transaction should originate from. If transaction.from matches any of these, the transaction /// will be returned. Keep in mind that this has an and relationship with to filter, so each transaction should /// match both of them. Empty means match all. @@ -90,8 +117,10 @@ pub struct AuthorizationSelection { pub address: Vec
, } +pub type TraceSelection = Selection; + #[derive(Default, Serialize, Deserialize, Clone, Debug)] -pub struct TraceSelection { +pub struct TraceFilter { #[serde(default)] pub from: Vec
, #[serde(default)] @@ -177,8 +206,13 @@ pub struct Query { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Copy)] pub enum JoinMode { + /// Join in this order logs -> transactions -> traces -> blocks Default, + /// Join everything to everything. For example if logSelection matches log0, we get the + /// associated transaction of log0 and then we get associated logs of that transaction as well. Applites similarly + /// to blocks, traces. JoinAll, + /// JoinNothing: join nothing. JoinNothing, }