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