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        Self {
29            max_iterations: 100,
30            block_range: 1000,
31        }
32    }
33}
34
35impl EventQueryConfig {
36    /// Creates a new event query configuration.
37    pub fn new(max_iterations: u64, block_range: u64) -> Self {
38        Self {
39            max_iterations,
40            block_range,
41        }
42    }
43
44    /// Sets the maximum number of iterations to search for a fulfilled event.
45    pub fn with_max_iterations(self, max_iterations: u64) -> Self {
46        Self {
47            max_iterations,
48            ..self
49        }
50    }
51
52    /// Sets the number of blocks to query in each iteration when searching for a fulfilled event.
53    pub fn with_block_range(self, block_range: u64) -> Self {
54        Self {
55            block_range,
56            ..self
57        }
58    }
59}