risc0_ethereum_contracts/
event_query.rs

1// Copyright 2025 RISC Zero, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/// Event query configuration.
16#[derive(Clone)]
17#[non_exhaustive]
18pub struct EventQueryConfig {
19    /// Maximum number of iterations to search for a fulfilled event.
20    pub max_iterations: u64,
21    /// Number of blocks to query in each iteration when searching for a fulfilled event.
22    pub block_range: u64,
23}
24
25impl Default for EventQueryConfig {
26    fn default() -> Self {
27        // Default values chosen based on the docs and pricing of requests on common RPC providers.
28        // NOTE: Alchemy free tier applies a limit of < 500 block range (exclusive) as of August 3, 2025.
29        Self {
30            max_iterations: 100,
31            block_range: 499,
32        }
33    }
34}
35
36impl EventQueryConfig {
37    /// Creates a new event query configuration.
38    pub const fn new(max_iterations: u64, block_range: u64) -> Self {
39        Self {
40            max_iterations,
41            block_range,
42        }
43    }
44
45    /// Sets the maximum number of iterations to search for a fulfilled event.
46    pub fn with_max_iterations(self, max_iterations: u64) -> Self {
47        Self {
48            max_iterations,
49            ..self
50        }
51    }
52
53    /// Sets the number of blocks to query in each iteration when searching for a fulfilled event.
54    pub fn with_block_range(self, block_range: u64) -> Self {
55        Self {
56            block_range,
57            ..self
58        }
59    }
60}