iota_data_ingestion_core/reader/config.rs
1// Copyright (c) 2026 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4//! Configuration types for the checkpoint reader.
5//!
6//! The two main types are:
7//!
8//! - [`CheckpointReaderConfig`]: the base configuration for the checkpoint reader. Suited for most
9//! default use cases.
10//! - [`CheckpointReaderConfigExt`]: extends [`CheckpointReaderConfig`] with opt-in configuration
11//! toggles beyond the base, such as server-side transaction filters for fullnode connections.
12//!
13//! [`CheckpointReaderConfigExt`] wraps [`CheckpointReaderConfig`] and exposes
14//! a builder for the extra toggles. A `From<CheckpointReaderConfig>` impl is
15//! provided so existing [`CheckpointReaderConfig`] values can be converted
16//! to [`CheckpointReaderConfigExt`].
17
18use std::path::PathBuf;
19
20use crate::filters::fullnode::TransactionFilter;
21pub use crate::{
22 ReaderOptions,
23 reader::v2::{CheckpointReaderConfig, RemoteUrl},
24};
25
26/// Extends [`CheckpointReaderConfig`] with opt-in configuration toggles.
27///
28/// Use this type when you need framework features beyond what the base
29/// [`CheckpointReaderConfig`] exposes (e.g. server-side transaction filtering
30/// for fullnode connections).
31///
32/// # Example
33///
34/// ```rust
35/// use iota_data_ingestion_core::{
36/// ReaderOptions,
37/// filters::fullnode::TransactionFilter,
38/// reader::config::{CheckpointReaderConfig, CheckpointReaderConfigExt, RemoteUrl},
39/// };
40///
41/// let config = CheckpointReaderConfigExt::new(ReaderOptions::default())
42/// .with_remote_store_url(RemoteUrl::Fullnode("http://127.0.0.1:50051".into()))
43/// .with_fullnode_transaction_filter(TransactionFilter::new().execution_status(true));
44/// ```
45/// # Example with an existing [`CheckpointReaderConfig`]
46/// ```rust
47/// use iota_data_ingestion_core::{
48/// ReaderOptions,
49/// filters::fullnode::TransactionFilter,
50/// reader::config::{CheckpointReaderConfig, CheckpointReaderConfigExt, RemoteUrl},
51/// };
52///
53/// let base_config = CheckpointReaderConfig {
54/// reader_options: ReaderOptions::default(),
55/// remote_store_url: Some(RemoteUrl::Fullnode("http://127.0.0.1:50051".into())),
56/// ..Default::default()
57/// };
58///
59/// let config = CheckpointReaderConfigExt::from(base_config)
60/// .with_fullnode_transaction_filter(TransactionFilter::new().execution_status(true));
61/// ```
62#[derive(Clone, Default)]
63pub struct CheckpointReaderConfigExt {
64 /// The base configuration for the checkpoint reader.
65 pub(crate) base: CheckpointReaderConfig,
66 /// Filter applied to transactions within a checkpoint.
67 pub(crate) fullnode_transaction_filter: Option<TransactionFilter>,
68}
69
70impl From<CheckpointReaderConfig> for CheckpointReaderConfigExt {
71 fn from(config: CheckpointReaderConfig) -> Self {
72 Self {
73 base: config,
74 ..Default::default()
75 }
76 }
77}
78
79impl CheckpointReaderConfigExt {
80 /// Constructs a new configuration with the given [`ReaderOptions`].
81 pub fn new(reader_options: ReaderOptions) -> Self {
82 Self {
83 base: CheckpointReaderConfig {
84 reader_options,
85 ..Default::default()
86 },
87 ..Default::default()
88 }
89 }
90
91 /// Sets the local path where checkpoints will be ingested from.
92 ///
93 /// If not provided, checkpoints will be ingested from a temporary
94 /// directory.
95 pub fn with_ingestion_path(mut self, path: impl Into<PathBuf>) -> Self {
96 self.base.ingestion_path = Some(path.into());
97 self
98 }
99
100 /// Sets the remote source from which checkpoints are downloaded.
101 pub fn with_remote_store_url(mut self, url: RemoteUrl) -> Self {
102 self.base.remote_store_url = Some(url);
103 self
104 }
105
106 /// Enables server-side filtering of transactions within each checkpoint.
107 ///
108 /// When set, the remote source will only return checkpoints containing
109 /// transactions that match the provided [`TransactionFilter`].
110 ///
111 /// # Errors
112 ///
113 /// Using this filter with any source other than [`RemoteUrl::Fullnode`]
114 /// will cause the executor to return an error when started.
115 pub fn with_fullnode_transaction_filter(mut self, filter: TransactionFilter) -> Self {
116 self.fullnode_transaction_filter = Some(filter);
117 self
118 }
119}